Source for file OCSP_GROUP.phpclass

Documentation is available at OCSP_GROUP.phpclass

  1. <?php
  2. /**
  3.   * Class file ADDRESS.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    user
  7.   *
  8.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-08-03-14
  12.   *
  13.   */
  14.  
  15. if (!class_exists('DBMS_TABLEOBJ'))
  16. {
  17.     require __OCSP_PHPINCPATH__."db/DBMS_TABLEOBJ.phpclass";    
  18. }
  19.  
  20. if (!class_exists('OCSP_GROUPTREE'))
  21. {
  22.     require dirname(__FILE___OCSP_DIRSEP_ "OCSP_GROUPTREE.phpclass";
  23. }
  24.  
  25. /**
  26.   * Class class OCSP_GROUP handles T_SYS_GROUP
  27.   *
  28.   * @project    Open CSP-Management
  29.   * @package    user
  30.   *
  31.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  32.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  33.   *
  34.   * @since pk-08-03-14
  35.   *
  36.   */
  37. class OCSP_GROUP
  38.     extends DBMS_TABLEOBJ
  39. {
  40.     /**
  41.       * @constant string CLASS_SRC_FILE
  42.       */
  43.     const CLASS_SRC_FILE = __FILE__;    
  44.     
  45.       /**
  46.       * @staticvar string $myTable name of the db table
  47.       */
  48.     protected $myTable="T_SYS_GROUP";
  49.     
  50.     // ------------------------------------------------------
  51.     // factory
  52.     // ------------------------------------------------------    
  53.         
  54.     /**
  55.      * factory a group object
  56.      *
  57.      * @param int $aId 
  58.      * @param boolean $debug 
  59.      * 
  60.      * @return OCSP_GROUP 
  61.      * 
  62.      */
  63.     public static function factory_fromId($aId,$debug=false)
  64.     {        
  65.         $obj_grpTree OCSP_GROUPTREE::getInstance();
  66.         if ($obj_grpTree->userIsMember($aId,OCSP_OBJ::currentUser()->getId()))
  67.         {
  68.             $obj_ret new OCSP_GROUP();
  69.             $obj_ret->setDBRow($obj_grpTree->getGroupRow($aId),true,$debug);
  70.             return $obj_ret;
  71.         
  72.         return NULL;
  73.     }
  74.  
  75.     // ------------------------------------------------------
  76.     // construct
  77.     // ------------------------------------------------------    
  78.     
  79.     public function __construct($debug=False)
  80.     {
  81.         $this->init($debug);
  82.     }
  83.  
  84.     // ------------------------------------------------------
  85.     // getter / setter
  86.     // ------------------------------------------------------    
  87.     
  88.     /**
  89.      * returns the group id
  90.      * 
  91.      * @return int 
  92.      * 
  93.      * @since pk-08-05-09
  94.      */
  95.     public function getId()
  96.     {
  97.         return intval($this->getDBField('GRP_ID'));
  98.     }
  99.     
  100.     /**
  101.      * return the group name
  102.      * 
  103.      * @return string 
  104.      * 
  105.      * @since pk-08-05-09
  106.      */
  107.        public function getName()
  108.        {
  109.            if (intval($this->getId()))
  110.            {
  111.                return $this->getDBField('GRP_NAME');
  112.            else {
  113.                return "PUBLIC";
  114.            }
  115.        }
  116.     
  117.     // ------------------------------------------------------
  118.     // tree
  119.     // ------------------------------------------------------    
  120.     
  121.     /**
  122.      * returns if the group is a child of $aGrpId
  123.      *
  124.      * @param int $aGrpId 
  125.      * 
  126.      * @return boolean 
  127.      * 
  128.      * @since pk-08-05-09
  129.      */
  130.     public function isChildOf($aGrpId)
  131.     {
  132.         return ((intval($this->getDBField('GRP_PARENT')) == intval($aGrpId)) True False);
  133.     }
  134.     
  135.     /**
  136.      * returns an array of child objects
  137.      * 
  138.      * if $childClass isset the class must have been loaded already
  139.      * 
  140.      * @param string $childClass class of the children
  141.      * @param boolean $debug 
  142.      * 
  143.      * @return array 
  144.      */
  145.     public function getChildren($childClass='OCSP_GROUP',$debug=False)
  146.     {      
  147.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::getChildren(" $childClass ")");
  148.         
  149.         if (!class_exists($childClass))
  150.         {
  151.             throw new Exception(_OCSP_EXCEP_CLASSNOTFOUND_);
  152.         }
  153.         
  154.         if (!$this->isConnected(True))
  155.         {
  156.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  157.         }
  158.                 
  159.         if ($arr_rows $this->myDBObj->getArray($this->myTable,array('GRP_PARENT' => intval($this->getId())),0,0,'GRP_NAME',$debug))
  160.         {
  161.             $int_idx 0;
  162.              $arr_ret array();
  163.             
  164.             foreach($arr_rows as $arr_row)
  165.             {
  166.                 eval("\$arr_ret[" $int_idx ."]=new ".$childClass."();");
  167.                 $arr_ret[$int_idx]->setDBRow($arr_row,True);
  168.                 $int_idx++;
  169.             }
  170.             
  171.             if ($int_idx>0)
  172.             {
  173.                 return $arr_ret;
  174.             
  175.             
  176.         }
  177.         
  178.         return Null;
  179.         
  180.     }
  181.     
  182.     // ------------------------------------------------------
  183.     // db methods
  184.     // ------------------------------------------------------    
  185.         
  186.     /**
  187.       * inserts a new row to the table
  188.       *
  189.       * @param boolean $debug 
  190.       *
  191.       * @returns int returns the autoIncFld ID if exists or 1 on success
  192.       *
  193.       */
  194.     function dbInsert($debug=false
  195.     {
  196.            if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::dbInsert()");
  197.            
  198.            if (!$this->isConnected(True))
  199.            {
  200.                throw new Exception(_OCSP_EXCEP_NODBCONN_);
  201.            }
  202.            
  203.            $this->setDBField('GRP_ID',$this->myDBObj->getOne("SELECT MAX(GRP_ID)+1 FROM " $this->myTable));
  204.            
  205.            if (parent::dbInsert($debug))
  206.            {
  207.                OCSP_GROUPTREE::getInstance()->populateGroups($debug);
  208.                return $this->getDBField('GRP_ID');
  209.            }
  210.            return Null;
  211.     }
  212.     
  213.     /**
  214.       * replaces a row in the table
  215.       *
  216.       * @param boolean $debug  show debug info
  217.       * @param boolean $ignorPopulated (if false the table MUST have been populated)
  218.       *
  219.       * @global array $OCSP_OBJ 
  220.       *
  221.       * @returns boolean
  222.       *
  223.       */
  224.     function dbReplace($debug=FALSE,$ignorPopulated=FALSE)
  225.     {
  226.            if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::dbReplace()");
  227.            
  228.            if ($int_grpId parent::dbReplace($debug,$ignorPopulated))
  229.            {
  230.                OCSP_GROUPTREE::getInstance()->populateGroups($debug);
  231.            }
  232.            return $int_grpId;
  233.     }    
  234.  
  235.     // ------------------------------------------------------
  236.     // rights
  237.     // ------------------------------------------------------    
  238.     
  239.     /**
  240.       * returns if the current user can edit the group
  241.       *
  242.       * @param boolean $debug 
  243.       *
  244.       * @return boolean 
  245.       */
  246.     function userCanShow($debug=false)
  247.     {
  248.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::userCanEdit()");
  249.         
  250.         if (!OCSP_OBJ::currentUser()) return false;
  251.         
  252.         return OCSP_GROUPTREE::getInstance()->userIsMember($this->getDBField('GRP_ID'),OCSP_OBJ::currentUser()->getId(),true,$debug);
  253.     }
  254.  
  255.     /**
  256.       * returns if the current user can edit the group
  257.       *
  258.       * @param boolean $debug 
  259.       *
  260.       * @return boolean 
  261.       */
  262.     function userCanInsert($debug=false)
  263.     {
  264.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::userCanEdit()");
  265.         
  266.         if (!OCSP_OBJ::currentUser()) return false;
  267.         
  268.         if ($int_parent intval($this->getDBField('GRP_PARENT')) && ($int_parent 0))
  269.         {
  270.             return OCSP_GROUPTREE::getInstance()->userIsMember($int_parent,OCSP_OBJ::currentUser()->getId(),true,$debug);
  271.         else {
  272.             return OCSP_OBJ::currentUser()->isAdmin();
  273.         }
  274.         
  275.         return false;
  276.     }
  277.     
  278.     /**
  279.       * returns if the current user can edit the group
  280.       *
  281.       * @param boolean $debug 
  282.       *
  283.       * @return boolean 
  284.       */
  285.     function userCanEdit($debug=false)
  286.     {
  287.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_GROUP::userCanEdit()");
  288.         
  289.         if (!OCSP_OBJ::currentUser()) return false;
  290.         
  291.         if ($int_grpId $this->getDBField('GRP_ID'&& ($int_grpId 0))
  292.         {
  293.             return OCSP_GROUPTREE::getInstance()->userIsAdmin($int_grpId,OCSP_OBJ::currentUser()->getId(),$debug);        
  294.         }
  295.  
  296.         return false;        
  297.     }
  298.     
  299.     /**
  300.      * returns if the current user can delete the group
  301.      *
  302.      * @param boolean $debug 
  303.      * 
  304.      * @return boolean 
  305.      */
  306.     function userCanDelete($debug=false)
  307.     {
  308.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLIENT::userCanDelete()");
  309.         
  310.         if (!OCSP_OBJ::currentUser()) return false;
  311.         
  312.         if ($int_grpId intval($this->getDBField('GRP_ID')))
  313.         {
  314.             if (($int_grpId 0&& ($int_grpId != _OCSP_GROUP_ADMIN_))
  315.             {
  316.                 return OCSP_OBJ::currentUser()->isAdmin();
  317.             }
  318.         }
  319.         
  320.         return false;
  321.     
  322.     
  323. }
  324. ?>

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