Example #1
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // Define fields
     $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'test_posts' => Jelly::field('manytomany'), 'parent' => Jelly::field('belongsto', array('foreign' => 'test_category', 'column' => 'parent_id'))));
 }
Example #2
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // All fields are aliased to different columns
     $meta->fields(array('id' => Jelly::field('primary', array('column' => 'id-alias')), 'name' => Jelly::field('string', array('column' => 'name-alias')), 'description' => Jelly::field('string', array('column' => 'description-alias')), '_id' => 'id', '_name' => 'name', '_description' => 'description', '_bar' => 'foo'));
 }
Example #3
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // Define fields
     $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string')));
 }
Example #4
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // Define fields
     $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'password' => Jelly::field('password'), 'email' => Jelly::field('email'), 'test_posts' => Jelly::field('hasmany'), 'test_post' => Jelly::field('hasone'), 'permission' => Jelly::field('belongsto', array('foreign' => 'test_role', 'column' => 'test_role_id')), '_id' => 'id'));
 }
Example #5
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'token' => new Field_String(array('unique' => true, 'rules' => array('max_length' => array(32)))), 'user' => new Field_BelongsTo(), 'user_agent' => new Field_String(), 'created' => new Field_Timestamp(array('auto_now_create' => true)), 'expires' => new Field_Timestamp()));
     // Garbace collection
     if (mt_rand(1, 100) === 1) {
         Jelly::delete('user_token')->where('expires', '<', time())->execute();
     }
 }
Example #6
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('left' => new Jelly_Field_MPTT_Left(array('column' => 'lft')), 'right' => new Jelly_Field_MPTT_Right(array('column' => 'rgt')), 'level' => new Jelly_Field_MPTT_Level(array('column' => 'lvl')), 'scope' => new Jelly_Field_MPTT_Scope(array('column' => 'scope'))));
     // Check we don't have a composite primary Key
     if (is_array($meta->primary_key())) {
         throw new Kohana_Exception('Jelly_MPTT does not support composite primary keys');
     }
 }
Example #7
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // Posts always load_with an author
     $meta->load_with(array('test_author'));
     // Set fields
     $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string'), 'slug' => Jelly::field('slug', array('unique' => TRUE)), 'status' => Jelly::field('enum', array('choices' => array('draft', 'published', 'review'))), 'created' => Jelly::field('timestamp', array('auto_now_create' => TRUE)), 'updated' => Jelly::field('timestamp', array('auto_now_update' => TRUE)), 'test_author' => Jelly::field('belongsto'), 'test_categories' => Jelly::field('manytomany'), 'approved_by' => Jelly::field('belongsto', array('foreign' => 'test_author.id', 'column' => 'approved_by')), '_id' => 'id', '_slug' => 'slug'));
 }
Example #8
0
 /**
  * Tests various properties on a meta object.
  */
 public function test_properties()
 {
     $fields = array('id' => new Jelly_Field_Primary(), 'id2' => new Jelly_Field_Primary(), 'name' => new Jelly_Field_String());
     $meta = new Jelly_Meta();
     $meta->db('foo')->table('foo')->builder('Jelly_Builder_Foo')->fields($fields)->fields(array('_id' => 'id2'))->sorting(array('foo' => 'bar'))->primary_key('id2')->name_key('name')->foreign_key('meta_fk')->load_with(array('test_post'))->behaviors(array(new Jelly_Behavior_Test()))->finalize('meta');
     // Ensure the simple properties are preserved
     $expected = array('initialized' => TRUE, 'db' => 'foo', 'table' => 'foo', 'model' => 'meta', 'primary_key' => 'id2', 'name_key' => 'name', 'foreign_key' => 'meta_fk', 'builder' => 'Jelly_Builder_Foo', 'sorting' => array('foo' => 'bar'), 'load_with' => array('test_post'));
     foreach ($expected as $property => $value) {
         $this->assertSame($meta->{$property}(), $value);
     }
     // Ensure we can retrieve fields properly
     $this->assertSame($meta->field('_id'), $fields['id2']);
     $this->assertSame($meta->field('id2')->name, 'id2');
     // Ensure all fields match
     $this->assertSame($meta->fields(), $fields);
     // Ensure defaults are set properly
     $this->assertSame($meta->defaults(), array('id' => NULL, 'id2' => NULL, 'name' => ''));
     foreach ($meta->behaviors() as $behavior) {
         // Ensure Behaviors return actual objects
         $this->assertTrue($behavior instanceof Jelly_Behavior);
     }
 }
Example #9
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Nazwa', 'rules' => array('not_empty' => NULL))), 'description' => new Field_Text(array('label' => 'Opis', 'rules' => array('not_empty' => NULL))), 'image' => new Field_File(array('label' => 'Miniaturka', 'path' => 'media/images/products', 'rules' => array('Upload::type' => array(array('jpg', 'png', 'gif'))))), 'current_image' => new Field_String(array('in_db' => FALSE)), 'category' => new Field_Category(array('label' => 'Kategoria', 'no_root' => TRUE)), 'unit' => new Field_BelongsTo(array('label' => 'Jednostka miary')), 'quantity' => new Field_Float(array('label' => 'Ilość')), 'minimal_quantity' => new Field_Float(array('label' => 'Minimalna ilość')), 'price' => new Field_Price(array('label' => 'Cena')), 'orders' => new Field_ManyToMany(array('label' => 'Zamówienia')), 'suppliers' => new Field_ManyToMany(array('label' => 'Dostawcy')), 'supplies' => new Field_HasMany(array('label' => 'Zapotrzebowanie'))))->load_with(array('unit', 'price'))->sorting(array(':name_key' => 'ASC'));
 }
Example #10
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Nazwa', 'rules' => array('not_empty' => NULL))), 'link' => new Field_String(array('label' => 'Link', 'unique' => TRUE, 'filters' => array('strtolower' => NULL))), 'description' => new Field_Text(array('label' => 'Opis', 'rules' => array('not_empty' => NULL))), 'file' => new Field_File(array('label' => 'Plik', 'path' => 'media/files', 'delete_old_file' => TRUE, 'rules' => array('Upload::not_empty' => NULL, 'Upload::type' => array(array('jpg', 'png', 'gif'))))), 'priority' => new Field_Priority(array('label' => 'Priorytet')), 'category' => new Field_BelongsTo(array('label' => 'Kategoria', 'rules' => array('not_empty' => NULL))), 'images' => new Field_HasMany(array('label' => 'Obrazy')), 'keywords' => new Field_Text(array('label' => 'Keywords', 'null' => TRUE))))->sorting(array('priority' => 'desc'));
 }
Example #11
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Nazwa')), 'value' => new Field_Float(array('label' => 'Koszt wysyłki', 'column' => 'price', 'default' => 0))))->sorting(array('value' => 'asc'));
 }
Example #12
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'file' => new Field_File(array('label' => 'Plik', 'path' => 'media/files', 'delete_old_file' => TRUE, 'rules' => array('Upload::not_empty' => NULL, 'Upload::type' => array(array('jpg', 'png', 'gif'))))), 'attributes' => new Field_Text(array('label' => 'Atrybuty HTML')), 'date' => new Field_Timestamp(array('label' => 'Data', 'auto_now_create' => TRUE, 'auto_now_update' => TRUE)), 'project' => new Field_BelongsTo(array('label' => 'Projekt'))))->sorting(array('date' => 'asc'));
 }
Example #13
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'page' => new Field_BelongsTo(array('model' => 'kohanut_page', 'column' => 'page', 'foreign' => 'kohanut_page.id')), 'area' => new Field_Integer(), 'order' => new Field_Integer(), 'elementtype' => new Field_BelongsTo(array('model' => 'kohanut_elementtype', 'column' => 'elementtype', 'foreign' => 'kohanut_elementtype.id')), 'element' => new Field_Integer()));
 }
Example #14
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'gmt' => new Field_Float(), 'dst' => new Field_Float()));
 }
Example #15
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'first_name' => new Field_String(array('label' => 'Imię', 'rules' => array('not_empty' => NULL))), 'second_name' => new Field_String(array('label' => 'Nazwisko', 'rules' => array('not_empty' => NULL))), 'email' => new Field_Email(array('label' => 'E-mail', 'unique' => TRUE, 'rules' => array('not_empty' => NULL, 'matches' => array('email_confirm')))), 'email_confirm' => new Field_Email(array('label' => 'Powtórz e-mail', 'in_db' => FALSE)), 'password' => new Field_Password(array('label' => 'Hasło', 'rules' => array('not_empty' => NULL, 'min_length' => array(4), 'matches' => array('password_confirm')))), 'password_confirm' => new Field_Password(array('label' => 'Powtórz hasło', 'in_db' => FALSE)), 'address' => new Field_Text(array('label' => 'Adres', 'rules' => array('not_empty' => NULL))), 'phone_number' => new Field_String(array('label' => 'Numer telefonu', 'rules' => array('not_empty' => NULL, 'phone' => array(array(9, 11))))), 'company_name' => new Field_String(array('label' => 'Nazwa firmy')), 'nip' => new Field_String(array('label' => 'NIP', 'unique' => TRUE, 'null' => TRUE, 'filters' => array('Model_Client::prepare_nip' => NULL), 'rules' => array('nip' => NULL)))))->sorting(array('second_name' => 'asc'));
 }
Example #16
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_Text()));
 }
Example #17
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'stamp' => new Field_Timestamp(array('auto_now_create' => true)), 'user' => new Field_BelongsTo(array('empty' => false, 'column' => 'uid')), 'username' => new Field_String(), 'ip' => new Field_String(), 'hostname' => new Field_String(), 'success' => new Field_Boolean(), 'password' => new Field_Boolean()));
 }
Example #18
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('rules' => array('not_empty' => array(true), 'max_length' => array(200)))), 'latitude' => new Field_Float(), 'longitude' => new Field_Float(), 'population' => new Field_Integer(), 'created' => new Field_Timestamp(array('auto_now_create' => true)), 'modified' => new Field_Timestamp(array('auto_now_update' => true)), 'i18n' => new Field_JSON(), 'country' => new Field_BelongsTo(array('foreign' => 'geo_country', 'rules' => array('not_empty' => array(true)))), 'timezone' => new Field_BelongsTo(array('foreign' => 'geo_timezone'))));
 }
Example #19
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Nazwa', 'filters' => array('trim' => NULL), 'rules' => array('not_empty' => NULL))), 'address' => new Field_Text(array('label' => 'Adres', 'filters' => array('trim' => NULL), 'rules' => array('not_empty' => NULL))), 'products' => new Field_ManyToMany(array('label' => 'Produkty'))))->sorting(array(':name_key' => 'asc'));
 }
Example #20
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->sorting = array('time' => 'desc');
     $meta->primary_key = 'user_id';
     $meta->fields(array('user' => new Field_BelongsTo(array('column' => 'user_id')), 'time' => new Field_Timestamp(array('empty' => TRUE, 'auto_now_create' => true)), 'history' => new Field_String()));
 }
Example #21
0
 /**
  * @param Jelly_Meta $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'username' => Jelly::field('string', array('unique' => TRUE, 'rules' => array(array('not_empty'), array('min_length', array(':value', 4)), array('max_length', array(':value', 4))))), 'password' => Jelly::field('password', array('hash_with' => array('Model_A1_User_Jelly', 'hash_password'), 'rules' => array(array('not_empty'), array('min_length', array(':value', 6)), array('max_length', array(':value', 50))))), 'password_confirm' => Jelly::field('password', array('in_db' => FALSE, 'rules' => array(array('not_empty'), array('min_length', array(':value', 6)), array('max_length', array(':value', 50)), array('matches', array(':validation', 'password', ':field')))))));
 }
Example #22
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'code' => new Field_Text(), 'markdown' => new Field_Boolean(array('default' => true)), 'twig' => new Field_Boolean(array('default' => false))));
 }
Example #23
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Nazwa')), 'roles' => new Field_ManyToMany(array('label' => 'Role')), 'users' => new Field_HasMany(array('label' => 'Użytkownicy'))));
 }
Example #24
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'user' => new Field_BelongsTo(), 'friend' => new Field_BelongsTo(array('column' => 'friend_id', 'foreign' => 'user.id')), 'created' => new Field_Timestamp()));
 }
Example #25
0
 protected function generate_fields(Jelly_Model $model, Jelly_Meta $meta, $field_prefix, array $validation_errors = array())
 {
     $has_autocomplete = FALSE;
     $fields = array();
     foreach ($meta->fields() as $field_id => $field) {
         $this->generate_field($model, $fields, $field_id, $field, $validation_errors, array(), $field_prefix);
         if ($field instanceof Field_Autocomplete) {
             $has_autocomplete = TRUE;
         }
     }
     if ($has_autocomplete) {
         $media = Route::get('kadmium/media');
         $this->scripts[] = $media->uri(array('file' => 'js/jquery.autocomplete.min.js'));
         $this->scripts[] = $media->uri(array('file' => 'js/kadmium.autocomplete.js'));
     }
     return $fields;
 }
Example #26
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'code' => new Field_String(array('unique' => true, 'rules' => array('not_empty' => null, 'exact_length' => array(16)))), 'email' => new Field_Email(array('rules' => array('not_empty' => null, 'min_length' => array(6), 'max_length' => array(127)), 'callbacks' => array('unique' => array('Model_Invitation', '_unique')))), 'created' => new Field_Timestamp(array('auto_now_create' => true))));
 }
Example #27
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'url' => new Field_String(array('empty' => TRUE, 'default' => NULL)), 'name' => new Field_String(), 'created' => new Field_Timestamp(array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'edited' => new Field_Timestamp(array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')), 'layout' => new Field_BelongsTo(array('model' => 'kohanut_layout', 'foreign' => 'kohanut_layout.id', 'column' => 'layout')), 'islink' => new Field_Boolean(array('default' => FALSE)), 'shownav' => new Field_Boolean(array('default' => TRUE)), 'showmap' => new Field_Boolean(array('default' => TRUE)), 'title' => new Field_String(array('empty' => true)), 'metadesc' => new Field_Text(array('empty' => true)), 'metakw' => new Field_Text(array('empty' => true)), 'lft' => new Jelly_Field_MPTT_Left(), 'rgt' => new Jelly_Field_MPTT_Right(), 'lvl' => new Jelly_Field_MPTT_Level(), 'scp' => new Jelly_Field_MPTT_Scope(), 'blocks' => new Field_HasMany(array('foreign' => 'kohanut_block.page'))));
     parent::initialize($meta);
 }
Example #28
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'url' => new Field_String(array('empty' => TRUE, 'default' => NULL)), 'newurl' => new Field_String(array()), 'type' => new Field_Enum(array('choices' => array('301' => '301 (' . __('permanent') . ')', '302' => '302 (' . __('temporary') . ')')))));
 }
Example #29
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('label' => 'Name')), 'desc' => new Field_String(array('label' => 'Description')), 'code' => new Field_Text(array('label' => 'Code')), 'pages' => new Field_HasMany(array('model' => 'page'))));
 }
Example #30
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->fields(array('id' => new Field_Primary(), 'url' => new Field_String()));
 }