/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $emp_id = null) { if ($emp_id == null) { $query = CellNumbers::find(); } else { $query = CellNumbers::find()->where(['employee_id' => $emp_id]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['status' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->joinWith('employee'); $query->andFilterWhere(['cell_numbers.id' => $this->id, 'status' => $this->status]); $query->andFilterWhere(['like', 'cell_number', $this->cell_number])->andFilterWhere(['like', 'employees.snp', $this->employee_id]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getCellNumbers() { return $this->hasMany(CellNumbers::className(), ['employee_id' => 'id']); }
/** * Finds the CellNumbers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CellNumbers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CellNumbers::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array|\yii\db\ActiveRecord[] */ public static function arrayCells() { return CellNumbers::find()->select('cell_number as value, cell_number as label')->where("cell_number > '' AND status = 1")->orderBy('cell_number')->asArray()->all(); }