public function getRow($select) { if (is_array($select) && count($select) == 1 && isset($select['equals']) && count($select['equals']) == 1 && isset($select['equals'][$this->getPrimaryKey()])) { $select = $select['equals'][$this->getPrimaryKey()]; } if (!is_object($select) && !is_array($select)) { if (isset($this->_cacheRows[$select])) { return $this->_cacheRows[$select]; } $cacheId = $this->_getCacheId($select); $success = false; $cacheData = Kwf_Cache_Simple::fetch($cacheId, $success); if (!$success) { $cacheData = array(); $row = parent::getRow($select); if (!$row) { return $row; } $cacheData[$this->getPrimaryKey()] = $select; foreach ($this->_cacheColumns as $c) { $cacheData[$c] = $row->{$c}; } Kwf_Cache_Simple::add($cacheId, $cacheData); $this->_cacheRows[$select] = $row; return $row; } $ret = new $this->_rowClass(array('model' => $this, 'cacheData' => $cacheData)); $this->_cacheRows[$select] = $ret; return $ret; } else { return parent::getRow($select); } }
public function testIssetWithProxySiblings() { $fnf = new Kwf_Model_FnF(array('columns' => array('id', 'name', 'data'), 'data' => array(array('id' => 4, 'name' => 'foo', 'data' => json_encode(array('name1' => 'foo1')))))); $model = new Kwf_Model_Proxy(array('proxyModel' => $fnf, 'siblingModels' => array(new Kwf_Model_Field(array('fieldName' => 'data', 'columns' => array('name1')))))); $this->assertEquals(array('id', 'name', 'data'), $fnf->getColumns()); $this->assertTrue($fnf->hasColumn('id')); $this->assertTrue($fnf->hasColumn('name')); $this->assertFalse($fnf->hasColumn('name1')); $this->assertEquals(array('id', 'name', 'data', 'name1'), $model->getColumns()); $this->assertTrue($model->hasColumn('id')); $this->assertTrue($model->hasColumn('name')); $this->assertTrue($model->hasColumn('name1')); $row = $model->getRow(4); // isset $this->assertTrue(isset($row->name)); $this->assertFalse(isset($row->bar)); $this->assertTrue(isset($row->name1)); // get $this->assertEquals(4, $row->id); $this->assertEquals('foo', $row->name); $this->assertEquals('foo1', $row->name1); // set $row->name = 'bar'; $this->assertEquals('bar', $row->name); }
public function testToArrayProxy() { $fnf = new Kwf_Model_FnF(array('uniqueIdentifier' => 'unique', 'columns' => array('id', 'firstname', 'timefield'), 'uniqueColumns' => array('id'), 'data' => array(array('id' => 1, 'firstname' => 'Max', 'timefield' => '2008-06-09 00:00:00')))); $proxy = new Kwf_Model_Proxy(array('proxyModel' => $fnf)); $result = $proxy->getRow(1)->toArray(); $this->assertEquals(1, $result['id']); $this->assertEquals('Max', $result['firstname']); $this->assertEquals('2008-06-09 00:00:00', $result['timefield']); }
public function testDirtyColumnsWithProxy() { $model = new Kwf_Model_Proxy(array('proxyModel' => new Kwf_Model_Db(array('table' => $this->_tableName)))); $row = $model->getRow(1); $this->assertEquals($row->getDirtyColumns(), array()); $this->assertEquals($row->isDirty(), false); $this->assertEquals($row->getCleanValue('test1'), 'foo'); $row->test1 = 'blubb'; $this->assertEquals($row->getDirtyColumns(), array('test1')); $this->assertEquals($row->isDirty(), true); $this->assertEquals($row->getCleanValue('test1'), 'foo'); }
public function testUniqueRowObjectCreateRow() { $fnf = new Kwf_Model_FnF(); $fnf->setData(array(array('id' => 1, 'name' => 'foo'))); $proxy = new Kwf_Model_Proxy(array('proxyModel' => $fnf)); $r1 = $proxy->createRow(); $newId = $r1->save(); $this->assertEquals(2, $newId); $r2 = $proxy->getRow(2); $r1->name = 'foo1'; $this->assertEquals($r2->name, 'foo1'); $this->assertTrue($r1 === $r2); }
public function getRow($select) { $syncDone = $this->_synchronize(); $ret = parent::getRow($select); $this->_unlockSync(); if ($syncDone) { $this->_afterSync(); } return $ret; }