[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/workflow/inc/engine/src/API/ -> BaseActivity.php (source)

   1  <?php
   2  require_once (GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php');
   3  //!! Abstract class representing activities
   4  //! An abstract class representing activities
   5  /*!
   6  This class represents activities, and must be derived for
   7  each activity type supported in the system. Derived activities extending this
   8  class can be found in the activities subfolder.
   9  This class is observable.
  10  */
  11  class BaseActivity extends Base {
  12    var $name;
  13    var $normalizedName;
  14    var $description;
  15    var $isInteractive;
  16    var $isAutoRouted;
  17    var $roles=Array();
  18    var $outbound=Array();
  19    var $inbound=Array();
  20    var $pId;
  21    var $activityId;
  22    var $type;
  23    var $defaultUser='*';
  24    var $agents=Array();
  25    
  26    /*!
  27    * @deprecated
  28    * seems to be the rest of a bad object architecture
  29    */
  30    function setDb(&$db)
  31    {
  32      $this->db =& $db;
  33    }
  34    
  35    /*!
  36    * constructor of the BaseActivity Object
  37    * @param $db is the ADODB object
  38    */
  39    function BaseActivity(&$db)
  40    {
  41      $this->type='base';
  42      $this->child_name = 'BaseActivity';
  43      parent::Base($db);
  44    }
  45  
  46    /*!
  47    * Factory method returning an activity of the desired type
  48    * loading the information from the database and populating the activity object 
  49    * with datas related to his activity type (being more than a BaseActivity then.
  50    * @param $activityId : it is the id of the wanted activity
  51    * @param $with_roles : true by default, gives you the basic roles information in the result
  52    * @param $with_agents : false by default, gives you the basic agents information in the result
  53    * @param $as_array : boolean false by default, if true the function will return an array instead of an object
  54    * @return an Activity Object of the right class (Child class) or an associative array containing the activity 
  55    * information if $as_array is set to true
  56    */
  57    function &getActivity($activityId, $with_roles= true,$with_agents=false,$as_array=false) 
  58    {
  59      $query = "select * from `".GALAXIA_TABLE_PREFIX."activities` where `wf_activity_id`=?";
  60      $result = $this->query($query,array($activityId));
  61      if(!$result || !$result->numRows() ) return false;
  62      $res = $result->fetchRow();
  63      switch($res['wf_type']) {
  64        case 'start':
  65          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Start.php');
  66          $act = new Start($this->db);  
  67          break;
  68        case 'end':
  69          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'End.php');
  70          $act = new End($this->db);
  71          break;
  72        case 'join':
  73          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Join.php');
  74          $act = new Join($this->db);
  75          break;
  76        case 'split':
  77          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Split.php');
  78          $act = new Split($this->db);
  79          break;
  80        case 'standalone':
  81          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Standalone.php');
  82          $act = new Standalone($this->db);
  83          break;
  84        case 'view':
  85          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'View.php');
  86          $act = new View($this->db);
  87          break;
  88        case 'switch':
  89          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'SwitchActivity.php');
  90          $act = new SwitchActivity($this->db);
  91          break;
  92        case 'activity':
  93          require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'API'.SEP.'activities'.SEP.'Activity.php');
  94          $act = new Activity($this->db);
  95          break;
  96        default:
  97          trigger_error('Unknown activity type:'.$res['wf_type'],E_USER_WARNING);
  98      }
  99      
 100      $act->setName($res['wf_name']);
 101      $act->setProcessId($res['wf_p_id']);
 102      $act->setNormalizedName($res['wf_normalized_name']);
 103      $act->setDescription($res['wf_description']);
 104      $act->setIsInteractive($res['wf_is_interactive']);
 105      $act->setIsAutoRouted($res['wf_is_autorouted']);
 106      $act->setActivityId($res['wf_activity_id']);
 107      $act->setType($res['wf_type']);
 108      $act->setDefaultUser($res['wf_default_user']);
 109      
 110      //Now get forward transitions 
 111      
 112      //Now get backward transitions
 113      
 114      //Now get roles
 115      if ($with_roles)
 116      {
 117        $query = "select `wf_role_id` from `".GALAXIA_TABLE_PREFIX."activity_roles` where `wf_activity_id`=?";
 118        $result=$this->query($query,array($activityId));
 119        if (!(empty($result)))
 120        {
 121          while($res = $result->fetchRow()) 
 122          {
 123            $this->roles[] = $res['wf_role_id'];
 124          }
 125        }
 126        $act->setRoles($this->roles);
 127      }
 128      
 129      //Now get agents if asked so
 130      if ($with_agents)
 131      {
 132        $query = "select wf_agent_id, wf_agent_type from ".GALAXIA_TABLE_PREFIX."activity_agents where wf_activity_id=?";
 133        $result=$this->query($query,array($activityId));
 134        if (!(empty($result)))
 135        {
 136          while($res = $result->fetchRow()) 
 137          {
 138            $this->agents[] = array(
 139                'wf_agent_id'    => $res['wf_agent_id'],
 140                'wf_agent_type'    => $res['wf_agent_type'],
 141              );
 142          }
 143        }
 144        $act->setAgents($this->agents);
 145      }
 146  
 147      if ($as_array)
 148      {//we wont return the object but an associative array instead
 149         $res['wf_name']=$act->getName();
 150         $res['wf_normalized_name']=$act->getNormalizedName();
 151         $res['wf_description']=$act->getDescription();
 152         $res['wf_is_interactive']=$act->isInteractive();
 153         $res['wf_is_autorouted']=$act->isAutoRouted();
 154         $res['wf_roles']=$act->getRoles();
 155         //$res['outbound']=$act->get();
 156         //$res['inbound']=$act->get();
 157         $res['wf_p_id']=$act->getProcessId();
 158         $res['wf_activity_id']=$act->getActivityId();
 159         $res['wf_type']=$act->getType();
 160         $res['wf_default_user']=$act->getDefaultUser();
 161         $res['wf_agents']= $act->getAgents();
 162         return $res;
 163      }
 164      else
 165      {
 166        return $act;
 167      }
 168    }
 169    
 170    /*! @return an Array of roleIds for the given user */
 171    function getUserRoles($user) {
 172      
 173      // retrieve user_groups information in an array containing all groups for this user
 174      $user_groups = galaxia_retrieve_user_groups($GLOBALS['phpgw_info']['user']['account_id'] );
 175      // and append it to query                      
 176      $query = 'select `wf_role_id` from `'.GALAXIA_TABLE_PREFIX."user_roles` 
 177            where (
 178              (wf_user=? and wf_account_type='u')";
 179      if (is_array($groups))
 180      {
 181        $mid .= '    or (wf_user in ('.implode(',',$groups).") and wf_account_type='g')";
 182      }
 183      $mid .= ')';
 184  
 185      $result=$this->query($query,array($user));
 186      $ret = Array();
 187      while($res = $result->fetchRow()) 
 188      {
 189        $ret[] = $res['wf_role_id'];
 190      }
 191      return $ret;
 192    }
 193  
 194    //! Returns an Array of associative arrays with roleId and names
 195    function getActivityRoleNames() {
 196      $aid = $this->activityId;
 197      $query = "select gr.`wf_role_id`, `wf_name` from `".GALAXIA_TABLE_PREFIX."activity_roles` gar, `".GALAXIA_TABLE_PREFIX."roles` gr where gar.`wf_role_id`=gr.`wf_role_id` and gar.`wf_activity_id`=?";
 198      $result=$this->query($query,array($aid));
 199      $ret = Array();
 200      while($res = $result->fetchRow()) {
 201        $ret[] = $res;
 202      }
 203      return $ret;
 204    }
 205    
 206    /*! Returns the normalized name for the activity */
 207    function getNormalizedName() {
 208      return $this->normalizedName;
 209    }
 210  
 211    /*! Sets normalized name for the activity */  
 212    function setNormalizedName($name) {
 213      $this->normalizedName=$name;
 214    }
 215    
 216    /*! Sets the name for the activity */
 217    function setName($name) {
 218      $this->name=$name;
 219    }
 220    
 221    /*! Gets the activity name */
 222    function getName() {
 223      return $this->name;
 224    }
 225  
 226    /*! 
 227    * Sets the agents for the activity object (no save)
 228    * @param $agents is an associative array with ['wf_agent_id'] and ['wf_agent_type'] keys
 229    * @return false if any problem is detected
 230    */
 231    function setAgents($agents) 
 232    {
 233      if (!(is_array($agents)))
 234      {
 235        $this->error[] = tra('bad parameter for setAgents, the parameter should be an array');
 236        return false;
 237      }
 238      $this->agents = $agents;
 239    }
 240    
 241    /*! 
 242    * Gets the activity agents 
 243    * @return an associative array with the basic agents informations (id an type) or false
 244    * if no agent is defined for this activity
 245    */
 246    function getAgents() 
 247    {
 248      if (empty($this->agents)) return false;
 249      return $this->agents;
 250    }
 251    
 252    /*! Sets the activity description */
 253    function setDescription($desc) {
 254      $this->description=$desc;
 255    }
 256    
 257    /*! Gets the activity description */
 258    function getDescription() {
 259      return $this->description;
 260    }
 261    
 262    /*! Sets the type for the activity - this does NOT allow you to change the actual type */
 263    function setType($type) {
 264      $this->type=$type;
 265    }
 266    
 267    /*! Gets the activity type */
 268    function getType() {
 269      return $this->type;
 270    }
 271  
 272    /*! Sets if the activity is interactive */
 273    function setIsInteractive($is) {
 274      $this->isInteractive=$is;
 275    }
 276    
 277    /*! Returns if the activity is interactive */
 278    function isInteractive() {
 279      return $this->isInteractive == 'y';
 280    }
 281    
 282    /*! Sets if the activity is auto-routed */
 283    function setIsAutoRouted($is) {
 284      $this->isAutoRouted = $is;
 285    }
 286    
 287    /*! Gets if the activity is auto routed */
 288    function isAutoRouted() {
 289      return $this->isAutoRouted == 'y';
 290    }
 291  
 292    /*! Sets the processId for this activity */
 293    function setProcessId($pid) {
 294      $this->pId=$pid;
 295    }
 296    
 297    /*! Gets the processId for this activity*/
 298    function getProcessId() {
 299      return $this->pId;
 300    }
 301  
 302    /*! Gets the activityId */
 303    function getActivityId() {
 304      return $this->activityId;
 305    }  
 306    
 307    /*! Sets the activityId */
 308    function setActivityId($id) {
 309      $this->activityId=$id;
 310    }
 311    
 312    /*! Gets array with roleIds asociated to this activity */
 313    function getRoles() {
 314      return $this->roles;
 315    }
 316    
 317    /*! Sets roles for this activities, should receive an
 318    array of roleIds */
 319    function setRoles($roles) {
 320      $this->roles = $roles;
 321    }
 322  
 323    /*! Gets default user id associated with this activity as he's recorded
 324    there's no check about validity of this user.
 325    */
 326    function getDefaultUser() {
 327      return $this->defaultUser;
 328    }
 329  
 330    /*! Sets the default user for an activity */
 331    function setDefaultUser($default_user)
 332    {
 333      if ((!isset($default_user)) || ($default_user=='') || ($default_user==false))
 334      {
 335        $default_user='*';
 336      }
 337      $this->defaultUser = $default_user;
 338    }
 339  
 340    //! DEPRECATED: unused function. old API, do not use it. return always false
 341    /*! 
 342    * Checks if a user has a certain role (by name) for this activity,
 343    *    e.g. $isadmin = $activity->checkUserRole($user,'admin'); 
 344    * @deprecated
 345    */
 346    function checkUserRole($user,$rolename) 
 347    {
 348      $this->error[] = 'use of an old deprecated function checkUserRole, return always false';
 349      return false;
 350    }
 351  
 352  }
 353  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7