Пример #1
0
 /**
  * Get all columns and tasks for a given project
  *
  * @access public
  * @param  integer  $project_id   Project id
  * @return array
  */
 public function get($project_id, array $filters = array())
 {
     $this->db->startTransaction();
     $columns = $this->getColumns($project_id);
     $filters[] = array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id);
     $filters[] = array('column' => 'is_active', 'operator' => 'eq', 'value' => Task::STATUS_OPEN);
     $taskModel = new Task($this->db, $this->event);
     $tasks = $taskModel->find($filters);
     foreach ($columns as &$column) {
         $column['tasks'] = array();
         foreach ($tasks as &$task) {
             if ($task['column_id'] == $column['id']) {
                 $column['tasks'][] = $task;
             }
         }
     }
     $this->db->closeTransaction();
     return $columns;
 }
Пример #2
0
 public function testFilter()
 {
     $t = new Task($this->registry);
     $p = new Project($this->registry);
     $this->assertEquals(1, $p->create(array('name' => 'test1')));
     $this->assertEquals(1, $t->create(array('title' => 'test a', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'description' => 'biloute')));
     $this->assertEquals(2, $t->create(array('title' => 'test b', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2, 'description' => 'toto et titi sont dans un bateau')));
     $tasks = $t->find(array(array('column' => 'project_id', 'operator' => 'eq', 'value' => '1')));
     $this->assertNotFalse($tasks);
     $this->assertEquals(2, count($tasks));
     $this->assertEquals(1, $tasks[0]['id']);
     $this->assertEquals(2, $tasks[1]['id']);
     $tasks = $t->find(array(array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), array('column' => 'owner_id', 'operator' => 'eq', 'value' => '2')));
     $this->assertEquals(1, count($tasks));
     $this->assertEquals(2, $tasks[0]['id']);
     $tasks = $t->find(array(array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), array('column' => 'title', 'operator' => 'like', 'value' => '%b%')));
     $this->assertEquals(1, count($tasks));
     $this->assertEquals(2, $tasks[0]['id']);
     // Condition with OR
     $search = 'bateau';
     $filters = array(array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), 'or' => array(array('column' => 'title', 'operator' => 'like', 'value' => '%' . $search . '%'), array('column' => 'description', 'operator' => 'like', 'value' => '%' . $search . '%')));
     $tasks = $t->find($filters);
     $this->assertEquals(1, count($tasks));
     $this->assertEquals(2, $tasks[0]['id']);
     $search = 'toto et titi';
     $filters = array(array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), 'or' => array(array('column' => 'title', 'operator' => 'like', 'value' => '%' . $search . '%'), array('column' => 'description', 'operator' => 'like', 'value' => '%' . $search . '%')));
     $tasks = $t->find($filters);
     $this->assertEquals(1, count($tasks));
     $this->assertEquals(2, $tasks[0]['id']);
     $search = 'john';
     $filters = array(array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), 'or' => array(array('column' => 'title', 'operator' => 'like', 'value' => '%' . $search . '%'), array('column' => 'description', 'operator' => 'like', 'value' => '%' . $search . '%')));
     $tasks = $t->find($filters);
     $this->assertEquals(0, count($tasks));
 }