Beispiel #1
0
 /**
  * Returns a Jelly model that, when load()ed will return a database
  * result of the models that this field has.
  *
  * @param   Jelly_Model  $model
  * @param   mixed        $value
  * @param   boolean      $loaded
  * @return  Jelly
  */
 public function get($model, $value)
 {
     if ($model->changed($this->name)) {
         // Return a real object
         return Jelly::select($this->foreign['model'])->where(':primary_key', 'IN', $value);
     } else {
         return Jelly::select($this->foreign['model'])->where($this->foreign['column'], '=', $model->id());
     }
 }
Beispiel #2
0
 /**
  * Hashes the password only if it's changed.
  *
  * @param   string       $password
  * @param   Jelly_Model  $model
  * @return  string
  */
 public function hash($password, Jelly_Model $model)
 {
     // Do we need to hash the password?
     if (!empty($password) and $this->hash_with and $model->changed($this->name)) {
         // Hash the password
         return call_user_func($this->hash_with, $password);
     }
     // Return plain password if no hashing is done
     return $password;
 }
Beispiel #3
0
 /**
  * Returns a pre-built Jelly model ready to be loaded
  *
  * @param   Jelly_Model  $model
  * @param   mixed        $value
  * @param   boolean      $loaded
  * @return  void
  */
 public function get($model, $value)
 {
     // If the value hasn't changed, we need to pull from the database
     if ($model->changed($this->name)) {
         return Jelly::select($this->foreign['model'])->where($this->foreign['column'], 'IN', $value);
     }
     $join_col1 = $this->through['model'] . '.' . $this->through['columns'][1];
     $join_col2 = $this->foreign['model'] . '.' . $this->foreign['column'];
     $where_col = $this->through['model'] . '.' . $this->through['columns'][0];
     return Jelly::select($this->foreign['model'])->join($this->through['model'])->on($join_col1, '=', $join_col2)->where($where_col, '=', $model->id());
 }
Beispiel #4
0
 /**
  * Implementation of Jelly_Field_Supports_Has.
  *
  * @param   Jelly_Model  $model
  * @param   mixed        $models
  * @return  boolean
  */
 public function has($model, $models)
 {
     // If the value hasn't changed, we need to pull from the database
     if (!$model->changed($this->name)) {
         $in = $this->_in($model, TRUE);
     } else {
         $in = $this->_ids($model->__get($this->name));
     }
     $ids = $this->_ids($models);
     // If ids is an empty array then the supplied models were invalid
     if (empty($ids)) {
         return FALSE;
     }
     foreach ($ids as $id) {
         if (!in_array($id, $in)) {
             return FALSE;
         }
     }
     return TRUE;
 }
Beispiel #5
0
 /**
  * Returns the record that the model has.
  *
  * @param   Jelly_Model  $model
  * @param   mixed        $value
  * @return  mixed
  */
 public function get($model, $value)
 {
     if ($model->changed($this->name)) {
         return Jelly::query($this->foreign['model'])->where($this->foreign['model'] . '.' . ':primary_key', '=', $value)->limit(1);
     } else {
         return Jelly::query($this->foreign['model'])->where($this->foreign['model'] . '.' . $this->foreign['field'], '=', $model->id())->limit(1);
     }
 }