Esempio n. 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);
     }
 }
Esempio n. 2
0
 /**
  * Create a new task that's linked from another object
  */
 public function newtaskAction($return = false)
 {
     $params = $this->_getAllParams();
     $params['createtype'] = 'Task';
     if (!isset($params['newtaskProjectid']) && ($params['type'] == 'Issue' || $params['type'] == 'Feature')) {
         $this->flash("No milestone specified!");
         $this->redirect('issue', 'edit', array('id' => ifset($params, 'id')));
         return;
     }
     $task = $this->itemLinkService->createNewItem($params);
     $prefix = ifset($params, 'prefix', '');
     $task->title = $prefix . ifset($params, 'tasktitle', $task->title);
     $task->projectid = ifset($params, 'projectid', ifset($params, 'newtaskProjectid'));
     if (isset($params['assignto'])) {
         $task->assignTo($params['assignto']);
     } else {
         $this->projectService->saveTask($task);
     }
     // if we're here by way of ajax, then lets send some js back that will
     // load a new dialog with the appropriate editing interface
     if ($this->_getParam('_ajax')) {
         $this->view->model = $task;
         $this->renderRawView('task/newtaskfromajax.php');
     } else {
         $this->redirect('task', 'edit', array('id' => $task->id, 'projectid' => $task->projectid));
     }
 }
Esempio n. 3
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;
         }
     }
 }