Source for file CMS_CHAPTER_STATE.phpclass

Documentation is available at CMS_CHAPTER_STATE.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file CMS_CHAPTER_STATE.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  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-17.10.2008
  12.   * @version $Id: INFA_CMS_CHAPTER.phpclass,v 1.2 2008/12/17 16:28:51 peterkrebs Exp $
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.     
  19.     if (!defined('__OCSP_CMS_PHPINCPATH__')) 
  20.     {
  21.         require_once __OCSP_DEFAULTCONFPATH__ "cms.conf.phpinc";
  22.     }
  23.  
  24. /**
  25.   * openCSP class CMS_CHAPTER_STATE
  26.   *
  27.   * @project Open CSP-Management
  28.   * @package default
  29.   *
  30.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  31.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @since pk-18.12.2008
  34.   * @version $Id: CMS_CHAPTER_STATE.phpclass,v 1.2 2008/12/17 16:28:51 peterkrebs Exp $
  35.   */
  36. {
  37.     // ---------------------------------------------------------------------------
  38.     // constants
  39.     // ---------------------------------------------------------------------------
  40.     
  41.  
  42.     // ---------------------------------------------------------------------------
  43.     // class (static)
  44.     // ---------------------------------------------------------------------------
  45.     
  46.     /*** class vars ------------------------------------------------------ */
  47.     
  48.     protected static $myStateInstances array();
  49.     
  50.     /*** class methods --------------------------------------------------- */
  51.     
  52.     /**
  53.      * returns the state instance with ID $aId
  54.      * 
  55.      * @param int $aId 
  56.      * 
  57.      * @return CMS_CHAPTER_STATE 
  58.      */
  59.     public static function &getInstance($aId)
  60.     {
  61.         if (!isset(self::$myStateInstances[intval($aId)]))
  62.         {
  63.             self::$myStateInstances[intval($aId)new CMS_CHAPTER_STATE(intval($aId));
  64.         }
  65.         return self::$myStateInstances[intval($aId)];
  66.     }
  67.     
  68.     /**
  69.      * returns an array with all state instances
  70.      * 
  71.      * @return array 
  72.      */
  73.     public static function getAllStates()
  74.     {
  75.         if ($arr_states OCSP_CONF::getInstance('OCSP_CMS')->getValue('CHAPTERSTATE'))
  76.         {
  77.             foreach($arr_states as $int_id => $arr_desc)
  78.             {
  79.                 if (!isset(self::$myStateInstances[$int_id]))
  80.                 {
  81.                     self::$myStateInstances[$int_idnew CMS_CHAPTER_STATE($int_id,$arr_desc);
  82.                 }
  83.             }
  84.         }
  85.         
  86.         return self::$myStateInstances;
  87.     }
  88.     
  89.     // ---------------------------------------------------------------------------
  90.     // object vars
  91.     // ---------------------------------------------------------------------------
  92.     
  93.     /*** compostion --------------------------------------------------- */
  94.     
  95.     /*** attributes  -------------------------------------------------- */
  96.     
  97.     /**
  98.      * @var int $myid 
  99.      */
  100.     protected $myId = 0;
  101.     
  102.     /**
  103.      * array with state description
  104.      *
  105.      * - NAME
  106.      * - SHOW  (chapter is online by state)
  107.      * - ICON  (path)
  108.      * - GROUP (members can change state)
  109.      * 
  110.      * @var array $myDesc 
  111.      */
  112.     protected $myDesc = array();
  113.     
  114.     // ---------------------------------------------------------------------------
  115.     // factory / construct
  116.     // ---------------------------------------------------------------------------
  117.     
  118.     /**
  119.      * constructor
  120.      * 
  121.      * if no description array is passed in $aDesc the description is taken from  OCSP_CONF::getInstance('OCSP_CMS')
  122.      * 
  123.      * @param int $aId 
  124.      * @param array $aDesc 
  125.      * 
  126.      */
  127.     protected function __construct($aId,$aDesc=Null)
  128.     {
  129.         $this->myId = intval($aId);
  130.         if (!is_array($aDesc))
  131.         {
  132.             if ($arr_all OCSP_CONF::getInstance('OCSP_CMS')->getValue('CHAPTERSTATE'))
  133.             {
  134.                 $this->myDesc = $arr_all[$this->myId];
  135.             }
  136.         else {
  137.             $this->myDesc = $aDesc;        
  138.         }
  139.     }
  140.     
  141.     // ---------------------------------------------------------------------------
  142.     // getter / setter
  143.     // ---------------------------------------------------------------------------
  144.  
  145.     /**
  146.      * returns the state id
  147.      */
  148.     public function getId()
  149.     {
  150.         return $this->myId;
  151.     }
  152.         
  153.     /**
  154.      * returns the state name
  155.      *
  156.      * @return string 
  157.      */
  158.     public function getName()
  159.     {
  160.         return $this->myDesc['NAME'];
  161.     }
  162.     
  163.     /**
  164.      * returns the icon URL
  165.      * 
  166.      * @return string 
  167.      */
  168.     public function getIconUrl()
  169.     {
  170.         return $this->myDesc['ICON'];
  171.     }
  172.     
  173.     /**
  174.      * returns if the state is online
  175.      * 
  176.      * @return boolean 
  177.      */
  178.     public function isOnline()
  179.     {
  180.         return $this->myDesc['SHOW'];
  181.     }
  182.     
  183.     /**
  184.      * returns the group which can edit the chapter
  185.      * 
  186.      * @return int 
  187.      */
  188.     public function getEditGroup()
  189.     {
  190.         return (isset($this->myDesc['GROUP']intval($this->myDesc['GROUP']_OCSP_GROUP_PROJ_ADMINGRP_);        
  191.     }
  192.     
  193.     // ---------------------------------------------------------------------------
  194.     // rights
  195.     // ---------------------------------------------------------------------------
  196.     
  197.     /**
  198.      * returns if the current user is in the state group
  199.      * 
  200.      * @param int $aProjId 
  201.      * 
  202.      * @return boolean 
  203.      */
  204.     public function curUserIsInGroup($aProjId)
  205.     {
  206.         $int_grpId $this->getEditGroup();
  207.         if ($int_grpId >= _OCSP_GROUP_LOGGEDIN_)                    
  208.         {
  209.             return OCSP_OBJ::currentUser(True)->isGroupMember($int_grpId);
  210.         else {
  211.             // check project groups
  212.             pcf_require_class('CMS_PROJECT',"cms/");
  213.             if ($obj_project CMS_PROJECT::getInstance(intval($aProjId)))
  214.             {
  215.                 switch($int_grpId)
  216.                 {
  217.                     case _OCSP_GROUP_PROJ_AUTHOR_GRP_:
  218.                         return $obj_project->curUserIsAuthor();
  219.                     case _OCSP_GROUP_PROJ_EDITOR_GRP_:
  220.                         return $obj_project->curUserIsEditor();
  221.                     default:    
  222.                         return $obj_project->curUserIsAdmin();
  223.                 }
  224.             }                            
  225.         }        
  226.         return False;
  227.     }
  228.     
  229. }
  230.  
  231.  
  232. ?>

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