public function actionUpdates() { $errors = ''; $tees_id = null; $models = Hole::find()->where(['id' => array_keys($_POST['Hole'])])->indexBy('id')->all(); if (Hole::loadMultiple($models, Yii::$app->request->post()) && Hole::validateMultiple($models)) { $count = 0; foreach ($models as $model) { // populate and save records for each model if (count($model->errors) > 0) { $errors .= print_r($model->errors, true); } if (!$tees_id) { $tees_id = $model->tees_id; } if ($model->save()) { $count++; } } Yii::$app->session->setFlash('success', Yii::t('igolf', "Processed {0} records successfully.", $count)); return $this->redirect(['tees/view', 'id' => $tees_id]); // redirect to your next desired page } else { Yii::$app->session->setFlash('error', Yii::t('igolf', "There are errors processing your request: " . $errors . ".")); return $this->redirect(['tees/view', 'id' => $tees_id]); // redirect to your next desired page } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Hole::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'tees_id' => $this->tees_id, 'position' => $this->position, 'par' => $this->par, 'si' => $this->si, 'length' => $this->length]); return $dataProvider; }
/** * Returns ActiveQuery of same hole from different tees. */ public function shareMedia() { return Hole::find()->andWhere(['position' => $this->position])->andWhere(['tees_id' => $this->tees->course->getTees()->select('id')]); }
public function getTeesWithHoles($gender = null) { $q = $this->getTees()->andWhere(['exists', Hole::find()->andWhere('hole.tees_id = tees.id')]); return $gender ? $q->andWhere(['gender' => $gender]) : $q; }