/** * Show the interface for creating * */ public function indexAction() { ini_set('memory_limit', '64M'); $validFormats = array('weekly'); $format = 'weekly'; // $this->_getParam('format', 'weekly'); if (!in_array($format, $validFormats)) { $this->flash('Format not valid'); $this->renderView('error.php'); return; } $reportingOn = 'Dynamic'; // -1 will mean that by default, just choose all timesheet records $timesheetid = -1; // Okay, so if we were passed in a timesheet, it means we want to view // the data for that timesheet. However, if that timesheet is locked, // we want to make sure that the tasks being viewed are ONLY those that // are found in that locked timesheet. $timesheet = $this->byId(); $start = null; $end = null; $this->view->showLinks = true; $cats = array(); if ($timesheet) { $this->_setParam('clientid', $timesheet->clientid); $this->_setParam('projectid', $timesheet->projectid); if ($timesheet->locked) { $timesheetid = $timesheet->id; $reportingOn = $timesheet->title; } else { $timesheetid = 0; $reportingOn = 'Preview: ' . $timesheet->title; } if (is_array($timesheet->tasktype)) { $cats = $timesheet->tasktype; } $start = date('Y-m-d 00:00:01', strtotime($timesheet->from)); $end = date('Y-m-d 23:59:59', strtotime($timesheet->to)); $this->view->showLinks = false; } else { if ($this->_getParam('category')) { $cats = array($this->_getParam('category')); } } $project = $this->_getParam('projectid') ? $this->byId($this->_getParam('projectid'), 'Project') : null; $client = null; if (!$project) { $client = $this->_getParam('clientid') ? $this->byId($this->_getParam('clientid'), 'Client') : null; } $user = $this->_getParam('username') ? $this->userService->getUserByField('username', $this->_getParam('username')) : null; $this->view->user = $user; $this->view->project = $project; $this->view->client = $client ? $client : ($project ? $this->byId($project->clientid, 'Client') : null); $this->view->category = $this->_getParam('category'); if (!$start) { // The start date, if not set in the parameters, will be just // the previous monday $start = $this->_getParam('start', $this->calculateDefaultStartDate()); // $end = $this->_getParam('end', date('Y-m-d', time())); $end = $this->_getParam('end', date('Y-m-d 23:59:59', strtotime($start) + 6 * 86400)); } // lets normalise the end date to make sure it's of 23:59:59 $end = date('Y-m-d 23:59:59', strtotime($end)); $this->view->title = $reportingOn; $order = 'endtime desc'; if ($format == 'weekly') { $order = 'starttime asc'; } $this->view->taskInfo = $this->projectService->getTimesheetReport($user, $project, $client, $timesheetid, $start, $end, $cats, $order); // get the hierachy for all the tasks in the task info. Make sure to record how 'deep' the hierarchy is too $hierarchies = array(); $maxHierarchyLength = 0; foreach ($this->view->taskInfo as $taskinfo) { if (!isset($hierarchies[$taskinfo->taskid])) { $task = $this->projectService->getTask($taskinfo->taskid); $taskHierarchy = array(); if ($task) { $taskHierarchy = $task->getHierarchy(); if (count($taskHierarchy) > $maxHierarchyLength) { $maxHierarchyLength = count($taskHierarchy); } } $hierarchies[$taskinfo->taskid] = $taskHierarchy; } } $this->view->hierarchies = $hierarchies; $this->view->maxHierarchyLength = $maxHierarchyLength; $this->view->startDate = $start; $this->view->endDate = $end; $this->view->params = $this->_getAllParams(); $this->view->dayDivision = za()->getConfig('day_length', 8) / 4; // za()->getConfig('day_division', 2); $this->view->divisionTolerance = za()->getConfig('division_tolerance', 20); $outputformat = $this->_getParam('outputformat'); if ($outputformat == 'csv') { $this->_response->setHeader("Content-type", "text/csv"); $this->_response->setHeader("Content-Disposition", "inline; filename=\"timesheet.csv\""); echo $this->renderRawView('timesheet/csv-export.php'); } else { if ($this->_getParam('_ajax')) { $this->renderRawView('timesheet/' . $format . '-report.php'); } else { $this->renderView('timesheet/' . $format . '-report.php'); } } }