Пример #1
0
 public function testIt()
 {
     $m = $this->_model;
     $r = $m->getRow(1);
     $this->assertEquals('aaabbbccc', $r->foo);
     $this->assertEquals('abcd', $r->bar);
     $this->assertEquals('aha', $r->baz);
     $r = $m->getRow(2);
     $this->assertEquals('bam', $r->foo);
     $this->assertEquals('bum', $r->bar);
     $this->assertEquals(null, $r->baz);
     $r = $m->getRow($m->select()->whereEquals('baz', 'aha'));
     $this->assertNotNull($r);
     $this->assertEquals(1, $r->id);
     $r = $m->getRow($m->select()->whereNull('baz'));
     $this->assertNotNull($r);
     $this->assertEquals(2, $r->id);
     $r = $m->getRows($m->select()->order('baz'));
     $this->assertEquals(2, count($r));
     $r = $m->createRow();
     $r->foo = 'xxy';
     $r->baz = 'xxz';
     $r->save();
     $tableName = Kwf_Model_Abstract::getInstance('Kwf_Model_DbWithConnection_DbSiblingProxy_DbModel')->getTable()->info(Zend_Db_Table_Abstract::NAME);
     $m = new Kwf_Model_Db(array('table' => $tableName));
     $r = $m->getRow(3);
     $this->assertEquals('xxy', $r->foo);
     $this->assertEquals(null, $r->bar);
     $tableName = Kwf_Model_Abstract::getInstance('Kwf_Model_DbWithConnection_DbSiblingProxy_SiblingModel')->getTable()->info(Zend_Db_Table_Abstract::NAME);
     $m = new Kwf_Model_Db(array('table' => $tableName));
     $r = $m->getRow(3);
     $this->assertEquals('xxz', $r->baz);
 }
Пример #2
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('sum_field_int' => new Kwf_Model_Select_Expr_SumFields(array('value2', 10)), 'sum_int_int' => new Kwf_Model_Select_Expr_SumFields(array(100, 10, 99)), 'sum_field_field' => new Kwf_Model_Select_Expr_SumFields(array('value2', 'id')));
     parent::__construct($config);
 }
Пример #3
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('date_year' => new Kwf_Model_Select_Expr_Date_Year('date'), 'date_year_two_digits' => new Kwf_Model_Select_Expr_Date_Year('date', Kwf_Model_Select_Expr_Date_Year::FORMAT_DIGITS_TWO), 'date_format' => new Kwf_Model_Select_Expr_Date_Format('date'), 'date_format2' => new Kwf_Model_Select_Expr_Date_Format('date', 'd.m.Y'));
     parent::__construct($config);
 }
Пример #4
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_child');
     $config['table'] = $this->_tableName;
     $this->_referenceMap = array('Parent' => 'parent_id->Kwf_Model_DbWithConnection_ParentExpr_ParentModel');
     parent::__construct($config);
 }
Пример #5
0
 public function __construct($config = array())
 {
     $this->_tableName = 'import' . uniqid();
     $config['table'] = $this->_tableName;
     Kwf_Registry::get('db')->query("CREATE TABLE {$this->_tableName} (\n            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n            `foo` VARCHAR( 200 ) NOT NULL ,\n            `bar` VARCHAR( 200 ) NOT NULL\n        ) ENGINE = INNODB");
     parent::__construct($config);
 }
Пример #6
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_childsum_foo');
     $config['table'] = $this->_tableName;
     $this->_dependentModels['FooTooBar'] = 'Kwf_Model_DbWithConnection_ExprChildSum_FooToBarModel';
     parent::__construct($config);
 }
Пример #7
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('foo1' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id'), 'foo2' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id', ', '));
     parent::__construct($config);
 }
Пример #8
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('age' => new Kwf_Model_Select_Expr_Date_Age('birth'), 'age2' => new Kwf_Model_Select_Expr_Sql("SELECT expr{age} + expr{age}"));
     parent::__construct($config);
 }
Пример #9
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_parent');
     $config['table'] = $this->_tableName;
     $this->_dependentModels['Childs'] = 'Kwf_Model_DbWithConnection_ParentParentExpr_MiddleModel';
     parent::__construct($config);
 }
Пример #10
0
 protected function _init()
 {
     parent::_init();
     $this->_exprs['name'] = new Kwf_Model_Select_Expr_Concat(array(new Kwf_Model_Select_Expr_Field('date'), new Kwf_Model_Select_Expr_String(': '), new Kwf_Model_Select_Expr_Field('title')));
     $this->_exprs['date_year'] = new Kwf_Model_Select_Expr_Date_Year('date');
     $this->_exprs['is_top'] = new Kwf_Model_Select_Expr_If(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('is_top_checked', 1), new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_IsNull('is_top_expire'), new Kwf_Model_Select_Expr_HigherEqual('is_top_expire', new Kwf_Date(mktime())))))), new Kwf_Model_Select_Expr_String(1), new Kwf_Model_Select_Expr_String(0));
 }
Пример #11
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('price' => new Kwf_Model_Select_Expr_Integer(100), 'amount' => new Kwf_Model_Select_Expr_Integer('3'), 'total' => new Kwf_Model_Select_Expr_Multiply(array(new Kwf_Model_Select_Expr_Field('price'), new Kwf_Model_Select_Expr_Field('amount'))));
     parent::__construct($config);
 }
Пример #12
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('position' => new Kwf_Model_Select_Expr_Position('points', array('gr')), 'position_dir' => new Kwf_Model_Select_Expr_Position('points', array('gr'), 'asc'));
     parent::__construct($config);
 }
Пример #13
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_parent2');
     $config['table'] = $this->_tableName;
     $this->_dependentModels['Childs'] = 'Kwf_Model_DbWithConnection_ProxyReferences_ChildModel';
     parent::__construct($config);
 }
Пример #14
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('inrange' => new Kwf_Model_Select_Expr_Area(47.8904081, 13.1834356, 50));
     parent::__construct($config);
 }
 protected function _init()
 {
     parent::_init();
     $this->_exprs['category_name'] = new Kwf_Model_Select_Expr_Parent('Category', 'name');
     if (!count($this->_referenceMap['Item'])) {
         throw new Kwf_Exception("Reference 'Item' must be set in model '" . get_class($this) . "' and set in component as setting 'categoryToItemModelName'");
     }
 }
Пример #16
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $s = new Kwf_Model_Select();
     $config['exprs'] = array('foo1' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id'), 'foo2' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id', ', '), 'foo3' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id', ', ', $s, 'sort_field'), 'foo4' => new Kwf_Model_Select_Expr_Child_GroupConcat('Children', 'id', ', ', $s, array('field' => 'sort_field', 'direction' => 'DESC')));
     parent::__construct($config);
 }
Пример #17
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_child');
     $config['table'] = $this->_tableName;
     $this->_referenceMap = array('Parent' => 'parent_id->Kwf_Model_DbWithConnection_ParentExprDeletedFlag_ParentModel');
     $this->_exprs['parent_foo'] = new Kwf_Model_Select_Expr_Parent('Parent', 'foo');
     parent::__construct($config);
 }
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_childstart');
     $config['table'] = $this->_tableName;
     $this->_dependentModels['Childs'] = 'Kwf_Model_DbWithConnection_ProxyReferences_ParentModel';
     $this->_referenceMap = array('StartParent' => 'parent_id->Kwf_Model_DbWithConnection_ProxyReferences_ParentModel');
     parent::__construct($config);
 }
Пример #19
0
 public function __construct($config = array())
 {
     $this->_tableName = 'sibling' . uniqid();
     $config['table'] = $this->_tableName;
     Kwf_Registry::get('db')->query("CREATE TABLE {$this->_tableName} (\n                `master_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                `baz` VARCHAR( 200 ) NOT NULL\n            ) ENGINE = INNODB");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (master_id, baz) VALUES ('1', 'aha')");
     parent::__construct($config);
 }
Пример #20
0
 public function __construct($config = array())
 {
     $today = date('Y-m-d');
     $tomorrow = date('Y-m-d', strtotime("{$today} +1 day"));
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array('age' => new Kwf_Model_Select_Expr_Date_Age('birth'), 'age_ref' => new Kwf_Model_Select_Expr_Date_Age('birth', new Kwf_Date($tomorrow)));
     parent::__construct($config);
 }
 public function __construct()
 {
     $this->_tableName = 'relation_sibling' . uniqid();
     $config['table'] = $this->_tableName;
     Kwf_Registry::get('db')->query("CREATE TABLE {$this->_tableName} (\n            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n            `foo` INT NOT NULL\n        ) ENGINE = INNODB");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id, foo) VALUES ('1', 123)");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id, foo) VALUES ('2', 321)");
     parent::__construct($config);
 }
 public function __construct()
 {
     $this->_tableName = 'master' . uniqid();
     $config['table'] = $this->_tableName;
     Kwf_Registry::get('db')->query("CREATE TABLE {$this->_tableName} (\n            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n        ) ENGINE = INNODB");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id) VALUES ('1')");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id) VALUES ('2')");
     parent::__construct($config);
 }
Пример #23
0
 protected function _init()
 {
     parent::_init();
     $this->_referenceMap['User'] = '******' . Kwf_Registry::get('config')->user->model;
     $this->_exprs['component_id'] = new Kwf_Model_Select_Expr_Parent('ComponentToTag', 'component_id');
     $this->_exprs['tag_count_used'] = new Kwf_Model_Select_Expr_Parent('ComponentToTag', 'tag_count_used');
     $this->_exprs['tag_name'] = new Kwf_Model_Select_Expr_Parent('ComponentToTag', 'tag_name');
     $this->_exprs['user_email'] = new Kwf_Model_Select_Expr_Parent('User', 'email');
 }
Пример #24
0
 public function __construct($config = array())
 {
     $this->_tableName = 'master' . uniqid();
     $config['table'] = $this->_tableName;
     Kwf_Registry::get('db')->query("CREATE TABLE {$this->_tableName} (\n            `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n            `foo` VARCHAR( 200 ) NOT NULL ,\n            `bar` VARCHAR( 200 ) NOT NULL\n        ) ENGINE = INNODB");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id, foo, bar) VALUES ('1', 'aaabbbccc', 'abcd')");
     Kwf_Registry::get('db')->query("INSERT INTO {$this->_tableName}\n                        (id, foo, bar) VALUES ('2', 'bam', 'bum')");
     parent::__construct($config);
 }
Пример #25
0
 protected function _init()
 {
     parent::_init();
     $this->_exprs['expr_bar'] = new Kwf_Model_Select_Expr_Field('bar');
     $this->_exprs['expr_bar2'] = new Kwf_Model_Select_Expr_Field('bar2');
     $this->_exprs['expr_foo'] = new Kwf_Model_Select_Expr_Field('foo');
     $this->_exprs['expr_bar_compare'] = new Kwf_Model_Select_Expr_Equals('expr_bar', new Kwf_Model_Select_Expr_Field('bar2'));
     $this->_exprs['expr_foo_bar_higher'] = new Kwf_Model_Select_Expr_HigherEqual('expr_bar', new Kwf_Model_Select_Expr_Field('expr_foo'));
 }
Пример #26
0
 protected function _init()
 {
     parent::_init();
     $s = $this->select();
     $s->limit(1);
     $s->order('valid_from', 'DESC');
     $s->where(new Kwf_Model_Select_Expr_Lower('valid_from', new Kwf_DateTime(time())));
     $this->_exprs['current_price'] = new Kwf_Model_Select_Expr_Child('Prices', new Kwf_Model_Select_Expr_Field('price'), $s);
     $this->_exprs['current_price_id'] = new Kwf_Model_Select_Expr_Child('Prices', new Kwf_Model_Select_Expr_Field('id'), $s);
 }
Пример #27
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_middle');
     $config['table'] = $this->_tableName;
     $this->_referenceMap = array('Parent' => 'parent_id->Kwf_Model_DbWithConnection_ParentParentExpr_ParentModel');
     $this->_dependentModels['Childs'] = 'Kwf_Model_DbWithConnection_ParentParentExpr_ChildModel';
     $this->_exprs['parent_foo'] = new Kwf_Model_Select_Expr_Parent('Parent', 'foo');
     $this->_exprs['child_count'] = new Kwf_Model_Select_Expr_Child_Count('Childs', null);
     parent::__construct($config);
 }
 public function hasColumn($col)
 {
     if ($col == 'visible') {
         return false;
     }
     if ($col == 'component_id') {
         return false;
     }
     return parent::hasColumn($col);
 }
Пример #29
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest_child');
     $config['table'] = $this->_tableName;
     $this->_referenceMap = array('Parent' => 'parent_id->Kwf_Model_DbWithConnection_ParentExprIf_ParentModel');
     $this->_exprs['bar_is_null'] = new Kwf_Model_Select_Expr_IsNull('bar');
     $this->_exprs['if_field'] = new Kwf_Model_Select_Expr_If(new Kwf_Model_Select_Expr_Field('bar_is_null'), new Kwf_Model_Select_Expr_Parent('Parent', 'id'), new Kwf_Model_Select_Expr_Parent('Parent', 'parent_value'));
     $this->_exprs['if_field_sibling'] = new Kwf_Model_Select_Expr_If(new Kwf_Model_Select_Expr_Field('bar_is_null'), new Kwf_Model_Select_Expr_Parent('Parent', 'id'), new Kwf_Model_Select_Expr_Parent('Parent', 'sibling_value'));
     $this->_exprs['parent_value'] = new Kwf_Model_Select_Expr_Parent('Parent', 'parent_value');
     $this->_exprs['sibling_value'] = new Kwf_Model_Select_Expr_Parent('Parent', 'sibling_value');
     parent::__construct($config);
 }
Пример #30
0
 public function __construct($config = array())
 {
     $this->_tableName = uniqid('dbtest');
     $config['table'] = $this->_tableName;
     $config['exprs'] = array();
     $config['exprs']['count_model2'] = new Kwf_Model_Select_Expr_Child_Count('Model2');
     $config['exprs']['count_model2_field'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Count('foo2'));
     $config['exprs']['count_model2_distinct'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Count('foo2', true));
     $config['exprs']['sum_model2'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Sum('foo2'));
     $select = new Kwf_Model_Select();
     $select->whereEquals('bar', 'bam');
     $config['exprs']['count_model2_bam'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Count(), $select);
     $config['exprs']['count_model2_bam_distinct'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Count('foo2', true), $select);
     $config['exprs']['sum_model2_bam'] = new Kwf_Model_Select_Expr_Child('Model2', new Kwf_Model_Select_Expr_Sum('foo2'), $select);
     parent::__construct($config);
 }