public function beforeDelete() { foreach ($this->hasMany(FieldValue::className(), ['field_id' => 'id'])->all() as $val) { $val->delete(); } return true; }
public function search($params) { $query = Order::find(); $query->joinWith('elementsRelation'); if ($elementTypes = yii::$app->request->get('element_types')) { $query->andFilterWhere(['order_element.model' => $elementTypes])->groupBy('order.id'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'status' => $this->status, 'promocode' => $this->promocode, 'seller_user_id' => $this->seller_user_id]); $query->andFilterWhere(['like', 'client_name', $this->client_name])->andFilterWhere(['like', 'shipping_type_id', $this->shipping_type_id])->andFilterWhere(['like', 'payment_type_id', $this->payment_type_id])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'time', $this->time]); if (yii::$app->request->get('promocode')) { $query->andWhere("promocode != ''"); $query->andWhere("promocode IS NOT NULL"); } if ($customField = yii::$app->request->get('order-custom-field')) { $orderIds = []; foreach ($customField as $id => $str) { if (!empty($str)) { if ($values = FieldValue::find()->select('order_id')->where(['field_id' => $id])->andWhere(['LIKE', 'value', $str])->all()) { foreach ($values as $value) { $orderIds[] = $value->order_id; } } } } if ($orderIds) { $query->andWhere(['order.id' => $orderIds]); } } if ($dateStart = yii::$app->request->get('date_start')) { $dateStart = date('Y-m-d', strtotime($dateStart)); if (!yii::$app->request->get('date_stop')) { $query->andWhere('DATE_FORMAT(date, "%Y-%m-%d") = :dateStart', [':dateStart' => $dateStart]); } else { $query->andWhere('date >= :dateStart', [':dateStart' => $dateStart]); } } else { if ($timeStart = yii::$app->request->get('time_start')) { $query->andWhere('date >= :timeStart', [':timeStart' => $timeStart]); } if ($timeStop = yii::$app->request->get('time_stop')) { if (urldecode($timeStop) == '0000-00-00 00:00:00') { $timeStop = date('Y-m-d H:i:s'); } $query->andWhere('date <= :timeStop', [':timeStop' => $timeStop]); } } if ($dateStop = yii::$app->request->get('date_stop')) { $dateStop = date('Y-m-d', strtotime($dateStop)); $query->andWhere('date <= :dateStop', [':dateStop' => $dateStop]); } return $dataProvider; }
public function search($params) { $query = FieldValue::find()->orderBy('id DESC'); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'order_id' => $this->order_id]); $query->andFilterWhere(['like', 'value', $this->value]); return $dataProvider; }
public function beforeDelete() { foreach ($this->hasMany(Element::className(), ['order_id' => 'id'])->all() as $elem) { $elem->delete(); } foreach ($this->hasMany(FieldValue::className(), ['order_id' => 'id'])->all() as $val) { $val->delete(); } return parent::beforeDelete(); }