Example #1
0
 /**
  * Load token by key, expire if necessary
  *
  * @param   mixed  $key
  * @return  Model_User_Token
  */
 public function load($key = null)
 {
     $object = parent::load($key);
     if ($object->loaded() && $object->expires < time()) {
         $object->delete();
     }
     return $object;
 }
Example #2
0
 public function sort()
 {
     $sort = Request::instance()->param('sort', 'quantity');
     $order = Request::instance()->param('order');
     if ($sort == 'quantity') {
         return $this->select('*', array(DB::expr('(quantity/minimal_quantity)'), 'sorting_row'))->order_by('sorting_row', $order);
     }
     return parent::sort();
 }
Example #3
0
 /**
  * Setup adapter
  * 
  * @param Jelly_Builder $source
  * @param array $config pagination config
  */
 public function __construct(Jelly_Builder $source, array $config = null)
 {
     $this->_target = new Pagination();
     $this->_source = $source;
     //merge config
     $this->_config += $this->_target->config_group();
     //merge config
     if ($config) {
         $this->_config += $config;
     }
     $order_how = isset($this->_config['current_order']) ? Request::current()->query($this->_config['current_order']['key']) : 'DESC';
     $this->_direct = $order_how == 'DESC' ? 'ASC' : 'DESC';
     $this->_limit = isset($this->_config['current_limit']) ? Request::current()->query($this->_config['current_limit']['key']) ? Request::current()->query($this->_config['current_limit']['key']) : 10 : 10;
     $this->_sort_column = Request::current()->query($this->_config['current_sort']['key']);
     $this->_target->setup(array('total_items' => $source->select()->count(), 'items_per_page' => $this->_limit));
     if (!is_null($this->_sort_column)) {
         $this->_source->order_by($this->_sort_column, $order_how);
     }
     // Get the current route name
     $current_route = Route::name(Request::initial()->route());
     //Current route
     $this->_route = Route::get($current_route);
 }
Example #4
0
 /**
  * Implementation of Jelly_Field_Behavior_Joinable.
  *
  * @param   Jelly_Builder  $builder
  * @return  void
  */
 public function with($builder)
 {
     $builder->join(':' . $this->name, 'LEFT')->on($this->model . '.' . $this->name, '=', ':' . $this->name . '.' . $this->foreign['field']);
 }
Example #5
0
 /**
  * Generates a builder where clause based on the provided values
  *
  * @param   Jelly_Builder   $builder
  * @param   string  $model  Model name used in the where clause
  * @param   mixed   $values argument list used to construct the clause
  * @return  Jelly_Builder
  */
 protected function _where($builder, $model, array $values)
 {
     // Check for an outer and/or indexed array
     $where = 'where';
     if (isset($values['or'])) {
         $where = 'or_where';
         $values = is_array($values['or']) ? $values['or'] : array($values['or']);
     } elseif (isset($values['and'])) {
         $where = 'and_where';
         $values = is_array($values['and']) ? $values['and'] : array($values['and']);
     }
     $count = count($values);
     /* One Argument is passed, can be:
      *  interger - for the primary key lookup
      *  string   - for the name key lookup
      *  object   - a loaded model of the same class
      */
     if ($count == 1) {
         if (is_integer($values[0])) {
             return $builder->{$where}($model . '.:primary_key', '=', $values[0]);
         } elseif (is_string($values[0])) {
             return $builder->{$where}($model . '.:name_key', '=', $values[0]);
         } elseif (is_object($values[0])) {
             $class = Jelly::class_name($model);
             if ($values[0] instanceof $class) {
                 return $builder->where($model . '.:primary_key', '=', $values[0]->id());
             }
         }
     } elseif ($count == 2) {
         if (!Jelly::meta($model)->fields($values[0])) {
             throw new Kohana_Exception('":field" is not a valid :model field', array(':field' => $values[0], ':model' => $model));
         }
         return $builder->{$where}($model . '.' . $values[0], '=', $values[1]);
     } elseif ($count == 3) {
         if (!Jelly::meta($model)->fields($values[0])) {
             throw new Kohana_Exception('":field" is not a valid :model field', array(':field' => $values[0], ':model' => $model));
         }
         return $builder->{$where}($model . '.' . $values[0], $values[1], $values[2]);
     }
     // Not Supported
     throw new Kohana_Exception('invalid or unsupported argument');
 }
Example #6
0
 /**
  * Implementation of Jelly_Field_Behavior_Joinable
  *
  * @param   Jelly_Builder  $builder
  * @return  void
  */
 public function with($builder)
 {
     $join_col1 = $this->model . '.' . $this->column;
     // We use this field's alias rather than the foreign model so the join alias can be resolved
     $join_col2 = $this->name . '.' . $this->foreign['column'];
     $builder->join(array($this->foreign['model'], Jelly::join_alias($this)), 'LEFT')->on($join_col1, '=', $join_col2);
 }
Example #7
0
 public function __construct($model = NULL, $type = NULL)
 {
     parent::__construct($model, $type);
     $this->where('extension', '=', 'com_weblinks');
 }
Example #8
0
 /**
  * Implementation of Jelly_Field_Behavior_Joinable
  *
  * @param   Jelly_Builder  $builder
  * @return  void
  */
 public function with($builder)
 {
     $join_col1 = $this->model . '.:primary_key';
     $join_col2 = $this->foreign['model'] . '.' . $this->foreign['column'];
     $builder->join(array($this->foreign['model'], $this->name), 'LEFT')->on($join_col1, '=', $join_col2);
 }
Example #9
0
 public function select_all($db = NULL)
 {
     /*$db = $this->_db($db);
     		$cache_key = sha1($this->compile(Database::instance($db)));
     		if(!$result = Kohana::cache($cache_key))
     		{
     			$result = parent::select_all($db);
     			if(Kohana::$caching)
     			{
     				Kohana::cache($cache_key, $result);
     			}
     		}
     		return $result;*/
     return parent::select_all($db);
 }