本文整理汇总了PHP中Jam类的典型用法代码示例。如果您正苦于以下问题:PHP Jam类的具体用法?PHP Jam怎么用?PHP Jam使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
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'))));
}
示例2: initialize
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'))));
}
示例3: test_empty_value
public function test_empty_value()
{
$model = Jam::build('test_position');
$field = new Jam_Field_Timestamp(array('timezone' => new Jam_Timezone()));
$value = $field->set($model, '', FALSE);
$this->assertNull($value);
}
示例4: duplicate
public function duplicate()
{
$duplicate = Jam::build('brand_purchase_shipping', array('brand_purchase' => $this->brand_purchase));
// This is needed to counteract inverse_of brand_purchase in brand_purchase_shipping
$this->brand_purchase->shipping = $this;
return $duplicate;
}
示例5: test_not_expired
/**
* @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);
}
示例6: test_change_password
/**
* @dataProvider data_change_password
*/
public function test_change_password($password, $expected_hashed)
{
$field = new Jam_Field_Password();
$model = Jam::build('test_position');
$hashed = $field->convert($model, $password, FALSE);
$this->assertEquals($expected_hashed, $hashed);
}
示例7: compile
public function compile($db = NULL)
{
if ($this->context_model() and $meta = Jam::meta(Jam_Query_Builder::aliased_model($this->context_model()))) {
$db = Database::instance($meta->db());
}
$original_on = $this->_on;
$original_using = $this->_using;
$original_table = $this->_table;
if (!empty($this->_on)) {
foreach ($this->_on as &$condition) {
$condition[0] = Jam_Query_Builder::resolve_attribute_name($condition[0], $this->model() ? $this->model() : $this->_table);
$condition[2] = Jam_Query_Builder::resolve_attribute_name($condition[2], $this->context_model());
}
}
$this->_table = Jam_Query_Builder::resolve_table_alias($this->_table);
if (!empty($this->_using)) {
foreach ($this->_using as &$column) {
$column = Jam_Query_Builder::resolve_attribute_name($column, $this->meta());
}
}
$additional_joins = '';
foreach ($this->_joins as $join) {
$additional_joins .= ' ' . $join->compile($db);
}
$compiled = parent::compile($db) . $additional_joins;
$this->_on = $original_on;
$this->_using = $original_using;
$this->_table = $original_table;
return $compiled;
}
示例8: initialize
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')));
}
示例9: initialize
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"))));
}
示例10: get_user
public function get_user()
{
if ($this->enabled() and $this->logged_in()) {
$user = Jam::find_or_build($this->_user_model, array($this->_service_field => $this->service_uid()));
$user->_is_new = TRUE;
$data = $this->service_user_info();
if (!$user->loaded()) {
if (isset($data['email'])) {
$user = Jam::find_or_build($this->_user_model, array('email' => $data['email']));
if ($user->loaded()) {
$user->_is_new = FALSE;
}
}
if (!$user->loaded() and Arr::get($this->_config, 'create_user')) {
$user = $this->build_user($data, TRUE);
}
if (!$user) {
throw new Auth_Exception_Service('Service :service user with service uid :id does not exist and faild to create', array(':service' => $this->type(), ':id' => $this->service_uid()));
}
$user->set($this->_service_field, $this->service_uid());
$user->save();
} elseif (Arr::get($this->_config, 'update_user')) {
$user->_is_new = FALSE;
$user->load_service_values($this, $data, FALSE);
$user->save();
} else {
$user->_is_new = FALSE;
}
return $user;
}
return FALSE;
}
示例11: test_constructor
public function test_constructor()
{
$select = Jam_Query_Builder_Select::factory('test_author');
$this->assertInstanceOf('Jam_Query_Builder_Select', $select);
$this->assertEquals(Jam::meta('test_author'), $select->meta());
$this->assertEquals('SELECT `test_authors`.* FROM `test_authors`', (string) $select);
}
示例12: initialize
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'))));
}
示例13: test_initialize
/**
* @covers Model_Purchase_Item_Promotion::initialize
*/
public function test_initialize()
{
$meta = Jam::meta('purchase_item_promotion');
$this->assertSame('purchase_items', $meta->table());
$this->assertTrue($meta->field('is_payable')->default);
$this->assertTrue($meta->field('is_discount')->default);
}
示例14: test_deep
public function test_deep()
{
$blog = Jam::find_or_create('test_blog', array('id' => 10, 'name' => 'created blog'));
$author = Jam::build('test_author')->load_fields(array('id' => 4, 'name' => 'Joe', 'test_posts' => array(array('id' => 1, 'name' => 'hardware', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 2, 'name' => 'cat2')), 'test_blog' => array('id' => 2, 'name' => 'loaded')), array('id' => 2, 'name' => 'software', 'test_categories' => array(array('id' => 1, 'name' => 'cat1'), array('id' => 3, 'name' => 'cat3')), 'test_blog' => 10))));
$post = Jam::build('test_post')->load_fields(array('id' => 3, 'name' => 'administration'));
$post2 = Jam::build('test_post', array('name' => 'unsaved'));
$author->test_posts->add($post)->add($post2);
$serialized_data = serialize($author);
$unserialized = unserialize($serialized_data);
$this->assertNotSame($author, $unserialized);
$this->assertTrue($unserialized->loaded());
$this->assertEquals($author->as_array(), $unserialized->as_array());
$this->assertCount(4, $unserialized->test_posts);
$this->assertTrue($unserialized->test_posts[0]->loaded());
$this->assertEquals($author->test_posts[0]->as_array(), $unserialized->test_posts[0]->as_array());
$this->assertNotNull($unserialized->test_posts[0]->test_blog);
$this->assertTrue($unserialized->test_posts[0]->test_blog->loaded());
$this->assertEquals($author->test_posts[0]->test_blog->as_array(), $unserialized->test_posts[0]->test_blog->as_array());
$this->assertNotNull($unserialized->test_posts[1]->test_blog);
$this->assertTrue($unserialized->test_posts[1]->test_blog->loaded());
$this->assertEquals($author->test_posts[1]->test_blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array());
$this->assertEquals($blog->as_array(), $unserialized->test_posts[1]->test_blog->as_array());
$this->assertTrue($unserialized->test_posts[1]->loaded());
$this->assertEquals($author->test_posts[1]->as_array(), $unserialized->test_posts[1]->as_array());
$this->assertTrue($unserialized->test_posts[2]->loaded());
$this->assertEquals($author->test_posts[2]->as_array(), $unserialized->test_posts[2]->as_array());
$this->assertFalse($unserialized->test_posts[3]->loaded());
$this->assertEquals($author->test_posts[3]->as_array(), $unserialized->test_posts[3]->as_array());
$blog->delete();
}
示例15: test_validate
/**
* @covers Jam_Validator_Rule_Currency
*/
public function test_validate()
{
$product = Jam::build('product', array('currency' => 'NNN'));
$this->assertFalse($product->check());
$product->currency = 'USD';
$this->assertTrue($product->check());
}