where() public method

Adds where condition, more calls appends with AND.
public where ( $condition, $params ) : self
return self
Exemplo n.º 1
0
 /**
  * Filter data
  * @param array $filter
  */
 public function filter(array $filter)
 {
     foreach ($filter as $key => $value) {
         $value = is_numeric($value) ? $value : '%' . $value . '%';
         $this->table->where($key . ' LIKE ?', $value);
     }
 }
Exemplo n.º 2
0
 public function validate(BaseControl $control)
 {
     $condition[$control->name] = $control->value;
     if ($this->id) {
         $condition['id!='] = $this->id;
     }
     return $this->selection->where($condition)->count() ? FALSE : TRUE;
 }
Exemplo n.º 3
0
  /** Nastavenie textov
 * @param array $texts
 * @return \App\FrontModule\Components\Clanky\AktualneClankyControl
 */
  public function setTexts($texts)
  {
      $this->texts = array_merge($this->texts, $texts);
      return $this;
  }
  /** Nastavenie cesty k titulnemu obrazku clanku
Exemplo n.º 4
0
 /**
  * Nastavi model
  * @param Nette\Database\Table\Selection
  */
 public function setModel(\Nette\Database\Table\Selection $model)
 {
     if (isset($this->filter['email']) && $this->filter['email'] != '') {
         $model->where('adress REGEXP ?', $this->filter['email']);
     }
     if (isset($this->filter['subject']) && $this->filter['subject'] != '') {
         $model->where('subject REGEXP ?', $this->filter['subject']);
     }
     $this->model = $model;
 }
Exemplo n.º 5
0
 /** Nacitanie udajov o produkte
  * @param int $id Id produktu
  * @param int $id_lang Id jazyka
  * @return array|FALSE
  */
 public function getProdukt($id, $id_lang = 1)
 {
     $hlavne_menu_lang = $this->hlavne_menu_lang->where(array("id_hlavne_menu" => $id, "id_lang" => $id_lang));
     if ($hlavne_menu_lang === FALSE) {
         return FALSE;
     }
     $produkt = $this->find($hlavne_menu_lang->hlavne_menu->clanok);
     if ($produkt === FALSE) {
         return FALSE;
     }
     return array("hlavne_menu_lang" => $hlavne_menu_lang, "produkt" => $produkt);
 }
Exemplo n.º 6
0
 public function search($q)
 {
     $query = "";
     $count = count($this->columns);
     $i = 0;
     $phldrs = array();
     foreach ($this->columns as $column) {
         $query .= new \Nette\Database\SqlLiteral($column . " " . $this->method . " ?");
         $phldrs[] = str_replace($this->placeholder, $q, $this->mask);
         if ($i < $count - 1) {
             $query .= " OR ";
         }
         $i++;
     }
     return $this->model->where($query, $phldrs);
 }
Exemplo n.º 7
0
Arquivo: DB.php Projeto: lohini/cf
 /**
  * Add filtering onto specified column
  *
  * @param string column name
  * @param string filter
  * @param string|array operation mode
  * @param string chain type (if third argument is array)
  * @return IDataSource (fluent)
  * @throws \Nette\InvalidArgumentException
  */
 public function filter($column, $operation = IDataSource::EQUAL, $value = NULL, $chainType = NULL)
 {
     if (!$this->hasColumn($column)) {
         throw new \Nette\InvalidArgumentException('Trying to filter data source by unknown column.');
     }
     if (is_array($operation)) {
         if ($chainType !== self::CHAIN_AND && $chainType !== self::CHAIN_OR) {
             throw new \Nette\InvalidArgumentException('Invalid chain operation type.');
         }
     } else {
         $operation = [$operation];
     }
     if (empty($operation)) {
         throw new \Nette\InvalidArgumentException('Operation cannot be empty.');
     }
     $conds = $values = [];
     foreach ($operation as $o) {
         $this->validateFilterOperation($o);
         $c = $this->mapping[$column] . " {$o}";
         if ($o !== self::IS_NULL && $o !== self::IS_NOT_NULL) {
             $c .= ' ?';
             $values[] = $o === self::LIKE || $o === self::NOT_LIKE ? DataSources\Utils\WildcardHelper::formatLikeStatementWildcards($value) : $value;
         }
         $conds[] = $c;
     }
     $conds = implode(" ( {$chainType} ) ", $conds);
     // "(cond1) OR (cond2) ..."  -- outer braces missing for now
     $this->selection->where("( {$conds} )", $values);
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Filter IT!
  * @param string $flags
  */
 public function filter($flags)
 {
     //One and main logic!
     $columns = array();
     foreach (str_split($flags) as $char) {
         if (!array_key_exists($char, $this->flags)) {
             throw new \Nette\InvalidArgumentException("Unrecognized flag '{$char}'", 3315);
         }
         $flag = $this->flags[$char];
         if (!is_array($flag)) {
             $arr = array();
             $arr["column"] = $flag;
             $arr["by"] = " = 1";
             $columns[] = $arr;
         } else {
             $columns[] = $flag;
         }
     }
     return $this->model->where($this->getQueryString($columns));
 }
Exemplo n.º 9
0
 static function appendFilter(Nette\Database\Table\Selection &$query, $filter = NULL, array $defaultFilterType = [], array $filterTranslate = [])
 {
     if (!is_null($filter)) {
         if (isset($filter[ABaseList::STRICT])) {
             $query->where($filter[ABaseList::STRICT]);
             unset($filter[ABaseList::STRICT]);
         }
         foreach ($filter as $k => $v) {
             $key = $k;
             if (array_key_exists($k, $filterTranslate)) {
                 $key = $filterTranslate[$k];
             }
             if (array_key_exists($k, $defaultFilterType)) {
                 switch ($defaultFilterType[$k]) {
                     case '<':
                         $query->where($key . ' < ?', $v);
                         break;
                     case '<=':
                         $query->where($key . ' <= ?', $v);
                         break;
                     case '<=date':
                         $query->where($key . ' < ? + INTERVAL 1 DAY', $v);
                         break;
                     case '>':
                         $query->where($key . ' > ?', $v);
                         break;
                     case '>=':
                         $query->where($key . ' >= ?', $v);
                         break;
                     case '=':
                         $query->where($key . ' = ?', $v);
                         break;
                     default:
                         throw new Trejjam\Utils\LogicException('Unknown filter type ' . $defaultFilterType[$k]);
                 }
             } else {
                 $query->where([$key . ' LIKE' => '%' . $v . '%']);
             }
         }
     }
     return $query;
 }
Exemplo n.º 10
0
 /**
  * @param Nette\Database\Table\Selection $dokumenty
  */
 public function __construct(Nette\Database\Table\Selection $dokumenty)
 {
     parent::__construct();
     //Najdem si len obrazky
     $this->dokumenty = $dokumenty->where("pripona", array("jpg", "png", "gif", "bmp"));
 }
Exemplo n.º 11
0
 /**
  * Returns referenced row.
  * @param  string
  * @return ActiveRow or NULL if the row does not exist
  */
 public function getReferencedTable($name, &$column = NULL)
 {
     $column = $this->connection->databaseReflection->getReferencedColumn($name, $this->name);
     $referenced =& $this->referenced[$name];
     if ($referenced === NULL) {
         $keys = array();
         foreach ($this->rows as $row) {
             if ($row[$column] !== NULL) {
                 $keys[$row[$column]] = NULL;
             }
         }
         if ($keys) {
             $table = $this->connection->databaseReflection->getReferencedTable($name, $this->name);
             $referenced = new Selection($table, $this->connection);
             $referenced->where($table . '.' . $this->getPrimary($table), array_keys($keys));
         } else {
             $referenced = array();
         }
     }
     return $referenced;
 }
Exemplo n.º 12
0
 public function setModel(\Nette\Database\Table\Selection $model)
 {
     parent::setModel($model->where('parent_id ?', null));
 }
Exemplo n.º 13
0
     $temp_pol->name = $v->hlavne_menu_cast->nazov;
     $temp_pol->link = $abs_link . "Homepage:";
     $temp_pol->id = -1 * $v->hlavne_menu_cast->id;
     $out[] = array("node" => $temp_pol, "nadradena" => FALSE);
     unset($temp_pol);
 }
Exemplo n.º 14
0
 /**
  * Returns referenced row.
  * @param  string
  * @param  string
  * @param  bool  checks if rows contains the same primary value relations
  * @return ActiveRow or NULL if the row does not exist
  */
 public function getReferencedTable($table, $column, $checkReferenceNewKeys = FALSE)
 {
     $referenced =& $this->referenced[$table][$column];
     if ($referenced === NULL || $checkReferenceNewKeys || $this->checkReferenceNewKeys) {
         $keys = array();
         foreach ($this->rows as $row) {
             if ($row[$column] === NULL) {
                 continue;
             }
             $key = $row[$column] instanceof ActiveRow ? $row[$column]->getPrimary() : $row[$column];
             $keys[$key] = TRUE;
         }
         if ($referenced !== NULL && $keys === array_keys($this->rows)) {
             $this->checkReferenceNewKeys = FALSE;
             return $referenced;
         }
         if ($keys) {
             $referenced = new Selection($table, $this->connection);
             $referenced->where($table . '.' . $referenced->primary, array_keys($keys));
         } else {
             $referenced = array();
         }
     }
     return $referenced;
 }
 /**
  * Filter by select value
  * @param  Filter\FilterSelect $filter
  * @return void
  */
 public function applyFilterSelect(Filter\FilterSelect $filter)
 {
     $this->data_source->where($filter->getCondition());
 }
 /**
  * @param $condition
  * @return self
  */
 public function addCondition($condition)
 {
     $this->selection->where($condition);
     return $this;
 }
Exemplo n.º 17
0
 /**
  * Hleda vyraz ve sloupci.
  * @param \Nette\Database\Table\Selection $selection
  * @param string $column
  * @param string $word
  * @param string $via
  * @return \Nette\Database\Table\Selection
  */
 public function filterSearch(Selection $selection, $column, $word, $via = '')
 {
     return $selection->where("? LIKE ?", new \Nette\Database\SqlLiteral($column), "%{$word}%");
 }
Exemplo n.º 18
0
 /**
  * @return Selection
  */
 public function build()
 {
     return $this->context->where($this->queryBuilder->create(), $this->value);
 }
Exemplo n.º 19
0
 /**
  * @param  \Nette\Database\Table\Selection
  */
 private function filterOutDeleted(Selection $selection)
 {
     $selection->where('deletedAt IS NULL');
 }
Exemplo n.º 20
0
delete(){return$this->query('DELETE'.$this->topString()." FROM $this->delimitedName".$this->whereString())->rowCount();}function
getReferencedTable($table,$column,$checkReferenceNewKeys=FALSE){$referenced=&$this->referenced["$table.$column"];if($referenced===NULL||$checkReferenceNewKeys||$this->checkReferenceNewKeys){$keys=array();foreach($this->rows
as$row){if($row[$column]===NULL)continue;$key=$row[$column]instanceof
ActiveRow?$row[$column]->getPrimary():$row[$column];$keys[$key]=TRUE;}if($referenced!==NULL&&$keys===array_keys($this->rows)){$this->checkReferenceNewKeys=FALSE;return$referenced;}if($keys){$referenced=new
Selection($table,$this->connection);$referenced->where($table.'.'.$referenced->primary,array_keys($keys));}else{$referenced=array();}}return$referenced;}function
Exemplo n.º 21
0
 private function applyAdditionalConditions(Selection $selection)
 {
     $additionalParameters = $this->currentFilter->getAdditionalConditions();
     if (array_key_exists(self::MEDIA_STORAGE_TABLE, $additionalParameters)) {
         foreach ($additionalParameters[self::MEDIA_STORAGE_TABLE] as $condition) {
             $selection->where($condition);
         }
     }
     if (array_key_exists(self::MEDIA_USAGE_TABLE, $additionalParameters)) {
         foreach ($additionalParameters[self::MEDIA_USAGE_TABLE] as $condition) {
             $selection->where(':' . self::MEDIA_USAGE_TABLE . '.' . $condition);
         }
     }
 }
Exemplo n.º 22
0
 /**
  * @param \Nette\Database\Table\Selection $selection
  * @param $column
  * @param $word
  * @param string $via
  * @return \Nette\Database\Table\Selection
  */
 public function filterDomainSearch(Selection $selection, $column, $word, $via = '')
 {
     return $selection->where("? LIKE ?", new SqlLiteral($column), "{$word}%");
 }