示例#1
0
文件: task.php 项目: nemein/openpsa
 /**
  * Queries status objects and sets correct value to $this->status
  */
 private function _get_status()
 {
     $return = array('status_comment' => '', 'status_time' => false);
     //Simplistic approach
     $mc = org_openpsa_projects_task_status_dba::new_collector('task', $this->id);
     $mc->add_value_property('type');
     $mc->add_value_property('comment');
     $mc->add_value_property('timestamp');
     if ($this->status > org_openpsa_projects_task_status_dba::PROPOSED) {
         //Only get proposed status objects here if are not over that phase
         $mc->add_constraint('type', '<>', org_openpsa_projects_task_status_dba::PROPOSED);
     }
     if (count($this->resources) > 0) {
         //Do not ever set status to declined if we still have resources left
         $mc->add_constraint('type', '<>', org_openpsa_projects_task_status_dba::DECLINED);
     }
     $mc->add_order('timestamp', 'DESC');
     $mc->add_order('type', 'DESC');
     //Our timestamps are not accurate enough so if we have multiple with same timestamp suppose highest type is latest
     $mc->set_limit(1);
     $mc->execute();
     $ret = $mc->list_keys();
     if (!is_array($ret) || count($ret) == 0) {
         //Failure to get status object
         //Default to last status if available
         debug_add('Could not find any status objects, defaulting to previous status');
         return $return;
     }
     $main_ret = key($ret);
     $type = $mc->get_subkey($main_ret, 'type');
     //Update the status cache if necessary
     if ($this->status != $type) {
         $this->status = $type;
         $this->update();
     }
     //TODO: Check various combinations of accept/decline etc etc
     $comment = $mc->get_subkey($main_ret, 'comment');
     $return['status_comment'] = $comment;
     $timestamp = $mc->get_subkey($main_ret, 'timestamp');
     $return['status_time'] = $timestamp;
     return $return;
 }