/** * This constructor initializes the class. * * @access public * @override * @param DB_ORM_Model $model a reference to the implementing model * @param array $metadata the relation's metadata */ public function __construct(DB_ORM_Model $model, array $metadata = array()) { parent::__construct($model, 'has_many'); // the parent model is the referenced table $parent_model = get_class($model); // Get parent model's name into variable, otherways a late static binding code throws a // syntax error when used like this: $this->metadata['parent_model']::primary_key() $this->metadata['parent_model'] = $parent_model; // the parent key (i.e. candidate key) is an ordered list of field names in the parent model $this->metadata['parent_key'] = isset($metadata['parent_key']) ? (array) $metadata['parent_key'] : $parent_model::primary_key(); // the through model is the pivot table if (isset($metadata['through_model'])) { $this->metadata['through_model'] = DB_ORM_Model::model_name($metadata['through_model']); } // the through keys is an array of two ordered lists of fields names: [0] matches with parent key and [1] matches with child key if (isset($metadata['through_keys'])) { $this->metadata['through_keys'] = (array) $metadata['through_keys']; } // the child model is the referencing table $this->metadata['child_model'] = DB_ORM_Model::model_name($metadata['child_model']); // the child key (i.e. foreign key) is an ordered list of field names in the child model $this->metadata['child_key'] = (array) $metadata['child_key']; // a set of options that will modify the query $this->metadata['options'] = isset($metadata['options']) ? (array) $metadata['options'] : array(); }
/** * This constructor instantiates this class using the specified model's name. * * @access public * @param string $model the model's name */ public function __construct($model) { $name = $model; $model = DB_ORM_Model::model_name($name); $this->data_source = DB_DataSource::instance($model::data_source(DB_DataSource::MASTER_INSTANCE)); $builder = 'DB_' . $this->data_source->dialect . '_Delete_Builder'; $this->builder = new $builder($this->data_source); $extension = DB_ORM_Model::builder_name($name); if (class_exists($extension)) { $this->extension = new $extension($this->builder); } $table = $model::table(); $this->builder->from($table); }
/** * This constructor initializes the class. * * @access public * @override * @param DB_ORM_Model $model a reference to the implementing model * @param array $metadata the relation's metadata */ public function __construct(DB_ORM_Model $model, array $metadata = array()) { parent::__construct($model, 'has_one'); // the parent model is the referenced table $parent_model = get_class($model); // Get parent model's name into variable, otherways a late static binding code throws a // syntax error when used like this: $this->metadata['parent_model']::primary_key() $this->metadata['parent_model'] = $parent_model; // the parent key (i.e. candidate key) is an ordered list of field names in the parent model $this->metadata['parent_key'] = isset($metadata['parent_key']) ? (array) $metadata['parent_key'] : $parent_model::primary_key(); // the child model is the referencing table $this->metadata['child_model'] = DB_ORM_Model::model_name($metadata['child_model']); // the child key (i.e. foreign key) is an ordered list of field names in the child model $this->metadata['child_key'] = (array) $metadata['child_key']; }
/** * This function returns an instance of the specified model. * * @access public * @static * @param string $model the model's name * @return mixed an instance of the specified model */ public static function factory($model) { $model = DB_ORM_Model::model_name($model); return new $model(); }
/** * This function returns an instance of the appropriate pre-compiler for the * specified model. * * @access public * @static * @param string $model the model's name * @return DB_SQL_Precompiler an instance of the pre-compiler */ public static function precompiler($model) { $model = DB_ORM_Model::model_name($model); $data_source = $model::data_source(DB_DataSource::MASTER_INSTANCE); $precompiler = 'DB_' . $data_source->dialect . '_Precompiler'; $object = new $precompiler($data_source); return $object; }
/** * This function logs the current user out. * * @access public * @param boolean $destroy whether the session is to be to completely * destroyed * @param boolean $logout_all whether all tokens for user are to be removed * @param boolean whether the logout was successful */ public function logout($destroy = FALSE, $logout_all = FALSE) { // Set by force_login() $this->_session->delete('auth_forced'); if ($token = Cookie::get('authautologin')) { // Delete the autologin cookie to prevent re-login Cookie::delete('authautologin'); // Clear the autologin token from the database $token = DB_ORM::select($this->models['token'])->where($this->columns['token'], DB_SQL_Operator::_EQUAL_TO_, $token)->limit(1)->query()->fetch(0); $token_model = DB_ORM_Model::model_name($this->models['token']); if ($logout_all) { DB_ORM::delete($this->models['token'])->where($this->columns['user_id'], DB_SQL_Operator::_EQUAL_TO_, $token->user)->execute(); } else { if ($token instanceof $token_model and $token->is_loaded()) { $token->delete(); } } } return parent::logout($destroy); }
/** * This constructor instantiates this class using the specified model's name. * * @access public * @param string $model the model's name * @param array $columns the columns to be selected */ public function __construct($model, array $columns = array()) { $name = $model; $model = DB_ORM_Model::model_name($name); $this->data_source = DB_DataSource::instance($model::data_source(DB_DataSource::SLAVE_INSTANCE)); $builder = 'DB_' . $this->data_source->dialect . '_Select_Builder'; $this->table = $model::table(); $this->builder = new $builder($this->data_source, $columns); if (empty($columns)) { $this->builder->all("{$this->table}.*"); } $this->builder->from($this->table); $extension = DB_ORM_Model::builder_name($name); if (class_exists($extension)) { $this->extension = new $extension($this->builder); } $this->model = $model; }