コード例 #1
0
ファイル: JobController.php プロジェクト: kevinaud/Jobocracy
 /**
  * Creates a new Job model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Job();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: JobController.php プロジェクト: sindotnet/cona
 /**
  * Creates a new Job model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $admin_id = Yii::$app->user->identity->id;
     $model = new Job();
     // $companies = Company::findBySql('SELECT * FROM wolf_company order by company_name')->all();
     // $companies = Company::find()->all();
     $companies = Company::find();
     if (Yii::$app->user->identity->type == 'normal') {
         $companies = $companies->innerJoin('wolf_admin_to_company wc', 'wc.company_id=wolf_company.company_id');
         $companies = $companies->where('admin_id=' . $admin_id);
     }
     $companies = $companies->orderBy('company_name');
     $companies = $companies->asArray();
     $companies = $companies->all();
     // echo $companies->createCommand()->getRawSql();exit;
     if ($model->load(Yii::$app->request->post())) {
         $time_in_hour = $_POST['Job']['time_in_hour'];
         $time_in_minute = $_POST['Job']['time_in_minute'];
         $time_out_hour = $_POST['Job']['time_out_hour'];
         $time_out_minute = $_POST['Job']['time_out_minute'];
         $model->time_in = $time_in_hour . ':' . $time_in_minute . ':00';
         $model->time_out = $time_out_hour . ':' . $time_out_minute . ':00';
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->job_id]);
     } else {
         return $this->render('create', ['model' => $model, 'companies' => $companies]);
     }
 }
コード例 #3
0
 /**
  * Updates an existing Person model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $jobModel = $model->job;
     if ($jobModel->load(Yii::$app->request->post()) && $jobModel->validate() && $model->load(Yii::$app->request->post()) && $model->validate()) {
         $transaction = $model->getDb()->beginTransaction();
         try {
             if (is_numeric($jobModel->name)) {
                 $jobModel = $jobModel->findOne($jobModel->name);
             } else {
                 $jobModel = new Job();
                 $jobModel->load(Yii::$app->request->post());
                 if (!$jobModel->save(false)) {
                     throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($jobModel->tableName())), 'msj' => print_r($jobModel->getErrors(), true)]), 500);
                 }
             }
             if ($model->job_id != $jobModel->id) {
                 $model->job_id = $jobModel->id;
             }
             if (!$model->save(false)) {
                 throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->getErrors(), true)]), 500);
             }
             $transaction->commit();
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'jobModel' => $jobModel]);
     }
 }