/** * Return a listing for the admin. * * @return array */ public function fetchAdminListing() { $orderSpec = array(); foreach ($this->getPrimaryKey() as $primaryKeyColumn) { $orderSpec[] = $primaryKeyColumn; } $select = $this->select()->from($this->getTableName())->order($orderSpec); return $this->db->fetchAll($select); }
/** * Load the current preferences for this component from the database. The * information will be returned in this format: * * <pre> * array( * array( * 'field_id' => 'products:name', * 'group_title' => 'My Field Group', * 'group_id' => 2 * ) * ) * </pre> * * The fields and groups will be sorted when returned from this method, so * can iterate over it without having to first sort it. * * @return array */ public function load() { $sql = $this->dbAdapter->quoteInto('SELECT f.field_id, g.title AS group_title, g.dewdrop_field_group_id AS group_id FROM dewdrop_sorted_fields f LEFT JOIN dewdrop_field_groups g ON g.dewdrop_field_group_id = f.dewdrop_field_group_id WHERE f.component = ? ORDER BY f.dewdrop_field_group_id IS NULL DESC, g.sort_index, f.sort_index', $this->componentName); return $this->dbAdapter->fetchAll($sql); }
public function testDelete() { $table = 'dewdrop_test_fruits'; $idField = 'dewdrop_test_fruit_id'; $fetchAllSql = "SELECT * FROM {$table} ORDER BY {$idField}"; $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(5, count($fruits)); $this->assertEquals(1, $fruits[0][$idField]); $fruit = $this->table->find(1); $this->assertSame(1, $fruit->delete()); $this->assertNull($fruit->get('dewdrop_test_fruit_id')); $this->assertNull($fruit->get('name')); $this->assertNull($fruit->get('is_delicious')); $this->assertNull($fruit->get('level_of_deliciousness')); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(4, count($fruits)); $this->assertEquals(2, $fruits[0][$idField]); }
public function testDelete() { $table = 'dewdrop_test_fruits'; $idField = 'dewdrop_test_fruit_id'; $fetchAllSql = "SELECT * FROM {$table} ORDER BY {$idField}"; $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(5, count($fruits)); $this->assertEquals(1, $fruits[0][$idField]); $this->assertSame(1, $this->table->delete("{$idField} = 1")); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(4, count($fruits)); $this->assertEquals(2, $fruits[0][$idField]); $this->assertSame(0, $this->table->delete("{$idField} = 7")); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(4, count($fruits)); $this->assertEquals(2, $fruits[0][$idField]); $this->assertSame(1, $this->table->delete(array("{$idField} = 2", 'is_delicious'))); $fruits = $this->db->fetchAll($fetchAllSql); $this->assertSame(3, count($fruits)); $this->assertEquals(3, $fruits[0][$idField]); }
/** * @expectedException \Dewdrop\Exception */ public function testBadFetchAllThrowsException() { $this->db->fetchAll('not even close to valid sql'); }