From 096b282a473fa2b27c3bfe3061f54b5fd83c75e0 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 27 Apr 2014 15:14:13 -0400 Subject: Add a basic task search --- controllers/project.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'controllers') diff --git a/controllers/project.php b/controllers/project.php index 6085caec..a9ce8634 100644 --- a/controllers/project.php +++ b/controllers/project.php @@ -25,6 +25,57 @@ class Project extends Base ))); } + /** + * Task search for a given project + * + * @access public + */ + public function search() + { + $project_id = $this->request->getIntegerParam('project_id'); + $search = $this->request->getStringParam('search'); + + $project = $this->project->getById($project_id); + $tasks = array(); + $nb_tasks = 0; + + if (! $project) { + $this->session->flashError(t('Project not found.')); + $this->response->redirect('?controller=project'); + } + + $this->checkProjectPermissions($project['id']); + + if ($search !== '') { + + $filters = array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id), + 'or' => array( + array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), + array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), + ) + ); + + $tasks = $this->task->find($filters); + $nb_tasks = count($tasks); + } + + $this->response->html($this->template->layout('project_search', array( + 'tasks' => $tasks, + 'nb_tasks' => $nb_tasks, + 'values' => array( + 'search' => $search, + 'controller' => 'project', + 'action' => 'search', + 'project_id' => $project['id'], + ), + 'menu' => 'projects', + 'project' => $project, + 'columns' => $this->board->getColumnsList($project_id), + 'title' => $project['name'].($nb_tasks > 0 ? ' ('.$nb_tasks.')' : '') + ))); + } + /** * List of completed tasks for a given project * -- cgit v1.2.3