Source for file CMS_MENU_V2.phpclass

Documentation is available at CMS_MENU_V2.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_MENU_V2.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   *
  8.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @version $Id: CMS_MENU_V2.phpclass,v 1.8 2008/06/16 07:07:03 pitlinz Exp $
  12.   */
  13.  
  14. /**
  15.  * requirements -----------------------------------------------/
  16.  * 
  17.  */
  18. if (!defined('__OCSP_CMS_PHPINCPATH__')) require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";
  19.  
  20. pcf_require_class('DBMS_TREE',__OCSP_PHPINCPATH__."db/DBMS_TREE.phpclass");
  21. pcf_require_class('CMS_MENU_NODE',__OCSP_CMS_PHPINCPATH__."menu/CMS_MENU_NODE.phpclass");
  22.  
  23.  
  24. /**
  25.   * Class CMS_MENU_V2
  26.   *
  27.   * @project    Open CSP-Management
  28.   * @package    cms
  29.   *
  30.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @version $Id: CMS_MENU_V2.phpclass,v 1.8 2008/06/16 07:07:03 pitlinz Exp $
  34.   */
  35. class CMS_MENU_V2 extends DBMS_TREE {
  36.     /** -----------------------------------------------------
  37.       * Aggregations:
  38.       */
  39.  
  40.  
  41.     /** -----------------------------------------------------
  42.       * Compositions:
  43.       */
  44.  
  45.     /**
  46.       * @var CMS_PROJECT $myProjObj 
  47.       * @access protected
  48.       * @since pk-07-08-15
  49.       */
  50.     protected $myProjObj=NULL;
  51.  
  52.     /** -----------------------------------------------------
  53.       * Attributes:
  54.       */
  55.  
  56.     /**
  57.       * @staticvar string $myTable 
  58.       * @access protected
  59.       */
  60.     protected $myTable="T_CMS_MENU";
  61.  
  62.     /**
  63.       * @staticvar  string  $myIdFld        id column = root
  64.       * @access protected
  65.       ***/
  66.     protected $myIdFld        ="MEN_ID";
  67.  
  68.     /**
  69.       * @staticvar  string  $myParentFld    name of the parent column
  70.       * @access protected
  71.       ***/
  72.     protected $myParentFld    ="MEN_PARENT";
  73.  
  74.     /**
  75.       * @staticvar  string  $mySortFld      name of the sort field
  76.       * @access protected
  77.       ***/
  78.     protected $mySortFld      ="MEN_SORTORDER";
  79.  
  80.     /**
  81.       * @staticvar string $myColPrevix 
  82.       * @since pk-07-06-17
  83.       * @access protected
  84.       */
  85.     protected $myColPrevix="MEN_";
  86.  
  87.     /**
  88.       * @var  string  $myChildClass 
  89.       * @access protected
  90.       ***/
  91.     protected $myChildClass = "CMS_MENU_NODE";
  92.  
  93.     /**
  94.       * @var  string  $myChildKeys    NOT FINAL comma sperated list of keys the children have to fit to
  95.       * @access protected
  96.       ***/
  97.     protected $myChildKeys    ="PROJ_ID";
  98.  
  99.     /**
  100.       * url to open for pages
  101.       * @var string $pageUrl 
  102.       * @access protected
  103.       ***/
  104.     protected $pageUrl = "/cms/index.php";
  105.  
  106.  
  107.     // ######################################
  108.  
  109.     /**
  110.       * constructor
  111.       *
  112.       * @param mixed $aProject (CMS_PROJECT) a project object or (int) a project ID
  113.       * @param boolean $autoPopulate 
  114.       * @param boolean $debug 
  115.       *
  116.       * @version pk-04-08-23
  117.       * @version pk-07-06-15
  118.       *
  119.       ***/
  120.     function CMS_MENU_V2(&$aProject,$autoPopulate=True,$debug=False{
  121.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::CMS_MENU_V2($projId)",($autoPopulate "AUTOPOPULATE" ""));
  122.  
  123.         if (pcf_is_instance_of($aProject,'CMS_PROJECT'))
  124.         {
  125.             if ($debugechoDebugLine(__FILE__,__LINE__,"setting project object with ID: ".$aProject->getId());
  126.             $this->setMyProject($aProject);
  127.             $projId=$aProject->getId();
  128.         else {
  129.             $projId=intval($aProject);
  130.             $this->setProjId($projId);
  131.         }
  132.  
  133.         parent::DBMS_TREE($this->myTable.$projId,$debug);
  134.         if ($autoPopulate{
  135.             $this->populateTree(True,True,"",$debug);
  136.         }
  137.     }
  138.  
  139.  
  140.     /**
  141.       * returns a node in the key tree
  142.       *
  143.       * @param array $dbRow 
  144.       * @param boolean $debug 
  145.       *
  146.       * @return array 
  147.       * @access protected
  148.       *
  149.       * @requires common/OCSP_DATE.phpclass
  150.       *
  151.       * @since pk-07-06-16
  152.       */
  153.     function getKeyTreeNode($dbRow,$debug=False)
  154.     {
  155.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TREE::getKeyTreeNode()");
  156.  
  157.         require_once $GLOBALS['OCSP']['PHPINCPATH']."common/OCSP_DATE.phpclass";
  158.         $obj_Date=new OCSP_DATE();
  159.         if (isset($dbRow[$this->myColPrevix.'SHOWFROM']))
  160.         {
  161.             $obj_Date->setDbString($dbRow[$this->myColPrevix.'SHOWFROM'],$debug);
  162.             $ts_showFrom=$obj_Date->getLinuxTime();
  163.         else {
  164.             $ts_showFrom=0;
  165.         }
  166.         if (isset($dbRow[$this->myColPrevix.'SHOWTILL']&& !empty($dbRow[$this->myColPrevix.'SHOWTILL']))
  167.         {
  168.             $obj_Date->setDbString($dbRow[$this->myColPrevix.'SHOWTILL'],$debug);
  169.             $ts_showTill=$obj_Date->getLinuxTime();
  170.         else {
  171.             $ts_showTill=-1;
  172.         }
  173.         unset($obj_Date);
  174.  
  175.         return array(
  176.                 'ID'        => $dbRow[$this->myIdFld],
  177.                 'LANG'      => $dbRow['LANG_ID'],
  178.                 'SHOW'      => (intval($dbRow[$this->myColPrevix.'SHOW']True False),
  179.                 'SHOWFROM'  => $ts_showFrom,
  180.                 'SHOWTILL'  => $ts_showTill,
  181.                 'SHOWGROUP' => intval($dbRow[$this->myColPrevix.'SHOWGROUP']),
  182.                 'SORTORDER' => intval($dbRow[$this->myColPrevix.'SORTORDER']),
  183.                 'TITLE'     => $dbRow[$this->myColPrevix.'TITLE']
  184.             );
  185.     }
  186.  
  187.     /**
  188.       * returns a array of pointers to the child objects
  189.       *
  190.       * @param bool $debug 
  191.       * @param bool $filtered 
  192.       *
  193.       * @returns array
  194.       *
  195.       * @since pk-04-07-23
  196.       *
  197.       * @version pk-05-01-06
  198.       * @version pk-06-07-27
  199.       * @version pk-07-08-09
  200.       *
  201.       ***/
  202.     function getChildrenList($debug=False,$filtered=False)
  203.     {
  204.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::getChildrenList()");
  205.         if ($filteredreturn parent::getChildrenList($debug,$filtered);
  206.  
  207.         if ($this->cmsCacheIsUsable())
  208.         {
  209.             if ($arr_keyTree=$this->getKeyTree()) // <pk-07-08-09>
  210.             {
  211.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>".print_r($arr_keyTree[0],True)."</pre>");
  212.                 $arr_ret=array();
  213.                 foreach($arr_keyTree[0as $i_Id => $a_keyTree)
  214.                 {
  215.                     $i_idx=intval($a_keyTree['SORTORDER']);
  216.                     while (isset($arr_ret[$i_idx])) $i_idx++;
  217.                     $arr_ret[$i_idx]=$this->populateNode($i_Id,True,$debug);
  218.                 }
  219.                 ksort($arr_ret);
  220.                 return $arr_ret;
  221.             else {
  222.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning empty array");
  223.                 return array();
  224.             }
  225.         else {
  226.             return parent::getChildrenList($debug,$filtered);
  227.         }
  228.  
  229.  
  230.     }
  231.  
  232.  
  233.     /**
  234.       * populates the tree
  235.       *
  236.       * @param boolean $useCache (is ignored here)
  237.       * @param boolean $keysOnly 
  238.       * @param string $where 
  239.       * @param boolean $debug 
  240.       *
  241.       * @return boolean 
  242.       */
  243.     function populateTree($useCache=True,$keysOnly=True,$where="",$debug=False)
  244.     {
  245.         if (
  246.             !isset($GLOBALS['OCSP_VAL']['MENTREE'][$this->getGlobalTreeKey()])
  247.             || !isset($GLOBALS['OCSP_VAL']['MENTREE'][$this->getGlobalTreeKey()]['ISLOADED'])
  248.             || ($GLOBALS['OCSP_VAL']['MENTREE'][$this->getGlobalTreeKey()]['ISLOADED'])
  249.            )
  250.         {
  251.             if ($this->cmsCacheIsUsable())
  252.             {
  253.                 if ($arr_keyTree=$this->myCmsCache->getMenuKeyTree($this->getProjId(),$debug))
  254.                 {
  255.                     $this->populateTS=$arr_keyTree['PEARCACHE_TS'];
  256.                     unset($arr_keyTree['PEARCACHE_TS']);
  257.                     $this->setKeyTree($arr_keyTree);
  258.                     return True;
  259.                 }
  260.             }
  261.         }
  262.  
  263.         if (empty($where))
  264.         {
  265.             $where=" WHERE ";
  266.             $b_cacheAble=True;
  267.         else {
  268.             $where.=" AND ";
  269.             $b_cacheAble=False;
  270.         }
  271.  
  272.         $where.=" (PROJ_ID=".$this->getProjId()." OR PROJ_ID=0)";
  273.         if (parent::populateTree($useCache,$keysOnly,$where,$debug))
  274.         {
  275.             if ($b_cacheAble && $this->cmsCacheIsUsable())
  276.             {
  277.                 $this->myCmsCache->setMenuKeyTree($this->getProjId(),$this->getKeyTree(),$debug);
  278.             }
  279.             return True;
  280.         }
  281.         return False;
  282.     }
  283.  
  284.  
  285.  
  286.     /**
  287.       * generates a new child object and add it to the cache
  288.       *
  289.       * @param int $aId the (cache) id of the object
  290.       * @param string $aClassName if !empty $this-myChildClass is overwriten if class exists
  291.       * @param boolean $debug 
  292.       *
  293.       * @return CMS_MENU_NODE 
  294.       *
  295.       * @since pk-07-10-08
  296.       *
  297.       ***/
  298.     function &newNodeObject($aId,$dataArr=NULL,$debug=False{
  299.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::newChildObj()","<pre>".print_r($dataArr,True)."</pre>");
  300.  
  301.         if (empty($dataArr['MEN_OBJCLASS']|| (!is_array($GLOBALS['OCSP_CMS']['MENUTYPE'][$dataArr['MEN_OBJCLASS']]))) {
  302.             // unknown object class asume default
  303.             if ($debugechoDebugLine(__FILE__,get_class($this),"MEN_OBJCLASS not set calling parent::newChildObj()");
  304.             return parent::newNodeObject($aId,$dataArr,$debug);
  305.         }
  306.  
  307.         $s_menuClass=$GLOBALS['OCSP_CMS']['MENUTYPE'][$dataArr['MEN_OBJCLASS']]['CLASS'];
  308.         if (!class_exists($s_menuClass)) {
  309.             require_once $GLOBALS['OCSP_CMS']['MENUTYPE'][$dataArr['MEN_OBJCLASS']]['INCLUDE'];
  310.         }
  311.  
  312.         $s_cmd="\$o_nodeObj=new ".$s_menuClass."();";
  313.         if ($debugechoDebugLine(__FILE__,__LINE__,"Object cmd: ".$s_cmd);
  314.         eval($s_cmd);
  315.  
  316.         if (!is_object($o_nodeObj))
  317.         {
  318.             ocsp_logError(__FILE__,__LINE__,"could not eval node command for node ID$aId in class".get_class($this));
  319.             return $o_nodeObj;
  320.         }
  321.  
  322.         $this->setChildClassVar($o_nodeObj,$debug);
  323.         if (is_array($dataArr)) {
  324.             $o_nodeObj->setDBVal($dataArr);
  325.         }
  326.  
  327.         $this->addNodeObjectToCache($aId,$o_nodeObj,$debug);
  328.         return $o_nodeObj;
  329.  
  330.     }
  331.  
  332.  
  333.  
  334.     /**
  335.       * populates a child
  336.       *
  337.       * @param  int     $aId 
  338.       * @param  bool    $useCache (ignored here always True)
  339.       * @param  bool    $debug 
  340.       *
  341.       *  return  mixed   DBMS_TREE_NODE if its a child
  342.       *
  343.       * @since pk-05-11-22
  344.       * @version pk-06-07-17
  345.       *
  346.       ***/
  347.     function &populateNode($aId,$useCache=True,$debug=False{
  348.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::populateNode($aId)");
  349.  
  350.         if (!intval($aId))
  351.         {
  352.             if ($debugechoDebugLine(__FILE__,__LINE__,"generating root node");
  353.             $obj_Node=new CMS_MENU_NODE();
  354.             $obj_Node->setDBObj($this->getDBObj);
  355.             $obj_Node->setProjId($this->getProjId());
  356.             $obj_Node->setId(0);
  357.             $obj_Node->setTreeObj($this);
  358.             return $obj_Node;
  359.         }
  360.  
  361.         if ($obj_Node=$this->getNodeObjectFromCache($aId,$debug))
  362.         {
  363.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning Node from 'OCSP_VAL'");
  364.             return $obj_Node;
  365.         }
  366.  
  367.         if ($arr_nodeVal=$this->cmsCacheGetNodeValArr($aId,$debug))
  368.         {
  369.             if ($debugechoDebugLine(__FILE__,__LINE__,"generating node from NODEVAL <pre>".print_r($arr_nodeVal,True)."</pre>");
  370.             $obj_Node=$this->newNodeObject($aId,$arr_nodeVal,$debug);
  371.             $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODES'][$aId]=$obj_Node->validateClass($debug);
  372.             return $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODES'][$aId];
  373.         }
  374.  
  375.         if ($arr_row $this->getNodeDBRowFromDB($aId,$debug))
  376.         {
  377.             if ($debugechoDebugLine(__FILE__,__LINE__,"loading node form database");
  378.             $obj_Node=$this->newNodeObject($aId,$arr_row,$debug);
  379.             $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODES'][$aId]=$obj_Node->validateClass();
  380.             if ($this->cmsCacheIsUsable())
  381.             {
  382.                 $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODEVAL'][$aId]['DATA']=$arr_row;
  383.                 //$this->myCmsCache->setMenuTreeIndex($this->getGlobalTreeKey());
  384.                 $this->myCmsCache->setMenuData($GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODES'][$aId],$debug);
  385.             }
  386.             return $GLOBALS['OCSP_VAL']['DBMS_TREE'][$this->getGlobalTreeKey()]['NODES'][$aId];
  387.         }
  388.  
  389.         if ($debugechoDebugMethod(__FILE__,__LINE__,"node with id $aId not found in the database");
  390.  
  391.     }
  392.  
  393.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394.     // project methods
  395.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  396.  
  397.     /**
  398.       * @return int 
  399.       * @since pk-05-07-26
  400.       * @version pk-07-08-15
  401.       ***/
  402.     function getProjId({
  403.         if (pcf_is_instance_of($this->myProjObj,'CMS_PROJECT'))
  404.         {
  405.             return $this->myProjObj->getId();
  406.         else if (isset($this->PROJ_ID)) {
  407.             return intval($this->PROJ_ID);
  408.         else {
  409.             return False;
  410.         }
  411.     }
  412.  
  413.     /**
  414.       * sets the project id if $projId != $this->PROJ_ID and the
  415.       * tree has children (sizeof($this->myChildren)) the childrens
  416.       * are reloaded
  417.       *
  418.       * @param int $projId 
  419.       *
  420.       * @since pk-05-07-26
  421.       *
  422.       ***/
  423.     function setProjId($projId,$debug=False{
  424.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::setProjId($projId)");
  425.         $this->PROJ_ID=intval($projId);
  426.  
  427.         /*
  428.         if ($this->PROJ_ID != intval($projId)) {
  429.             $this->PROJ_ID=intval($projId);
  430.             $this->myGlobalTreeKey=$this->myTable.intval($projId);
  431.             if (sizeof($this->myChildren)) {
  432.                 if ($debug) echo "<blockquote><p><b>RELOADING CHILDREN</b></p>";
  433.                 $this->myChildren=array();
  434.                 $this->populate(False,$debug);
  435.                 if ($debug) echo "</blockquote>";
  436.             }
  437.         }
  438.         */
  439.     }
  440.  
  441.     /**
  442.       * @param CMS_PROJECT $aProject 
  443.       */
  444.     function setMyProject(&$aProject)
  445.     {
  446.         $this->myProjObj=$aProject;
  447.         if (method_exists($aProject,'getId'))
  448.         {
  449.             $this->setProjId($this->myProjObj->getId());
  450.         }
  451.     }
  452.  
  453.  
  454.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  455.     // Cache Methods
  456.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  457.  
  458.     /**
  459.       * returns if the cms cache is usable
  460.       *
  461.       * if (_OCSP_USEPEARCACHE_) it's ensured that
  462.       * $GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'] is an object
  463.       *
  464.       * @param boolean $debug 
  465.       *
  466.       * @return boolean 
  467.       */
  468.     function cmsCacheIsUsable($debug=False)
  469.     {
  470.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::cmsCacheIsUsable()");
  471.         if (_OCSP_USEPEARCACHE_{
  472.             if (!pcf_is_instance_of($GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'],'OCSP_CMS_PEARCACHE'))
  473.             {
  474.                 //if ($debug)
  475.                 echoDebugLine(__FILE__,__LINE__,"generating new cacheobj");
  476.                 require_once $GLOBALS['OCSP_CMS']['PHPINCPATH']."OCSP_CMS_PEARCACHE.phpclass";
  477.                 $GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE']=new OCSP_CMS_PEARCACHE();
  478.             }
  479.             $this->myCmsCache=&$GLOBALS['OCSP_OBJ']['CMS_PEARCHACHE'];
  480.  
  481.             return True;
  482.         }
  483.         return False;
  484.     }
  485.  
  486.  
  487.     /**
  488.       * returns the cache array for a node
  489.       *
  490.       * @param int $aId 
  491.       * @param boolean $debug 
  492.       *
  493.       * @return array 
  494.       * @access public
  495.       *
  496.       * @since pk-07-06-18
  497.       */
  498.     function cmsCacheGetNodeValArr($aId,$debug=False)
  499.     {
  500.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_MENU_V2::cmsCacheGetNodeValArr($aId)");
  501.  
  502.         if ($this->cmsCacheIsUsable())
  503.         {
  504.             return $this->myCmsCache->getMenuVal($aId,$debug);
  505.         }
  506.         return False;
  507.     }
  508.  
  509.     /**
  510.       * @param boolean $debug 
  511.       * @returns OCSP_CMS_PEARCACHE
  512.       * @access public
  513.       */
  514.     function &cmsCacheGetObj($debug)
  515.     {
  516.         if ($this->cmsCacheIsUsable()) return $this->myCmsCache;
  517.     }
  518. }
  519. ?>

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