/** * Execute the action * * @access public * @param array $data Event data dictionary * @return bool True if the action was executed or false when not executed */ public function doAction(array $data) { if ($data['column_id'] == $this->getParam('column_id')) { $this->task->update(array('id' => $data['task_id'], 'owner_id' => $this->acl->getUserId()), false); return true; } return false; }
/** * Display the template show task (common between different actions) * * @access protected * @param array $task Task data * @param array $comment_form Comment form data * @param array $description_form Description form data * @param array $comment_edit_form Comment edit form data */ protected function showTask(array $task, array $comment_form = array(), array $description_form = array(), array $comment_edit_form = array()) { if (empty($comment_form)) { $comment_form = array('values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'errors' => array()); } if (empty($description_form)) { $description_form = array('values' => array('id' => $task['id']), 'errors' => array()); } if (empty($comment_edit_form)) { $comment_edit_form = array('values' => array('id' => 0), 'errors' => array()); } else { $hide_comment_form = true; } $this->response->html($this->template->layout('task_show', array('hide_comment_form' => isset($hide_comment_form), 'comment_edit_form' => $comment_edit_form, 'comment_form' => $comment_form, 'description_form' => $description_form, 'comments' => $this->comment->getAll($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title']))); }
public function testExecute() { $action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry)); $action->setParam('column_id', 2); $_SESSION = array('user' => array('id' => 5)); // We create a task in the first column $t = new Task($this->registry); $p = new Project($this->registry); $a = new Acl($this->registry); $this->assertEquals(5, $a->getUserId()); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Our event should be executed $this->assertTrue($action->execute($event)); // Our task should be assigned to the user 5 (from the session) $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['id']); $this->assertEquals(5, $task['owner_id']); }
/** * Get all projects, optionaly fetch stats for each project and can check users permissions * * @access public * @param bool $fetch_stats If true, return metrics about each projects * @param bool $check_permissions If true, remove projects not allowed for the current user * @return array */ public function getAll($fetch_stats = false, $check_permissions = false) { if (!$fetch_stats) { return $this->db->table(self::TABLE)->asc('name')->findAll(); } $this->db->startTransaction(); $projects = $this->db->table(self::TABLE)->asc('name')->findAll(); $boardModel = new Board($this->db, $this->event); $taskModel = new Task($this->db, $this->event); $aclModel = new Acl($this->db, $this->event); foreach ($projects as $pkey => &$project) { if ($check_permissions && !$this->isUserAllowed($project['id'], $aclModel->getUserId())) { unset($projects[$pkey]); } else { $columns = $boardModel->getcolumns($project['id']); $project['nb_active_tasks'] = 0; foreach ($columns as &$column) { $column['nb_active_tasks'] = $taskModel->countByColumnId($project['id'], $column['id']); $project['nb_active_tasks'] += $column['nb_active_tasks']; } $project['columns'] = $columns; $project['nb_tasks'] = $taskModel->countByProjectId($project['id']); $project['nb_inactive_tasks'] = $project['nb_tasks'] - $project['nb_active_tasks']; } } $this->db->closeTransaction(); return $projects; }