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

Source for file PNCategoryArray.class.php

Documentation is available at PNCategoryArray.class.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright value4business GmbH
  6.  * @link http://www.zikula.org
  7.  * @version $Id: PNCategoryArray.class.php 20307 2006-10-14 21:06:59Z rgasch $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Robert Gasch rgasch@gmail.com
  10.  * @package Zikula_Core
  11.  */
  12.  
  13.  
  14. /**
  15.  * PNCategoryArray
  16.  *
  17.  * @package Zikula_System_Modules
  18.  * @subpackage Categories
  19.  */
  20. {
  21.     function PNCategoryArray($init=null$where='')
  22.     {
  23.         $this->PNObjectArray ();
  24.  
  25.         $this->_objType  'categories_category';
  26.         $this->_objField 'id';
  27.         $this->_objPath  'categories_category_array';
  28.         $this->_objPermissionFilter[array('realm' => 0,
  29.                                               'component_left'   => 'Categories',
  30.                                               'component_middle' => '',
  31.                                               'component_right'  => '',
  32.                                               'instance_left'    => 'id',
  33.                                               'instance_middle'  => 'ipath',
  34.                                               'instance_right'   => 'path',
  35.                                               'level'            => ACCESS_READ);
  36.  
  37.         $this->_init($init$where);
  38.     }
  39.  
  40.     function buildRelativePaths ($rootCategory$includeRoot=false)
  41.     {
  42.         Loader::loadClass ('CategoryUtil');
  43.         CategoryUtil::buildRelativePaths ($rootCategory$this->_objData$includeRoot);
  44.     }
  45.  
  46.     // checkbox has to be explicitly processed
  47.     function getDataFromInputPostProcess ($objArray=null)
  48.     {
  49.         if (!$objArray{
  50.             $objArray =$this->_objData;
  51.         }
  52.  
  53.         if (!$objArray{
  54.             return $objArray;
  55.         }
  56.  
  57.         foreach ($objArray as $k => $obj{
  58.             if (isset($obj['status'])) {
  59.                 $objArray[$k]['status''A';
  60.             else {
  61.                 $objArray[$k]['status''I';
  62.             }
  63.         }
  64.  
  65.         return $objArray;
  66.     }
  67.  
  68.     // the only reason we need al this stuff beflow is the because of the serialization
  69.     function selectPostProcess ($objArray=null)
  70.     {
  71.         if (!$objArray{
  72.             $objArray =$this->_objData;
  73.         }
  74.  
  75.         if (!$objArray{
  76.             return $objArray;
  77.         }
  78.  
  79.         foreach ($objArray as $k => $obj)
  80.         {
  81.             $objArray[$k]['display_name'DataUtil::formatForDisplayHTML(unserialize($obj['display_name']));
  82.             $objArray[$k]['display_desc'DataUtil::formatForDisplayHTML(unserialize($obj['display_desc']));
  83.         }
  84.  
  85.         return $objArray;
  86.     }
  87.  
  88.     function insertPreProcess ($objArray=null)
  89.     {
  90.         if (!$objArray{
  91.             $objArray =$this->_objData;
  92.         }
  93.  
  94.         if (!$objArray{
  95.             return $objArray;
  96.         }
  97.  
  98.         foreach ($objArray as $k => $obj)
  99.         {
  100.             $objArray[$k]['display_name_org'$obj['display_name'];
  101.             $objArray[$k]['display_desc_org'$obj['display_desc'];
  102.             $objArray[$k]['display_name']     serialize($obj['display_name']);
  103.             $objArray[$k]['display_desc']     serialize($obj['display_desc']);
  104.         }
  105.  
  106.         return $objArray;
  107.     }
  108.  
  109.     function insertPostProcess($objArray=null)
  110.     {
  111.         if (!$objArray{
  112.             $objArray =$this->_objData;
  113.         }
  114.  
  115.         if (!$objArray{
  116.             return $objArray;
  117.         }
  118.  
  119.         foreach ($objArray as $k => $obj{
  120.             $objArray[$k]['display_name'$obj['display_name_org'];
  121.             $objArray[$k]['display_desc'$obj['display_desc_org'];
  122.             unset ($objArray[$k]['display_name_org']);
  123.             unset ($objArray[$k]['display_desc_org']);
  124.         }
  125.  
  126.         return $objArray;
  127.     }
  128.  
  129.     function updatePreProcess ($objArray=null)
  130.     {
  131.         if (!$objArray{
  132.             $objArray =$this->_objData;
  133.         }
  134.  
  135.         if (!$objArray{
  136.             return $objArray;
  137.         }
  138.  
  139.         foreach ($objArray as $k => $obj{
  140.             $pid    =  $obj['parent_id'];
  141.             $parent =  CategoryUtil::getCategoryByID ((int)$pid);
  142.  
  143.             $this->insertPreProcess ();
  144.             $objArray[$k]['path']         "$parent[path]/$obj[name]";
  145.             $objArray[$k]['ipath']        "$parent[ipath]/$obj[id]";
  146.         }
  147.  
  148.         return $objArray;
  149.     }
  150.  
  151.     function updatePostProcess ($objArray=null)
  152.     {
  153.         if ($objArray{
  154.             return $this->insertPostProcess ($objArray);
  155.         }
  156.  
  157.         return $this->insertPostProcess ();
  158.     }
  159.  
  160.     function delete ($deleteSubcats=false$newParentID=0)
  161.     {
  162.         $objArray $this->_objData;
  163.  
  164.         if (!$objArray{
  165.             return $objArray;
  166.         }
  167.  
  168.         foreach ($objArray as $k => $obj{
  169.             if ($deleteSubcats{
  170.                 CategoryUtil::deleteCategoriesByPath ($obj['ipath']);
  171.             elseif ($newParentID{
  172.                 CategoryUtil::moveSubCategoriesByPath ($obj['ipath']$newParentID);
  173.                 CategoryUtil::deleteCategoryByID ($obj['id']);
  174.             else {
  175.                 exit ('Can not delete category while preserving subcategories without specifying a new parent ID');
  176.             }
  177.         }
  178.     }
  179. }

Documentation generated on Fri, 18 Jul 2008 21:52:48 +0200 by phpDocumentor 1.4.1