Exemplo n.º 1
0
 static function getArrayInfo($raw_data, $full = false)
 {
     $desc = "";
     if ($full) {
         if (config_option("wysiwyg_tasks")) {
             if ($raw_data['type_content'] == "text") {
                 $desc = nl2br(htmlspecialchars($raw_data['text']));
             } else {
                 $desc = purify_html(nl2br($raw_data['text']));
             }
         } else {
             if ($raw_data['type_content'] == "text") {
                 $desc = htmlspecialchars($raw_data['text']);
             } else {
                 $desc = html_to_text(html_entity_decode(nl2br($raw_data['text']), null, "UTF-8"));
             }
         }
     }
     $member_ids = ObjectMembers::instance()->getCachedObjectMembers($raw_data['id']);
     $tmp_task = new ProjectTask();
     $tmp_task->setObjectId($raw_data['id']);
     $tmp_task->setId($raw_data['id']);
     $tmp_task->setAssignedToContactId($raw_data['assigned_to_contact_id']);
     $result = array('id' => (int) $raw_data['id'], 'name' => $raw_data['name'], 'description' => $desc, 'members' => $member_ids, 'createdOn' => strtotime($raw_data['created_on']), 'createdById' => (int) $raw_data['created_by_id'], 'otype' => $raw_data['object_subtype'], 'percentCompleted' => (int) $raw_data['percent_completed'], 'memPath' => str_replace('"', "'", escape_character(json_encode($tmp_task->getMembersIdsToDisplayPath()))));
     if (isset($raw_data['isread'])) {
         $result['isread'] = $raw_data['isread'];
     }
     $result['multiAssignment'] = (int) array_var($raw_data, 'multi_assignment');
     if ($raw_data['completed_by_id'] > 0) {
         $result['status'] = 1;
     }
     if ($raw_data['parent_id'] > 0) {
         $result['parentId'] = (int) $raw_data['parent_id'];
     }
     $result['subtasksIds'] = $tmp_task->getSubTasksIds();
     //if ($this->getPriority() != 200)
     $result['priority'] = (int) $raw_data['priority'];
     if ($raw_data['milestone_id'] > 0) {
         $result['milestoneId'] = (int) $raw_data['milestone_id'];
     }
     if ($raw_data['assigned_by_id'] > 0) {
         $result['assignedById'] = (int) $raw_data['assigned_by_id'];
     }
     if ($raw_data['assigned_to_contact_id'] > 0) {
         $result['assignedToContactId'] = (int) $raw_data['assigned_to_contact_id'];
     }
     $result['atName'] = $tmp_task->getAssignedToName();
     if ($raw_data['completed_by_id'] > 0) {
         $result['completedById'] = (int) $raw_data['completed_by_id'];
         $result['completedOn'] = strtotime($raw_data['completed_on']);
     }
     if ($raw_data['due_date'] != EMPTY_DATETIME) {
         $result['useDueTime'] = $raw_data['use_due_time'] ? 1 : 0;
         if ($result['useDueTime']) {
             $result['dueDate'] = strtotime($raw_data['due_date']) + logged_user()->getTimezone() * 3600;
         } else {
             $result['dueDate'] = strtotime($raw_data['due_date']);
         }
     }
     if ($raw_data['start_date'] != EMPTY_DATETIME) {
         $result['useStartTime'] = $raw_data['use_start_time'] ? 1 : 0;
         if ($result['useStartTime']) {
             $result['startDate'] = strtotime($raw_data['start_date']) + logged_user()->getTimezone() * 3600;
         } else {
             $result['startDate'] = strtotime($raw_data['start_date']);
         }
     }
     $time_estimate = $raw_data['time_estimate'];
     $result['timeEstimate'] = $raw_data['time_estimate'];
     if ($time_estimate > 0) {
         $result['timeEstimateString'] = str_replace(',', ',<br>', DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($time_estimate * 60), 'hm', 60));
     }
     $result['timeZone'] = logged_user()->getTimezone() * 3600;
     $ot = $tmp_task->getOpenTimeslots();
     if ($ot) {
         $users = array();
         $time = array();
         $paused = array();
         foreach ($ot as $t) {
             if (!$t instanceof Timeslot) {
                 continue;
             }
             $time[] = $t->getSeconds();
             $users[] = $t->getContactId();
             $paused[] = $t->isPaused() ? 1 : 0;
             if ($t->isPaused() && $t->getContactId() == logged_user()->getId()) {
                 $result['pauseTime'] = $t->getPausedOn()->getTimestamp();
             }
         }
         $result['workingOnTimes'] = $time;
         $result['workingOnIds'] = $users;
         $result['workingOnPauses'] = $paused;
     }
     $total_minutes = $tmp_task->getTotalMinutes();
     if ($total_minutes > 0) {
         $result['worked_time'] = $total_minutes;
         $result['worked_time_string'] = str_replace(',', ',<br>', DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($total_minutes * 60), 'hm', 60));
     } else {
         $result['worked_time'] = 0;
     }
     $pending_time = $time_estimate - $total_minutes;
     if ($pending_time > 0) {
         $result['pending_time'] = $pending_time;
         $result['pending_time_string'] = str_replace(',', ',<br>', DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($pending_time * 60), 'hm', 60));
     } else {
         $result['pending_time'] = 0;
     }
     if ($raw_data['repeat_forever'] > 0 || $raw_data['repeat_num'] > 0 || $raw_data['repeat_end'] != EMPTY_DATETIME && $raw_data['repeat_end'] != '') {
         $result['repetitive'] = 1;
     }
     $tmp_members = array();
     if (count($member_ids) > 0) {
         $tmp_members = Members::findAll(array("conditions" => "id IN (" . implode(',', $member_ids) . ")"));
     }
     $result['can_add_timeslots'] = can_add_timeslots(logged_user(), $tmp_members);
     //tasks dependencies
     if (config_option('use tasks dependencies')) {
         //get all dependant tasks ids, not completed yet
         $pending_tasks_ids = ProjectTaskDependencies::getDependenciesForTaskOnlyPendingIds($tmp_task->getId());
         //get the total of previous tasks
         $result['dependants'] = $pending_tasks_ids;
         $result['previous_tasks_total'] = ProjectTaskDependencies::countPendingPreviousTasks($tmp_task->getId());
     }
     return $result;
 }
Exemplo n.º 2
0
 function canAddTimeslot($user)
 {
     return can_add_timeslots($user, $this->getMembers());
 }