/** * Finds the Hole model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Hole the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Hole::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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; }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['thru'], 'in', 'range' => Hole::validNumber()], [['status'], 'in', 'range' => array_keys(self::getConstants('STATUS_'))]]); }
/** * 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')]); }
/** * @return \yii\db\ActiveQuery */ public function getHoles() { return $this->hasMany(Hole::className(), ['id' => 'hole_id'])->viaTable('score', ['scorecard_id' => '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; }
/** * Deletes an existing Tees model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); $course_id = $model->course_id; Hole::deleteAll(['tees_id' => $model->id]); $model->delete(); return $this->redirect(['course/view', 'id' => $course_id]); }
/** * @return \yii\db\ActiveQuery */ public function getHole() { return $this->hasOne(Hole::className(), ['id' => 'hole_id']); }
/** * @return \yii\db\ActiveQuery */ public function getHoles() { return $this->hasMany(Hole::className(), ['tees_id' => 'id']); }