Example #1
0
 public function testApproveOwnTask()
 {
     $stat = org_openpsa_projects_workflow::approve(self::$_task, 'test comment');
     $this->assertTrue($stat);
     self::$_task->refresh();
     $this->assertEquals(org_openpsa_projects_task_status_dba::CLOSED, self::$_task->status);
     $this->assertEquals('closed', self::$_task->status_type);
     $this->assertEquals('test comment', self::$_task->status_comment);
     $qb = org_openpsa_projects_task_status_dba::new_query_builder();
     $qb->add_constraint('task', '=', self::$_task->id);
     $result = $qb->execute();
     $this->assertEquals(sizeof($result), 2);
     $status = $result[0];
     $this->assertEquals($status->targetPerson, 0);
 }
Example #2
0
 /**
  * Shortcut for creating status object
  *
  * @param org_openpsa_projects_task_dba &$task The task we're working on
  * @param integer $status The status to convert
  * @param integer $target_person The person ID, if any
  * @param string $comment The status comment, if any
  */
 public static function create_status(&$task, $status_type, $target_person = 0, $comment = '')
 {
     debug_print_function_stack('create_status called from: ');
     $status = new org_openpsa_projects_task_status_dba();
     if ($target_person != 0) {
         $status->targetPerson = $target_person;
     }
     $status->task = $task->id;
     $status->type = $status_type;
     //This shouldn't be needed
     $status->timestamp = $status->gmtime();
     $status->comment = $comment;
     $ret = $status->create();
     if (!$ret) {
         debug_add('failed to create status object, errstr: ' . midcom_connection::get_error_string(), MIDCOM_LOG_WARN);
     }
     return $ret;
 }
Example #3
0
 /**
  * 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;
 }
Example #4
0
 /**
  * Support for contacts person merge
  */
 function org_openpsa_contacts_duplicates_merge_person(&$person1, &$person2, $mode)
 {
     switch ($mode) {
         case 'all':
             break;
             /* In theory we could have future things (like resource/manager ships), but now we don't support that mode, we just exit */
         /* In theory we could have future things (like resource/manager ships), but now we don't support that mode, we just exit */
         case 'future':
             return true;
             break;
         default:
             // Mode not implemented
             debug_add("mode {$mode} not implemented", MIDCOM_LOG_ERROR);
             return false;
             break;
     }
     // Transfer links from classes we drive
     // ** resources **
     $qb_member = org_openpsa_projects_task_resource_dba::new_query_builder();
     $qb_member->add_constraint('person', '=', $person2->id);
     $members = $qb_member->execute();
     if ($members === false) {
         // Some error with QB
         debug_add('QB Error', MIDCOM_LOG_ERROR);
         return false;
     }
     // Transfer memberships
     foreach ($members as $member) {
         // TODO: figure out duplicate memberships and delete unneeded ones
         $member->person = $person1->id;
         debug_add("Transferred task resource #{$member->id} to person #{$person1->id} (from #{$member->person})", MIDCOM_LOG_INFO);
         if (!$member->update()) {
             debug_add("Failed to update task resource #{$member->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             return false;
         }
     }
     // ** task statuses **
     $qb_receipt = org_openpsa_projects_task_status_dba::new_query_builder();
     $qb_receipt->add_constraint('targetPerson', '=', $person2->id);
     $receipts = $qb_receipt->execute();
     if ($receipts === false) {
         // Some error with QB
         debug_add('QB Error / status', MIDCOM_LOG_ERROR);
         return false;
     }
     foreach ($receipts as $receipt) {
         debug_add("Transferred task_status #{$receipt->id} to person #{$person1->id} (from #{$receipt->person})", MIDCOM_LOG_INFO);
         $receipt->targetPerson = $person1->id;
         if (!$receipt->update()) {
             // Error updating
             debug_add("Failed to update status #{$receipt->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             return false;
         }
     }
     // ** hour reports **
     $qb_log = org_openpsa_projects_hour_report_dba::new_query_builder();
     $qb_log->add_constraint('person', '=', $person2->id);
     $logs = $qb_log->execute();
     if ($logs === false) {
         // Some error with QB
         debug_add('QB Error / hours', MIDCOM_LOG_ERROR);
         return false;
     }
     foreach ($logs as $log) {
         debug_add("Transferred hour_report #{$log->id} to person #{$person1->id} (from #{$log->person})", MIDCOM_LOG_INFO);
         $log->person = $person1->id;
         if (!$log->update()) {
             // Error updating
             debug_add("Failed to update hour_report #{$log->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             return false;
         }
     }
     // ** Task managers **
     $qb_task = org_openpsa_projects_task_dba::new_query_builder();
     $qb_task->add_constraint('manager', '=', $person2->id);
     $tasks = $qb_task->execute();
     if ($tasks === false) {
         // Some error with QB
         debug_add('QB Error / tasks', MIDCOM_LOG_ERROR);
         return false;
     }
     foreach ($tasks as $task) {
         debug_add("Transferred task #{$task->id} to person #{$person1->id} (from #{$task->person})", MIDCOM_LOG_INFO);
         $task->manager = $person1->id;
         if (!$task->update()) {
             // Error updating
             debug_add("Failed to update task #{$task->id}, errstr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             return false;
         }
     }
     // Transfer metadata dependencies from classes that we drive
     $classes = array('org_openpsa_projects_task_resource_dba', 'org_openpsa_projects_task_status_dba', 'org_openpsa_projects_task_dba', 'org_openpsa_projects_hour_report_dba');
     $metadata_fields = array('creator' => 'guid', 'revisor' => 'guid');
     foreach ($classes as $class) {
         $ret = org_openpsa_contacts_duplicates_merge::person_metadata_dependencies_helper($class, $person1, $person2, $metadata_fields);
         if (!$ret) {
             // Failure updating metadata
             debug_add("Failed to update metadata dependencies in class {$class}, errsrtr: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             return false;
         }
     }
     // All done
     return true;
 }
Example #5
0
 private function _list_task_statuses_between(&$data_array, $person, $from, $to)
 {
     // List user's hour reports
     $qb = org_openpsa_projects_task_status_dba::new_query_builder();
     $qb->add_constraint('timestamp', '>=', $from);
     $qb->add_constraint('timestamp', '<=', $to);
     $qb->begin_group('OR');
     $qb->add_constraint('targetPerson', '=', $person->id);
     $qb->add_constraint('metadata.creator', '=', $person->guid);
     $qb->end_group();
     $task_statuses = $qb->execute();
     foreach ($task_statuses as $task_status) {
         $time = $task_status->timestamp;
         $date = date('Y-m-d', $time);
         if (!array_key_exists($date, $data_array)) {
             $data_array[$date] = array();
         }
         if (!array_key_exists($time, $data_array[$date])) {
             $data_array[$date][$time] = array();
         }
         $data_array[$date][$time][$task_status->guid] = $task_status;
     }
 }
Example #6
0
            $contact = org_openpsa_widgets_contact::get($contact_id);
            echo $contact->show_inline() . " ";
        }
    }
}
if (count($task->contacts) > 0) {
    echo "<h2>" . $data['l10n']->get('contacts') . "</h2>\n";
    foreach ($task->contacts as $contact_id => $display) {
        $contact = org_openpsa_widgets_contact::get($contact_id);
        echo $contact->show();
    }
}
?>
<div class="org_openpsa_helper_box history status">
    <?php 
$qb = org_openpsa_projects_task_status_dba::new_query_builder();
$qb->add_constraint('task', '=', $task->id);
$qb->add_order('timestamp', 'DESC');
$qb->add_order('type', 'DESC');
$ret = $qb->execute();
if (is_array($ret) && count($ret) > 0) {
    echo "<h3>" . $data['l10n']->get('status history') . "</h3>\n";
    echo "<div class=\"current-status {$task->status_type}\">" . $data['l10n']->get('task status') . ': ' . $data['l10n']->get($task->status_type) . "</div>\n";
    echo "<ul>\n";
    $fallback_creator = midcom_db_person::get_cached(1);
    foreach ($ret as $status_change) {
        echo "<li>";
        $status_changer_label = $data['l10n']->get('system');
        $target_person_label = $data['l10n']->get('system');
        if ($status_change->metadata->creator && $status_change->metadata->creator != $fallback_creator->guid) {
            $status_changer = org_openpsa_widgets_contact::get($status_change->metadata->creator);