/** * Creates a new Functionality model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Functionality(); $projects = Project::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->functionality_id]); } else { return $this->render('create', ['model' => $model, 'projects' => $projects]); } }
public function saveAsFunctionality($project_id) { $functionality = new Functionality(); $functionality->project_id = $project_id; $functionality->name = $this->name; $functionality->price = round($this->price, 2); $functionality->amount = 1; $functionality->description = $this->description; $functionality->deleted = false; if (!$functionality->validate()) { return false; } else { return $functionality->save(); } }
/** * * @param Model $step * @param integer $project_id * @param integer $uid * @return string $comments */ private function saveFunctionalities($step, $project_id, $uid) { $comment = ''; foreach ($step->attributes as $key => $attribute) { if (!empty($attribute)) { if ($key == 'comment') { $comment = $attribute; } else { $bidpart = BidPart::find()->where(['attribute_name' => $key])->one(); if ($bidpart->file_upload) { $file = new File(); $file->name = $attribute->baseName . '.' . $attribute->extension; $file->description = $bidpart->description; $file->project_id = $project_id; $file->todo_id = null; $file->deleted = 0; $file->creator_id = $uid; $file->updater_id = $uid; $file->save(); rename($this->tempFileLocation . $file->name, $this->permFileLocation . $project_id . '/' . $file->name); } else { $functionality = new Functionality(); $functionality->name = $bidpart->name; $functionality->description = $attribute; $functionality->project_id = $project_id; $functionality->deleted = 0; $functionality->amount = 1; $functionality->price = $bidpart->price; $functionality->creator_id = $uid; $functionality->updater_id = $uid; $functionality->monthly_costs = $bidpart->monthly_costs; $functionality->save(false); } } } } return $comment; }