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

   1  <?php
   2  require_once(GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php');
   3  //!! ProcessMonitor
   4  //! ProcessMonitor class
   5  /*!
   6  This class provides methods for use in typical monitoring scripts
   7  A first part are methods for cleaning up instances and workitems associated with a process
   8  A second part are methods to obtains information about the actual state or histroy of the process
   9  */
  10  class ProcessMonitor extends Base 
  11  {
  12  
  13    // Constructor receiving a database abstraction object.
  14    function ProcessMonitor(&$db)
  15    {
  16      $this->child_name = 'ProcessMonitor';
  17      parent::Base($db);
  18      // check the the actual user can really do this
  19      if ( !(galaxia_user_can_monitor()))
  20      {
  21        unset($this);
  22        galaxia_show_error('forbidden access to ProcessMonitor object');
  23      }
  24    }
  25  
  26  
  27    //! return statistics about all processes handled by the engine.
  28    /*!
  29    * result is an array of this form:
  30    * array(
  31    *   [active_processes] => number
  32    *   [processes] => number (total number of processes)
  33    *   [running_processes] => number
  34    *   [active_instances] => number
  35    *   [completed_instances] => number
  36    *   [exception_instances] => number
  37    *   [aborted_instances] => number
  38    * )
  39    */
  40    function monitor_stats() {
  41      $res = Array();
  42      $res['active_processes'] = $this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."processes` where `wf_is_active`=?",array('y'));
  43      $res['processes'] = $this->getOne("select count(*) from `".GALAXIA_TABLE_PREFIX."processes`");
  44      $result = $this->query("select distinct(`wf_p_id`) from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?",array('active'));
  45      $res['running_processes'] = $result->numRows();
  46      // get the number of instances per status
  47      $query = "select wf_status, count(*) as num_instances from ".GALAXIA_TABLE_PREFIX."instances group by wf_status";
  48      $result = $this->query($query);
  49      $status = array();
  50      while($info = $result->fetchRow()) {
  51        $status[$info['wf_status']] = $info['num_instances'];
  52      }
  53      $res['active_instances'] = isset($status['active']) ? $status['active'] : 0;
  54      $res['completed_instances'] = isset($status['completed']) ? $status['completed'] : 0;
  55      $res['exception_instances'] = isset($status['exception']) ? $status['exception'] : 0;
  56      $res['aborted_instances'] = isset($status['aborted']) ? $status['aborted'] : 0;
  57      return $res;
  58    }
  59  
  60    //! no need for an update function here. function update_instance_status Deprecated @deprecated
  61    /*
  62    function update_instance_status($iid,$status) {
  63      $query = "update `".GALAXIA_TABLE_PREFIX."instances` set `wf_status`=? where `wf_instance_id`=?";
  64      $this->query($query,array($status,$iid));
  65    }
  66    */
  67    
  68    //! no need for an update function here. function update_instance_activity_status Deprecated @deprecated
  69    /*
  70    function update_instance_activity_status($iid,$activityId,$status) {
  71      $query = "update `".GALAXIA_TABLE_PREFIX."instance_activities` set `wf_status`=? where `wf_instance_id`=? and `wf_activity_id`=?";
  72      $this->query($query,array($status,$iid,$activityId));
  73    }
  74    */
  75    
  76    //! definitively remove an instance from the database. DANGEROUS
  77    /*!
  78    * The instance will be removed but all workitems (history) will be removed as well and all actual activities
  79    * and properties of this instance as well.
  80    * @param iid is the instance id
  81    * @return true if everything was ok, false in the other case (and nothing was done)
  82    */
  83    function remove_instance($iid) 
  84    {
  85      // start a transaction
  86      $this->db->StartTrans();
  87      $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?";
  88      $this->query($query,array($iid));
  89      $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?";
  90      $this->query($query,array($iid));
  91      $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_instance_id`=?";
  92      $this->query($query,array($iid));
  93      // perform commit (return true) or Rollback (return false)
  94      return $this->db->CompleteTrans();
  95  
  96    }
  97    
  98    //! definitively remove __all__ aborted instance from the database. DANGEROUS
  99    /*!
 100    * All aborted instances will be removed but all workitems (history) associated with theses instances as well
 101    * you can limit this behaviour to one process by specifying a process id.
 102    * @param $process_id is a process id you can give to limit this function to only one process.
 103    * Aborted instances from other processes wont be removed
 104    * @return true if everything was ok, false in the other case (and nothing was done)
 105    */
 106    function remove_aborted($pId=0) 
 107    {
 108      // check the the actual user can really do this
 109      if ( !((galaxia_user_can_clean_instances()) || (galaxia_user_can_clean_aborted_instances())) )
 110      {
 111        $this->error[] = tra('user is not authorized to delete aborted instances');
 112        return false;
 113      }
 114      if (!(pId))
 115      {
 116        $whereand = '';
 117        $bindvars = array('aborted');
 118      }
 119      else
 120      {
 121        $whereand = 'and wf_p_id = ?';
 122        $bindvars = array('aborted', $pId);
 123      }
 124      $query="select `wf_instance_id` from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?".$whereand;
 125      // start a transaction
 126      $this->db->StartTrans();
 127      $result = $this->query($query,$bindvars);
 128      while($res = $result->fetchRow()) 
 129      {  
 130        $iid = $res['wf_instance_id'];
 131        $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?";
 132        $this->query($query,array($iid));
 133        $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?";
 134        $this->query($query,array($iid));  
 135      }
 136      $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_status`=?".$whereand;
 137      $this->query($query,$bindvars);
 138      // perform commit (return true) or Rollback (return false)
 139      return $this->db->CompleteTrans();
 140    }
 141  
 142    //! definitively remove __all__ instance/history of a process from the database. VERY DANGEROUS
 143    /*!
 144    * For a given process, all instances, in all states, completed, aborted, exception, running...  will be removed 
 145    * and all workitems (history) or activities actually running  associated with theses instances as well.
 146    * @param process_id is the id of the process for which we will remove theses things
 147    * @return true if everything was ok, false in the other case (and nothing was done)
 148    */
 149    function remove_all($pId) {
 150      // check the the actual user can really do this
 151      if ( !(galaxia_user_can_clean_instances()) )
 152      {
 153        $this->error[] = tra('user is not authorized to delete instances');
 154        return false;
 155      }
 156      $query="select `wf_instance_id` from `".GALAXIA_TABLE_PREFIX."instances` where `wf_p_id`=?";
 157      // start a transaction
 158      $this->db->StartTrans();
 159      $result = $this->query($query,array($pId));
 160      while($res = $result->fetchRow()) {
 161        $iid = $res['wf_instance_id'];
 162        $query = "delete from `".GALAXIA_TABLE_PREFIX."instance_activities` where `wf_instance_id`=?";
 163        $this->query($query,array($iid));
 164        $query = "delete from `".GALAXIA_TABLE_PREFIX."workitems` where `wf_instance_id`=?";
 165        $this->query($query,array($iid));  
 166      }
 167      $query = "delete from `".GALAXIA_TABLE_PREFIX."instances` where `wf_p_id`=?";
 168      $this->query($query,array($pId));
 169      // perform commit (return true) or Rollback (return false)
 170      return $this->db->CompleteTrans();
 171    }
 172  
 173    /*! list all process
 174    * List all processes and return stats
 175    * @param $offset is the first row number to return
 176    * @param $maxRecords is the maximumnumber of records to return
 177    * @param $sort_mode is the sort order
 178    * @param $find is a string to search for in process name or process description
 179    * @param $where is a string to ad to the query, be carefull with this string, read the query before
 180    * @param $add_stats is true by default, by setting it to false you wont get the statistics associated with
 181    * the processes, this could be helpfull for gui listing on selects, to avoid (a big number of) unnecessary queries
 182    * @return an associative array with the number of records for the 'cant' key and an array of process stats for the 
 183    * 'data' key. each row is of this form:
 184    *    * key : process_id
 185    *    * value : an array of infos:
 186    *        * keys are : wf_p_id, wf_name, wf_is_valid, wf_is_active, wf_version, wf_description, wf_last_modif,
 187    *        and  wf_normalized_name for the 'classical part' and for the 'stats part' whe have: active_instances, 
 188    *        exception_instances, completed_instances, aborted_instances, all_instances, activities
 189    */
 190    function monitor_list_processes($offset,$maxRecords,$sort_mode,$find,$where='', $add_stats=true) 
 191    {
 192    
 193      $sort_mode = $this->convert_sortmode($sort_mode);
 194      if($find) {
 195        $findesc = '%'.$find.'%';
 196        $mid=" where ((wf_name like ?) or (wf_description like ?))";
 197        $bindvars = array($findesc,$findesc);
 198      } else {
 199        $mid="";
 200        $bindvars = array();
 201      }
 202      if($where) {
 203        if($mid) {
 204          $mid.= " and ($where) ";
 205        } else {
 206          $mid.= " where ($where) ";
 207        }
 208      }
 209      // get the requested processes
 210      $query = "select * from ".GALAXIA_TABLE_PREFIX."processes $mid order by $sort_mode";
 211      $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."processes $mid";
 212      $result = $this->query($query,$bindvars,$maxRecords,$offset);
 213      $cant = $this->getOne($query_cant,$bindvars);
 214      $ret = Array();
 215      while($res = $result->fetchRow()) {
 216        $pId = $res['wf_p_id'];
 217        // Number of active instances
 218        $res['active_instances'] = 0;
 219        // Number of exception instances
 220        $res['exception_instances'] = 0;
 221        // Number of completed instances
 222        $res['completed_instances'] = 0;
 223        // Number of aborted instances
 224        $res['aborted_instances'] = 0;
 225        $res['all_instances'] = 0;
 226        // Number of activities
 227        $res['activities'] = 0;
 228        $ret[$pId] = $res;
 229      }
 230      if (count($ret) < 1) {
 231        $retval = Array();
 232        $retval["data"] = $ret;
 233        $retval["cant"] = $cant;
 234        return $retval;
 235      }
 236      if ($add_stats)
 237      {
 238        // get number of instances and timing statistics per process and status
 239        $query = "select wf_p_id, wf_status, count(*) as num_instances,
 240                  min(wf_ended - wf_started) as min_time, avg(wf_ended - wf_started) as avg_time, max(wf_ended - wf_started) as max_time
 241                  from ".GALAXIA_TABLE_PREFIX."instances where wf_p_id in (" . join(', ', array_keys($ret)) . ") group by wf_p_id, wf_status";
 242        $result = $this->query($query);
 243        while($res = $result->fetchRow()) {
 244          $pId = $res['wf_p_id'];
 245          if (!isset($ret[$pId])) continue;
 246          switch ($res['wf_status']) {
 247            case 'active':
 248              $ret[$pId]['active_instances'] = $res['num_instances'];
 249              $ret[$pId]['all_instances'] += $res['num_instances'];
 250              break;
 251            case 'completed':
 252              $ret[$pId]['completed_instances'] = $res['num_instances'];
 253              $ret[$pId]['all_instances'] += $res['num_instances'];
 254              $ret[$pId]['duration'] = array('min' => $res['min_time'], 'avg' => $res['avg_time'], 'max' => $res['max_time']);
 255              break;
 256            case 'exception':
 257              $ret[$pId]['exception_instances'] = $res['num_instances'];
 258              $ret[$pId]['all_instances'] += $res['num_instances'];
 259              break;
 260            case 'aborted':
 261              $ret[$pId]['aborted_instances'] = $res['num_instances'];
 262              $ret[$pId]['all_instances'] += $res['num_instances'];
 263              break;
 264          }
 265        }
 266        // get number of activities per process
 267        $query = "select wf_p_id, count(*) as num_activities
 268                  from ".GALAXIA_TABLE_PREFIX."activities
 269                  where wf_p_id in (" . join(', ', array_keys($ret)) . ")
 270                  group by wf_p_id";
 271        $result = $this->query($query);
 272        while($res = $result->fetchRow()) {
 273          $pId = $res['wf_p_id'];
 274          if (!isset($ret[$pId])) continue;
 275          $ret[$pId]['activities'] = $res['num_activities'];
 276        }
 277      }
 278      $retval = Array();
 279      $retval["data"] = $ret;
 280      $retval["cant"] = $cant;
 281      return $retval;
 282    }
 283  
 284    /*! list all activities
 285    * List all activities and return stats
 286    * @param $offset is the first row number to return
 287    * @param $maxRecords is the maximumnumber of records to return
 288    * @param $sort_mode is the sort order
 289    * @param $find is a string to search for in activity name or activity description
 290    * @param $where is a string to ad to the query, be carefull with this string, read the query before
 291    * @param $add_stats is true by default, by setting it to false you wont get the statistics associated with
 292    * the activities, this could be helpfull for gui listing on selects, to avoid (a big number of) unnecessary queries
 293    * @return an associative array with the number of records for the 'cant' key and an array of process stats for the 
 294    * 'data' key. each row is of this form:
 295    *    * key : activity_id
 296    *    * value : an array of infos:, 
 297    *        * keys are : wf_procname, wf_version, wf_activity_id, wf_name, wf_normalized_name, wf_p_id, wf_type
 298    *        wf_is_autorouted, wf_flow_num, wf_is_interactive, wf_last_modif, wf_description, wf_default_user
 299    *        and for the stats part: active_instances, completed_instances ,aborted_instances, exception_instances
 300    *        act_running_instances, act_completed_instances
 301    */
 302    function monitor_list_activities($offset,$maxRecords,$sort_mode,$find,$where='', $add_stats=true) 
 303    {
 304    
 305      $sort_mode = $this->convert_sortmode($sort_mode);
 306      if($find) {
 307        $findesc = '%'.$find.'%';
 308        $mid=" where ((ga.wf_name like ?) or (ga.wf_description like ?))";
 309        $bindvars = array($findesc,$findesc);
 310      } else {
 311        $mid="";
 312        $bindvars = array();
 313      }
 314      if($where) {
 315        $where = preg_replace('/pId/', 'ga.wf_p_id', $where);
 316        if($mid) {
 317          $mid.= " and ($where) ";
 318        } else {
 319          $mid.= " where ($where) ";
 320        }
 321      }
 322      $query = "select gp.`wf_name` as `wf_procname`, gp.`wf_version`, ga.*
 323                from ".GALAXIA_TABLE_PREFIX."activities ga
 324                  left join ".GALAXIA_TABLE_PREFIX."processes gp on gp.wf_p_id=ga.wf_p_id
 325                $mid order by $sort_mode";
 326      $query_cant = "select count(*) from ".GALAXIA_TABLE_PREFIX."activities ga $mid";
 327      $result = $this->query($query,$bindvars,$maxRecords,$offset);
 328      $cant = $this->getOne($query_cant,$bindvars);
 329      $ret = Array();
 330      while($res = $result->fetchRow()) {
 331        // Number of active instances
 332        $aid = $res['wf_activity_id'];
 333        if ($add_stats)
 334        {
 335          $res['active_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gi.wf_status='active' and wf_p_id=".$res['wf_p_id']);
 336        // activities of completed instances are all removed from the instance_activities table for some reason, so we need to look at workitems
 337          $res['completed_instances']=$this->getOne("select count(distinct gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."workitems gw where gi.wf_instance_id=gw.wf_instance_id and gw.wf_activity_id=$aid and gi.wf_status='completed' and wf_p_id=".$res['wf_p_id']);
 338        // activities of aborted instances are all removed from the instance_activities table for some reason, so we need to look at workitems
 339          $res['aborted_instances']=$this->getOne("select count(distinct gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."workitems gw where gi.wf_instance_id=gw.wf_instance_id and gw.wf_activity_id=$aid and gi.wf_status='aborted' and wf_p_id=".$res['wf_p_id']);
 340          $res['exception_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gi.wf_status='exception' and wf_p_id=".$res['wf_p_id']);
 341          $res['act_running_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.wf_activity_id=$aid and gia.wf_status='running' and wf_p_id=".$res['wf_p_id']);      
 342        // completed activities are removed from the instance_activities table unless they're part of a split for some reason, so this won't work
 343        //  $res['act_completed_instances']=$this->getOne("select count(gi.wf_instance_id) from ".GALAXIA_TABLE_PREFIX."instances gi,".GALAXIA_TABLE_PREFIX."instance_activities gia where gi.wf_instance_id=gia.wf_instance_id and gia.activityId=$aid and gia.status='completed' and pId=".$res['pId']);      
 344          $res['act_completed_instances'] = 0;
 345        }
 346        $ret[$aid] = $res;
 347      }
 348      if (count($ret) < 1) {
 349        $retval = Array();
 350        $retval["data"] = $ret;
 351        $retval["cant"] = $cant;
 352        return $retval;
 353      }
 354      if ($add_stats)
 355      {
 356        $query = "select wf_activity_id, count(distinct wf_instance_id) as num_instances, min(wf_ended - wf_started) as min_time, avg(wf_ended - wf_started) as avg_time, max(wf_ended - wf_started) as max_time
 357                  from ".GALAXIA_TABLE_PREFIX."workitems
 358                  where wf_activity_id in (" . join(', ', array_keys($ret)) . ")
 359                  group by wf_activity_id";
 360        $result = $this->query($query);
 361        while($res = $result->fetchRow()) {
 362          // Number of active instances
 363          $aid = $res['wf_activity_id'];
 364          if (!isset($ret[$aid])) continue;
 365          $ret[$aid]['act_completed_instances'] = $res['num_instances'] - $ret[$aid]['aborted_instances'];
 366          $ret[$aid]['duration'] = array('min' => $res['min_time'], 'avg' => $res['avg_time'], 'max' => $res['max_time']);
 367        }
 368      }
 369      $retval = Array();
 370      $retval["data"] = $ret;
 371      $retval["cant"] = $cant;
 372      return $retval;
 373    }
 374  
 375    //! list all instances
 376    function monitor_list_instances($offset,$maxRecords,$sort_mode,$find,$where='', $addstats=true) 
 377    {
 378      $wherevars = array();
 379      if($find) {
 380        $findesc = $this->qstr('%'.$find.'%');
 381        $mid=' where ((`wf_properties` like ?) or (gi.`wf_name` like ?)
 382          or (ga.`wf_name` like ?) or (gp.`wf_name` like ?))';
 383          $wherevars[] = $findesc;
 384          $wherevars[] = $findesc;
 385          $wherevars[] = $findesc;
 386          $wherevars[] = $findesc;
 387      } else {
 388        $mid='';
 389      }
 390      if($where) {
 391        if($mid) {
 392          $mid.= " and ($where) ";
 393        } else {
 394          $mid.= " where ($where) ";
 395        }
 396      }
 397  
 398      $query = 'select gp.`wf_p_id`, ga.`wf_is_interactive`, gi.`wf_owner`, gp.`wf_name` as `wf_procname`, gp.`wf_version`, ga.`wf_type`,';
 399      $query.= ' ga.`wf_activity_id`, ga.`wf_name` as `wf_activity_name`, gi.`wf_instance_id`, gi.`wf_name` as `wf_instance_name`, gi.`wf_status`, gia.`wf_activity_id`, gia.`wf_user`, gi.`wf_started`, gi.`wf_ended`, gia.`wf_status` as wf_act_status ';
 400      $query.= ' from `'.GALAXIA_TABLE_PREFIX.'instances` gi LEFT JOIN `'.GALAXIA_TABLE_PREFIX.'instance_activities` gia ON gi.`wf_instance_id`=gia.`wf_instance_id` ';
 401      $query.= 'LEFT JOIN `'.GALAXIA_TABLE_PREFIX.'activities` ga ON gia.`wf_activity_id` = ga.`wf_activity_id` ';
 402      $query.= 'LEFT JOIN `'.GALAXIA_TABLE_PREFIX."processes` gp ON gp.`wf_p_id`=gi.`wf_p_id` $mid";
 403  
 404      $query_cant = 'select count(*) from `'.GALAXIA_TABLE_PREFIX.'instances` gi LEFT JOIN `'.GALAXIA_TABLE_PREFIX.'instance_activities` gia ON gi.`wf_instance_id`=gia.`wf_instance_id` ';
 405      $query_cant.= 'LEFT JOIN `'.GALAXIA_TABLE_PREFIX.'activities` ga ON gia.`wf_activity_id` = ga.`wf_activity_id` LEFT JOIN `'.GALAXIA_TABLE_PREFIX."processes` gp ON gp.`wf_p_id`=gi.`wf_p_id` $mid";
 406      $result = $this->query($query,$wherevars,$maxRecords,$offset,true,$this->convert_sortmode($sort_mode));
 407      $cant = $this->getOne($query_cant,$wherevars);
 408      $ret = Array();
 409      while($res = $result->fetchRow()) {
 410        $iid = $res['wf_instance_id'];
 411        $res['workitems']=$this->getOne('select count(*) from `'.GALAXIA_TABLE_PREFIX.'workitems` where `wf_instance_id`=?',array($iid));
 412        $ret[$iid] = $res;
 413      }
 414      $retval = Array();
 415      $retval['data'] = $ret;
 416      $retval['cant'] = $cant;
 417      return $retval;
 418    }
 419  
 420    //! list all processes
 421    function monitor_list_all_processes($sort_mode = 'wf_name_asc', $where = '') {
 422      if (!empty($where)) {
 423        $where = " where ($where) ";
 424      }
 425      $query = "select `wf_name`,`wf_version`,`wf_p_id` from `".GALAXIA_TABLE_PREFIX."processes` $where order by ".$this->convert_sortmode($sort_mode);
 426      $result = $this->query($query);
 427      $ret = Array();
 428      while($res = $result->fetchRow()) {
 429        $pId = $res['wf_p_id'];
 430        $ret[$pId] = $res;
 431      }
 432      return $ret;
 433    }
 434    
 435    //! list all activities
 436    function monitor_list_all_activities($sort_mode = 'wf_name_asc', $where = '') {
 437      if (!empty($where)) {
 438        $where = " where ($where) ";
 439      }
 440      $query = "select `wf_name`,`wf_activity_id` from `".GALAXIA_TABLE_PREFIX."activities` $where order by ".$this->convert_sortmode($sort_mode);
 441      $result = $this->query($query);
 442      $ret = Array();
 443      while($res = $result->fetchRow()) {
 444        $aid = $res['wf_activity_id'];
 445        $ret[$aid] = $res;
 446      }
 447      return $ret;
 448    }
 449    
 450    //! list instances status we have in the database. 
 451    function monitor_list_statuses() {
 452      $query = "select distinct(`wf_status`) from `".GALAXIA_TABLE_PREFIX."instances`";
 453      $result = $this->query($query);
 454      $ret = Array();
 455      while($res = $result->fetchRow()) {
 456        $ret[] = $res['wf_status'];
 457      }
 458      return $ret;
 459    }
 460    
 461    //! list all users associated with instances avaible in the actual database
 462    function monitor_list_users() {
 463      $query = "select distinct(`wf_user`) from `".GALAXIA_TABLE_PREFIX."instance_activities`";
 464      $result = $this->query($query);
 465      $ret = Array();
 466      while($res = $result->fetchRow()) {
 467        $ret[] = $res['wf_user'];
 468      }
 469      return $ret;
 470    }
 471  
 472    //! list all user associated with workitems avaible in the actual database
 473    function monitor_list_wi_users() {
 474      $query = "select distinct(`wf_user`) from `".GALAXIA_TABLE_PREFIX."workitems`";
 475      $result = $this->query($query);
 476      $ret = Array();
 477      while($res = $result->fetchRow()) {
 478        $ret[] = $res['wf_user'];
 479      }
 480      return $ret;
 481    }
 482  
 483    //! list all intance owner we have in the actual databse
 484    function monitor_list_owners() {
 485      $query = "select distinct(`wf_owner`) from `".GALAXIA_TABLE_PREFIX."instances`";
 486      $result = $this->query($query);
 487      $ret = Array();
 488      while($res = $result->fetchRow()) {
 489        $ret[] = $res['wf_owner'];
 490      }
 491      return $ret;
 492    }
 493    
 494    //! list all activity types we have in the actual database (used activity types)
 495    function monitor_list_activity_types() {
 496      $query = "select distinct(`wf_type`) from `".GALAXIA_TABLE_PREFIX."activities`";
 497      $result = $this->query($query);
 498      $ret = Array();
 499      while($res = $result->fetchRow()) {
 500        $ret[] = $res['wf_type'];
 501      }
 502      return $ret;  
 503    }
 504    
 505    //! return an array containing information about a given workitem
 506    /*!
 507    * @param itemId is the workitem Id
 508    */
 509    function monitor_get_workitem($itemId) {
 510      $query = "select gw.`wf_order_id`,ga.`wf_name`,ga.`wf_type`,ga.`wf_is_interactive`,gp.`wf_name` as `wf_wf_procname`,gp.`wf_version`,";
 511      $query.= "gw.`wf_item_id`,gw.`wf_properties`,gw.`wf_user`,`wf_started`,`wf_ended`-`wf_started` as wf_duration ";
 512      $query.= "from `".GALAXIA_TABLE_PREFIX."workitems` gw,`".GALAXIA_TABLE_PREFIX."activities` ga,`".GALAXIA_TABLE_PREFIX."processes` gp where ga.`wf_activity_id`=gw.`wf_activity_id` and ga.`wf_p_id`=gp.`wf_p_id` and `wf_item_id`=?";
 513      $result = $this->query($query, array($itemId));
 514      $res = $result->fetchRow();
 515      $res['wf_properties'] = unserialize($res['wf_properties']);
 516      return $res;
 517    }
 518  
 519    //! List workitems per instance 
 520    /*!
 521    *
 522    */
 523    function monitor_list_workitems($offset,$maxRecords,$sort_mode,$find,$where='',$wherevars=array()) {
 524      $mid = '';
 525      if ($where) {
 526        $mid.= " and ($where) ";
 527      }
 528      if($find) {
 529        $findesc = $this->qstr('%'.$find.'%');
 530        $mid.=" and ((`wf_properties` like $findesc) or (gp.wf_name like $findesc) or (ga.wf_name like $findesc))";
 531      }
 532  // TODO: retrieve instance status as well
 533      $query = 'select wf_item_id,wf_ended-wf_started as wf_duration,ga.wf_is_interactive, ga.wf_type,gp.wf_name as wf_procname,gp.wf_version,ga.wf_name as wf_act_name,';
 534      $query.= 'ga.wf_activity_id,wf_instance_id,wf_order_id,wf_properties,wf_started,wf_ended,wf_user';
 535      $query.= ' from '.GALAXIA_TABLE_PREFIX.'workitems gw,'.GALAXIA_TABLE_PREFIX.'activities ga,'.GALAXIA_TABLE_PREFIX.'processes gp';
 536      $query.= ' where gw.wf_activity_id=ga.wf_activity_id and ga.wf_p_id=gp.wf_p_id '.$mid.' order by '.$this->convert_sortmode($sort_mode);
 537      $query_cant = "select count(*) from `".GALAXIA_TABLE_PREFIX."workitems` gw,`".GALAXIA_TABLE_PREFIX."activities` ga,`".GALAXIA_TABLE_PREFIX."processes` gp where gw.`wf_activity_id`=ga.`wf_activity_id` and ga.`wf_p_id`=gp.`wf_p_id` $mid";
 538      $result = $this->query($query,$wherevars,$maxRecords,$offset);
 539      $cant = $this->getOne($query_cant,$wherevars);
 540      $ret = Array();
 541      while($res = $result->fetchRow()) {
 542        $itemId = $res['wf_item_id'];
 543        $ret[$itemId] = $res;
 544      }
 545      $retval = Array();
 546      $retval["data"] = $ret;
 547      $retval["cant"] = $cant;
 548      return $retval;
 549    }
 550    
 551  
 552  }
 553  ?>


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