Example #1
0
 public function import($project, $filename)
 {
     $handle = fopen($filename, "r");
     $fields = fgetcsv($handle, 1000, ",");
     $detail = array();
     while ($data = fgetcsv($handle, 1000, ",")) {
         $detail[] = $data;
     }
     $x = 0;
     $y = 0;
     if (!in_array('Name', $fields)) {
         throw new Exception("Malformed input file");
     }
     $errors = array();
     $lines = array();
     foreach ($detail as $i) {
         if (count($i) != count($fields)) {
             continue;
         }
         foreach ($fields as $z) {
             $fieldName = trim($z);
             if (!mb_strlen($fieldName)) {
                 ++$y;
                 continue;
             }
             $lines[$x][$fieldName] = trim($i[$y]);
             ++$y;
         }
         $y = 0;
         $x++;
     }
     $errors = array();
     $number = 0;
     foreach ($lines as $line) {
         // Get the task if it exists
         $title = $line['Name'];
         if (!mb_strlen($title)) {
             continue;
         }
         $existing = $this->projectService->getTasks(array('projectid=' => $project->id, 'title=' => $line['Name'], 'complete=' => 0));
         if (count($existing)) {
             $task = $existing[0];
         } else {
             $task = new Task();
         }
         $task->title = $line['Name'];
         $task->startdate = $this->getDate($line['Begin date']);
         $task->due = $this->getDate($line['End date']);
         $task->description = $line['Notes'];
         if (mb_strlen($line['Resources'])) {
             $users = split(';', $line['Resources']);
             $task->userid = $users;
         }
         $task->projectid = $project->id;
         // save the updated task info
         $this->projectService->saveTask($task);
     }
 }
Example #2
0
 /**
  * Prepare a feature to be edited
  *
  * @param Feature $model
  * @return
  */
 public function prepareForEdit($model)
 {
     $project = $this->projectService->getProject((int) $this->_getParam('projectid', $model->projectid));
     $parentFeature = $this->projectService->getFeature((int) $this->_getParam('parent'));
     if ($project == null) {
         $this->flash("Specified project not found");
         $this->renderView('error.php');
         return;
     }
     $this->view->project = $project;
     if ($parentFeature) {
         $this->view->parentfeature = $parentFeature->id;
     }
     if ($model->id) {
         $this->view->linkedToFeatures = $this->itemLinkService->getLinkedItems($model, 'from', 'Feature');
         $this->view->linkedFromFeatures = $this->itemLinkService->getLinkedItems($model, 'to', 'Feature');
     } else {
         $model->milestone = $this->_getParam('milestone');
     }
     $this->view->projects = $this->projectService->getProjectsForClient($project->clientid);
     $this->view->projectFeatures = $this->featureService->getFeatures(array('projectid=' => $project->id));
     $this->view->projectTasks = $this->projectService->getTasks(array('projectid=' => $project->id), 'title asc');
     $this->view->priorities = array('Must Have', 'Should Have', 'Would Like', 'Nice To Have');
     $this->view->statuses = $model->constraints['status']->getValues();
     $this->view->linkedTasks = array();
     if ($model->id) {
         $this->view->linkedTasks = $this->itemLinkService->getLinkedItemsOfType($model, 'from', 'Task');
     }
     parent::prepareForEdit($model);
 }
Example #3
0
 /**
  * Chart all the tasks in this project
  *
  */
 public function chartAction()
 {
     $project = $this->byId();
     if (!$project) {
         throw new Exception("Invalid project specified");
     }
     $this->view->project = $project;
     $this->view->tasks = $this->projectService->getTasks(array('projectid =' => $project->id), new Zend_Db_Expr('startdate asc, due asc'));
     $this->renderView('project/chart.php');
 }
Example #4
0
 /**
  * Get a list of tasks that match the given search string
  */
 public function tasklistAction()
 {
     $return = array();
     $query = $this->_getParam('query', '');
     if (mb_strlen($query) > 2) {
         $tasks = $this->projectService->getTasks(array('title like ' => '%' . $query . '%'));
         foreach ($tasks as $task) {
             $return[$task->id] = $task->title;
         }
     }
     $this->_response->setHeader('Content-type', 'text/javascript');
     echo Zend_Json_Encoder::encode($return);
 }
Example #5
0
 /**
  * Override the edit action to supply some selectable relationships
  *
  * @param MappedObject $model
  */
 public function prepareForEdit($model = null)
 {
     if ($this->view->model == null) {
         $this->flash("Invalid request specified");
         $this->redirect('error');
         return;
     }
     $this->view->issueHistory = $this->issueService->getIssueHistory($this->view->model);
     $pid = (int) $this->_getParam('projectid');
     $cid = (int) $this->_getParam('clientid');
     if ($this->view->model->projectid) {
         $pid = $this->view->model->projectid;
     }
     if ($this->view->model->clientid) {
         $cid = $this->view->model->clientid;
     }
     // Which one?
     if ($pid) {
         $this->view->project = $this->projectService->getProject($pid);
         $this->view->client = $this->clientService->getClient($this->view->project->clientid);
         // figure out the releases available for this project
         $this->view->releases = $this->issueService->getProjectReleases($this->view->project);
     } else {
         if ($cid) {
             $this->view->client = $this->clientService->getClient($cid);
             $this->view->releases = array();
         }
     }
     if ($this->view->client != null) {
         $this->view->categories = $this->issueService->getIssueCategoriesForCompany($this->view->client);
     } else {
         $this->view->categories = array();
     }
     // if it's a new issue, and it's a normal user set it to be private by default
     // User can always specify a different one though
     if (!$this->view->model->id && za()->getUser()->hasRole(User::ROLE_USER)) {
         $this->view->model->isprivate = true;
     }
     $this->view->users = $this->userService->getUserList();
     $this->view->severities = $this->view->model->constraints['severity']->getValues();
     $this->view->types = $this->view->model->constraints['issuetype']->getValues();
     $this->view->statuses = $this->view->model->constraints['status']->getValues();
     if ($this->view->model->id) {
         $this->view->notes = $this->notificationService->getNotesFor($this->view->model);
         $this->view->existingWatch = $this->notificationService->getWatch(za()->getUser(), $this->view->model->id, 'Issue');
         $this->view->userStatuses = $this->view->model->getUserStatuses();
         $clientUsers = $this->userService->getUsersForClient($this->view->model->clientid);
         foreach ($this->view->users as $user) {
             $clientUsers->append($user);
         }
         $this->view->allUsers = $clientUsers;
         $this->view->subscribers = $this->notificationService->getSubscribers($this->view->model->id, 'Issue');
         $this->view->project = $this->projectService->getProject($this->view->model->projectid);
         $this->view->client = $this->clientService->getClient($this->view->model->clientid);
         $this->view->files = $this->issueService->getIssueFiles($this->view->model);
         $path = 'Clients/' . $this->view->client->title . '/Issues/' . $this->view->model->id;
         $this->view->filePath = $path;
         // Get all the features for this project
         $this->view->projectFeatures = $this->featureService->getFeatures(array('projectid=' => $this->view->model->projectid));
         $this->view->projectTasks = $this->projectService->getTasks(array('projectid=' => $this->view->project->id), 'title asc');
         $this->view->linkedTasks = $this->itemLinkService->getLinkedItems($this->view->model, 'from', 'Task');
         $this->view->linkedToFeatures = $this->itemLinkService->getLinkedItems($this->view->model, 'from', 'Feature');
         $this->view->linkedFromFeatures = $this->itemLinkService->getLinkedItems($this->view->model, 'to', 'Feature');
     }
     $this->view->clients = $this->clientService->getClients();
     if ($this->view->client) {
         $this->view->projects = $this->projectService->getProjectsForClient($this->view->client->id);
     }
 }
Example #6
0
 /**
  * Get the task that represents the leave for a given leave application
  * and add some time to it for the given application
  */
 public function applyTimeForLeave(LeaveApplication $leaveApplication)
 {
     $project = $this->projectService->getProject(za()->getConfig('leave_project'));
     if (!$project) {
         throw new Exception("Leave project not set correctly in configuration");
     }
     $monthYear = date('F Y', strtotime($leaveApplication->to));
     $params = array('parentid=' => $project->id, 'title=' => $monthYear);
     // get the appropriate milestone
     $projs = $this->projectService->getProjects($params);
     $milestone = null;
     if (count($projs)) {
         $milestone = $projs[0];
     } else {
         // create a new milestone
         // $milestone
         $date = date('Y-m-t', strtotime($leaveApplication->to)) . ' 23:59:59';
         $milestone = $this->projectService->createMilestone($project, $monthYear, $date);
     }
     // now get the task for the given leave app
     $taskTitle = $leaveApplication->leavetype . ' Leave #' . $leaveApplication->id . ': ' . $leaveApplication->username . ' ' . date('Y-m-d', strtotime($leaveApplication->from)) . ' - ' . date('Y-m-d', strtotime($leaveApplication->to));
     $params = array('projectid=' => $milestone->id, 'title=' => $taskTitle);
     $tasks = $this->projectService->getTasks($params);
     $user = $this->getUserByField('username', $leaveApplication->username);
     $task = null;
     if (count($tasks)) {
         $task = $tasks[0];
         // delete all timesheet entries for this user on this task
         $records = $this->projectService->getDetailedTimesheet($user, $task->id);
         foreach ($records as $record) {
             $this->projectService->removeTimesheetRecord($record);
         }
     } else {
         // create the new task
         $task = new Task();
         za()->inject($task);
         $task->title = $taskTitle;
         $task->projectid = $milestone->id;
         $task->category = 'Leave';
         $task->due = $leaveApplication->to;
         $task->description = $leaveApplication->reason;
         $task->estimated = za()->getConfig('day_length') * $leaveApplication->days;
         $task->complete = 1;
         $task = $this->projectService->saveTask($task);
     }
     if ($task != null) {
         // now add all the timesheet entries for each given day
         $startTime = strtotime(date('Y-m-d', strtotime($leaveApplication->from)) . ' 09:00:00');
         // now go through and add time for the given day
         for ($i = 0; $i < $leaveApplication->days; $i++) {
             // see if today's a weekend, if so we want to skip til the next monday
             $curDay = date('D', $startTime);
             if ($curDay == 'Sat') {
                 $startTime += 2 * 86400;
             } else {
                 if ($curDay == 'Sun') {
                     $startTime += 86400;
                 }
             }
             $endTime = $startTime + za()->getConfig('day_length') * 3600;
             $this->projectService->addTimesheetRecord($task, $user, $startTime, $endTime);
             $startTime += 86400;
         }
     }
 }
Example #7
0
 protected function getChildDataProject(Project $project, $options = null)
 {
     $data = array();
     switch ($options) {
         case 'subprojects':
             $children = $project->getSubProjects();
             foreach ($children as $child) {
                 $item = new stdClass();
                 $item->id = get_class($child) . '-' . $child->id;
                 $item->text = $child->title . ' <a href="' . build_url('project', 'view', array('id' => $child->id)) . '"><img src="' . resource('images/bullet_go.png') . '" /></a>';
                 $item->expanded = false;
                 $item->classes = "project-item iconed";
                 $item->hasChildren = true;
                 $data[] = $item;
             }
             break;
         case 'milestones':
             $children = $project->getMilestones();
             foreach ($children as $child) {
                 $item = new stdClass();
                 $item->id = get_class($child) . '-' . $child->id . '-tasks';
                 $item->text = $child->title . ' <a href="' . build_url('project', 'view', array('id' => $child->id)) . '"><img src="' . resource('images/bullet_go.png') . '" /></a>';
                 $item->expanded = false;
                 $item->classes = "tree-milestone iconed";
                 $item->hasChildren = true;
                 $data[] = $item;
             }
             break;
         case 'features':
             $items = $this->featureService->getFeatures(array('projectid=' => $project->id));
             foreach ($items as $child) {
                 $item = new stdClass();
                 $item->id = get_class($child) . '-' . $child->id . '-tasks';
                 $item->text = $child->title . ' <a href="' . build_url('feature', 'edit', array('id' => $child->id)) . '"><img src="' . resource('images/bullet_go.png') . '" /></a>';
                 $item->expanded = false;
                 $item->classes = "tree-feature iconed";
                 $item->hasChildren = true;
                 $data[] = $item;
             }
             break;
         case 'requests':
             $items = $this->issueService->getIssues(array('projectid=' => $project->id, 'status <> ' => Issue::STATUS_CLOSED));
             foreach ($items as $child) {
                 $item = new stdClass();
                 $item->id = get_class($child) . '-' . $child->id . '-tasks';
                 $item->text = $child->title . ' <a href="' . build_url('issue', 'edit', array('id' => $child->id)) . '"><img src="' . resource('images/bullet_go.png') . '" /></a>';
                 $item->expanded = false;
                 $item->classes = "tree-request iconed";
                 $item->hasChildren = true;
                 $data[] = $item;
             }
             break;
         case 'tasks':
             $items = $this->projectService->getTasks(array('projectid=' => $project->id, 'complete=' => 0));
             foreach ($items as $child) {
                 $item = new stdClass();
                 $item->id = get_class($child) . '-' . $child->id . '';
                 ob_start();
                 $this->view->percentageBar($child->getPercentage());
                 $bar = ob_get_clean();
                 $item->text = $bar . $child->title . ' <a href="' . build_url('task', 'edit', array('id' => $child->id)) . '"><img src="' . resource('images/bullet_go.png') . '" /></a>';
                 $item->expanded = false;
                 $item->classes = "tree-task iconed";
                 $item->hasChildren = false;
                 $data[] = $item;
             }
             break;
         default:
             $subProjects = $project->getSubProjects();
             if (count($subProjects)) {
                 $option = new stdClass();
                 $option->text = 'Sub Projects';
                 $option->id = get_class($project) . '-' . $project->id . '-subprojects';
                 $option->classes = "tree-folder iconed";
                 $option->hasChildren = true;
                 $data[] = $option;
             }
             if ($project->hasMilestones()) {
                 $option = new stdClass();
                 $option->text = 'Milestones';
                 $option->id = get_class($project) . '-' . $project->id . '-milestones';
                 $option->classes = "tree-folder iconed";
                 $option->hasChildren = true;
                 $data[] = $option;
             }
             // see if there are features
             $items = $this->featureService->getFeatures(array('projectid=' => $project->id));
             if (count($items)) {
                 $option = new stdClass();
                 $option->text = 'Features';
                 $option->id = get_class($project) . '-' . $project->id . '-features';
                 $option->classes = "tree-folder iconed";
                 $option->hasChildren = true;
                 $data[] = $option;
             }
             // see if there are requests
             $items = $this->issueService->getIssues(array('projectid=' => $project->id, 'status <> ' => Issue::STATUS_CLOSED));
             if (count($items)) {
                 $option = new stdClass();
                 $option->text = 'Requests';
                 $option->id = get_class($project) . '-' . $project->id . '-requests';
                 $option->classes = "tree-folder iconed";
                 $option->hasChildren = true;
                 $data[] = $option;
             }
             break;
     }
     return $data;
 }