/** * Creates a new Score model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Score(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->idscore]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates Score entry for each hole of the scorecard if none exists. */ public function makeScores() { if (!$this->hasDetails() && $this->tees) { $allowed = $this->player->allowed($this->tees); $holes = $this->tees->getHoles()->orderBy('position')->indexBy('position')->all(); $hole_count = count($holes); $holes_to_play = $this->holes(); $start_hole = $this->startHole(); Yii::trace('toplay=' . $holes_to_play . ', tees=' . $this->tees->holes . ', start=' . $start_hole, 'Scorecard::makeScores'); if ($holes_to_play > $this->tees->holes) { return; } for ($i = 0; $i < $holes_to_play; $i++) { $hole_num = $start_hole + $i % $hole_count; $score = new Score(['scorecard_id' => $this->id, 'hole_id' => $holes[$hole_num]->id, 'allowed' => $allowed[$hole_num - 1]]); $score->save(); } } }