コード例 #1
0
 /**
  * Creates a new Project model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Project();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'id' => $model->pr_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: ProjectController.php プロジェクト: Kulkow/mainsite
 /**
  * Creates a new Project model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Project();
     $model->setScenario('update');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #3
0
 private function generateProject($uid)
 {
     // Get the Parts
     $steps = $this->getSessionPartsAsArray();
     // Create Project
     $project = new Project();
     $user;
     $customer;
     $previousUser = false;
     if (Yii::$app->session->has('customer')) {
         $customer = Yii::$app->session->get('customer');
         $user = $customer->user;
     } else {
         $user = User::find()->where(['id' => $uid])->one();
         $customer = Customer::find()->where(['user_id' => $user->id])->one();
     }
     // Log in the user temporarily so the project and functionalities get the right creator_id and updater_id
     if (Yii::$app->user->isGuest) {
         Yii::$app->user->login($user);
     } else {
         $previousUser = true;
     }
     $project->client_id = $customer->customer_id;
     $project->status = 0;
     $project->name = $customer->name;
     $project->deleted = 0;
     $project->description = 'Doel van de website: ' . $steps[1]->goal;
     $project->save(false);
     $location = $this->permFileLocation . $project->project_id . '/';
     if (!file_exists($location)) {
         mkdir($location);
     }
     $i = 1;
     $comments = Yii::t('request-project', ' Comments:');
     foreach ($steps as $step) {
         $comment = $this->saveFunctionalities($step, $project->project_id, $uid);
         if (!empty($comment)) {
             $comments .= ' ' . Yii::t('request-project', 'Step');
             $comments .= ' ' . $i . ': ';
             $comments .= $comment;
         }
         $i++;
     }
     if ($comments != Yii::t('request-project', ' Comments:')) {
         $project->description .= $comments;
         $project->save(false);
     }
     // Log the user out
     if (!$previousUser) {
         Yii::$app->user->logout();
     }
     // Notify the admin
     $mail = Yii::$app->mailer->compose(['html' => 'newProjectRegistered-html', 'text' => 'newProjectRegistered-text'], ['customer' => $customer, 'project' => $project]);
     $mail->setFrom('*****@*****.**');
     $mail->setTo('*****@*****.**');
     $mail->setSubject('Er is een nieuw project aangevraagd door ' . $customer->name);
     $mail->send();
     return $project;
 }
コード例 #4
0
ファイル: ProjectController.php プロジェクト: pjoger/pon4ik
 public function actionUpdate($id = 0)
 {
     //      $out = ['status' => 'err', 'error' => 'Unknown error'];
     if (\Yii::$app->user->isGuest) {
         throw new NotFoundHttpException();
     }
     $r = new Request();
     if (isset($r->post('Project')['id']) && $r->post('Project')['id']) {
         $id = $r->post('Project')['id'];
     }
     //      vd($r->post('Company'));
     $userID = \Yii::$app->user->getId();
     if ($id) {
         $project = Project::findOne(['id' => $id, 'user_id' => $userID]);
     } else {
         $project = new Project();
         //        \Yii::$app->session->setFlash('error', 'Company ID is required.');
         //        $this->redirect(array('view','id'=>$company));
         //        $this->redirect(array('index'));
         //        return;
     }
     //        vd($company);
     if ($project) {
         if ($project->load($r->post())) {
             $project->user_id = $userID;
             if ($project->validate() && $project->save()) {
                 //vd([$r->post(),$order->attributes]);
                 //          $out = [
                 //            'status' => 'ok',
                 //            'order' => $order->id,
                 //            'user' => $order->user_id,
                 //            'sum' => $order->price / 100,
                 //          ];
                 //          $this->redirect(array('view','id'=>$company));
             } else {
                 //          vd($company->errors);
                 \Yii::$app->session->setFlash('error', array_values($project->errors)[0][0]);
                 //          $out['error'] = array_values($order->errors)[0][0];
                 //vd($order->errors);
             }
         }
     } else {
         \Yii::$app->session->setFlash('error', 'Такой проект не существует');
         $this->redirect(array('my'));
         return;
     }
     return $this->render('update', ['project' => $project]);
     //      \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     //      return $out;
     /*vd(['get' => $r->getQueryParams() ,
       'post' => $r->post(),
       'order' => $order],1); //*/
 }