示例#1
0
 /**
  * Creates a new Task model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Task();
     $model->teacher_id = Yii::$app->user->identity->teacher->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['control']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 /**
  * Creates a new Task model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Task();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     }
     return $this->render('create', ['model' => $model]);
 }
示例#3
0
 /**
  * Creates the ConstructBuildingTask.
  */
 public function createTask()
 {
     $building = $this->buildingFinder->getById($this->buildingId);
     /* @var $user \common\models\User */
     $user = Yii::$app->user->identity;
     $base = $user->getBase($this->baseId);
     // TODO once the ConstructionQueueRule is implemented, use it to pass
     //      the currently appropriate factor.
     $base->payFor($building, 1.0);
     $now = $this->getTimeComponent()->getStartTime();
     $finished = clone $now;
     $finished->add($building->getCostTime());
     $taskModel = new Task();
     $taskModel->data = ['baseId' => $this->baseId, 'buildingId' => $this->buildingId];
     $taskModel->dateTimeFinished = $finished;
     $taskModel->type = ConstructBuildingTask::className();
     $taskModel->user_id = $user->id;
     if (!$taskModel->save()) {
         throw new Exception('Failed to create task: ' . print_r($taskModel->firstErrors, true));
     }
 }