[ 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/ -> Process.php (source)

   1  <?php
   2  require_once (GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php');
   3  //!! Process.php
   4  //! A class representing a process
   5  /*!
   6  This class representes the process that is being executed when an activity
   7  is executed. You can access this class methods using $process from any activity.
   8  No need to instantiate a new object.
   9  */
  10  class Process extends Base {
  11    var $name;
  12    var $description;
  13    var $version;
  14    var $normalizedName;
  15    var $pId = 0;
  16    var $config = array();
  17  
  18    function Process(&$db) 
  19    {
  20      $this->child_name = 'Process';
  21      parent::Base($db);
  22    }
  23  
  24    /*!
  25    Loads a process from the database
  26    */
  27    function getProcess($pId) {
  28      $query = "select * from `".GALAXIA_TABLE_PREFIX."processes` where `wf_p_id`=?";
  29      $result = $this->query($query,array($pId));
  30      if(!$result->numRows()) return false;
  31      $res = $result->fetchRow();
  32      $this->name = $res['wf_name'];
  33      $this->description = $res['wf_description'];
  34      $this->normalizedName = $res['wf_normalized_name'];
  35      $this->version = $res['wf_version'];
  36      $this->pId = $res['wf_p_id'];
  37      //config is load only on the first getConfigValues call
  38    }
  39    
  40    /*!
  41    Gets the process Id
  42    */
  43    function getProcessId() {
  44      return $this->pId;
  45    }
  46    
  47    
  48    /*!
  49    Gets the normalized name of the process
  50    */
  51    function getNormalizedName() {
  52      return $this->normalizedName;
  53    }
  54    
  55    /*!
  56    Gets the process name
  57    */
  58    function getName() {
  59      return $this->name;
  60    }
  61    
  62    /*!
  63    Gets the process version
  64    */
  65    function getVersion() {
  66      return $this->version;
  67    }
  68  
  69    /*!
  70    Gets information about an activity in this process by name,
  71    e.g. $actinfo = $process->getActivityByName('Approve CD Request');
  72      if ($actinfo) {
  73        $some_url = 'tiki-g-run_activity.php?activityId=' . $actinfo['activityId'];
  74      }
  75    */
  76    function getActivityByName($actname) {
  77      // Get the activity data
  78      $query = "select * from `".GALAXIA_TABLE_PREFIX."activities` where `wf_p_id`=? and `wf_name`=?";
  79      $pId = $this->pId;
  80      $result = $this->query($query,array($pId,$actname));
  81      if(!$result->numRows()) return false;
  82      $res = $result->fetchRow();
  83      return $res;
  84    }
  85  
  86  
  87  //! Store config values for this process.
  88  /*!
  89  Parameter: an array containing pairs of (config_variables_names => (type => value))
  90  type can be int or text, anything else is considered text
  91  int value of -1 is considered as 'default global configuration option'. So nothing
  92  will be stored for this process (and existing values are erased)
  93  */
  94    function setConfigValues(&$parameters) 
  95    {
  96      if (!is_array($parameters))
  97      {
  98        return false;
  99      }
 100      $array_delete=array();
 101      $array_set=array();
 102      $pId = (string)$this->pId;
 103      foreach ($parameters as $config_var => $config_value)
 104      {
 105        //all config values will be deleted
 106        $array_delete[] = array($pId, $config_var);
 107        
 108        //foreach but normally there's only one loop
 109        foreach($config_value as $value_type => $value_zone)
 110        {
 111          $ok = true;
 112          if ($value_type=='int')
 113          {
 114            //special value, refer to global config values for this process conf variable
 115            //we don't want any value stored for this process conf variable
 116            //so we break the foreach before setting the $array_set
 117            if ($value_zone == -1)
 118            {
 119              $ok=false;
 120              break;
 121            }
 122            //else it's classic
 123            $value_int = $value_zone;
 124            $value= '';
 125          }
 126          else
 127          {
 128            $value = $value_zone;
 129            $value_int = null;
 130          }
 131        }
 132        //we are going to set this config value if $ok says so
 133        if ($ok) $array_set[] = array($config_var, $value, $value_int, $pId);
 134      }
 135      //delete previous config values if they are in a bulk statement
 136      if (count($array_delete)>0) 
 137      {
 138        $result= $this->query("DELETE from ".GALAXIA_TABLE_PREFIX."process_config where wf_p_id=? and wf_config_name=?",$array_delete, -1,-1,true,'',true);
 139      }
 140      //insert in a bulk statement
 141      if (count($array_set)>0) 
 142      {
 143          $result= $this->query("INSERT into ".GALAXIA_TABLE_PREFIX."process_config 
 144            (wf_config_name,wf_config_value,wf_config_value_int,wf_p_id) values (?,?,?,?)"
 145            ,$array_set, -1,-1,true,'', true);
 146      }
 147    }
 148    
 149  //!  Return an array containing all the process configuration values. The configuration data is then cached for this process object life.
 150  /*!
 151  Parameter: an array containing pairs of (config_variables_names => default_values)
 152  For a variable name which has no previous value and no global value (default process value)
 153  it will return default_value and this default value will be the NEW STORED value. 
 154  If no default value is given we assume it's a false.
 155  */
 156    function getConfigValues(&$parameters) 
 157    {
 158      if (!is_array($parameters))
 159      {
 160        return false;
 161      }
 162      if (count($this->config) == 0) 
 163      { // first time we come
 164        // Get all the config data for this process
 165        $query = "select * from ".GALAXIA_TABLE_PREFIX."process_config where wf_p_id=?";
 166        $pId = $this->pId;
 167        $result = $this->query($query,array($pId));
 168  
 169        if($result->numRows()>0) 
 170        {
 171          //we add process datas for some config_name, we store it in $this->config
 172          while ($res=$result->fetchRow())
 173          {
 174            //int values are not stored in the same field
 175            $int_value= $res['wf_config_value_int'];
 176            if (isset($int_value))
 177            {
 178              $this->config[$res['wf_config_name']] = $int_value;
 179            }
 180            else
 181            {
 182              $this->config[$res['wf_config_name']] = $res['wf_config_value'];
 183            }
 184          }
 185        }
 186      }// the second time we jump here
 187  
 188      //parse config_name asked
 189      $local_array = array();
 190      $global_default_array = array();
 191      foreach ($parameters as $config_var => $default_value)
 192      {
 193        if (isset($this->config[$config_var]))
 194        {// we already know this config value
 195          //echo "<br>ok we had one for ".$config_var;
 196          $local_array[$config_var] = $this->config[$config_var];
 197        }
 198        else
 199        {
 200          // we have no value for it here, we'll ask it in the global conf
 201          //echo "<br>we had nothing for ".$config_var;
 202          $global_default_array[$config_var] = $default_value;
 203        }
 204      }
 205  
 206      // if we have some not set value that we need to check in global conf
 207      if (count($global_default_array) > 0)
 208      {
 209        $global_array =& galaxia_get_config_values($global_default_array);
 210      }
 211      $result = (array)$local_array + (array)$global_array;
 212      return $result;
 213    }
 214  
 215  }
 216  
 217  ?>


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