/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $app */ $app = $this->getContainer()->get('app'); $app->getUser()->authorize('manage'); $project = $app->getProject(); try { $this->model->setProject($project); $data = $app->input->get('category', array(), 'array'); if (isset($data['id'])) { $this->model->save($data); } else { $this->model->add($data); } // Reload the project. $this->model->setProject($project); $app->enqueueMessage('The changes have been saved.', 'success'); $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias); } catch (\Exception $exception) { $app->enqueueMessage($exception->getMessage(), 'error'); if ($app->input->get('id')) { $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/' . $app->input->get('id') . '/edit'); } else { $app->redirect($app->get('uri.base.path') . 'category/' . $project->alias . '/add'); } } parent::execute(); }
/** * Initialize the controller. * * This will set up default model and view classes. * * @return $this Method allows chaining * * @since 1.0 * @throws \RuntimeException */ public function initialize() { parent::initialize(); $this->getContainer()->get('app')->getUser()->authorize('manage'); $this->model->setProject($this->getContainer()->get('app')->getProject()); $this->view->setProject($this->getContainer()->get('app')->getProject()); return $this; }
/** * Execute the controller. * * @return string * * @since 1.0 */ public function execute() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $application->getUser()->authorize('manage'); $item = $this->model->getItem($application->input->getUint('id')); $this->view->setProject($application->getProject()); $this->model->setProject($application->getProject()); $this->view->setItem($item); return parent::execute(); }
/** * Setting model state that will be used for filtering. * * @return void * * @since 1.0 */ private function setModelState() { /* @type \JTracker\Application $application */ $application = $this->getContainer()->get('app'); $state = $this->model->getState(); $projectId = $application->getProject()->project_id; // Set up filters $sort = $application->getUserStateFromRequest('project_' . $projectId . '.filter.sort', 'sort', 'issue', 'word'); $direction = $application->getUserStateFromRequest('project_' . $projectId . '.filter.direction', 'direction', 'desc', 'word'); // Update the sort filters from the GET request switch (strtolower($sort)) { case 'updated': $state->set('list.ordering', 'a.modified_date'); $sort = $sort + 2; break; default: $sort = 0; } switch (strtoupper($direction)) { case 'ASC': $state->set('list.direction', 'ASC'); $sort++; break; default: $state->set('list.direction', 'DESC'); } $state->set('filter.sort', $sort); $priority = $application->getUserStateFromRequest('project_' . $projectId . '.filter.priority', 'priority', 0, 'cmd'); // Update the priority filter from the GET request switch (strtolower($priority)) { case 'critical': $priority = 1; break; case 'urgent': $priority = 2; break; case 'medium': $priority = 3; break; case 'low': $priority = 4; break; case 'very-low': $priority = 5; break; } $state->set('filter.priority', $priority); $issuesState = $application->getUserStateFromRequest('project_' . $projectId . '.filter.state', 'state', 'open', 'word'); // Update the state filter from the GET request switch (strtolower($issuesState)) { case 'open': $issuesState = 0; break; case 'closed': $issuesState = 1; break; } $state->set('filter.state', $issuesState); $state->set('filter.status', $application->getUserStateFromRequest('project_' . $projectId . '.filter.status', 'status', 0, 'uint')); $state->set('filter.search', $application->getUserStateFromRequest('project_' . $projectId . '.filter.search', 'search', '', 'string')); $user = $application->getUserStateFromRequest('project_' . $projectId . '.filter.user', 'user', 0, 'word'); // Update the user filter from the GET request switch ((string) $user) { case 'created': $user = 1; break; case 'participated': $user = 2; break; } $state->set('filter.user', $user); $state->set('filter.created_by', $application->getUserStateFromRequest('project_' . $projectId . '.filter.created_by', 'created_by', '', 'string')); $categoryAlias = $application->input->get->get('category', '', 'cmd'); // Update the category filter from the GET request if ($categoryAlias != '' && !is_numeric($categoryAlias)) { $categoryId = 0; $categoryModel = new CategoryModel($this->getContainer()->get('db')); $category = $categoryModel->setProject($application->getProject())->getByAlias($categoryAlias); if ($category) { $categoryId = $category->id; } } else { $categoryId = $application->getUserStateFromRequest('project_' . $projectId . '.filter.category', 'category', 0, 'int'); } $state->set('filter.category', (int) $categoryId); $state->set('filter.label', $application->getUserStateFromRequest('project_' . $projectId . '.filter.label', 'label', 0, 'uint')); $state->set('stools-active', $application->input->get('stools-active', 0, 'uint')); if ($application->getUser()->username) { $state->set('username', $application->getUser()->username); } // Update the page from the GET request $state->set('page', $application->getUserStateFromRequest('project_' . $projectId . '.page', 'page', 1, 'uint')); $state->set('filter.tests', $application->getUserStateFromRequest('project_' . $projectId . '.filter.tests', 'tests', 0, 'uint')); $state->set('filter.easytest', $application->getUserStateFromRequest('project_' . $projectId . '.filter.easytest', 'easytest', 0, 'uint')); $state->set('filter.type', $application->getUserStateFromRequest('project_' . $projectId . '.filter.type', 'type', 0, 'uint')); $this->model->setState($state); }