orWhere() public method

The new condition and the existing one will be joined using the 'OR' operator.
See also: where()
See also: andWhere()
public orWhere ( string | array | yii\db\Expression $condition, array $params = [] )
$condition string | array | yii\db\Expression the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.
$params array the parameters (name => value) to be bound to the query.
Exemplo n.º 1
0
 public function testWhere()
 {
     $query = new Query();
     $query->where('id = :id', [':id' => 1]);
     $this->assertEquals('id = :id', $query->where);
     $this->assertEquals([':id' => 1], $query->params);
     $query->andWhere('name = :name', [':name' => 'something']);
     $this->assertEquals(['and', 'id = :id', 'name = :name'], $query->where);
     $this->assertEquals([':id' => 1, ':name' => 'something'], $query->params);
     $query->orWhere('age = :age', [':age' => '30']);
     $this->assertEquals(['or', ['and', 'id = :id', 'name = :name'], 'age = :age'], $query->where);
     $this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
 }
Exemplo n.º 2
0
 /**
  * @return array
  * @throws yii\web\NotFoundHttpException
  */
 public function run()
 {
     if (!isset($_GET[$this->query_variable])) {
         throw new yii\web\NotFoundHttpException();
     }
     $modelName = $this->modelName;
     Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
     $query = new yii\db\Query();
     $query->select($this->json_attributes)->from($modelName::tableName());
     $search_query = $_GET[$this->query_variable];
     foreach ($this->search_attributes as $attribute) {
         $query->orWhere(['like', $attribute, $search_query]);
     }
     $suggest = $query->limit($this->limit)->all();
     return $suggest;
 }
Exemplo n.º 3
0
 public function ur_l()
 {
     $db = new Query();
     if ($_POST['search']['value'] != "") {
         $db->where(['like', 'name', $_POST['search']['value']]);
         $db->orWhere(['like', 'address', $_POST['search']['value']]);
         $db->orWhere(['like', 'inn', $_POST['search']['value']]);
         $db->orWhere(['like', 'wabc', $_POST['search']['value']]);
     }
     if (is_numeric($_POST['region'])) {
         $db->InnerJoin('region_ur_l', 'id_ur = ur_l.id');
         $db->andWhere(['=', 'id_reg', $_POST['region']]);
     }
     if ($_POST['pharmopeka']) {
         $db->andWhere(['=', 'ur_l.farmopeka', '1']);
     }
     if ($_POST['order'][0]['column']) {
         $column_order = $_POST['order'][0]['column'];
         $column = $_POST['columns'][$column_order]['data'];
         $db->orderBy($_POST['columns'][$column_order]['data'] . " " . $_POST['order'][0]['dir']);
     }
     if (Yii::$app->user->identity->status == 2) {
         //Регионалы
         $db->andFilterWhere(['=', 'ur_l.regional_id', Yii::$app->user->identity->id]);
     }
     if (Yii::$app->user->identity->status == 3) {
         //Провизоры
         $db->andFilterWhere(['=', 'ur_l.pi_id', Yii::$app->user->identity->id]);
     }
     $db->from('ur_l');
     $db->select(['ur_l.name', 'ur_l.id', 'ur_l.inn', 'ur_l.address', 'ur_l.wabc']);
     $db->limit(10);
     $db->offset(intval(Yii::$app->request->post('start')));
     $data = $db->all();
     $count = $db->count();
     for ($i = 0; $i < count($data); $i++) {
         $data[$i]['name'] = "<a href=\"/ur/update?id=" . $data[$i][id] . "\">" . $data[$i][name] . "</a>";
         $data[$i]['id'] = "<a href=\"/ur/update?id=" . $data[$i][id] . "\">" . $data[$i][id] . "</a>";
     }
     $array = array('draw' => intval(Yii::$app->request->post('draw')), 'recordsTotal' => $count, 'recordsFiltered' => $count, 'data' => $data);
     return $array;
 }