Esempio n. 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'), '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'));
 }
Esempio n. 2
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')));
 }
Esempio n. 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'), 'test_posts' => Jelly::field('manytomany'), 'parent' => Jelly::field('belongsto', array('foreign' => 'test_category', 'column' => 'parent_id'))));
 }
Esempio n. 4
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'));
 }
Esempio n. 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();
     }
 }
Esempio n. 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');
     }
 }
Esempio n. 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'));
 }
Esempio n. 8
0
 /**
  * 
  * @param array $fields
  */
 protected function _set_fields(array $fields)
 {
     if ((bool) $this->_group) {
         foreach ($fields as $field) {
             $this->_fields[$this->_group][$field] = $this->_meta->field($field);
         }
         //clear current group
         $this->_group = null;
         return;
     }
     foreach ($fields as $field) {
         $this->_fields['jelly_form_fields'][$field] = $this->_meta->field($field);
     }
 }
Esempio n. 9
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);
     }
 }
Esempio n. 10
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()));
 }
Esempio n. 11
0
 /**
  * Initializating model meta information
  *
  * @param Jelly_Meta $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->table('users')->fields(array('id' => Jelly::field('Primary'), 'email' => Jelly::field('Email'), 'name' => Jelly::field('String'), 'password' => Jelly::field('Password')));
 }
Esempio n. 12
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $visitor = Visitor::instance();
     $meta->name_key('username')->fields(array('id' => new Field_Primary(), 'username' => new Field_String(array('label' => __('Username'), 'unique' => true, 'rules' => array('not_empty' => null, 'min_length' => array(max((int) Kohana::config('visitor.username.length_min'), 1)), 'max_length' => array(min((int) Kohana::config('visitor.username.length_max'), 30)), 'regex' => array('/^[' . Kohana::config('visitor.username.chars') . ']+$/ui')))), 'username_clean' => new Field_String(array('unique' => true, 'rules' => array('not_empty' => null))), 'password' => new Field_Password(array('label' => __('Password'), 'hash_with' => array($visitor, 'hash_password'), 'rules' => array('not_empty' => null, 'min_length' => array(6)))), 'password_confirm' => new Field_Password(array('label' => __('Password confirmation'), 'in_db' => false, 'callbacks' => array('matches' => array('Model_User', '_check_password_matches')), 'rules' => array('not_empty' => null, 'min_length' => array(max((int) $visitor->get_config('password.length_min'), 1))))), 'email' => new Field_Email(array('label' => __('Email'), 'unique' => true, 'filters' => array('mb_strtolower' => null))), 'name' => new Field_String(array('label' => __('Name'), 'rules' => array('min_length' => array(1), 'max_length' => array(50)))), 'dob' => new Field_Date(array('null' => true, 'label' => __('Date of Birth'), 'format' => 'Y-m-d', 'pretty_format' => 'j.n.Y')), 'gender' => new Field_Enum(array('label' => __('Gender'), 'choices' => array('f' => __('Female'), 'm' => __('Male')))), 'avatar' => new Field_String(array('label' => __('Avatar'))), 'address_street' => new Field_String(array('label' => __('Street address'), 'rules' => array('max_length' => array(50)))), 'address_zip' => new Field_String(array('label' => __('Zip code'), 'rules' => array('min_length' => array(4), 'max_length' => array(5), 'digit' => null))), 'address_city' => new Field_String(array('label' => __('City'), 'rules' => array('max_length' => array(50)))), 'city' => new Field_BelongsTo(array('column' => 'city_id', 'foreign' => 'geo_city')), 'latitude' => new Field_Float(), 'longitude' => new Field_Float(), 'title' => new Field_String(array('label' => __('Title'))), 'signature' => new Field_Text(array('label' => __('Signature'))), 'description' => new Field_Text(array('label' => __('Description'))), 'homepage' => new Field_URL(array('label' => __('Homepage'))), 'login_count' => new Field_Integer(array('column' => 'logins', 'default' => 0)), 'last_login' => new Field_Timestamp(), 'created' => new Field_Timestamp(array('auto_now_create' => true)), 'modified' => new Field_Timestamp(), 'post_count' => new Field_Integer(array('column' => 'posts', 'default' => 0)), 'new_comment_count' => new Field_Integer(array('column' => 'newcomments', 'default' => 0)), 'comment_count' => new Field_Integer(array('column' => 'comments', 'default' => 0)), 'left_comment_count' => new Field_Integer(array('column' => 'commentsleft', 'default' => 0)), 'tokens' => new Field_HasMany(array('foreign' => 'user_token')), 'roles' => new Field_ManyToMany(), 'picture' => new Field_String(), 'default_image' => new Field_BelongsTo(array('foreign' => 'image', 'column' => 'default_image_id')), 'images' => new Field_ManyToMany(), 'friends' => new Field_HasMany(array('foreign' => 'friend')), 'comments' => new Field_HasMany(array('foreign' => 'user_comment'))));
 }
Esempio n. 13
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->name_key('value')->fields(array('id' => new Field_Primary(), 'product' => new Field_BelongsTo(array()), 'value' => new Field_Float(array('label' => 'Cena', 'column' => 'price', 'default' => 0)), 'date' => new Field_Timestamp(array('auto_now_create' => TRUE)), 'vat' => new Field_BelongsTo(array('label' => 'VAT'))))->load_with(array('vat'));
 }
Esempio n. 14
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))));
 }
Esempio n. 15
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()));
 }
Esempio n. 16
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Notice how the MPTT fields are added automatically
     $meta->db('unit_testing')->table('jelly_mptt_owner')->fields = array('id' => new Field_Primary(), 'owned' => new Field_HasMany(array('foreign' => 'owned.owner_id')));
 }
Esempio n. 17
0
 public static function initialize(Jelly_Meta $meta)
 {
     // Notice how the MPTT fields are added automatically
     $meta->db('unit_testing')->table('jelly_mptt_test')->fields = array('id' => new Field_Primary(), 'name' => new Field_String());
     parent::initialize($meta);
 }
Esempio n. 18
0
File: user.php Progetto: jonlb/JxCMS
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->name_key('username')->sorting(array('username' => 'ASC'))->fields(array('id' => new Field_Primary(), 'username' => new Field_String(array('unique' => TRUE, 'rules' => array('not_empty' => array(TRUE), 'max_length' => array(32), 'min_length' => array(3), 'regex' => array('/^[\\pL_.-]+$/ui')))), 'password' => new Field_Password(array('hash_with' => array(Auth::instance(), 'hash_password'), 'rules' => array('not_empty' => array(TRUE), 'max_length' => array(50), 'min_length' => array(6)))), 'password_confirm' => new Field_Password(array('in_db' => FALSE, 'callbacks' => array('matches' => array('Model_Auth_User', '_check_password_matches')), 'rules' => array('not_empty' => array(TRUE), 'max_length' => array(50), 'min_length' => array(6)))), 'email' => new Field_Email(array('unique' => TRUE)), 'logins' => new Field_Integer(array('default' => 0)), 'last_login' => new Field_Timestamp(), 'tokens' => new Field_HasMany(array('foreign' => 'user_token')), 'roles' => new Field_ManyToMany(), 'capabilities' => new Field_ManyToMany()));
 }
Esempio n. 19
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->table('kohanut_element_content')->fields(array('id' => new Field_Primary(), 'code' => new Field_Wysiwyg(), 'markdown' => new Field_Boolean(array('default' => true)), 'twig' => new Field_Boolean(array('default' => false))));
 }
Esempio n. 20
0
 /**
  * Create new model
  *
  * @param  Jelly_Meta  $meta
  */
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->sorting(array('id' => 'DESC'))->fields(array('id' => new Field_Primary(), 'user' => new Field_BelongsTo(), 'stamp' => new Field_Timestamp(array('auto_now_create' => true)), 'class' => new Field_String(), 'type' => new Field_String(), 'data' => new Field_JSON()));
 }
Esempio n. 21
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;
 }
Esempio n. 22
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->table('kohanut_roles');
     parent::initialize($meta);
 }
Esempio n. 23
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->table('library_books')->fields(array('id' => new Field_Primary(), 'title' => new Field_String(), 'author' => new Field_BelongsTo(), 'genre' => new Field_BelongsTo()));
 }
Esempio n. 24
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'));
 }
Esempio n. 25
0
 public static function initialize(Jelly_Meta $meta)
 {
     $meta->name_key('name')->fields(array('id' => new Field_Primary(), 'name' => new Field_String(array('unique' => TRUE, 'rules' => array('max_length' => array(32), 'not_empty' => array(TRUE)))), 'description' => new Field_Text(), 'users' => new Field_ManyToMany()));
 }
Esempio n. 26
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')))))));
 }
Esempio n. 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);
 }
Esempio n. 28
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'));
 }
Esempio n. 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'))));
 }
Esempio n. 30
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'))));
 }