/** * Complete this task and subtasks and check if we need to complete the parent * * @access public * @param void * @return $log_info */ function completeTask($options) { if (!$this->canChangeStatus(logged_user())) { flash_error('no access permissions'); ajx_current("empty"); return; } $ret = null; Hook::fire("before_completing_task", array('task' => $this), $ret); $this->setCompletedOn(DateTimeValueLib::now()); $this->setCompletedById(logged_user()->getId()); if ($options == "yes") { foreach ($this->getAllSubTasks() as $subt) { $subt->completeTask($options); } } if (user_config_option('close timeslot open')) { $timeslots = Timeslots::getOpenTimeslotsByObject($this->getId()); if ($timeslots) { foreach ($timeslots as $timeslot) { if ($timeslot->isOpen()) { $timeslot->close(); } $timeslot->save(); } } } // check if all previuos tasks are completed $log_info = ""; if (config_option('use tasks dependencies')) { $saved_ptasks = ProjectTaskDependencies::findAll(array('conditions' => 'task_id = ' . $this->getId())); foreach ($saved_ptasks as $pdep) { $ptask = ProjectTasks::findById($pdep->getPreviousTaskId()); if ($ptask instanceof ProjectTask && !$ptask->isCompleted()) { flash_error(lang('previous tasks must be completed before completion of this task')); ajx_current("empty"); return; } } //Seeking the subscribers of the completed task not to repeat in the notifications $contact_notification = array(); $task = ProjectTasks::findById($this->getId()); foreach ($task->getSubscribers() as $task_sub) { $contact_notification[] = $task_sub->getId(); } //Send notification to subscribers of the task_dependency on the task completed $next_dependency = ProjectTaskDependencies::findAll(array('conditions' => 'previous_task_id = ' . $this->getId())); foreach ($next_dependency as $ndep) { $ntask = ProjectTasks::findById($ndep->getTaskId()); if ($ntask instanceof ProjectTask) { foreach ($ntask->getSubscribers() as $task_dep) { if (!in_array($task_dep->getId(), $contact_notification)) { $log_info .= $task_dep->getId() . ","; } } } } } $this->setPercentCompleted(100); $this->save(); return $log_info; }
function getOpenTimeslots() { return Timeslots::getOpenTimeslotsByObject($this); }
function getOpenTimeslots() { if (is_null($this->timeslots)) { return Timeslots::getOpenTimeslotsByObject($this); } else { $result = array(); for ($i = 0; $i < count($this->timeslots); $i++) { if ($this->timeslots[$i]->isOpen()) { $result[] = $this->timeslots[$i]; } } return $result; } }