/** * Updates an existing ColourSchemes model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { foreach ($model->colors as $color) { if (isset($_POST['Colour'][$color->id])) { $color->value = $_POST['Colour'][$color->id]; $color->save(); } else { $color->delete(); } } foreach ($_POST['Colour'] as $key => $value) { if (preg_match_all("#c_#is", $key)) { $color = new Colors(); $color->value = $this->get_fixed_color($value); $color->colour_scheme_id = $model->id; $color->save(); } } $this->redirect('index'); } else { $coloursProvider = new ActiveDataProvider(['query' => Colors::find()->where("colour_scheme_id = :id", ["id" => $id])]); return $this->renderAjax('update', ['model' => $model, 'coloursProvider' => $coloursProvider]); } }
function getTempRanges() { $colors = Colors::all(); $hi = 95; $low = 30; $colorCount = count($colors); $increment = ($hi - $low) / $colorCount; $temp = $low; for ($i = 0; $i < $colorCount; $i++) { $startTemp = $temp; $temp += $increment; $tempRanges[] = ["low" => ceil($startTemp), "high" => floor($temp), "color" => $colors[$i]]; } return $tempRanges; }
public function getColors() { return $this->hasMany(Colors::className(), ['colour_scheme_id' => 'id']); }