Пример #1
0
 function update_status($task_counts = null)
 {
     //there is no way to assess status on projects without a due date
     if (!$this->has_due_date()) {
         $this->set('status_text', 'on-schedule');
         return true;
     }
     if ($this->is_template == true) {
         return;
     }
     //it's possible to pass in the task counts (an array with the number of incomplete, complete, and total number
     //of tasks. This will be used to determine if the project has been started or not (a task count greater than
     //0 indicates that the project has started
     $expected_progress = $this->calculate_expected_progress();
     $old_status = $this->status_text;
     //if the due date has passed and the current progress isn't 100%, then the project is overdue regardless
     //of the expected progress value
     if ($this->due_date < time() && $this->progress < 100) {
         if ($this->progress <= 100) {
             $this->set('status_text', 'overdue');
         }
     } else {
         if ($expected_progress > 0) {
             //the due date is sometime in the future, so let's set the status based on the expected progress
             if ($this->progress >= 100) {
                 //if the task counts hasn't been passed in, we will need them to differentiate between a complete project
                 //and a project that hasn't been started
                 if (!isset($task_counts)) {
                     $task_counts = $this->get_task_counts();
                 }
                 //if we're passing in the task counts and there arent' yet any tasks, the project status should be not
                 //started.
                 if ($task_counts['total'] == 0) {
                     $this->set('status_text', 'not-started');
                 } else {
                     $this->set('status_text', 'complete');
                 }
             } else {
                 if ($expected_progress - $this->progress >= 25) {
                     $this->set('status_text', 'behind-schedule');
                 } else {
                     if ($expected_progress - $this->progress >= 10) {
                         $this->set('status_text', 'at-risk');
                     } else {
                         $this->set('status_text', 'on-schedule');
                     }
                 }
             }
         } else {
             $this->set('status_text', 'on-schedule');
         }
     }
     //
     if ($old_status != $this->status_text) {
         ActivityManager::project_status_changed($this);
     }
     return true;
 }