Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PersonItem::find();
     $query->innerJoinWith(['person', 'item']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new Sort(['attributes' => ['item_name' => ['asc' => ['item.name' => SORT_ASC], 'desc' => ['item.name' => SORT_DESC]], 'person_name' => ['asc' => ['person.lastname' => SORT_ASC], 'desc' => ['person.lastname' => SORT_DESC]], 'amount', 'created_at', 'updated_at']])]);
     $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->andFilterWhere(['created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andWhere('item.name LIKE :in OR item.code LIKE :in OR person.firstname LIKE :pn OR person.lastname LIKE :pn', [':pn' => '%' . $this->person_name . '%', ':in' => '%' . $this->person_name . '%']);
     return $dataProvider;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPersonItems()
 {
     return $this->hasMany(PersonItem::className(), ['item_id' => 'id']);
 }
Пример #3
0
 /**
  * Finds the PersonItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return PersonItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PersonItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }