Esempio n. 1
0
 public function test_find_by_token()
 {
     $current_time = time();
     $expected_sql = "SELECT `test_user_tokens`.* FROM `test_user_tokens` WHERE `test_user_tokens`.`token` = '59ed73c1a3c105e7409c69c21770d674949c07e9' AND `test_user_tokens`.`expires` >= {$current_time}";
     $sql = (string) Jam::all('test_user_token')->valid_token('59ed73c1a3c105e7409c69c21770d674949c07e9', $current_time);
     $this->assertEquals($expected_sql, $sql);
 }
Esempio n. 2
0
 public function model_call_update_token(Jam_Model $model, Jam_Event_Data $data)
 {
     do {
         $model->{$this->_field} = $this->new_token();
     } while (Jam::all($model->meta()->model())->where($this->_field, '=', $model->{$this->_field})->count_all() > 0);
     $data->return = $model;
 }
Esempio n. 3
0
 public function test_collection_class()
 {
     $this->assertInstanceOf('Model_Collection_Test_Author', Jam::all('test_author'));
     $collection = Jam::all('test_author')->where_author(1);
     $this->assertCount(1, $collection->where);
     $this->assertInstanceOf('Jam_Query_Builder_Collection', Jam::all('test_blog'));
 }
Esempio n. 4
0
 /**
  * @covers Model_Collection_Promotion::not_expired
  */
 public function test_not_expired()
 {
     $time = strtotime('2013-02-02');
     $sql = (string) Jam::all('promotion')->not_expired($time);
     $expected_sql = "SELECT `promotions`.* FROM `promotions` WHERE (`promotions`.`expires_at` IS NULL OR `promotions`.`expires_at` >= '2013-02-02 00:00:00')";
     $this->assertEquals($expected_sql, $sql);
 }
Esempio n. 5
0
File: Test.php Progetto: Konro1/pms
 protected function _load_token($token)
 {
     if (!$token) {
         return NULL;
     }
     return is_object($token) ? $token : Jam::all('test_user_token')->valid_token($token)->first();
 }
Esempio n. 6
0
    public function test_render()
    {
        $collection = Jam::all('test_city')->load_fields(array(array('id' => 1, 'name' => 'London', 'population' => 10), array('id' => 2, 'name' => 'New York', 'population' => 15)));
        $name = new Tart_Column();
        $name->sort(FALSE);
        $population = new Tart_Column();
        $population->sort(FALSE);
        $columns = array('name' => $name, 'population' => $population);
        $table = new Tart_Table($collection, $columns);
        $table->selected(FALSE);
        $expected = <<<HTML
<table class="table table-striped table-hover">
  <thead>
    <th>Name</th>
    <th>Population</th>
  </thead>
  <tbody>
    <tr class="test_city-1">
      <td>London</td>
      <td>10</td>
    </tr>
    <tr class="test_city-2">
      <td>New York</td>
      <td>15</td>
    </tr>
  </tbody>
</table>
HTML;
        $this->assertSame($expected, $table->render());
        $table->selected(array(1));
        $expected = <<<HTML_SELECTED
<table class="table table-striped table-hover">
  <thead>
    <th width="10">
      <input type="checkbox" name="all" value="1"/>
    </th>
    <th>Name</th>
    <th>Population</th>
  </thead>
  <tbody>
    <tr class="test_city-1">
      <td>
        <input type="checkbox" name="id[]" value="1" checked="1"/>
      </td>
      <td>London</td>
      <td>10</td>
    </tr>
    <tr class="test_city-2">
      <td>
        <input type="checkbox" name="id[]" value="2"/>
      </td>
      <td>New York</td>
      <td>15</td>
    </tr>
  </tbody>
</table>
HTML_SELECTED;
        $this->assertSame($expected, $table->render());
    }
Esempio n. 7
0
File: Token.php Progetto: Konro1/pms
 public function generate_unique_token()
 {
     do {
         $this->token = Model_Auth_User_Token::generate_token();
         $collection = Jam::all($this->meta()->model())->where_key($this->token)->limit(1);
     } while (Jam::all($this)->where('token', '=', $this->token)->limit(1)->count_all() > 0);
     return $this;
 }
Esempio n. 8
0
 public function assertPositions($group, array $expected_positions)
 {
     $positions = Jam::all('test_video');
     if ($group) {
         $positions->where('group', '=', $group);
     }
     $this->assertSame($expected_positions, $positions->as_array('id', 'position'));
 }
Esempio n. 9
0
 public function action_name()
 {
     $q = $this->request->query('query');
     $model = $this->request->query('model');
     $names = Jam::all($model)->where(':name_key', 'LIKE', "%{$q}%")->limit(5);
     $this->response->headers('Content-Type', 'application/json');
     $this->response->body(json_encode($names->as_array(NULL, ':name_key')));
 }
Esempio n. 10
0
 public function test_remember()
 {
     $user = Jam::find('test_user', 1);
     $token = $this->auth->remember($user);
     $jam_token = Jam::all('test_user_token')->valid_token($token->token)->first();
     $this->assertNotNull($jam_token);
     $this->auth->login_with_token($token);
     $this->assertTrue($this->auth->logged_in(), 'should be logged in after complete login');
 }
 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. 12
0
 public function test_table()
 {
     $collection = Jam::all('test_city')->load_fields(array('id' => 1, 'name' => 'London'));
     $items = array('name' => Tart::column());
     $table = Tart::table($collection, $items);
     $this->assertInstanceOf('Tart_Table', $table);
     $this->assertEquals($collection, $table->collection());
     $this->assertEquals($items, $table->items());
 }
Esempio n. 13
0
 public function action_reorder()
 {
     if ($this->request->method() === Request::POST) {
         Jam::all($this->request->query('model'))->sort_ids(Arr::get($this->request->post(), 'item', array()));
         $this->response->body('OK');
     } else {
         $this->response->body('Empty post');
     }
 }
Esempio n. 14
0
 public function collection(Jam_Model $model)
 {
     $collection = Jam::all($this->foreign_model);
     $collection->join_table($this->join_table)->context_model($this->foreign_model)->on($this->association_foreign_key, '=', ':primary_key')->end()->where($this->join_table . '.' . $this->foreign_key, '=', $model->id());
     if ($this->join_table_paranoid) {
         $collection->where($this->join_table . '.' . $this->join_table_paranoid, '=', FALSE);
     }
     return $collection;
 }
Esempio n. 15
0
 public function cetak_jadwal()
 {
     $tahun = Input::get('tahun');
     $t = DB::table('kelas')->where('kelas', '7')->count();
     $d = DB::table('kelas')->where('kelas', '8')->count();
     $s = DB::table('kelas')->where('kelas', '9')->count();
     $jam = Jam::all();
     return View::make('laporan.cetak_jadwal')->withTitle('Laporan Jadwal Pelajaran')->with('t', $t)->with('d', $d)->with('s', $s)->with('jam', $jam)->with('tahun', $tahun);
 }
Esempio n. 16
0
 public function collection(Jam_Model $model)
 {
     $collection = Jam::all($this->foreign_model);
     $collection->join_table($this->join_table)->context_model($this->foreign_model)->on($this->join_table . '.' . $this->term_key, '=', ':primary_key')->end()->where($this->join_table . '.' . $this->item_polymorphic_key, '=', DB::expr(':model', array(':model' => $model->meta()->model())))->where($this->join_table . '.' . $this->item_key, '=', $model->id());
     if ($this->vocabulary_ids()) {
         $collection->where($this->vocabulary_foreign_key, 'IN', $this->vocabulary_ids());
     }
     return $collection;
 }
Esempio n. 17
0
 public function test_choices()
 {
     $blogs = Jam::all('test_blog')->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')));
     $select = $blogs->as_array(':primary_key', ':name_key');
     $choices = Jam_Form::list_choices($blogs);
     $this->assertEquals($select, $choices);
     $choices = Jam_Form::list_choices($select);
     $this->assertEquals($select, $choices);
 }
 /**
  * @covers Kohana_Jam_Association_Materializedpath_Belongsto::model_after_save
  */
 public function test_belongsto()
 {
     $two = Jam::find('category', 2);
     $seven = Jam::find('category', 7);
     $two->parent = $seven;
     $two->save();
     $result = Jam::all('category')->as_array('id', 'path');
     $expected = array(1 => NULL, 2 => '1/3/6/7', 3 => '1', 4 => '1/3/6/7/2', 5 => '1/3/6/7/2', 6 => '1/3', 7 => '1/3/6', 8 => '1/3/6');
     $this->assertEquals($expected, $result);
 }
Esempio n. 19
0
 public function test_set_filter()
 {
     $column = new Tart_Column();
     $filter = new Tart_Filter(array());
     $table = new Tart_Table(Jam::all('test_city'));
     $column->item($this->city);
     $column->set_filter($filter, 'area');
     $rendered = (string) $column->name('name')->item($this->city)->render();
     $this->assertSelectEquals('span[data-provide="filters"][draggable="true"][data-dropzone=".tart-filter"', 'Bigville', TRUE, $rendered);
 }
 public function feed_content($model, array $filters, $view)
 {
     $collection = Jam::all($model);
     if ($filters) {
         foreach ($filters as $filter) {
             $collection->{$filter}();
         }
     }
     return View::factory($view, array('collection' => $collection))->render();
 }
Esempio n. 21
0
 public function test_promocode_find()
 {
     $find_by_id = Jam::all('promo_code')->where(':unique_key', '=', 1);
     $expected_sql = "SELECT `promo_codes`.* FROM `promo_codes` WHERE `promo_codes`.`id` = 1";
     $this->assertEquals($expected_sql, (string) $find_by_id);
     $find_by_string = Jam::all('promo_code')->where(':unique_key', '=', 'ads');
     $expected_sql = "SELECT `promo_codes`.* FROM `promo_codes` WHERE `promo_codes`.`code` = 'ads'";
     $this->assertEquals($expected_sql, (string) $find_by_string);
     $find_by_code = Jam::all('promo_code')->where(':unique_key', '=', '621ZWM');
     $expected_sql = "SELECT `promo_codes`.* FROM `promo_codes` WHERE `promo_codes`.`code` = '621ZWM'";
     $this->assertEquals($expected_sql, (string) $find_by_code);
 }
Esempio n. 22
0
    public function test_render_batch_actions()
    {
        $collection = Jam::all('test_city');
        $index = new Tart_Index($collection, 0);
        $index->batch_actions(array('test' => 'batch'));
        $expected = <<<HTML
<div class="form-inline">
  <label>With Selected:</label>
  <button type="submit" name="action" value="test" class="btn">batch</button>
</div>
HTML;
        $this->assertEquals($expected, (string) $index->render_batch_actions());
    }
Esempio n. 23
0
 public function test_association_create()
 {
     $author = Jam::build('test_author', array('name' => 'Joe'));
     $author->test_posts = array(Jam::build('test_post', array('name' => 'hardware', 'test_categories' => array(Jam::build('test_category', array('name' => 'cat1', 'test_author' => $author)), Jam::build('test_category', array('name' => 'cat2', 'test_author' => $author)), array('id' => 1), 5), 'test_images' => Jam::build('test_image', array('file' => 'file11', 'test_copyright' => Jam::build('test_copyright', array('name' => 'copy 1')))), 'test_blog' => array('name' => 'new blog'))), Jam::build('test_post', array('name' => 'software', 'test_categories' => array(Jam::build('test_category', array('name' => 'cat3', 'test_author' => $author)), Jam::build('test_category', array('name' => 'cat4', 'test_author' => $author)), 'Category Two'), 'test_blog' => array('id' => 1, 'name' => 'new blog title'))), array('name' => 'new post', 'test_cover_image' => array('file' => 'new file')));
     $this->assertSame($author, $author->test_posts[0]->test_categories[0]->test_author, 'Should be the same object');
     $this->assertInstanceOf('Model_Test_Blog', $author->test_posts[0]->test_blog);
     $this->assertEquals('new blog', $author->test_posts[0]->test_blog->name());
     $this->assertFalse($author->test_posts[0]->test_blog->loaded());
     $this->assertInstanceOf('Model_Test_Blog', $author->test_posts[1]->test_blog);
     $this->assertEquals('new blog title', $author->test_posts[1]->test_blog->name());
     $this->assertEquals(1, $author->test_posts[1]->test_blog->id());
     $this->assertTrue($author->test_posts[1]->test_blog->loaded());
     $this->assertInstanceOf('Model_Test_Post', $author->test_posts[2]);
     $this->assertEquals('new post', $author->test_posts[2]->name());
     $this->assertFalse($author->test_posts[2]->loaded());
     $this->assertInstanceOf('Model_Test_Image', $author->test_posts[2]->test_cover_image);
     $this->assertEquals('new file', (string) $author->test_posts[2]->test_cover_image->file);
     $this->assertFalse($author->test_posts[2]->test_cover_image->loaded());
     $this->assertTrue($author->test_posts[0]->test_categories->has(1));
     $this->assertTrue($author->test_posts[0]->test_categories->has(5));
     $author->save();
     $author = Jam::all('test_author')->where('name', '=', 'Joe')->first();
     $this->assertEquals($author->id(), $author->test_posts[0]->test_categories[0]->test_author->id(), 'Should be the same author');
     $this->assertEquals('cat1', $author->test_posts[0]->test_categories[0]->name(), 'Should have created the test_category');
     $this->assertEquals('Category One', $author->test_posts[0]->test_categories[2]->name(), 'Should have loaded the category based on id');
     $this->assertEquals($author->id(), $author->test_posts[0]->test_categories[1]->test_author->id(), 'Should be the same author');
     $this->assertCount(1, $author->test_posts[0]->test_images);
     $this->assertNotNull($author->test_posts[0]->test_images[0]->test_copyright);
     $this->assertEquals($author->test_posts[0]->test_images[0]->file, 'file11');
     $this->assertEquals($author->test_posts[0]->test_images[0]->test_copyright->name(), 'copy 1');
     $this->assertEquals($author->id(), $author->test_posts[1]->test_categories[0]->test_author->id(), 'Should be the same author');
     $this->assertEquals('cat3', $author->test_posts[1]->test_categories[0]->name, 'Should have created the test_category');
     $this->assertEquals('Category Two', $author->test_posts[1]->test_categories[2]->name(), 'Should have loaded the category based on name');
     $this->assertEquals($author->id(), $author->test_posts[1]->test_categories[1]->test_author->id(), 'Should be the same author');
     $this->assertInstanceOf('Model_Test_Blog', $author->test_posts[0]->test_blog);
     $this->assertEquals('new blog', $author->test_posts[0]->test_blog->name());
     $this->assertTrue($author->test_posts[0]->test_blog->loaded());
     $this->assertInstanceOf('Model_Test_Blog', $author->test_posts[1]->test_blog);
     $this->assertEquals('new blog title', $author->test_posts[1]->test_blog->name());
     $this->assertEquals(1, $author->test_posts[1]->test_blog->id());
     $this->assertTrue($author->test_posts[1]->test_blog->loaded());
     $this->assertInstanceOf('Model_Test_Image', $author->test_posts[2]->test_cover_image);
     $this->assertEquals('new file', (string) $author->test_posts[2]->test_cover_image->file);
     $this->assertTrue($author->test_posts[2]->test_cover_image->loaded());
     $this->assertTrue($author->test_posts[0]->test_categories->has(1));
     $this->assertTrue($author->test_posts[0]->test_categories->has(5));
 }
Esempio n. 24
0
 public function builder_call_with_terms(Database_Query $builder, Jam_Event_Data $data, $term_slugs, $operator = 'IN', $nesting_level = 1)
 {
     if ($term_slugs) {
         if (!$term_slugs instanceof Jam_Query_Builder_Collection and !$term_slugs instanceof Jam_Array_Association) {
             $term_slugs = Jam::all('term')->slugs_children($term_slugs)->order_by('id');
         }
         $terms = $term_slugs->as_array('id', 'slug');
         $terms_ids = array_keys($terms);
         if ($nesting_level > 1) {
             $terms = Jam::all('term')->slugs_children(array_values($terms))->order_by('id');
             $terms_ids = Arr::merge($terms_ids, $terms->ids());
         }
         if ($terms_ids) {
             $unique_alias = 'terms-' . join('-', $terms_ids);
             $builder->join(array('terms_items', $unique_alias))->on($unique_alias . '.term_id', $operator, DB::expr("(" . join(',', $terms_ids) . ')'));
         }
     }
     return $builder;
 }
Esempio n. 25
0
 public function cari_jam_jadwal()
 {
     if (Request::ajax()) {
         $rombel = Input::get('rombel');
         $hari = Input::get('hari');
         $setting = Setting::first();
         if ($hari == "Senin") {
             for ($i = 2; $i <= 7; $i++) {
                 echo "<option value='{$i}'>{$i}</option>";
             }
         } else {
             $jam = Jam::all();
             echo "<option>--Pilih Jam--</option>";
             foreach ($jam as $row) {
                 echo "<option value='{$row->jam_ke}'>{$row->jam_ke}</option>";
             }
         }
     }
 }
Esempio n. 26
0
 public function validate(Jam_Validated $model, $attribute, $value)
 {
     // According to the SQL standard NULL is not checked by the unique constraint
     // We also skip this test if the value is the same as the default value
     if ($value !== $model->meta()->defaults($attribute)) {
         // Build query
         $query = Jam::all($model)->where($attribute, '=', $value);
         if ($this->scope) {
             foreach ((array) $this->scope as $scope_attribute) {
                 $query->where($scope_attribute, '=', $model->{$scope_attribute});
             }
         }
         $query->limit(1);
         if ($query->count() and (!$model->loaded() or $query[0]->id() !== $model->id())) {
             // Add error if duplicate found
             $model->errors()->add($attribute, 'unique');
         }
     }
 }
Esempio n. 27
0
 /**
  * Get the belonging model for this association using the foreign key, 
  * if the data was changed, use the key from the changed data.
  * Assign inverse_of 
  * 
  * @param  Jam_Validated $model      
  * @param  mixed         $value      changed data
  * @param  boolean       $is_changed 
  * @return Jam_Model
  */
 public function get(Jam_Validated $model, $value, $is_changed)
 {
     if ($is_changed) {
         if ($value instanceof Jam_Validated or !$value) {
             return $value;
         }
         $key = Jam_Association::primary_key($this->foreign_model, $value);
         if ($key) {
             $item = Jam::find($this->foreign_model, $key);
         } elseif (is_array($value)) {
             $item = Jam::build($this->foreign_model);
         } else {
             $item = NULL;
         }
         if ($item and is_array($value)) {
             $item->set($value);
         }
     } else {
         $item = Jam::all($this->foreign_model)->join_table($this->branches_table)->on($this->ansestor_key, '=', ':primary_key')->on($this->depth_key, '=', DB::expr(':depth', array(':depth' => 1)))->end()->where($this->branches_table . '.' . $this->descendant_key, '=', $model->id())->first();
     }
     return $this->set($model, $item, $is_changed);
 }
 /**
  * @covers Jam_Behavior_Taxonomable::builder_call_with_terms
  */
 public function test_builder_method_with_terms()
 {
     Jam::create('taxonomy_event', array('name' => 'abc', 'terms' => array(array('id' => 100, 'name' => 'poiuy', 'slug' => 'poiuy', 'vocabulary' => 1))));
     Jam::create('taxonomy_event', array('name' => 'xyz', 'terms' => array(array('id' => 101, 'name' => 'qwerty', 'slug' => 'qwerty', 'vocabulary' => 1))));
     $builder = Jam::all('taxonomy_event');
     $this->assertEquals('SELECT `taxonomy_events`.* FROM `taxonomy_events`', $builder);
     $builder->with_terms('qwerty');
     $this->assertEquals("SELECT `taxonomy_events`.* FROM `taxonomy_events` JOIN `terms_items` AS `terms-101` ON (`terms-101`.`item_id` = `taxonomy_events`.`id` AND `terms-101`.`item_model` = 'taxonomy_event' AND `terms-101`.`term_id` IN (101))", (string) $builder);
     $builder->reset();
     $builder->with_terms('poiuy');
     $this->assertEquals("SELECT `taxonomy_events`.* FROM `taxonomy_events` JOIN `terms_items` AS `terms-100` ON (`terms-100`.`item_id` = `taxonomy_events`.`id` AND `terms-100`.`item_model` = 'taxonomy_event' AND `terms-100`.`term_id` IN (100))", (string) $builder);
     $builder->reset();
     $builder->with_terms(array('qwerty', 'poiuy'));
     $this->assertEquals("SELECT `taxonomy_events`.* FROM `taxonomy_events` JOIN `terms_items` AS `terms-100-101` ON (`terms-100-101`.`item_id` = `taxonomy_events`.`id` AND `terms-100-101`.`item_model` = 'taxonomy_event' AND `terms-100-101`.`term_id` IN (100,101))", (string) $builder);
     $builder->reset();
     $builder->with_terms(array('qwerty', 'poiuy'), 'NOT IN');
     $this->assertEquals("SELECT `taxonomy_events`.* FROM `taxonomy_events` JOIN `terms_items` AS `terms-100-101` ON (`terms-100-101`.`item_id` = `taxonomy_events`.`id` AND `terms-100-101`.`item_model` = 'taxonomy_event' AND `terms-100-101`.`term_id` NOT IN (100,101))", (string) $builder);
     $builder->reset();
     $builder->with_terms('poiusadsfdsfy');
     // Missing slugs are completely ignored and do not limit the query
     $this->assertEquals("SELECT `taxonomy_events`.* FROM `taxonomy_events`", (string) $builder);
 }
Esempio n. 29
0
    public function test_render()
    {
        $filter = new Tart_Filter(array('name' => 'nn', 'test' => 'ttt'));
        $filter->entries(array('name' => Tart::entry('search', NULL, function () {
            return 'Name Active';
        }), 'test' => Tart::entry('select', array('1' => 'test 1', '2' => 'test 2'), function () {
            return 'Test Active';
        })));
        $filter->apply(Jam::all('test_city'));
        $base = Tart::uri();
        $expected = <<<HTML
<form action="{$base}/test_cities" method="GET" class="tart-filter" enctype="multipart/form-data">
  <div class="control-group control-group-input">
  <label class="control-label" for="name">Search</label>
  <div class="controls">
<input type="text" id="name" name="name" value="nn" tabindex="1" class="search" />
    
  </div>
</div>
  <div class="control-group control-group-select">
  <label class="control-label" for="test">Test</label>
  <div class="controls">
<select id="test" name="test" tabindex="2">
<option value=""> -- Select -- </option>
<option value="1">test 1</option>
<option value="2">test 2</option>
</select>
    
  </div>
</div>
  <div class="form-actions">
    <button tabindex="2" class="btn">Go</button>
  </div>
</form>
HTML;
        $this->assertSame($expected, $filter->render());
    }
Esempio n. 30
0
 public function country($name, array $options = array(), array $attributes = array(), $template = NULL)
 {
     $options = Arr::merge(array('choices' => Jam::all('location')->where('type', '=', 'country')->order_by('name')->as_array('id', 'name'), 'include_blank' => __('Select Country')), $options);
     return $this->select($name, $options, $attributes, $template);
 }