Source for file MED_CATEGORY.phpclass

Documentation is available at MED_CATEGORY.phpclass

  1. <?php
  2. /**
  3.   * Class file MED_CATEGORY.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    media
  7.   * @category   category-tree
  8.   *
  9.   * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. require_once __OCSP_PHPINCPATH__."db/dbms_tree.phpclass";
  16. require_once __OCSP_PHPINCPATH__."default_config/media.conf.phpinc";
  17. require_once $GLOBALS['MED']['PHPINCPATH']."MED_MIMETYPE.phpclass";
  18. require_once $GLOBALS['MED']['PHPINCPATH']."MED_CATEGORY_NODE.phpclass";
  19.  
  20. class MED_CATEGORY extends DBMS_TREE {
  21.     /**
  22.       * @var  string  $myGlobalTreeKey      index in $GLOABLS['DBMS_TREE'][]
  23.       ***/
  24.     var $myGlobalTreeKey = "T_MED_CATEGORY";
  25.  
  26.     /**
  27.       * @staticvar string $myTable 
  28.       */
  29.     var $myTable="T_MED_CATEGORY";
  30.  
  31.     /**
  32.       * @staticvar  string  $myIdFld        id column = root
  33.       ***/
  34.     var $myIdFld        ="MEC_ID";
  35.  
  36.     /**
  37.       * @staticvar  string  $myParentFld    name of the parent column
  38.       ***/
  39.     var $myParentFld    ="MEC_PARENT";
  40.  
  41.     /**
  42.       * @staticvar  string  $mySortFld      name of the sort field
  43.       ***/
  44.     var $mySortFld      ="MEC_NAME";
  45.  
  46.     /**
  47.       * @var  string  $myChildClass 
  48.       ***/
  49.     var $myChildClass = "MED_CATEGORY_NODE";
  50.  
  51.     /**
  52.       * @var int $projId CMS_PROJECT (-1 == all)
  53.       * @since pk-06-03-03
  54.       ***/
  55.     var $projId=-1;
  56.  
  57.     /**
  58.       * @var boolean $addDefaultProj show project and default project (PROJ_ID=0)
  59.       * @since pk-06-03-05
  60.       ***/
  61.     var $addDefaultProj=FALSE;
  62.  
  63.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64.     // object var access methods
  65.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66.  
  67.     /**
  68.       * sets the projectID
  69.       *
  70.       * @param int $aProjId 
  71.       *
  72.       * @since pk-06-03-03
  73.       *
  74.       ***/
  75.     function set_projId($aProjId{
  76.         $this->projId = $aProjId;
  77.     }
  78.  
  79.     /**
  80.       * returns if we have set a projId
  81.       *
  82.       * @returns boolean
  83.       *
  84.       ***/
  85.     function projId_IsSet({
  86.         if ($this->projId > -1return TRUE;
  87.         return FALSE;
  88.     }
  89.  
  90.     /**
  91.       * sets $addDefaultProj
  92.       *
  93.       * @param boolean $onOff on TRUE off =FALSE
  94.       *
  95.       * @since pk-06-03-05
  96.       *
  97.       ***/
  98.     function setAddDefaulProj_OnOff($onOff{
  99.         $this->addDefaultProj=$onOff;
  100.     }
  101.  
  102.  
  103.     /**
  104.       * sets child class vars
  105.       *
  106.       * @param &DBMS_TREE_NODE   $child 
  107.       *
  108.       * @since pk-06-03-05
  109.       *
  110.       ***/
  111.     function setChildClassVar(&$child{
  112.         parent::setChildClassVar($child);
  113.         $child->set_projId($this->projId);
  114.         $child->setAddDefaulProj_OnOff($this->addDefaultProj);
  115.     }
  116.  
  117.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.     // database methods
  119.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120.  
  121.     /**
  122.       * populates the children
  123.       *
  124.       * @param  bool    $useCache 
  125.       * @param  bool    $debug 
  126.       *
  127.       * @version pk-05-07-27
  128.       *
  129.       ***/
  130.     function populate($useCache=TRUE,$debug=FALSE,$filtered=FALSE{
  131.         if ($debugecho "<hr /><p><b>DBMS_TREE::populate(".($useCache "USECACHE" "NOCACHE").")</b> (".get_class($this).")</p><blockquote>";
  132.  
  133.         $s_query ="SELECT * FROM ".$this->myTable;
  134.         $s_query.=" WHERE ".$this->myParentFld."=".$this->getRootId();        // IDs are integer COLUMNS and VALUES
  135.  
  136.         if ((!empty($this->myChildKeys)) && ($keyCols=explode(",",$this->myChildKeys))) {
  137.             foreach($keyCols as $col{
  138.                 $s_query.=" AND ".$col." = ".$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue($this->getKey($col));
  139.             }
  140.         }
  141.  
  142.         if ($this->projId_IsSet()) {
  143.             $s_query.=" AND (PROJ_ID=".intval($this->projId);
  144.             if (intval($this->projId&& $this->addDefaultProj{
  145.                 $s_query.=" OR PROJ_ID=0";
  146.             }
  147.             $s_query.=")";
  148.         }
  149.  
  150.  
  151.         if ($filtered && (is_array($this->myFilterArr))) {
  152.             foreach($this->myFilterArr as $s_Col => $s_Val{
  153.                 $s_query.=" AND ".$s_Col."=".$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue($s_Val);
  154.             }
  155.         }
  156.  
  157.         if (!empty($this->mySortFld)) {
  158.             $s_query.=" ORDER BY ".$this->mySortFld;
  159.         }
  160.  
  161.         if ($debugecho "<pre sytle='font-size:10px'>DB: ".$this->get_gDBIDX()."\n$s_query</pre>";
  162.  
  163.         if ($cursor=$GLOBALS[$this->get_gDBIDX()]->query($s_query)) {
  164.             $this->myChildren=array();
  165.             $noc=0;
  166.             while($row $cursor->fetchArrayFld()) {
  167.                 $noc++;
  168.                 if (($useCache&& is_object($GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$row[$this->myIdFld]])) {
  169.                     if ($debugecho "<p>using <b>cached object</b></p>";
  170.                     $tmpObj=$GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$row[$this->myIdFld]];
  171.                 else {
  172.                     // send 0 as id to avoid reselecting the node from the database
  173.                     $cmd="\$tmpObj=new ".$this->myChildClass."(0,\"".$this->get_gDBIDX()."\",".($debug "TRUE" "FALSE").");";  /* <pk-04-12-21 /> */
  174.                     if ($debugecho "<pre style='font-size:10px;'>CHILD NEW:\n$cmd</pre><blockquote>";
  175.                     eval($cmd);
  176.                     if ($debugecho "</blockquote>";
  177.                 }
  178.                 if ($debugecho "<p>Object Nr $noc created<br />".print_r(implode(";",$row),TRUE)."</p>";
  179.                 $tmpObj->setDBRow($row,TRUE,FALSE)// no debug
  180.                 $tmpObj->setOrderNr($noc);
  181.                 $this->setChildClassVar($tmpObj);
  182.                 $tmpObj->setParentId($this->getRootId());
  183.                 $tmpObj->setLevel(1);
  184.                 $tmpObj->myTree=&$this;
  185.  
  186.                 if ($debugecho "<blockquote><pre>".print_r($tmpObj->getDBVal())."</pre></blockquote>";
  187.                 if ($debugecho "<p style='font-size: 11px;'>Setting GLOBALS['DBMS_TREE'][".$this->getGlobalTreeKey()."][".$row[$this->myIdFld]."]</p>";
  188.                 $GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$row[$this->myIdFld]]=$tmpObj;
  189.                     // copies tmpObj  -> do not manipulate $tmpObj from here !!!!!
  190.  
  191.                 $this->myChildren[$noc]=$row[$this->myIdFld]// only the index
  192.             }
  193.         }
  194.  
  195.         if ($debugecho "</blockquote>";
  196.         return TRUE;
  197.     }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.     /**
  204.       * returns a html code to use in select elements
  205.       *
  206.       * @param MED_CATEGORY_NODE $rootNode 
  207.       * @param boolean $debug 
  208.       *
  209.       * @returns string
  210.       *
  211.       * @since pk-04-08-12
  212.       *
  213.       ***/
  214.     function getHTMLSelectOptionList($rootNode=NULL,$selectedId=0,$debug=FALSE{
  215.         $nodeArr=$this->getIndexedTreeArr($rootNode,"","","&nbsp;&nbsp;","MEC_NAME",$debug);
  216.         $ret="";
  217.         if ($debugecho "<hr><blockquote><pre>".pcf_print_r($nodeArr,TRUE,3)."</pre></blockquote>";
  218.         if (pcf_is_instance_of($rootNode,"DBMS_TREE_NODE")) {
  219.             $ret.="<option value=".$rootNode->getId().">".$rootNode->getDBField("MEC_NAME")."</option>\n";
  220.         }
  221.         foreach($nodeArr as $node{
  222.             $ret.="<option value=".$node['NODEID'];
  223.             if ($selectedId==$node['NODEID']$ret.= " selected";
  224.             $ret.=">".$node['INTEND'].$node['INDEX']." ".$node['NODENAME']."</option>\n";
  225.         }
  226.         return $ret;
  227.     }
  228. }

Documentation generated on Thu, 08 Jan 2009 17:44:38 +0100 by phpDocumentor 1.4.0a2