/** * Constructs a {@link Serialization} object. * * @param Model $model The model to serialize * @param array &$options Options for serialization * @return Serialization */ public function __construct(Model $model, &$options) { $this->model = $model; $this->options = $options; $this->attributes = $model->attributes(); $this->parse_options(); }
public function to_array() { $array = parent::to_array(); $array['use_admin'] = $this->can('use_admin'); $array['users'] = User::count(['conditions' => ['group_id = ?', $this->id]]); return $array; }
/** * 初始化信息 * * @param array $attributes */ public function init(array $attributes = array()) { parent::__construct($attributes); $this->message_created = time(); $this->has_read = 0; $this->message_is_deleted = 0; }
/** * @param bool $validate * @return bool */ public function save($validate = true) { if (parent::save($validate)) { return static::updatePermissionsList(); } return false; }
public static function getSingleRow($filter) { $data = parent::find(self::getOptions($filter)); if (empty($data)) { return false; } return $data->to_array(); }
public function init(array $attributes = array()) { parent::__construct($attributes); $this->demandthing_is_deleted = 0; $this->demandthing_click_count = 0; $this->demandthing_time = time(); $this->user_id = CURRENT_YIKE; $this->status_id = 10; }
/** * @override * Save the model to the database. * * This function will automatically determine if an INSERT or UPDATE needs to occur. * If a validation or a callback for this model returns false, then the model will * not be saved and this will return false. * * If saving an existing model only data that has changed will be saved. * * @param boolean $validate Set to true or false depending on if you want the validators to run or not * @return boolean True if the model was saved to the database otherwise false */ public function save($validate = true) { if ($this->is_new_record()) { $dt = new \DateTime(); //var_dump($dt->getTimestamp()); $this->set_attributes(array($this->get_primary_key() => ZiUtil::GetTransID())); } //still use save parent return parent::save($validate); }
/** * Fetches a user's info by either its username or its email and its password * @param string $username_or_email The users ID or username * @param string $password the user's email or password if password no set it only will search by username or email * @return user */ public static function Fetch($username_or_email, $password = NULL) { # find the user with its username or email and password $cond = array("(username = ? OR email = ?)", $username_or_email, $username_or_email); if ($password) { $cond[0] .= " AND password = MD5(?)"; $cond[] = $password; } return parent::find("first", array('conditions' => $cond)); }
/** * 对象初始化 * * 由于构造函数对已有的对象产生影响,所以对象的初始化由 init() 完成 * @param array $attributes * @return void */ public function init(array $attributes = array()) { parent::__construct($attributes); $this->user_pwd = $this->hashpwd($attributes['user_pwd']); //进行密码加密 $this->user_join_time = time(); $this->last_login_time = time(); $this->last_login_ip = $_SERVER['REMOTE_ADDR']; $this->user_is_deleted = 0; $this->role_id = 1; }
public function __construct($attributes = array(), $guard_attributes = true, $instantiating_via_find = false, $new_record = true) { $className = (new \ReflectionClass($this))->getShortName(); self::$table_name = strtolower($className); if (self::$connection == null) { $cfg = \ActiveRecord\Config::instance(); self::$dsn = $cfg->get_default_connection_string(); } $pdo = $this->connection()->connection; $this->validationRulesBuilder = new ValidationRulesBuilder(self::$table_name, self::$dsn, $pdo); if (!isset(self::$ruleList[self::$table_name])) { $this->buildRules(); $this->populateRules(); } else { // for code coverage analysis } parent::__construct($attributes, $guard_attributes, $instantiating_via_find, $new_record); }
/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'user' => $this->user->to_array()], parent::to_array()); }
/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'forum' => $this->forum->to_array(), 'close' => $this->close_id ? $this->close->to_array() : [], 'posts' => intval(ForumPost::count(['conditions' => ['theme_id = ?', $this->id]]))], parent::to_array()); }
/** * Determines if an attribute or relationship exists for this Model * * @see \ActiveRecord\Model::__isset() * @param string $name * @return bool */ public function __isset($name) { if (parent::__isset($name)) { return true; } $table = static::table(); return $table->has_relationship($name); }
/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'forum' => $this->forum_id ? $this->forum->to_array() : [], 'subjects' => $this->forum_id ? 0 : Forum::count(['conditions' => ['forum_id = ?', $this->id]]), 'topics' => $this->forum_id ? ForumTheme::count(['conditions' => ['forum_id = ?', $this->id]]) : 0], parent::to_array()); }
/** * @return array|null */ public function to_array() { if (!$this->id) { return null; } $user = parent::to_array(); unset($user['session_id'], $user['password']); return array_merge(array('banned' => $this->banned(), 'ban_user' => $this->ban_user ? $this->ban_user->to_array() : [], 'group' => $this->group->to_array(), 'permissions' => $this->getPermissions()->getArrayCopy()), $user); }
protected function createConditionsFromKeys(Model $model, $condition_keys = [], $value_keys = []) { $condition_string = \implode('_and_', $condition_keys); $condition_values = \array_values($model->getValuesFor($value_keys)); // return null if all the foreign key values are null so that we don't try to do a query like "id is null" if (all(null, $condition_values)) { return null; } $conditions = SQLBuilder::createConditionsFromUnderscoredString(Table::load(\get_class($model))->conn, $condition_string, $condition_values); # DO NOT CHANGE THE NEXT TWO LINES. add_condition operates on a reference and will screw options array up if (isset($this->options['conditions'])) { $options_conditions = $this->options['conditions']; } else { $options_conditions = []; } return Utils::addCondition($options_conditions, $conditions); }
public function paginate($limit, $offset) { return parent::find('all', array('limit' => $limit, 'offset' => $offset)); }
/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'category' => $this->category->to_array(), 'tags' => array_map(function ($i) { return trim($i, ' ,'); }, explode(' ', $this->keywords))], parent::to_array()); }
public function init(array $attributes = array()) { parent::__construct($attributes); }
/** * Routes delete operations to "master" connection then * switches back to the "slave" db connection. */ public function delete() { $slave_db = $this->switch_connection($this->master_db); parent::delete(); $this->switch_connection($slave_db); }
/** * Método construtor * @param array $attributes Atributo obrigatório do PHP ActiveRecord * @param boolean $guard_attributes Atributo obrigatório do PHP ActiveRecord * @param boolean $instantiating_via_find Atributo obrigatório do PHP ActiveRecord * @param boolean $new_record Atributo obrigatório do PHP ActiveRecord */ public function __construct($attributes = array(), $guard_attributes = TRUE, $instantiating_via_find = FALSE, $new_record = TRUE) { parent::__construct($attributes, $guard_attributes, $instantiating_via_find, $new_record); return $this; }
/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'parent' => $this->parent ? $this->parent->to_array() : []], parent::to_array()); }
public function destroy($id) { return \ActiveRecord\Model::find($id)->delete(); }