/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Workers();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Workers'])) {
         $model->attributes = $_POST['Workers'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     if (isset($_GET['providerid'])) {
         $model->providers_id = $_GET['providerid'];
     }
     $this->render('create', array('model' => $model, 'providers_array' => CMap::mergeArray(array("" => ""), CHtml::listData(Providers::model()->findAll("id in (select providers_id from workers where users_id=" . Yii::app()->user->id . ")"), "id", 'name')), 'users_array' => CMap::mergeArray(array("" => ""), CHtml::listData(Users::model()->findAll('id in (select userid from AuthAssignment where ' . 'itemname="technician" and userid in ' . '(select users_id from workers where providers_id in ' . '(select providers_id from workers where users_id=' . Yii::app()->user->id . ')))'), "id", 'email'))));
 }
Ejemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreatetechnician()
 {
     $this->pagename = "Register Technician " . $this->pagename;
     $model = new Users();
     $modelprovider = new Providers();
     $transaction = $model->getDbConnection()->beginTransaction();
     if (isset($_POST['Users'])) {
         $model->attributes = $_POST['Users'];
         $temp = $_POST['Providers'];
         try {
             if ($model->save()) {
                 $authmodel = new AuthAssignment();
                 //$transactionauth=$authmodel->getDbConnection()->beginTransaction();
                 $authmodel->itemname = 'technician';
                 $authmodel->userid = $model->id;
                 if ($authmodel->save()) {
                     $worker = new Workers();
                     //$transactionWorker=$worker->getDbConnection()->beginTransaction();
                     $worker->users_id = $model->id;
                     $worker->providers_id = $temp['id'];
                     if ($worker->save()) {
                         $transaction->commit();
                         //$transactionauth->commit();
                         //$transactionWorker->commit();
                         $this->redirect(array('view', 'id' => $model->id));
                     } else {
                         //$transaction->rollback();
                         //$transactionauth->rollback();
                         //$transactionWorker->rollback();
                     }
                 } else {
                     $transaction->rollback();
                 }
             }
         } catch (Exception $e) {
             $transaction->rollback();
         }
     }
     $this->render('createTechnician', array('model' => $model, 'modelprovider' => $modelprovider, 'providers_array' => CMap::mergeArray(array("" => ""), CHtml::listData(Providers::model()->findAll("id in (select providers_id from workers where users_id=" . Yii::app()->user->id . ")"), "id", 'name'))));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Providers the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Providers::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }