public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'model' => Jam::field('polymorphic'))); }
public static function initialize(Jam_Meta $meta) { $meta->table('vocabularies')->name_key('name'); $meta->behaviors(array('paranoid' => Jam::behavior('paranoid', array()))); $meta->associations(array('terms' => Jam::association('hasmany', array('inverse_of' => 'vocabulary')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s', 'label' => "Last edited")))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // All fields are aliased to different columns $meta->fields(array('id' => Jam::field('primary', array('column' => 'id-alias')), 'name' => Jam::field('string', array('column' => 'name-alias')), 'description' => Jam::field('string', array('column' => 'description-alias')))); }
public static function initialize(Jam_Meta $meta) { $meta->db(Kohana::TESTING); parent::initialize($meta); $meta->behaviors(['username' => Jam::behavior('username')]); $meta->associations(array('user_tokens' => Jam::association('hasmany', array('foreign_model' => 'test_user_token', 'foreign_key' => 'test_user_id')), 'roles' => Jam::association('manytomany', array('foreign_model' => 'test_role', 'join_table' => 'test_roles_users', 'foreign_key' => 'test_role_id', 'association_foreign_key' => 'test_user_id')))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('server' => 'test_local')), 'file2' => Jam::field('upload', array('server' => 'test_local', 'path' => 'test/:model/:model:id')))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_owner' => Jam::association('belongsto', array('foreign_model' => 'test_author', 'foreign_key' => 'test_owner_id')), 'test_featured_category' => Jam::association('hasone', array('foreign_model' => 'test_category')), 'test_posts' => Jam::association('hasmany', array('inverse_of' => 'test_blog', 'count_cache' => TRUE, 'dependent' => Jam_Association::DELETE)), 'test_categories' => Jam::association('hasmany', array('required' => TRUE, 'inverse_of' => 'test_blog')), 'test_tags' => Jam::association('manytomany', array()))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'url' => Jam::field('weblink'), 'test_posts_count' => Jam::field('integer'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_holder' => Jam::association('belongsto', array('polymorphic' => TRUE)), 'test_copyright' => Jam::association('hasone', array('dependent' => Jam_Association::ERASE)), 'test_copyrights' => Jam::association('hasmany', array('dependent' => Jam_Association::ERASE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('upload', array('delete_file' => TRUE)))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_image' => Jam::association('belongsto', array('dependent' => Jam_Association::DELETE)))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_post' => Jam::association('hasone', array('inverse_of' => 'test_author')), 'test_posts' => Jam::association('hasmany'), 'test_blogs_owned' => Jam::association('hasmany', array('foreign_model' => 'test_blog', 'foreign_key' => 'test_owner_id')), 'test_categories' => Jam::association('hasmany'), 'test_position' => Jam::association('belongsto'), 'permission' => Jam::association('belongsto', array('foreign_model' => 'test_position', 'foreign_key' => 'test_position_id')))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'password' => Jam::field('password'), 'email' => Jam::field('string'))); }
public static function attribute_label(Jam_Meta $meta, $attribute_name) { if ($attribute = $meta->attribute($attribute_name)) { $label = $attribute->label; } else { $label = Inflector::humanize($attribute_name); } return UTF8::ucfirst($label); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->behaviors(array('nested' => Jam::behavior('nested'))); $meta->associations(array('test_blog' => Jam::association('belongsto', array('inverse_of' => 'test_categories')), 'test_posts' => Jam::association('manytomany'), 'test_author' => Jam::association('belongsto'))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_featured' => Jam::field('boolean'))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_post' => Jam::association('belongsto', array('conditions' => array('where' => array('test_post._approved_by', 'IS', NULL)), 'counter_cache' => TRUE, 'touch' => 'updated')), 'test_blogs' => Jam::association('manytomany', array('join_table' => 'test_blogs_test_tags')))); $meta->behaviors(array('sluggable' => Jam::behavior('sluggable', array('uses_primary_key' => FALSE, 'unique' => TRUE, 'slug' => 'Model_Test_Tag::_slug')))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
/** * This is called after construction so that fields can finish * constructing themselves with a copy of the column it represents. * * @param string $model * @param string $column * @return void **/ public function initialize(Jam_Meta $meta, $name) { // This will come in handy for setting complex relationships if (!$this->model) { $this->model = $meta->model(); } // This is for naming form fields $this->name = $name; // Check for a name, because we can easily provide a default if (!$this->label) { $this->label = Inflector::humanize($name); } $meta->events()->discover_events($this, Jam_Event::ATTRIBUTE_PRIORITY); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->name_key('file'); $meta->behaviors(array('paranoid' => Jam::behavior('paranoid', array('field' => 'deleted')), 'sortable' => Jam::behavior('sortable', array('field' => 'position', 'scope' => 'group')), 'sluggable' => Jam::behavior('sluggable', array('auto_save' => TRUE)), 'tokenable' => Jam::behavior('tokenable', array('uppercase' => TRUE)))); $meta->associations(array('test_holder' => Jam::association('belongsto', array('polymorphic' => 'test_holder_type')))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'file' => Jam::field('string'), 'group' => Jam::field('string'))); $meta->validator('file', array('length' => array('minimum' => 4))); }
public static function initialize(Jam_Meta $meta) { $meta->table('terms')->name_key('name'); $meta->behaviors(array('nested' => Jam::behavior('Nested'), 'sluggable' => Jam::behavior('Sluggable', array('uses_primary_key' => FALSE, 'auto_save' => FALSE, 'unique' => TRUE)))); $meta->associations(array('vocabulary' => Jam::association('belongsto', array('inverse_of' => 'terms')))); $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'is_hidden' => Jam::field('boolean', array()), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s')))); $meta->validator('name', array('present' => TRUE)); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); $meta->associations(array('test_author' => Jam::association('belongsto'))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'url' => Jam::field('string'), 'email' => Jam::field('string'), 'description' => Jam::field('string'), 'amount' => Jam::field('integer'))); $meta->validator('name', array('present' => TRUE))->validator('name', 'email', 'url', array('count' => array('minimum' => 2)))->validator('email', array('format' => array('filter' => FILTER_VALIDATE_EMAIL)))->validator('url', array('format' => array('filter' => FILTER_VALIDATE_URL)))->validator('amount', array('numeric' => array('greater_than' => 10, 'less_than' => 100)))->validator('description', array('length' => array('between' => array(10, 1000))))->validator('name', array('format' => array('filter' => FILTER_VALIDATE_IP), 'if' => 'name_is_ip'))->validator('name', array('length' => array('minimum' => 2))); $meta->with_options(array('unless' => 'name_is_normal()'))->validator('name', array('format' => array('filter' => FILTER_VALIDATE_EMAIL))); }
public static function initialize(Jam_Meta $meta) { // Set database to connect to $meta->db(Kohana::TESTING); // Posts always load_with an author //$meta->load_with(array('test_author')); $meta->name_key('name'); $meta->associations(array('test_blog' => Jam::association('belongsto', array('inverse_of' => 'test_posts')), 'test_author' => Jam::association('belongsto', array()), 'test_tags' => Jam::association('hasmany', array('inverse_of' => 'test_post')), 'approved_by' => Jam::association('belongsto', array('foreign_model' => 'test_author', 'foreign_key' => '_approved_by')), 'test_images' => Jam::association('hasmany', array('as' => 'test_holder', 'dependent' => Jam_Association::DELETE)), 'test_cover_image' => Jam::association('hasone', array('as' => 'test_holder', 'foreign_model' => 'test_image', 'dependent' => Jam_Association::DELETE)), 'test_categories' => Jam::association('manytomany'))); // Set fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'slug' => Jam::field('slug', array('unique' => TRUE)), 'status' => Jam::field('string', array()), 'created' => Jam::field('timestamp', array('auto_now_create' => TRUE)), 'updated' => Jam::field('timestamp', array('auto_now_update' => TRUE)))); // Set some custom validators $meta->validator('name', array('present' => TRUE, 'if' => 'slug')); }
/** * Tests various properties on a meta object. */ public function test_properties() { $fields = array('id' => new Jam_Field_Primary(), 'id2' => new Jam_Field_Primary(), 'name' => new Jam_Field_String()); $meta = new Jam_Meta('foo'); $meta->db('foo')->table('foo')->fields($fields)->sorting(array('foo' => 'bar'))->primary_key('id2')->name_key('name')->foreign_key('meta_fk')->behaviors(array(new Jam_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', 'sorting' => array('foo' => 'bar')); foreach ($expected as $property => $value) { $this->assertSame($meta->{$property}(), $value); } // Ensure we can retrieve fields properly $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 Jam_Behavior); } }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->unique_key(function ($key) { return is_numeric($key) ? 'id' : 'identifier'; })->table('promotions')->associations(array('purchase_items' => Jam::association('hasmany', array('as' => 'reference', 'foreign_model' => 'purchase_item_promotion')), 'promo_codes' => Jam::association('hasmany', array('inverse_of' => 'promotion'))))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'currency' => Jam::field('string'), 'identifier' => Jam::field('string'), 'description' => Jam::field('text'), 'priority' => Jam::field('integer', array('default' => 1)), 'model' => Jam::field('polymorphic'), 'created_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s', 'auto_now_create' => TRUE)), 'expires_at' => Jam::field('timestamp', array('format' => 'Y-m-d H:i:s'))))->validator('name', array('present' => TRUE))->validator('currency', array('currency' => TRUE)); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->name_key('number')->behaviors(array('tokenable' => Jam::behavior('tokenable', array('uppercase' => TRUE, 'field' => 'number')), 'paranoid' => Jam::behavior('paranoid')))->associations(array('purchase' => Jam::association('belongsto', array('inverse_of' => 'brand_purchases')), 'items' => Jam::association('hasmany', array('inverse_of' => 'brand_purchase', 'foreign_model' => 'purchase_item', 'delete_on_remove' => Jam_Association::DELETE, 'dependent' => Jam_Association::DELETE)), 'refunds' => Jam::association('hasmany', array('inverse_of' => 'brand_purchase', 'foreign_model' => 'brand_refund', 'delete_on_remove' => Jam_Association::DELETE, 'dependent' => Jam_Association::DELETE)), 'brand' => Jam::association('belongsto', array('inverse_of' => 'brand_purchases'))))->fields(array('id' => Jam::field('primary'), 'is_frozen' => Jam::field('boolean'), 'created_at' => Jam::field('timestamp', array('auto_now_create' => TRUE, 'format' => 'Y-m-d H:i:s')), 'updated_at' => Jam::field('timestamp', array('auto_now_update' => TRUE, 'format' => 'Y-m-d H:i:s'))))->validator('purchase', 'brand', array('present' => TRUE)); }
public static function initialize(Jam_Meta $meta) { $meta->fields(array('q' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('materializedpath' => Jam::behavior('materializedpath')))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('paranoid' => Jam::behavior('paranoid')))->associations(array('groups' => Jam::association('hasmany', array('foreign_model' => 'shipping_group', 'foreign_key' => 'shipping_id', 'inverse_of' => 'shipping', 'delete_on_remove' => Jam_Association::DELETE)), 'methods' => Jam::association('manytomany', array('foreign_model' => 'shipping_method', 'association_foreign_key' => 'method_id', 'join_table' => 'shipping_groups', 'readonly' => TRUE, 'join_table_paranoid' => TRUE)), 'locations' => Jam::association('manytomany', array('join_table' => 'shipping_groups', 'join_table_paranoid' => TRUE, 'readonly' => TRUE)), 'ships_from' => Jam::association('belongsto', array('foreign_model' => 'location')), 'brand' => Jam::association('belongsto', array('inverse_of' => 'shippings'))))->fields(array('id' => Jam::field('primary'), 'model' => Jam::field('polymorphic'), 'name' => Jam::field('string'), 'currency' => Jam::field('string')))->validator('name', 'currency', array('present' => TRUE))->validator('currency', array('currency' => TRUE)); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('freezable' => Jam::behavior('freezable', array('fields' => 'monetary', 'associations' => array('test_store_purchases', 'test_payment')))))->associations(array('test_store_purchases' => Jam::association('hasmany', array('inverse_of' => 'test_purchase', 'foreign_model' => 'test_store_purchase')), 'test_payment' => Jam::association('hasone')))->fields(array('id' => Jam::field('primary'), 'monetary' => Jam::field('serialized'))); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('shippable_brand' => Jam::behavior('shippable_brand')))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->associations(array('styles' => Jam::association('taxonomy_terms', array('vocabulary' => 'Styles')), 'types' => Jam::association('taxonomy_terms', array('vocabulary' => 'Types')))); // Define fields $meta->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('paranoid' => Jam::behavior('paranoid')))->associations(array('brand_refund' => Jam::association('belongsto', array('inverse_of' => 'items')), 'purchase_item' => Jam::association('belongsto', array('inverse_of' => 'refund_items'))))->fields(array('id' => Jam::field('primary'), 'amount' => Jam::field('price')))->validator('brand_refund', 'purchase_item', array('present' => TRUE)); }
/** * @codeCoverageIgnore */ public static function initialize(Jam_Meta $meta) { $meta->fields(array('name' => Jam::field('string', array('filters' => array('trim'))), 'number' => Jam::field('string', array('filters' => array('Model_Card_Form::process_credit_card'))), 'expiryMonth' => Jam::field('string'), 'expiryYear' => Jam::field('string'), 'cvv' => Jam::field('string', array('filters' => array('trim')))))->validator('name', 'number', 'expiryMonth', 'expiryYear', 'cvv', array('present' => TRUE))->validator('name', array('format' => array('regex' => "/^[\\p{L}\\p{M}\\.\\-\\' ]+\$/u"), 'length' => array('minimum' => 3, 'maximum' => 40)))->validator('number', array('length' => array('maximum' => 20), 'format' => array('credit_card' => TRUE)))->validator('expiryMonth', array('format' => array('regex' => '/\\d{2}/')))->validator('expiryYear', array('format' => array('regex' => '/\\d{2}/')))->validator('cvv', array('format' => array('regex' => '/\\d{2,4}/'))); }
public static function initialize(Jam_Meta $meta) { $meta->db(Kohana::TESTING); $meta->behaviors(array('closuretable' => Jam::behavior('closuretable', array('children_dependent' => Jam_Association::DELETE))))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'))); }
public static function initialize(Jam_Meta $meta) { $meta->behaviors(array('location_auto' => Jam::behavior('location_auto', array('locations' => array('city' => 'city', 'country' => 'country_name')))))->associations(array('country' => Jam::association('belongsto', array('foreign_model' => 'location')), 'city' => Jam::association('belongsto', array('foreign_model' => 'location'))))->fields(array('id' => Jam::field('primary'), 'name' => Jam::field('string'), 'ip' => Jam::field('ip'))); }