[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/com_vtiger_workflow/ -> VTTaskQueue.inc (source)

   1  <?php
   2  /*+**********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   ************************************************************************************/
  10      
  11      /**
  12       * Time based Queue of tasks ready for execution.
  13       *
  14       */
  15      class VTTaskQueue{
  16          
  17  		public function __construct($adb){
  18              $this->adb = $adb;
  19          }
  20          
  21          /**
  22           * Queue a task for execution.
  23           *
  24           * @param $taskId The id of the task to queue
  25           * @param $entityId The id of the crm entity the task is assiciated with.
  26           * @param $when The time after which the task should be executed. This is 
  27           *        an optional value with a default value of 0.
  28           */
  29  		public function queueTask($taskId, $entityId, $when=0, $taskContents = false){
  30              $adb = $this->adb;
  31              $adb->pquery('INSERT INTO com_vtiger_workflowtask_queue (task_id, entity_id, do_after, task_contents) VALUES(?, ?, ?, ?)',
  32                                                                  array($taskId, $entityId, $when, $taskContents));
  33              return true;
  34          }
  35          
  36          /**
  37           * Get a list of taskId/entityId pairs ready for execution.
  38           *
  39           * The method fetches task id/entity id where the when timestamp
  40           * is less than the current time when the method was called.
  41           *
  42           * @return A list of pairs of the form array(taskId, entityId)
  43           */
  44  		public function getReadyTasks(){
  45              $adb = $this->adb;
  46              $time = time();
  47              $result = $adb->pquery('SELECT task_id, entity_id, task_contents FROM com_vtiger_workflowtask_queue WHERE do_after<?', array($time));
  48              $it =  new SqlResultIterator($adb, $result);
  49              $arr = array();
  50              foreach($it as $row){
  51                  $arr[]=array($row->task_id, $row->entity_id, $row->task_contents);
  52              }
  53              $adb->pquery("delete from com_vtiger_workflowtask_queue where do_after<?", array($time));
  54              return $arr;
  55          }
  56          
  57      }
  58  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1