Esempio n. 1
0
 public function test_collection()
 {
     $collection = new Jam_Query_Builder_Collection('test_position');
     $data = array(array('id' => 1, 'name' => 'name 1', 'model' => 'test_position'), array('id' => 2, 'name' => 'name 2', 'model' => 'test_position'), array('id' => 3, 'name' => 'name 3', 'model' => 'test_position'));
     $collection->load_fields($data);
     $unserialized = unserialize(serialize($collection));
     $this->assertCount(3, $unserialized);
     foreach ($data as $i => $item) {
         $this->assertTrue($unserialized[$i]->loaded());
         $this->assertEquals($item, $unserialized[$i]->as_array());
     }
 }
 public function model_call_ansestors(Jam_Model $model, Jam_event_data $data)
 {
     $path_ids = $model->path_ids();
     if ($path_ids) {
         $data->return = Jam::all($model)->where($model->meta()->primary_key(), 'IN', $path_ids);
     } else {
         $data->return = Jam_Query_Builder_Collection::factory($model)->load_fields(array());
     }
 }
Esempio n. 3
0
 public function test_select()
 {
     $select = $this->form->select('status', array('choices' => array('draft' => 'Draft Title', 'published' => 'Published Title', 'review' => 'Published Review')), array('class' => 'myclass'));
     $this->assertSelectCount('select.myclass[name="status"][id="status"]', 1, $select);
     $this->assertSelectCount('option', 3, $select);
     $this->assertSelectEquals('option[value="draft"][selected="selected"]', 'Draft Title', 1, $select);
     $this->assertSelectEquals('option[value="published"]', 'Published Title', 1, $select);
     $this->assertSelectEquals('option[value="review"]', 'Published Review', 1, $select);
     $blogs = new Jam_Query_Builder_Collection('test_blog');
     $blogs->load_fields(array(array('id' => 1, 'name' => 'Flowers blog', 'url' => 'http://flowers.wordpress.com'), array('id' => 2, 'name' => 'Awesome programming', 'url' => 'http://programming-blog.com'), array('id' => 3, 'name' => 'Tabless', 'url' => 'http://bobby-tables-ftw.com')));
     $this->form->object()->test_blog = $blogs[0];
     $select = $this->form->select('test_blog', array('choices' => $blogs, 'include_blank' => 'BLANK'), array('class' => 'myclass2'));
     $this->assertSelectCount('select.myclass2[name="test_blog"][id="test_blog"]', 1, $select);
     $this->assertSelectCount('option', count($blogs) + 1, $select);
     $this->assertSelectEquals('option[value="' . $this->post->test_blog_id . '"][selected="selected"]', $blogs[0]->name(), 1, $select);
     foreach ($blogs as $blog) {
         $this->assertSelectEquals('option[value="' . $blog->id() . '"]', $blog->name(), 1, $select);
     }
 }
Esempio n. 4
0
 public function test_load_polymorphic()
 {
     $collection = new Jam_Query_Builder_Collection('test_position');
     $data = array(array('id' => 2, 'name' => 'Freelancer', 'model' => 'test_position_big', 'size' => 'big'), array('id' => 1, 'name' => 'Staff', 'model' => 'test_position'));
     $collection->load_fields($data);
     $this->assertInstanceOf('Model_Test_Position_Big', $collection[0]);
     $this->assertEquals($data[0], $collection[0]->as_array());
     $this->assertInstanceOf('Model_Test_Position_Big', $collection->first());
     $this->assertEquals($data[0], $collection->first()->as_array());
     $this->assertInstanceOf('Model_Test_Position', $collection[1]);
     $this->assertEquals($data[1], $collection[1]->as_array());
 }
 public function builder_call_descendants_of(Jam_Query_Builder_Collection $collection, Jam_Event_Data $data, $parent)
 {
     $collection->join_table($this->_branches_table)->on($this->_descendant_key, '=', ':primary_key')->end()->where($this->_branches_table . '.' . $this->_ansestor_key, '=', $parent);
 }
Esempio n. 6
0
 public function data_remove()
 {
     $collection1 = new Jam_Query_Builder_Collection('test_element');
     $collection1->load_fields(array(array('id' => 1, 'name' => 'one'), array('id' => 3, 'name' => 'three')));
     return array(array(Jam::build('test_element')->load_fields(array('id' => 1, 'name' => 'one')), array(3 => 'three')), array(Jam::build('test_element')->load_fields(array('id' => 6, 'name' => 'one')), array(1 => 'one', 3 => 'three')), array(3, array(1 => 'one')), array(array('id' => 3), array(1 => 'one')), array($collection1, array()), array(array(Jam::build('test_element')->load_fields(array('id' => 3, 'name' => 'three')), Jam::build('test_element')->load_fields(array('id' => 1, 'name' => 'one'))), array()));
 }
Esempio n. 7
0
 protected function _find_item($foreign_model, $key)
 {
     if (!$key) {
         return;
     }
     if ($key instanceof Jam_Model) {
         if (!$key->loaded()) {
             return;
         }
         $query = $this->query_builder('all', $key);
     } else {
         $query = new Jam_Query_Builder_Collection($foreign_model);
         $query->where(':unique_key', '=', $key)->limit(1);
     }
     return $query->current();
 }
Esempio n. 8
0
 public function apply(Jam_Query_Builder_Collection $collection)
 {
     $collection->limit($this->per_page())->offset($this->offset());
     return $this;
 }