Пример #1
0
	static function getArrayInfo($raw_data, $full = false){
		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' => $raw_data['id'],
			't' => $raw_data['name'],
			'desc' => $desc,
			'members' => $member_ids,
			'c' => strtotime($raw_data['created_on']),
			'cid' => (int)$raw_data['created_by_id'],
			'otype' => $raw_data['object_subtype'],
			'pc' => (int)$raw_data['percent_completed'],
			'memPath' => str_replace('"',"'", str_replace("'", "\'", json_encode($tmp_task->getMembersToDisplayPath($member_ids))))
		);

		if ($full) {
			$result['description'] = $raw_data['text'];
		}

		$result['mas'] = (int)array_var($raw_data, 'multi_assignment');
			
		if ($raw_data['completed_by_id'] > 0) {
			$result['s'] = 1;
		}
			
		if ($raw_data['parent_id'] > 0) {
			$result['pid'] = (int)$raw_data['parent_id'];
		}
		//if ($this->getPriority() != 200)
		$result['pr'] = (int)$raw_data['priority'];

		if ($raw_data['milestone_id'] > 0) {
			$result['mid'] = (int)$raw_data['milestone_id'];
		}
			
		if ($raw_data['assigned_to_contact_id'] > 0) {
			$result['atid'] = (int)$raw_data['assigned_to_contact_id'];
		}
		$result['atName'] = $tmp_task->getAssignedToName();

		if ($raw_data['completed_by_id'] > 0) {
			$result['cbid'] = (int)$raw_data['completed_by_id'];
			$result['con'] = strtotime($raw_data['completed_on']);;
		}
			
		if ($raw_data['due_date'] != EMPTY_DATETIME) {
			$result['dd'] = strtotime($raw_data['due_date']) + logged_user()->getTimezone() * 3600;
			$result['udt'] = $raw_data['use_due_time'] ? 1 : 0;
		}
		if ($raw_data['start_date'] != EMPTY_DATETIME) {
			$result['sd'] = strtotime($raw_data['start_date']) + logged_user()->getTimezone() * 3600;
			$result['ust'] = $raw_data['use_start_time'] ? 1 : 0;
		}

		$time_estimate = $raw_data['time_estimate'];
		$result['te'] = $raw_data['time_estimate'];
		if ($time_estimate > 0) $result['et'] = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($time_estimate * 60), 'hm', 60) ;


		$result['tz'] = 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['wpt'] = $t->getPausedOn()->getTimestamp();
				}
			}
			$result['wt'] = $time;
			$result['wid'] = $users;
			$result['wp'] = $paused;
		}

		if ($raw_data['repeat_forever'] > 0 || $raw_data['repeat_num'] > 0 || $raw_data['repeat_end'] != EMPTY_DATETIME) {
			$result['rep'] = 1;
		}
		
		return $result;
	}
Пример #2
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;
 }
Пример #3
0
 if ($event['due_date'] != EMPTY_DATETIME) {
     $due_date = new DateTimeValue(strtotime($event['due_date']) + logged_user()->getTimezone() * 3600);
     if ($dtv->getTimestamp() == mktime(0, 0, 0, $due_date->getMonth(), $due_date->getDay(), $due_date->getYear())) {
         $end_of_task = true;
     }
 }
 if ($event['start_date'] != EMPTY_DATETIME) {
     $start_date = new DateTimeValue(strtotime($event['start_date']) + logged_user()->getTimezone() * 3600);
     if ($dtv->getTimestamp() == mktime(0, 0, 0, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear())) {
         $start_of_task = true;
     }
 }
 if ($start_of_task || $end_of_task) {
     $task = new ProjectTask();
     $task->setFromAttributes($event);
     $task->setId($event['id']);
     $task->setNew(false);
     if ($start_of_task && $end_of_task) {
         $tip_title = lang('task');
         $ico = "ico-task";
         $tip_pre = '';
     } else {
         if ($end_of_task) {
             $tip_title = lang('end of task');
             $ico = "ico-task-end";
             $tip_pre = 'end_';
         } else {
             $tip_title = lang('start of task');
             $ico = "ico-task-start";
             $tip_pre = 'st_';
         }
Пример #4
0
function replicateRepetitiveTaskForCalendar(ProjectTask $task, $from_date, $to_date)
{
    $new_task_array = array($task);
    if ($task->isRepetitive()) {
        $res = forwardRepDate($task, $from_date);
        $ref_date = $res['date'];
        $top_repeat_num = $task->getRepeatNum() - $res['count'];
        $last_repeat = $task->getRepeatEnd() instanceof DateTimeValue ? new DateTimeValue($task->getRepeatEnd()->getTimestamp()) : null;
        if ($task->getRepeatNum() > 0 && $top_repeat_num <= 0 || $last_repeat instanceof DateTimeValue && $last_repeat->getTimestamp() < $ref_date->getTimestamp()) {
            return array();
        }
        $num_repetitions = 0;
        while ($ref_date->getTimestamp() < $to_date->getTimestamp()) {
            if ($task->getRepeatBy() == 'start_date' && !$task->getStartDate() instanceof DateTimeValue) {
                return $new_task_array;
            }
            if ($task->getRepeatBy() == 'due_date' && !$task->getDueDate() instanceof DateTimeValue) {
                return $new_task_array;
            }
            if ($task->getRepeatBy() == 'start_date') {
                $diff = $ref_date->getTimestamp() - $task->getStartDate()->getTimestamp();
                $task->setStartDate(new DateTimeValue($ref_date->getTimestamp()));
                if ($task->getDueDate() instanceof DateTimeValue) {
                    $task->getDueDate()->advance($diff);
                }
            } else {
                if ($task->getRepeatBy() == 'due_date') {
                    $diff = $ref_date->getTimestamp() - $task->getDueDate()->getTimestamp();
                    $task->setDueDate(new DateTimeValue($ref_date->getTimestamp()));
                    if ($task->getStartDate() instanceof DateTimeValue) {
                        $task->getStartDate()->advance($diff);
                    }
                }
            }
            $info = array('name' => $task->getObjectName(), 'text' => $task->getText(), 'due_date' => $task->getDueDate() instanceof DateTimeValue ? new DateTimeValue($task->getDueDate()->getTimestamp()) : null, 'start_date' => $task->getStartDate() instanceof DateTimeValue ? new DateTimeValue($task->getStartDate()->getTimestamp()) : null, 'use_due_time' => $task->getUseDueTime(), 'use_start_time' => $task->getUseStartTime(), 'assigned_to_contact_id' => $task->getAssignedToContactId(), 'priority' => $task->getPriority(), 'state' => $task->getState(), 'milestone_id' => $task->getMilestoneId(), 'repeat_by' => $task->getRepeatBy(), 'repeat_d' => $task->getRepeatD(), 'repeat_m' => $task->getRepeatM(), 'repeat_y' => $task->getRepeatY());
            $new_task = new ProjectTask();
            $new_task->setFromAttributes($info);
            $new_task->setId($task->getId());
            $new_task->setNew(false);
            $new_due_date = null;
            $new_st_date = null;
            if ($task->getStartDate() instanceof DateTimeValue) {
                $new_st_date = new DateTimeValue($task->getStartDate()->getTimestamp());
            }
            if ($task->getDueDate() instanceof DateTimeValue) {
                $new_due_date = new DateTimeValue($task->getDueDate()->getTimestamp());
            }
            if ($task->getRepeatD() > 0) {
                if ($new_st_date instanceof DateTimeValue) {
                    $new_st_date = $new_st_date->add('d', $task->getRepeatD());
                }
                if ($new_due_date instanceof DateTimeValue) {
                    $new_due_date = $new_due_date->add('d', $task->getRepeatD());
                }
                $ref_date->add('d', $task->getRepeatD());
            } else {
                if ($task->getRepeatM() > 0) {
                    if ($new_st_date instanceof DateTimeValue) {
                        $new_st_date = $new_st_date->add('M', $task->getRepeatM());
                    }
                    if ($new_due_date instanceof DateTimeValue) {
                        $new_due_date = $new_due_date->add('M', $task->getRepeatM());
                    }
                    $ref_date->add('M', $task->getRepeatM());
                } else {
                    if ($task->getRepeatY() > 0) {
                        if ($new_st_date instanceof DateTimeValue) {
                            $new_st_date = $new_st_date->add('y', $task->getRepeatY());
                        }
                        if ($new_due_date instanceof DateTimeValue) {
                            $new_due_date = $new_due_date->add('y', $task->getRepeatY());
                        }
                        $ref_date->add('y', $task->getRepeatY());
                    }
                }
            }
            if ($new_st_date instanceof DateTimeValue) {
                $new_task->setStartDate($new_st_date);
            }
            if ($new_due_date instanceof DateTimeValue) {
                $new_task->setDueDate($new_due_date);
            }
            $num_repetitions++;
            if ($top_repeat_num > 0 && $top_repeat_num == $num_repetitions) {
                break;
            }
            if ($last_repeat instanceof DateTimeValue && $last_repeat->getTimestamp() < $ref_date->getTimestamp()) {
                break;
            }
            $new_task_array[] = $new_task;
            $task = $new_task;
        }
    }
    return $new_task_array;
}