/** * Adds a new holes with values copied from another tees set. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCopyholes($id, $copy_id) { $model = $this->findModel($id); $src = $this->findModel($copy_id)->getHoles()->all(); if (sizeof($src) > 0) { $start = $model->front_back == Tees::TEE_BACK ? 9 : 0; $offset = count($src) == 9 && $model->front_back == Tees::TEE_BACK ? 9 : 0; Yii::trace('s=' . $start . '/o=' . $offset); for ($i = 0; $i < $model->holes; $i++) { $srchole = $src[$start + $i - $offset]; $hole = new Hole(); $hole->tees_id = intval($id); $hole->position = $srchole->position; $hole->par = $srchole->par; $hole->si = $srchole->si; $hole->length = $srchole->length; if (!$hole->save()) { Yii::$app->session->setFlash('danger', Yii::t('igolf', 'Error(s): {0}', [VarDumper::dumpAsString($hole->errors, 4, true)])); } } } else { Yii::$app->session->setFlash('error', 'Could not find source holes.'); } return $this->redirect(['view', 'id' => $id]); }