public function search($params) { $query = JobModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); // load the search form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } // adjust the query by adding the filters if ($this->id > 0) { $query->andFilterWhere(['id' => $this->id]); } if ($this->name) { $query->andFilterWhere(['like', 'name', $this->name]); } if ($this->cmd) { $query->andFilterWhere(['like', 'cmd', $this->cmd]); } if ($this->cron_str) { $query->andFilterWhere(['like', 'cron_str', $this->cron_str]); } if ($this->owner) { $query->andFilterWhere(['owner' => $this->owner]); } if ($this->status !== null) { $query->andFilterWhere(['statis' => $this->status]); } return $dataProvider; }
/** * * @param string $nameLike * @param string $owner * @param string $newOrStop, use to match status. can be null, one integer, or integer array; * @param number $page * @param number $size * @return string */ public static function getJobs($nameLike = '', $owner = '', $newOrStop = Null, $page = 0, $size = 20) { $page = intval($page); $size = intval($size); if ($size > 100) { $size = 100; } $sql = 'select * from wm_jobs '; $cond = ''; $params = []; if (!empty($nameLike)) { if (!empty($cond)) { $cond .= ' and '; } $cond .= 'name like :name'; $params[':name'] = '%' + $nameLike + '%'; } if (!empty($like)) { if (!empty($cond)) { $cond .= ' and '; } $cond .= 'owner = :owner'; $params[':owner'] = $owner; } if (!empty($cond)) { $cond .= ' and '; } if ($newOrStop) { if (is_int($newOrStop)) { $cond .= ' status = 0'; } else { if (is_array($newOrStop)) { $cond .= ' status in (' . implode(',', $newOrStop) . ')'; } } } if ($cond) { $sql .= ' where ' . $cond; } $sql .= ' limit ' . $page * $size . ',' . $size; return JobModel::findBySql($sql, $params)->all(); }