Exemplo n.º 1
0
 /**
  * Get all permisions for all user roles.
  * @param  $user permissions for the specific user or for the currently loaded one
  * @return array - key contains permission name, value contains permission description
  */
 public function model_call_permissions(Jam_Model $user, Jam_Event_Data $data)
 {
     $cache_key = $user->id();
     if (!isset($this->_permissions[$cache_key]) or $this->_permissions[$cache_key] === NULL) {
         $res = DB::select(array('p.name', 'permission'), array('p.description', 'description'))->from(array('roles_users', 'ru'))->join(array('permissions_roles', 'pr'), 'INNER')->on('pr.role_id', '=', 'ru.role_id')->join(array('permissions', 'p'), 'INNER')->on('p.id', '=', 'pr.permission_id')->where('ru.user_id', '=', $user->id());
         $this->_permissions[$cache_key] = $res->execute()->as_array('permission', 'description');
     }
     $data->return = $this->_permissions[$cache_key];
     $data->stop = TRUE;
 }
Exemplo n.º 2
0
 public function add_items_query(Jam_Model $model, array $ids)
 {
     $query = DB::insert($this->join_table)->columns(array($this->term_key, $this->item_polymorphic_key, $this->item_key));
     foreach ($ids as $id) {
         $query->values(array($model->id(), $this->foreign_model, $id));
     }
     return $query;
 }
Exemplo n.º 3
0
 /**
  * Generate a query to add models from the association (without deleting them), for specific ids
  * @param  Jam_Model $model
  * @param  array     $ids  
  * @return Database_Query
  */
 public function add_items_query(Jam_Model $model, array $ids)
 {
     $query = DB::insert($this->branches_table)->columns(array($this->ansestor_key, $this->descendant_key, $this->depth_key));
     foreach ($ids as $id) {
         foreach ($this->ansestors_query($model->id())->execute($model->meta()->db()) as $ansestor) {
             $query->values(array($ansestor[$this->ansestor_key], $id, $ansestor[$this->depth_key] + 1));
             foreach ($this->descendants_query($id)->where($this->depth_key, '>', 0)->execute($model->meta()->db()) as $descendant) {
                 $query->values(array($ansestor[$this->ansestor_key], $descendant[$this->descendant_key], $ansestor[$this->depth_key] + $descendant[$this->depth_key] + 1));
             }
         }
     }
     return $query;
 }
 public function model_after_delete(Jam_Model $model)
 {
     DB::delete($this->_branches_table)->where($this->_ansestor_key, '=', $model->id())->where($this->_descendant_key, '=', $model->id())->execute($model->meta()->db());
 }
Exemplo n.º 5
0
 /**
  * Generate a query to add models from the association (without deleting them), for specific ids
  * @param  Jam_Model $model
  * @param  array     $ids
  * @return Database_Query
  */
 public function add_items_query(Jam_Model $model, array $ids)
 {
     $query = Jam_Query_Builder_Update::factory($this->foreign_model)->where(':primary_key', 'IN', $ids)->value($this->foreign_key, $model->id());
     if ($this->is_polymorphic()) {
         $query->value($this->polymorphic_key, $this->model);
     }
     return $query;
 }
Exemplo n.º 6
0
 public static function _uses_primary_key_pattern(Jam_Model $model)
 {
     return $model->name() . '-' . $model->id();
 }
Exemplo n.º 7
0
 /**
  * Get the localized path for a given model, so that there are less filename conflicts and files are easily located,
  * for example the default path is model/id so that Model_Image(1) images will be stored as images/1/file.jpg
  *
  * @param  Jam_Model $model the model for the context
  * @return string
  */
 protected function path(Jam_Model $model)
 {
     $converted_params = array();
     preg_match_all('#\\:[a-zA-z]*#', $this->path, $params);
     foreach ($params[0] as $param) {
         switch ($param) {
             case ':column':
                 $converted_params[$param] = $this->column;
                 break;
             case ':model':
                 $converted_params[$param] = $this->model;
                 break;
             case ':name':
                 $converted_params[$param] = $this->name;
                 break;
             case ':id':
                 $converted_params[$param] = $model->loaded() ? $model->id() : 'new';
                 break;
             case ':id_group':
                 $converted_params[$param] = $model->loaded() ? ceil($model->id() / 10000) : 'new';
                 break;
             default:
                 $converted_params[$param] = $model->{str_replace(':', '', $param)};
         }
     }
     return rtrim(strtr($this->path, $converted_params), '/') . '/';
 }
Exemplo n.º 8
0
 /**
  * $model->restore_delete() Perform this to "undelete" a model
  *
  * @param Jam_Model      $model
  * @param Jam_Event_Data $data
  */
 public function model_call_restore_delete(Jam_Model $model)
 {
     Jam::update($this->_model)->where_key($model->id())->deleted(Jam_Behavior_Paranoid::DELETED)->value($this->_field, FALSE)->execute();
 }
 public function model_call_is_decendent_of(Jam_Model $model, Jam_event_data $data, Jam_Model $ancestor)
 {
     $data->return = in_array($ancestor->id(), $model->path_ids());
 }
Exemplo n.º 10
0
 public function query_builder($type, Jam_Model $model)
 {
     $query = call_user_func("Jam::{$type}", $this->foreign_model)->where($this->foreign_key, '=', $model->id());
     if ($this->is_polymorphic()) {
         $query->where($this->polymorphic_key, '=', $model->meta()->model());
     }
     return $query;
 }
Exemplo n.º 11
0
 public function set_query(Jam_Model $model, $ansestor_id)
 {
     $query = DB::insert($this->branches_table)->columns(array($this->ansestor_key, $this->descendant_key, $this->depth_key));
     foreach ($this->ansestors_query($ansestor_id)->execute($model->meta()->db()) as $ansestor) {
         $query->values(array($ansestor[$this->ansestor_key], $model->id(), $ansestor[$this->depth_key] + 1));
     }
     return $query;
 }