Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file CategoryRegistryUtil.class.php

Documentation is available at CategoryRegistryUtil.class.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright Robert Gasch
  6.  * @link http://www.zikula.org
  7.  * @version $Id: CategoryRegistry.class.php 19257 2006-06-12 10:12:27Z rgasch $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Robert Gasch rgasch@gmail.com
  10.  * @uses category utililty class
  11.  * @package Zikula_Core
  12.  * @subpackage CategoryRegistryUtil
  13.  */
  14.  
  15. /**
  16.  * CategoryRegistryUtil
  17.  *
  18.  * @package Zikula_Core
  19.  * @subpackage CategoryRegistryUtil
  20.  */
  21. {
  22.     /**
  23.      * Register a module category
  24.      *
  25.      * @param catreg    The array of category map data objects
  26.      *
  27.      * @return boolean The DB insert operation result code cast to a boolean
  28.      */
  29.     function registerModuleCategory ($catreg)
  30.     {
  31.         if (!$catreg)
  32.             return false;
  33.  
  34.         if (!pnModDBInfoLoad ('Categories'))
  35.             return false;
  36.  
  37.         if ($catreg['id'])
  38.             $res DBUtil::updateObject ($catreg'categories_registry');
  39.         else
  40.             $res DBUtil::insertObject ($catreg'categories_registry');
  41.  
  42.         return (boolean)$res;
  43.     }
  44.  
  45.  
  46.     /**
  47.      * Register module categories
  48.      *
  49.      * @param catregs    The array of category map data objects
  50.      *
  51.      * @return true 
  52.      */
  53.     function registerModuleCategories ($catregs)
  54.     {
  55.         if (!$catregs)
  56.             return false;
  57.  
  58.         if (!pnModDBInfoLoad ('Categories'))
  59.             return false;
  60.  
  61.         foreach ($catregs as $catreg)
  62.         {
  63.             if ($catreg['id'])
  64.                 $res DBUtil::updateObject ($catreg'categories_registry');
  65.             else
  66.                 $res DBUtil::insertObject ($catreg'categories_registry');
  67.         }
  68.  
  69.         return true;
  70.     }
  71.  
  72.  
  73.     /**
  74.      * Get registered Categories for a module
  75.      *
  76.      * @param modname    The module name
  77.      * @param tablename  The tablename for which we wish to get the property for
  78.      * 
  79.      * @return The associative field array of registered categories for the specified module
  80.      */
  81.     function getRegisteredModuleCategories ($modname$tablename)
  82.     {
  83.         if (!$modname || !$tablename)
  84.             return pn_exit ("Invalid specs [$modname], [$tablename] received ...");
  85.  
  86.         if (!pnModDBInfoLoad ('Categories'))
  87.             return false;
  88.  
  89.         static $cache array();
  90.         if (isset($cache[$modname][$tablename]))
  91.             return $cache[$modname][$tablename];
  92.  
  93.         $wheres   array();
  94.         $pntables pnDBGetTables();
  95.         $col      $pntables['categories_registry_column'];
  96.         $wheres["$col[modname]='".DataUtil::formatForStore($modname)."'";
  97.         $wheres["$col[table]='".DataUtil::formatForStore($tablename)."'";
  98.         $where    implode (' AND '$wheres);
  99.         $sort     "$col[id] ASC";
  100.         $fArr     DBUtil::selectFieldArray ('categories_registry''category_id'$where$sortfalse'property');
  101.  
  102.         $cache[$modname][$tablename$fArr;
  103.         return $fArr;
  104.     }
  105.  
  106.  
  107.     /**
  108.      * Get registered category for module property
  109.      *
  110.      * @param modname    The module we wish to get the property for
  111.      * @param tablename  The tablename for which we wish to get the property for
  112.      * @param property   The property name
  113.      * @param default    The default value to return if the requested value is not set (optional) (default=null)
  114.      *
  115.      * @return The associative field array of registered categories for the specified module
  116.      */
  117.     function getRegisteredModuleCategory ($modname$tablename$property$default=null)
  118.     {
  119.         if (!$modname || !$property)
  120.             return $default;
  121.  
  122.         $fArr CategoryRegistryUtil::getRegisteredModuleCategories ($modname$tablename);
  123.  
  124.         if ($fArr && isset($fArr[$property]&& $fArr[$property])
  125.             return $fArr[$property];
  126.  
  127.         // if we have a path default, we get the ID
  128.         if ($default && !is_integer($default))
  129.         {
  130.             if (!($class Loader::loadClass('CategoryUtil')))
  131.                 return pn_exit ("Unable to load class [$ot] ...");
  132.  
  133.             $cat CategoryUtil::getCategoryByPath ($default);
  134.             if ($cat)
  135.                 $default $cat['id'];
  136.         }
  137.  
  138.         return $default;
  139.     }
  140.  
  141.  
  142.     /**
  143.      * Get the IDs of the property registers
  144.      *
  145.      * @param modname    The module name
  146.      * @param tablename  The tablename for which we wish to get the property for
  147.      * 
  148.      * @return The associative field array of register ids for the specified module
  149.      */
  150.     function getRegisteredModuleCategoriesIds ($modname$tablename)
  151.     {
  152.         if (!$modname || !$tablename)
  153.             return pn_exit ("Invalid specs [$modname], [$tablename] received ...");
  154.  
  155.         if (!pnModDBInfoLoad ('Categories'))
  156.             return false;
  157.  
  158.         $wheres   array();
  159.         $pntables pnDBGetTables();
  160.         $col      $pntables['categories_registry_column'];
  161.         $wheres["$col[modname]='".DataUtil::formatForStore($modname)."'";
  162.         $wheres["$col[table]='".DataUtil::formatForStore($tablename)."'";
  163.         $where    implode (' AND '$wheres);
  164.         $fArr     DBUtil::selectFieldArray ('categories_registry''id'$where''false'property');
  165.  
  166.         return $fArr;
  167.     }
  168. }

Documentation generated on Fri, 18 Jul 2008 21:43:15 +0200 by phpDocumentor 1.4.1