Example #1
0
 /**
  * Return the version of OG currently installed MaestroOgCommon::OG_VERSION_1 or OG_VERSION_2
  * @return type
  */
 public static function getOGVersion()
 {
     if (self::$ogVersion === NULL) {
         self::$ogVersion = function_exists('og_get_group') ? MaestroOgCommon::OG_VERSION_1 : MaestroOgCommon::OG_VERSION_2;
     }
     return self::$ogVersion;
 }
 function getQueue($show_system_tasks = FALSE)
 {
     if (!empty($this->_userId) and $this->_userId > 0) {
         /* Instance where the user id is known.  need to see if there is a processID given.
          * This means that the mode in which we're working is user based.. we only care about a user in this case
          */
         $queries = array();
         //query to get the user assigned to this task
         if ($this->_mode != 'admin') {
             $this->_mode = 'user';
         }
         if ($this->_debug) {
             watchdog('maestro', "Entering getQueue - {$this->_mode} mode");
         }
         $this->_userTaskCount = 0;
         $query = db_select('maestro_queue', 'a');
         $query->join('maestro_template_data', 'b', 'a.template_data_id = b.id');
         $query->leftJoin('maestro_production_assignments', 'c', 'a.id = c.task_id');
         $query->join('maestro_process', 'd', 'a.process_id = d.id');
         $query->fields('a', array('id', 'template_data_id', 'process_id', 'is_interactive', 'handler', 'task_data', 'created_date', 'started_date'));
         $query->fields('b', array('task_class_name', 'template_id', 'taskname', 'is_dynamic_taskname', 'dynamic_taskname_variable_id'));
         if ($this->_mode == 'admin') {
             $query->fields('c', array('assign_id', 'assign_type'));
             $query->fields('e', array('name'));
             $query->leftJoin('users', 'e', 'c.assign_id = e.uid');
         }
         $query->addField('d', 'pid', 'parent_process_id');
         $query->fields('d', array('tracking_id', 'flow_name'));
         if ($this->_mode != 'admin') {
             $query->condition('c.assign_id', $this->_userId, '=');
         }
         if ($show_system_tasks == FALSE) {
             $query->condition('a.is_interactive', MaestroInteractiveFlag::IS_INTERACTIVE);
         }
         $query->condition(db_or()->condition('a.archived', 0)->condition('a.archived', NULL));
         $query->condition(db_and()->condition('a.status', 0, '>='));
         $query->condition('c.assign_type', MaestroAssignmentTypes::USER, '=');
         $query->orderBy('a.id', 'DESC');
         $queries[MaestroAssignmentTypes::USER] = $query;
         //query to get the users associated with a role assigned to this task
         $query = db_select('maestro_queue', 'a');
         $query->join('maestro_template_data', 'b', 'a.template_data_id = b.id');
         $query->leftJoin('maestro_production_assignments', 'c', 'a.id = c.task_id');
         $query->join('maestro_process', 'd', 'a.process_id = d.id');
         $query->leftJoin('users_roles', 'f', 'c.assign_id = f.rid');
         $query->fields('a', array('id', 'template_data_id', 'process_id', 'is_interactive', 'handler', 'task_data', 'created_date', 'started_date'));
         $query->fields('b', array('task_class_name', 'template_id', 'taskname', 'is_dynamic_taskname', 'dynamic_taskname_variable_id'));
         if ($this->_mode == 'admin') {
             $query->fields('c', array('assign_id', 'assign_type'));
             $query->fields('g', array('name'));
             $query->leftJoin('users', 'e', 'f.uid = e.uid');
             $query->leftJoin('role', 'g', 'c.assign_id = g.rid');
         }
         $query->addField('d', 'pid', 'parent_process_id');
         $query->fields('d', array('tracking_id', 'flow_name'));
         if ($this->_mode != 'admin') {
             $query->condition('f.uid', $this->_userId, '=');
         }
         if ($show_system_tasks == FALSE) {
             $query->condition('a.is_interactive', MaestroInteractiveFlag::IS_INTERACTIVE);
         }
         $query->condition(db_or()->condition('a.archived', 0)->condition('a.archived', NULL));
         $query->condition(db_and()->condition('a.status', 0, '>='));
         $query->condition('c.assign_type', MaestroAssignmentTypes::ROLE, '=');
         $query->orderBy('a.id', 'DESC');
         $queries[MaestroAssignmentTypes::ROLE] = $query;
         if (module_exists('og')) {
             //query gets all og's assigned to this task, up to the logic to determine whether or not they are assigned
             $query = db_select('maestro_queue', 'a');
             $query->join('maestro_template_data', 'b', 'a.template_data_id = b.id');
             $query->leftJoin('maestro_production_assignments', 'c', 'a.id = c.task_id');
             $query->join('maestro_process', 'd', 'a.process_id = d.id');
             $query->leftJoin('users_roles', 'f', 'c.assign_id = f.rid');
             $query->fields('a', array('id', 'template_data_id', 'process_id', 'is_interactive', 'handler', 'task_data', 'created_date', 'started_date'));
             $query->fields('b', array('task_class_name', 'template_id', 'taskname', 'is_dynamic_taskname', 'dynamic_taskname_variable_id'));
             $query->fields('c', array('assign_id', 'assign_type', 'process_variable'));
             if ($this->_mode == 'admin') {
                 $og_values = MaestroOgCommon::getOgTableValues();
                 $query->leftJoin($og_values['table'], 'g', 'c.assign_id = g.' . $og_values['gid_column']);
                 $query->addField('g', $og_values['title_column'], 'name');
             }
             $query->addField('d', 'pid', 'parent_process_id');
             $query->fields('d', array('tracking_id', 'flow_name'));
             if ($show_system_tasks == FALSE) {
                 $query->condition('a.is_interactive', MaestroInteractiveFlag::IS_INTERACTIVE);
             }
             $query->condition(db_or()->condition('a.archived', 0)->condition('a.archived', NULL));
             $query->condition(db_and()->condition('a.status', 0, '>='));
             $query->condition('c.assign_type', MaestroAssignmentTypes::GROUP, '=');
             $query->orderBy('a.id', 'DESC');
             $queries[MaestroAssignmentTypes::GROUP] = $query;
         }
         foreach ($queries as $assign_type => $query) {
             $userTaskResult = $query->execute();
             $numTaskRows = $query->countQuery()->execute()->fetchField();
             if ($numTaskRows > 0) {
                 // Return a semi-colon delimited list of queue id's for that user.
                 foreach ($userTaskResult as $userTaskRecord) {
                     if ($assign_type == MaestroAssignmentTypes::GROUP && $this->_mode != 'admin') {
                         // Test if group name has been set to use a variable for this task
                         if ($userTaskRecord->assign_id == 0 or $userTaskRecord->process_variable > 0) {
                             // The group variable is expected to contain the group name
                             $group_variable = $this->getProcessVariable($userTaskRecord->process_variable, $userTaskRecord->process_id);
                             $og_groups = MaestroOgCommon::getAllGroups();
                             foreach ($og_groups as $og_group) {
                                 if ($og_group->label == $group_variable) {
                                     $userTaskRecord->assign_id = $og_group->gid;
                                 }
                             }
                         }
                         if ($userTaskRecord->assign_id > 0) {
                             if (MaestroOgCommon::getOGVersion() === MaestroOgCommon::OG_VERSION_2) {
                                 $query = db_select("og_membership", "a");
                                 $query->fields("a", array("gid"));
                                 $query->condition("a.gid", $userTaskRecord->assign_id);
                                 $query->condition("a.etid", $this->_userId);
                                 $res = $query->execute()->fetchAssoc();
                                 if (count($res) == 0) {
                                     continue;
                                 }
                             } else {
                                 $og_query = new EntityFieldQuery();
                                 $og_query->entityCondition('entity_type', 'user')->fieldCondition(OG_AUDIENCE_FIELD, 'gid', $userTaskRecord->assign_id, '=');
                                 $og_res = $og_query->execute();
                                 if (!array_key_exists($this->_userId, $og_res['user'])) {
                                     continue;
                                 }
                             }
                         } else {
                             watchdog('maestro', "maestro->getQueue could not resolve the assigned to user id for queue record {$userTaskRecord->id}");
                             break;
                         }
                     }
                     if ($this->_queueId == '') {
                         $this->_queueId = $userTaskRecord->id;
                     } else {
                         $this->_queueId .= ";" . $userTaskRecord->id;
                     }
                     // Simple test to determine if the task ID already exists for this user
                     $flag = 0;
                     for ($flagcntr = 0; $flagcntr <= $this->_userTaskCount; $flagcntr++) {
                         if (isset($this->_userTaskObject[$flagcntr]->queue_id) and $this->_userTaskObject[$flagcntr]->queue_id == $userTaskRecord->id) {
                             $flag = 1;
                         }
                     }
                     if ($flag == 0) {
                         $taskObject = new stdClass();
                         $templatename = db_query("SELECT template_name FROM {maestro_template} WHERE id = :tid", array(':tid' => $userTaskRecord->template_id))->fetchField();
                         // Determine if this task is for a regenerated workflow and we need to update the main project/request record
                         $taskObject->regen = FALSE;
                         if ($userTaskRecord->parent_process_id > 0) {
                             // Now check if this same template task id was executed in the previous process - if so then it is a recycled task
                             // Don't show the re-generated attribute if in this instance of the process we proceed further and are executing new tasks
                             $regenquery = db_select('maestro_queue', 'a');
                             $regenquery->addExpression('COUNT(id)', 'rec_count');
                             $regenquery->condition('a.process_id', $userTaskRecord->parent_process_id, '=');
                             $regenquery->condition(db_and()->condition('a.template_data_id', $userTaskRecord->template_data_id, '='));
                             if ($regenquery->execute()->fetchField() > 0) {
                                 $taskObject->regen = TRUE;
                             }
                         }
                         $queueRecDates = array('created' => $userTaskRecord->created_date, 'started' => $userTaskRecord->started_date);
                         $queueRecFlags = array('is_interactive' => $userTaskRecord->is_interactive);
                         $taskObject->task_data = $userTaskRecord->task_data;
                         $taskObject->queue_id = $userTaskRecord->id;
                         $taskObject->task_id = $userTaskRecord->template_data_id;
                         $taskObject->process_id = $userTaskRecord->process_id;
                         $taskObject->parent_process_id = $userTaskRecord->parent_process_id;
                         $taskObject->template_id = $userTaskRecord->template_id;
                         $taskObject->template_name = $templatename;
                         $taskObject->flow_name = $userTaskRecord->flow_name;
                         $taskObject->tracking_id = $userTaskRecord->tracking_id;
                         $taskObject->url = $userTaskRecord->handler;
                         $taskObject->dates = $queueRecDates;
                         $taskObject->flags = $queueRecFlags;
                         if ($this->_mode == 'admin') {
                             $taskObject->assign_type = $userTaskRecord->assign_type;
                             $taskObject->uid = $userTaskRecord->assign_id;
                             $taskObject->username = $userTaskRecord->name != '' ? $userTaskRecord->name : '[' . t('nobody assigned') . ']';
                         }
                         // Handle dynamic task name based on a variable's value
                         $taskname = '';
                         if ($userTaskRecord->is_dynamic_taskname == 1) {
                             $q2 = db_select('maestro_process_variables', 'a');
                             $q2->addField('a', 'variable_value');
                             $q2->condition('a.process_id', $userTaskRecord->process_id, '=');
                             $q2->condition('a.template_variable_id', $userTaskRecord->dynamic_taskname_variable_id, '=');
                             $res1 = $query->execute()->fetchObject();
                             if ($res1) {
                                 $userTaskRecord->taskname = $res1->variable_value;
                             }
                         }
                         /* @TODO: Need to look at using a module HOOK that can be used in a similar way to define an custom taskname */
                         /*
                         if (function_exists('PLG_Nexflow_taskname')) {
                         $parms = array('pid' => $A['nf_processID'], 'tid' => $A['nf_templateDataID'], 'qid' => $A['id'], 'user' => $this->_nfUserId);
                         if (!empty($taskame)) {
                         $apiRetval = PLG_Nexflow_taskname($parms,$taskname);
                         } else {
                         $apiRetval = PLG_Nexflow_taskname($parms,$A['taskname']);
                         }
                         $taskname = $apiRetval['taskname'];
                         }
                         */
                         $taskObject->taskname = $userTaskRecord->taskname;
                         $taskObject->tasktype = $userTaskRecord->task_class_name;
                         $this->_userTaskObject[$this->_userTaskCount] = $taskObject;
                         $this->_userTaskCount += 1;
                         // Increment the total user task counter
                     }
                 }
             }
         }
     }
     if ($this->_debug) {
         watchdog('maestro', "Exiting getQueue - user mode");
     }
     // Now sort the array of task objects so that the newest task (highest queue_id_) is first
     $sorted = array();
     if (is_array($this->_userTaskObject) and count($this->_userTaskObject) > 0) {
         foreach ($this->_userTaskObject as $task) {
             $sorted[$task->queue_id] = $task;
         }
         krsort($sorted);
     }
     return $sorted;
 }
 function modulateExportOG($group)
 {
     if (module_exists('og')) {
         $og_values = MaestroOgCommon::getOgTableValues();
         $query = db_select($og_values['table'], 'a');
         $query->addField('a', $og_values['gid_column'], 'gid');
         $query->condition('a.' . $og_values['title_column'], $group, '=');
         $gid = current($query->execute()->fetchAll());
         if (is_numeric($gid->gid)) {
             return intval($gid->gid);
         } else {
             //here's the problem... we should return false here so that the import can insert the initiator
             return FALSE;
         }
     }
 }