コード例 #1
0
ファイル: Model.php プロジェクト: DavBfr/BlogMVC
 public function save(array $properties, $key = null, array $options = [])
 {
     if (empty($properties['slug'])) {
         $properties['slug'] = \ICanBoogie\normalize($properties['name']);
     }
     return parent::save($properties, $key, $options);
 }
コード例 #2
0
ファイル: model.constructor.php プロジェクト: icybee/core
 /**
  * Overwrites the `constructor` property of new records.
  */
 public function save(array $properties, $key = null, array $options = array())
 {
     if (!$key && empty($properties[self::T_CONSTRUCTOR])) {
         $properties[self::T_CONSTRUCTOR] = $this->constructor;
     }
     return parent::save($properties, $key, $options);
 }
コード例 #3
0
 public function save(array $properties, $key = null, array $options = array())
 {
     if (!$key && empty($properties['uuid'])) {
         $properties['uuid'] = $this->generate_uuid();
     }
     return parent::save($properties, $key, $options);
 }
コード例 #4
0
 /**
  * Adds the `status` and `notify` properties if they are not defined, they default to
  * `pending` and `no`.
  *
  * @throws \InvalidArgumentException if the value of the `notify` property is not one of `no`,
  * `yes`, `author` or `done`.
  */
 public function save(array $properties, $key = null, array $options = array())
 {
     $properties += array(Comment::CREATED => DateTime::now(), Comment::STATUS => 'pending', Comment::NOTIFY => 'no');
     if (!in_array($properties[Comment::NOTIFY], array('no', 'yes', 'author', 'done'))) {
         throw new \InvalidArgumentException(\ICanBoogie\format('Invalid value for property %property: %value', array('%property' => Comment::NOTIFY, '%value' => $properties[Comment::NOTIFY])));
     }
     return parent::save($properties, $key, $options);
 }
コード例 #5
0
 /**
  * If the `termslug` property is empty it is created from the `term` property, otherwise
  * the it is normalized.
  */
 public function save(array $properties, $key = null, array $options = array())
 {
     if (isset($properties[Term::TERM]) && empty($properties[Term::TERMSLUG])) {
         $properties[Term::TERMSLUG] = \Icybee\slugize($properties[Term::TERM]);
     } else {
         if (isset($properties[Term::TERMSLUG])) {
             $properties[Term::TERMSLUG] = \ICanBoogie\normalize($properties[Term::TERMSLUG]);
         }
     }
     return parent::save($properties, $key, $options);
 }
コード例 #6
0
ファイル: blueprint.php プロジェクト: icybee/module-pages
 /**
  * Populates the blueprint by loading the associated records.
  *
  * The method adds the `record` property to the blueprint nodes.
  *
  * @return array[int]\Icybee\Modules\Pages\Page
  */
 public function populate()
 {
     if (!$this->index) {
         return array();
     }
     $records = $this->model->find(array_keys($this->index));
     foreach ($records as $nid => $record) {
         $this->index[$nid]->record = $record;
     }
     return $records;
 }
コード例 #7
0
ファイル: Query.php プロジェクト: icanboogie/activerecord
 /**
  * Delete the records matching the conditions and limits of the query.
  *
  * @param string $tables When using a JOIN, `$tables` is used to specify the tables in which
  * records should be deleted. Default: The alias of queried model, only if at least one join
  * clause has been defined using the {@link join()} method.
  *
  * @return bool The result of the operation.
  *
  * @todo-20140901: reflect on join to add the required tables by default, discarding tables
  * joined with the LEFT mode.
  */
 public function delete($tables = null)
 {
     if (!$tables && $this->joints) {
         $tables = "`{alias}`";
     }
     if ($tables) {
         $query = "DELETE {$tables} FROM {self} AS `{alias}`";
     } else {
         $query = "DELETE FROM {self}";
     }
     $query .= $this->render_main();
     return $this->model->execute($query, $this->args);
 }
コード例 #8
0
ファイル: manage.php プロジェクト: icybee/module-users
 private function resolve_user_names(Model $model)
 {
     global $core;
     $query = $model->select("DISTINCT `{$this->id}`");
     if ($model->has_scope('own')) {
         $query = $query->own;
     }
     if ($model->has_scope('similar_site')) {
         $query = $query->similar_site;
     }
     $users_keys = $query->all(\PDO::FETCH_COLUMN);
     if (count($users_keys) < 2) {
         return;
     }
     return $core->models['users']->select('uid, IF((firstname != "" AND lastname != ""), CONCAT_WS(" ", firstname, lastname), username) name')->filter_by_uid($users_keys)->order('name')->pairs;
 }
コード例 #9
0
ファイル: Hooks.php プロジェクト: icanboogie/bind-facets
 /**
  * Fetches a record matching the specified conditions.
  *
  * The model's {@link fetch_records} prototype method is used to retrieve the record.
  *
  * @param Model|ModelBindings $model
  * @param array $conditions
  * @param Fetcher $fetcher If the parameter `fetcher` is present, the {@link Fetcher}
  * instance used to fetch the record is stored inside.
  *
  * @return ActiveRecord|null
  */
 public static function fetch_record(Model $model, array $conditions, &$fetcher = null)
 {
     $records = $model->fetch_records($conditions + ['limit' => 1]);
     if (!$records) {
         return null;
     }
     $fetcher = $records->fetcher;
     return $records->one;
 }