Esempio n. 1
0
 /**
  * Perform the actual where modification when it is needed
  *
  * @param Jam_Query_Builder_Select    $builder
  */
 public function builder_paranoid_filter(Database_Query $builder)
 {
     $filter_type = $builder->params('paranoid_filter_type') ?: Jam_Behavior_Paranoid::filter();
     switch ($filter_type) {
         case Jam_Behavior_Paranoid::ALL:
             break;
         case Jam_Behavior_Paranoid::DELETED:
             $builder->where($this->_field, '=', TRUE);
             break;
         case Jam_Behavior_Paranoid::NORMAL:
         default:
             $builder->where($this->_field, '=', FALSE);
             break;
     }
 }
Esempio n. 2
0
 /**
  * Set a primary key condition. If its an array make in an IN condition.
  * @param  Database_Query $query
  * @param  string         $key
  * @return Database_Query
  */
 public static function find_by_primary_key(Database_Query $query, $key)
 {
     if (is_array($key)) {
         if (!$key) {
             throw new Kohana_Exception('Arrays of primary keys is empty');
         }
         $query->where(':primary_key', 'IN', $key);
     } else {
         if (!$key) {
             throw new Kohana_Exception('Primary key must not be empty');
         }
         $query->where(':unique_key', '=', $key);
     }
     return $query;
 }
Esempio n. 3
0
 private function apply_where_to_query(Database_Query $query, array $where)
 {
     foreach ($where as $col => $value) {
         $query->where($col, is_array($value) ? 'IN' : '=', $value);
     }
     return $query;
 }
Esempio n. 4
0
 /**
  * $builder->root() select only the root items
  *
  * @param Jam_Builder    $builder
  * @param Jam_Event_Data $data
  * @return Jam_Builder
  */
 public function builder_call_root(Database_Query $builder, Jam_Event_Data $data, $is_root = TRUE)
 {
     if ($is_root) {
         $data->return = $builder->where_open()->where($this->_field, '=', 0)->or_where($this->_field, 'IS', NULL)->where_close();
     } else {
         $data->return = $builder->where($this->_field, '!=', 0)->where($this->_field, 'IS NOT', NULL);
     }
     $data->stop = TRUE;
 }
Esempio n. 5
0
 /**
  * 
  * @param Database_Query $query
  */
 protected function _search_by_keyword(Database_Query $query, $only_title = FALSE)
 {
     if ($this->search_key === NULL or trim($this->search_key) == '') {
         return $query;
     }
     $keyword = $this->_ctx->get($this->search_key);
     if (empty($keyword)) {
         return $query;
     }
     $ids = Search::instance()->find_by_keyword($keyword, $only_title, 'ds_' . $this->ds_id, NULL);
     $ids = Arr::get($ids, 'ds_' . $this->ds_id);
     if (!empty($ids)) {
         return $query->where('d.id', 'in', array_keys($ids));
     }
     return $query;
 }
Esempio n. 6
0
 /**
  * 
  * @param string $keyword
  * @param boolean $only_title
  * @param string $modules
  * @param integer $limit
  * @param integer $offset
  * @param boolean $fulltextsearch
  * @return Database_Query
  */
 protected function _get_query(Database_Query $query, $keyword, $only_title = FALSE, $modules = NULL, $limit = 50, $offset = 0)
 {
     $keyword = $this->stem_query($keyword);
     if ($limit !== NULL) {
         $query->limit((int) $limit)->offset($offset);
     }
     if (is_array($modules)) {
         $query->where('search_index.module', 'in', $modules);
     } elseif ($modules !== NULL) {
         $query->where('search_index.module', '=', $modules);
     }
     if ($this->config('full_text_search') === TRUE) {
         $query->where(DB::expr('MATCH(`search_index`.`header`, `search_index`.`content`)'), 'AGAINST', DB::expr("('" . self::match_against_query($keyword) . "' IN BOOLEAN MODE)"));
     } else {
         $words = explode(' ', $keyword);
         $query->where_open();
         $query->where_open();
         foreach ($words as $word) {
             if (!empty($word)) {
                 $query->where('search_index.header', 'like', '%' . $word . '%');
             }
         }
         $query->where_close();
         if ($only_title === FALSE) {
             $query->or_where_open();
             foreach ($words as $word) {
                 if (!empty($word)) {
                     $query->where('search_index.content', 'like', '%' . $word . '%');
                 }
             }
             $query->where_close();
         }
         $query->where_close();
     }
     return $query;
 }
Esempio n. 7
0
 /**
  * Метод используется для поиска по документам по ключевому слову.
  * 
  * Ключевое слово передается в качестве $_GET запроса с ключем "keyword"
  * 
  * @param Database_Query $query
  * @return Database_Query
  */
 public function search_by_keyword(Database_Query $query)
 {
     $keyword = Request::initial()->query('keyword');
     if (empty($keyword)) {
         return $query;
     }
     if ($this->_section->is_indexable()) {
         $ids = Search::instance()->find_by_keyword($keyword, FALSE, 'ds_' . $this->_section->id(), NULL);
         $ids = Arr::get($ids, 'ds_' . $this->_section->id());
         if (!empty($ids)) {
             $query->where('d.id', 'in', array_keys($ids));
         } else {
             $query->where('d.id', '=', 0);
         }
     } else {
         $query->where_open()->where('d.id', 'like', '%' . $keyword . '%')->or_where('d.header', 'like', '%' . $keyword . '%')->where_close();
     }
     return $query;
 }
Esempio n. 8
0
 /**
  * Условие фильтрации текущего поля, если оно используется в фильтре виджета
  * "Список ГД документов"
  * 
  * @see DataSource_Hybrid_Agent::_fetch_filters()
  * 
  * @param Database_Query $query
  * @param string $condition
  * @param string $value
  * @return type
  */
 public function filter_condition(Database_Query $query, $condition, $value, array $params = NULL)
 {
     $field = $this->name;
     if (isset($params['db_function'])) {
         $field = $this->build_sql_field($params['db_function'], $field, $value);
     }
     $query->where($field, $condition, $value);
 }
Esempio n. 9
0
File: Token.php Progetto: Konro1/pms
 public function builder_call_expired(Database_Query $query, Jam_Event_Data $data, $token = TRUE, $current_time = NULL)
 {
     $query->where('expires', (bool) $token ? '<' : '>=', $current_time === NULL ? time() : $current_time);
 }
Esempio n. 10
0
 /**
  * 
  * @param Database_Query $db
  * @param array $clause
  * @return type
  */
 public static function _conditions($db, array $clause)
 {
     foreach ($clause as $type => $params) {
         switch ($type) {
             case 'select':
                 foreach ($params as $param) {
                     $db->select($param);
                 }
                 break;
             case 'where':
                 foreach ($params as $param) {
                     $db->where($param[0], $param[1], $param[2]);
                 }
                 break;
             case 'or_where':
                 foreach ($params as $param) {
                     $db->or_where($param[0], $param[1], $param[2]);
                 }
                 break;
             case 'order_by':
                 foreach ($params as $param) {
                     $db->order_by($param[0], $param[1]);
                 }
                 break;
             case 'limit':
                 $db->limit((int) $params);
                 break;
             case 'offset':
                 $db->offset((int) $params);
                 break;
         }
     }
     return $db;
 }