Exemplo n.º 1
0
 /**
  * Creates a new HarvestTools model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($tools_id = 0)
 {
     $model = new HarvestTools();
     $model->state_id = Yii::$app->user->identity->state_id;
     $model->year = date('Y');
     if (in_array(date('m'), [10, 11, 12])) {
         $model->quarter = 4;
     }
     if (in_array(date('m'), [7, 8, 9])) {
         $model->quarter = 3;
     }
     if (in_array(date('m'), [4, 5, 6])) {
         $model->quarter = 2;
     }
     if (in_array(date('m'), [1, 2, 1])) {
         $model->quarter = 1;
     }
     if ($tools_id > 0) {
         $tools = Tools::findOne($tools_id);
         $typeTools = TypeTools::findOne($tools->type_tools_id);
         $model->tools_id = $tools_id;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'typeTools' => $typeTools]);
     }
 }