Example #1
0
 private function iterateSubProjects(Project $project, $select, $value, $level = 0, $showmilestones = true)
 {
     $selected = $value == $project->id ? 'selected="selected"' : '';
     $disabled = '';
     if ($project->ismilestone) {
         if (!$showmilestones) {
             return "";
         }
         $disabled = $select == 'project' ? 'disabled="disabled"' : '';
     } else {
         $disabled = $select == 'milestone' ? 'disabled="disabled"' : '';
     }
     $prepend = '';
     for ($i = 0; $i < $level; $i++) {
         $prepend .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     }
     if (isset($this->view->model->id) && $project->id == $this->view->model->id) {
         $disabled = 'disabled="disabled"';
     }
     $html = '<option value="' . $project->id . '" ' . $disabled . ' ' . $selected . '>' . $prepend . $this->view->escape($project->title) . " (" . $project->id . ")" . '</option>';
     $children = $project->getChildProjects();
     foreach ($children as $childProject) {
         $html .= "\n" . $this->iterateSubProjects($childProject, $select, $value, $level + 1);
     }
     return $html;
 }
Example #2
0
 /**
  * Update a project's estimated time
  *
  * This method does NOT save the project explicitly - it is assumed that
  * our caller will do that.
  */
 public function updateProjectEstimate(Project $project)
 {
     if (!$project->id) {
         return;
     }
     $estimate = 0;
     // do we actually save this project and update its parents?
     $update = false;
     // if it's a milestone, then update based on all of its tasks
     if ($project->ismilestone) {
         $allTasks = $project->getContainedTasks();
         $estimate = 0;
         foreach ($allTasks as $task) {
             $estimate += $task->estimated;
         }
         $taskestimate = $estimate ? $estimate / za()->getConfig('day_length', 8) : 0;
         if ($taskestimate && $taskestimate != $project->taskestimate) {
             $project->taskestimate = $taskestimate;
             $update = true;
         }
     } else {
         // otherwise, update based on the total of all of its direct children projects,
         // plus any features attached at this project level
         $select = $this->dbService->select();
         /* @var $select Zend_Db_Select */
         $select->from('feature', 'sum(estimated) as projectestimate');
         $select->where('projectid=?', $project->id);
         $result = $this->dbService->query($select, array());
         /* @var $result Zend_Db_Statement */
         $row = $result->fetch(Zend_Db::FETCH_ASSOC);
         $estimate = ifset($row, 'projectestimate', 0);
         // now update based on all its children projects/milestones
         $children = $project->getChildProjects();
         $taskestimate = 0;
         $featureestimate = $estimate;
         foreach ($children as $child) {
             $taskestimate += $child->taskestimate;
             $featureestimate += $child->featureestimate;
         }
         if ($taskestimate && $taskestimate != $project->taskestimate) {
             $project->taskestimate = $taskestimate;
             $update = true;
         }
         if ($featureestimate && $featureestimate != $project->featureestimate) {
             $project->featureestimate = $featureestimate;
             $project->estimated = $featureestimate * za()->getConfig('day_length', 8);
             $update = true;
         }
     }
     // Now, get all the time for this project
     $summary = $this->getSummaryTimesheet(null, null, $project->id, null, -1, '2000-01-01 00:00:00', '2100-01-01 00:00:00');
     $taken = 0;
     foreach ($summary as $task) {
         $taken += $task->timespent;
     }
     $grandchildren = $project->getAllSubProjects();
     foreach ($grandchildren as $grandkid) {
         $taken += $grandkid->currenttime;
     }
     $taken = $taken > 0 ? $taken / 3600 : 0;
     if ($taken > 0 && $project->currenttime != $taken) {
         $project->currenttime = $taken;
         // note that we do NOT save this here; we're assuming our caller will
         // save when appropriate
         $update = true;
     }
     if ($update) {
         // get its parent and update that too
         if ($project->parentid) {
             $parent = $this->getProject($project->parentid);
             $this->saveProject($parent);
         }
     }
 }