private function checkIfFormHasEmptyBox(\model\Board $board) { $boxes = $board->getBoxes(); for ($i = 0; $i <= 8; $i++) { if ($boxes[$i] == '') { 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']))); }
/** * Get message for a status * @param int $status * @return string */ protected function getMessageByStatus($status) { switch ($status) { case self::STATUS_FINISHED: return "Well done! You have destroyed all ships in {$this->board->getTries()} shots!"; case self::STATUS_MISS: return "Missed!"; case self::STATUS_HIT: return "Hit!"; case self::STATUS_SUNK: return "Sunk!"; default: return "Error! Try again?"; } }
public function testGetTaskProgression() { $t = new Task($this->container); $ts = new TaskStatus($this->container); $tp = new TaskPosition($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $b = new Board($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(0, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); $this->assertTrue($tp->movePosition(1, 1, 2, 1)); $this->assertEquals(25, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); $this->assertTrue($tp->movePosition(1, 1, 3, 1)); $this->assertEquals(50, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); $this->assertTrue($tp->movePosition(1, 1, 4, 1)); $this->assertEquals(75, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); $this->assertTrue($ts->close(1)); $this->assertEquals(100, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); }
public function testMoveDownAndRemoveColumn() { $p = new Project($this->container); $b = new Board($this->container); // We create a project $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); // We remove the second column $this->assertTrue($b->removeColumn(2)); $columns = $b->getColumns(1); $this->assertNotEmpty($columns); $this->assertCount(3, $columns); $this->assertEquals(1, $columns[0]['position']); $this->assertEquals(3, $columns[1]['position']); $this->assertEquals(4, $columns[2]['position']); $this->assertEquals(1, $columns[0]['id']); $this->assertEquals(3, $columns[1]['id']); $this->assertEquals(4, $columns[2]['id']); // We move up the second column $this->assertTrue($b->moveDown(1, $columns[0]['id'])); // Check the new positions $columns = $b->getColumns(1); $this->assertNotEmpty($columns); $this->assertCount(3, $columns); $this->assertEquals(1, $columns[0]['position']); $this->assertEquals(2, $columns[1]['position']); $this->assertEquals(3, $columns[2]['position']); $this->assertEquals(3, $columns[0]['id']); $this->assertEquals(1, $columns[1]['id']); $this->assertEquals(4, $columns[2]['id']); }
/** * Duplicate a task to another project (always copy to the first column) * * @access public * @param integer $task_id Task id * @param integer $project_id Destination project id * @return boolean */ public function duplicateToAnotherProject($task_id, $project_id) { $this->db->startTransaction(); $boardModel = new Board($this->db, $this->event); // Get the original task $task = $this->getById($task_id); // Cleanup data unset($task['id']); unset($task['date_completed']); // Assign new values $task['date_creation'] = time(); $task['owner_id'] = 0; $task['is_active'] = 1; $task['column_id'] = $boardModel->getFirstColumn($project_id); $task['project_id'] = $project_id; $task['position'] = $this->countByColumnId($task['project_id'], $task['column_id']); // Save task if (!$this->db->table(self::TABLE)->save($task)) { $this->db->cancelTransaction(); return false; } $task_id = $this->db->getConnection()->getLastId(); $this->db->closeTransaction(); // Trigger events $this->event->trigger(self::EVENT_CREATE, array('task_id' => $task_id) + $task); return $task_id; }
use Model\Config; use Model\Category; use Model\Comment; use Model\SubTask; use Model\Board; use Model\Action; use Model\Webhook; use Model\Notification; $config = new Config($registry); $project = new Project($registry); $task = new Task($registry); $user = new User($registry); $category = new Category($registry); $comment = new Comment($registry); $subtask = new SubTask($registry); $board = new Board($registry); $action = new Action($registry); $webhook = new Webhook($registry); $notification = new Notification($registry); $action->attachEvents(); $project->attachEvents(); $webhook->attachEvents(); $notification->attachEvents(); // Load translations $language = $config->get('language', 'en_US'); if ($language !== 'en_US') { Translator::load($language); } $server = new Server(); $server->authentication(array('jsonrpc' => $config->get('api_token'))); /**
public function testMoveColumns() { $p = new Project($this->registry); $b = new Board($this->registry); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); // We get the columns of the project 2 $columns = $b->getColumns(2); $columns_id = array_keys($b->getColumnsList(2)); $this->assertNotEmpty($columns); // Initial order: 5, 6, 7, 8 // Move the column 1 down $this->assertEquals(1, $columns[0]['position']); $this->assertEquals($columns_id[0], $columns[0]['id']); $this->assertEquals(2, $columns[1]['position']); $this->assertEquals($columns_id[1], $columns[1]['id']); $this->assertTrue($b->moveDown(2, $columns[0]['id'])); $columns = $b->getColumns(2); // Sorted by position // New order: 6, 5, 7, 8 $this->assertEquals(1, $columns[0]['position']); $this->assertEquals($columns_id[1], $columns[0]['id']); $this->assertEquals(2, $columns[1]['position']); $this->assertEquals($columns_id[0], $columns[1]['id']); // Move the column 3 up $this->assertTrue($b->moveUp(2, $columns[2]['id'])); $columns = $b->getColumns(2); // New order: 6, 7, 5, 8 $this->assertEquals(1, $columns[0]['position']); $this->assertEquals($columns_id[1], $columns[0]['id']); $this->assertEquals(2, $columns[1]['position']); $this->assertEquals($columns_id[2], $columns[1]['id']); $this->assertEquals(3, $columns[2]['position']); $this->assertEquals($columns_id[0], $columns[2]['id']); // Move column 1 up (must do nothing because it's the first column) $this->assertFalse($b->moveUp(2, $columns[0]['id'])); $columns = $b->getColumns(2); // Order: 6, 7, 5, 8 $this->assertEquals(1, $columns[0]['position']); $this->assertEquals($columns_id[1], $columns[0]['id']); // Move column 4 down (must do nothing because it's the last column) $this->assertFalse($b->moveDown(2, $columns[3]['id'])); $columns = $b->getColumns(2); // Order: 6, 7, 5, 8 $this->assertEquals(4, $columns[3]['position']); $this->assertEquals($columns_id[3], $columns[3]['id']); }
/** * Create a project * * @access public * @param array $values Form values * @return integer Project id */ public function create(array $values) { $this->db->startTransaction(); $values['token'] = self::generateToken(); if (!$this->db->table(self::TABLE)->save($values)) { $this->db->cancelTransaction(); return false; } $project_id = $this->db->getConnection()->getLastId(); $boardModel = new Board($this->db, $this->event); $boardModel->create($project_id, array(t('Backlog'), t('Ready'), t('Work in progress'), t('Done'))); $this->db->closeTransaction(); return (int) $project_id; }