示例#1
0
 public function setAuthAssignment($role, $id)
 {
     if (!empty($role) && !empty($id)) {
         $authAssign = AuthAssignment::find()->where(['user_id' => $id])->one();
         if ($authAssign !== null) {
             $authAssign->item_name = $role;
             $authAssign->user_id = $id;
             return $authAssign->save(false);
         } else {
             $authAssign = new AuthAssignment();
             $authAssign->item_name = $role;
             $authAssign->user_id = $id;
             return $authAssign->save(false);
         }
     } else {
         return false;
     }
 }
示例#2
0
 public function actionAjaxchangeroles()
 {
     $user = \app\models\AuthAssignment::findOne(['user_id' => Yii::$app->request->post()['id']]);
     if ($user->user->profile_id == Yii::$app->params['god']) {
         return false;
     }
     $user->item_name = Yii::$app->request->post()['role'];
     if ($user->update()) {
         return true;
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthAssignment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['like', 'user_id', $this->user_id]);
     return $dataProvider;
 }
示例#4
0
 public function getRole()
 {
     return $this->hasOne(AuthAssignment::className(), ['user_id' => 'id']);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthAssignments()
 {
     return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']);
 }
 /**
  * Creates a new EmpMaster model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new EmpMaster();
     $info = new EmpInfo();
     $user = new User();
     $address = new EmpAddress();
     $auth_assign = new AuthAssignment();
     $empUniqueId = EmpInfo::find()->max('emp_unique_id');
     $empno = null;
     if (empty($empUniqueId)) {
         $empno = $info->emp_unique_id = 1;
     } else {
         $chkId = EmpInfo::find()->where(['emp_unique_id' => $empUniqueId])->exists();
         if ($chkId) {
             $empno = $empUniqueId + 1;
         } else {
             $empno = $empUniqueId;
         }
     }
     if ($model->load(Yii::$app->request->post()) && $info->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($info);
         }
         if (Yii::$app->request->isAjax) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         $model->attributes = $_POST['EmpMaster'];
         $info->attributes = $_POST['EmpInfo'];
         $info->emp_dob = Yii::$app->dateformatter->getDateFormat($_POST['EmpInfo']['emp_dob']);
         $info->emp_joining_date = Yii::$app->dateformatter->getDateFormat($_POST['EmpInfo']['emp_joining_date']);
         $info->emp_unique_id = $empno;
         if (empty($_POST['EmpInfo']['emp_email_id'])) {
             $info->emp_email_id = NULL;
         } else {
             $info->emp_email_id = strtolower($info->emp_email_id);
         }
         $user->user_login_id = \app\models\Organization::find()->one()->org_emp_prefix . $info->emp_unique_id;
         $user->user_password = md5($user->user_login_id . $user->user_login_id);
         $user->user_type = "E";
         $user->created_by = Yii::$app->getid->getId();
         $user->created_at = new \yii\db\Expression('NOW()');
         if ($info->save(false)) {
             $user->save(false);
             $address->save(false);
         }
         $model->emp_master_emp_address_id = $address->emp_address_id;
         $model->emp_master_emp_info_id = $info->emp_info_id;
         $model->emp_master_user_id = $user->user_id;
         $model->created_by = Yii::$app->getid->getId();
         $model->created_at = new \yii\db\Expression('NOW()');
         $model->save(false);
         $emp_info = EmpInfo::findOne($model->emp_master_emp_info_id);
         $emp_info->emp_info_emp_master_id = $model->emp_master_id;
         $emp_info->save(false);
         $auth_assign->item_name = 'Employee';
         $auth_assign->user_id = $user->user_id;
         $auth_assign->created_at = date_format(date_create(), 'U');
         $auth_assign->save(false);
         if ($model->save(false)) {
             return $this->redirect(['view', 'id' => $model->emp_master_id]);
         } else {
             return $this->render('create', ['model' => $model, 'info' => $info, 'user' => $user, 'empno' => $empno]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'info' => $info, 'user' => $user, 'empno' => $empno]);
     }
 }
 /**
  * Finds the AuthAssignment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $item_name
  * @param string $user_id
  * @return AuthAssignment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($item_name, $user_id)
 {
     if (($model = AuthAssignment::findOne(['item_name' => $item_name, 'user_id' => $user_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Update an existing User model. If update is successful, the browser
  * will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if ((Yii::$app->user->can("update-user") || Yii::$app->user->can("user")) && $id != 1) {
         $permissoes = AuthItem::getListToDropDownList();
         // set up user and profile
         $user = $this->findModel($id);
         $user->setScenario("admin");
         $profile = $user->profile;
         $mensagem = "";
         //Informa ao usuário mensagens de erro na view
         //Permissão do usuário
         $authAssignment = new AuthAssignment();
         $authItensUser = AuthAssignment::find()->where(['user_id' => $id])->all();
         $permissoesUser = [];
         foreach ($authItensUser as $aiu) {
             array_push($permissoesUser, $aiu->item_name);
         }
         //Recebe as permissões salvas do usuário
         $authAssignment->item_name = $permissoesUser;
         // load post data and validate
         $post = Yii::$app->request->post();
         if ($user->load($post) && $user->validate() && $profile->load($post) && $profile->validate()) {
             //Inicia a transação:
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 $itensInseridos = true;
                 if (isset($post['AuthAssignment']['item_name']) && !empty($post['AuthAssignment']['item_name'])) {
                     Yii::$app->db->createCommand("DELETE from auth_assignment WHERE \n                user_id = :iduser ", [':iduser' => $user->id])->execute();
                     $roles = $post['AuthAssignment']['item_name'];
                     foreach ($roles as $role) {
                         $user->alterarPermissoes($role, $user->id);
                     }
                 } else {
                     Yii::$app->db->createCommand("DELETE from auth_assignment WHERE \n                user_id = :iduser ", [':iduser' => $user->id])->execute();
                 }
                 if (!$user->save()) {
                     $mensagem = "Não foi possível salvar os dados";
                     $transaction->rollBack();
                     //desfaz alterações no BD
                     $itensInseridos = false;
                 }
                 if (!$profile->setUser($user->id)->save()) {
                     $mensagem = "Não foi possível salvar os dados";
                     $transaction->rollBack();
                     //desfaz alterações no BD
                     $itensInseridos = false;
                 }
                 if ($itensInseridos) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $user->id]);
                 }
             } catch (\Exception $exception) {
                 $transaction->rollBack();
                 $mensagem = "Ocorreu uma falha inesperada ao tentar salvar";
             }
         }
         // render
         return $this->render('update', compact('user', 'profile', 'permissoes', 'permissoesUser', 'mensagem', 'authAssignment'));
     } else {
         throw new ForbiddenHttpException("Acesso negado!");
     }
 }
示例#9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthAssignments()
 {
     return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
 }
示例#10
0
 public function importStuData($model)
 {
     $dispResults = [];
     $totalSuccess = 0;
     $objPHPExcel = PHPExcel_IOFactory::load($model->importFilePath . $model->importFile);
     $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
     //print_r($sheetData); exit;
     unset($sheetData[1]);
     //start import student row by row
     foreach ($sheetData as $k => $line) {
         //print_r($line); exit;
         if (!array_filter($line)) {
             continue;
         }
         $line = array_map('trim', $line);
         $line = array_map(function ($value) {
             return empty($value) ? NULL : $value;
         }, $line);
         $stuMaster = new StuMaster();
         $stuInfo = new StuInfo();
         $stuInfo->scenario = 'import-stu';
         $stuAddress = new StuAddress();
         $user = new User();
         $auth_assign = new AuthAssignment();
         //set student info attributes
         $stuInfo->stu_unique_id = $stuInfo->getUniqueId();
         // Student Unique Id
         $stuInfo->stu_title = $this->valueReplace($line['A'], $stuInfo->getTitleOptions());
         //Title Name
         $stuInfo->stu_first_name = $line['B'];
         //First Name
         $stuInfo->stu_last_name = $line['C'];
         //Last Name
         $stuInfo->stu_dob = Yii::$app->dateformatter->getDateFormat($line['D']);
         //Date of Birth
         $stuInfo->stu_admission_date = Yii::$app->dateformatter->getDateFormat($line['H']);
         //Student Admission Date
         $stuInfo->stu_gender = $this->valueReplace($line['I'], $stuInfo->getGenderOptions());
         // Gender
         $stuInfo->stu_email_id = $line['J'];
         // Email ID
         $stuInfo->stu_mobile_no = $line['K'];
         // Mobile No
         //set student master attribute
         $stuMaster->stu_master_course_id = $this->valueReplace($line['E'], Courses::getStuCourse());
         // Course
         $stuMaster->stu_master_batch_id = $this->valueReplace($line['F'], Batches::getStuBatches());
         // Batch
         $stuMaster->stu_master_section_id = $this->valueReplace($line['G'], Section::getStuSection());
         // Section
         $stuMaster->stu_master_category_id = $this->valueReplace($line['L'], StuCategory::getStuCategoryId());
         //Admission Category
         $stuMaster->stu_master_nationality_id = $this->valueReplace($line['M'], Nationality::getNationality());
         //Nationality
         //set student address attribute
         $stuAddress->stu_cadd = $line['N'];
         //Current Address
         $stuAddress->stu_cadd_city = $this->valueReplace($line['O'], City::getAllCity());
         //City
         $stuAddress->stu_cadd_state = $this->valueReplace($line['P'], State::getAllState());
         //State
         $stuAddress->stu_cadd_country = $this->valueReplace($line['Q'], Country::getAllCountry());
         //Country
         $stuAddress->stu_cadd_pincode = $line['R'];
         //Pincode
         $stuAddress->stu_cadd_house_no = $line['S'];
         //House No
         $stuAddress->stu_cadd_phone_no = $line['T'];
         //Phone No
         //set user login info attributes
         $uniq_id = $stuInfo->getUniqueId();
         $login_id = \app\models\Organization::find()->one()->org_stu_prefix . $uniq_id;
         $user->user_login_id = $login_id;
         //user login id
         $user->user_password = md5($user->user_login_id . $user->user_login_id);
         //user password
         $user->user_type = "S";
         //user type
         $user->created_by = Yii::$app->getid->getId();
         //created by
         $user->created_at = new \yii\db\Expression('NOW()');
         //created at
         if ($user->validate() && $stuInfo->validate() && $stuAddress->validate()) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($stuInfo->save() && $user->save() && $stuAddress->save()) {
                     $stuMaster->stu_master_stu_info_id = $stuInfo->stu_info_id;
                     $stuMaster->stu_master_user_id = $user->user_id;
                     $stuMaster->stu_master_stu_address_id = $stuAddress->stu_address_id;
                     $stuMaster->created_by = Yii::$app->getid->getId();
                     $stuMaster->created_at = new \yii\db\Expression('NOW()');
                     if ($stuMaster->save()) {
                         $stuInfo->stu_info_stu_master_id = $stuMaster->stu_master_id;
                         if ($stuInfo->save(false)) {
                             $auth_assign->item_name = 'Student';
                             $auth_assign->user_id = $user->user_id;
                             $auth_assign->created_at = date_format(date_create(), 'U');
                             $auth_assign->save(false);
                             $transaction->commit();
                             $totalSuccess += 1;
                             $dispResults[] = array_merge($line, ['type' => 'S', 'stuMasterId' => $stuMaster->stu_master_id, 'message' => 'Success']);
                         }
                     } else {
                         $dispResults[] = array_merge($line, ['type' => 'E', 'message' => Html::errorSummary($stuMaster)]);
                     }
                 }
                 // end stuInfo, user, StuAddress
                 $transaction->rollback();
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 $dispResults[] = array_merge($line, ['type' => 'E', 'message' => $e->getMessage()]);
             }
         } else {
             $dispResults[] = array_merge($line, ['type' => 'E', 'message' => Html::errorSummary([$user, $stuInfo, $stuMaster, $stuAddress])]);
         }
         //end validated if
     }
     //end foreach
     return ['dispResults' => $dispResults, 'totalSuccess' => $totalSuccess];
 }
示例#11
0
 /**
  * Creates a new StuMaster model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new StuMaster();
     $info = new StuInfo();
     $address = new StuAddress();
     $user = new User();
     $auth_assign = new AuthAssignment();
     if (Yii::$app->request->isAjax) {
         if ($info->load(Yii::$app->request->post())) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($info);
         }
         if ($model->load(Yii::$app->request->post())) {
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     $stud_uniq_no = \app\modules\student\models\StuInfo::find()->max('stu_unique_id');
     $uniq_id = NULL;
     if (empty($stud_uniq_no)) {
         $uniq_id = $info->stu_unique_id = 1;
     } else {
         $chk_id = StuInfo::find()->where(['stu_unique_id' => $stud_uniq_no])->exists();
         if ($chk_id) {
             $uniq_id = $stud_uniq_no + 1;
         } else {
             $uniq_id = $stud_uniq_no;
         }
     }
     if ($model->load(Yii::$app->request->post()) || $info->load(Yii::$app->request->post())) {
         $login_id = \app\models\Organization::find()->one()->org_stu_prefix . $uniq_id;
         $model->attributes = $_POST['StuMaster'];
         $info->attributes = $_POST['StuInfo'];
         $info->stu_dob = Yii::$app->dateformatter->getDateFormat($_POST['StuInfo']['stu_dob']);
         $info->stu_admission_date = Yii::$app->dateformatter->getDateFormat($_POST['StuInfo']['stu_admission_date']);
         if (empty($_POST['StuInfo']['stu_email_id'])) {
             $info->stu_email_id = NULL;
         } else {
             $info->stu_email_id = strtolower($_POST['StuInfo']['stu_email_id']);
         }
         $user->user_login_id = $login_id;
         $user->user_password = md5($user->user_login_id . $user->user_login_id);
         $user->user_type = "S";
         $user->created_by = Yii::$app->getid->getId();
         $user->created_at = new \yii\db\Expression('NOW()');
         if ($info->save(false)) {
             $user->save(false);
             $address->save(false);
         }
         $model->stu_master_stu_address_id = $address->stu_address_id;
         $model->stu_master_stu_info_id = $info->stu_info_id;
         $model->stu_master_user_id = $user->user_id;
         $model->created_by = Yii::$app->getid->getId();
         $model->created_at = new \yii\db\Expression('NOW()');
         $model->save(false);
         $s_info = StuInfo::findOne($model->stu_master_stu_info_id);
         $s_info->stu_info_stu_master_id = $model->stu_master_id;
         $s_info->save(false);
         $auth_assign->item_name = 'Student';
         $auth_assign->user_id = $user->user_id;
         $auth_assign->created_at = date_format(date_create(), 'U');
         $auth_assign->save(false);
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->stu_master_id]);
         } else {
             return $this->render('create', ['model' => $model, 'info' => $info, 'uniq_id' => $uniq_id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'info' => $info, 'uniq_id' => $uniq_id]);
     }
 }
示例#12
0
 /**
  * Retorna permissões cadastradas
  * @return null|string
  */
 public function getPermissoes()
 {
     if (is_null($this->cachePermissoes)) {
         $obj = AuthAssignment::find()->where(['user_id' => $this->id])->all();
         if (!is_null($obj)) {
             if (count($obj) > 0) {
                 $authitem = new AuthItem();
                 $this->cachePermissoes = $obj;
                 $aux = array();
                 foreach ($obj as $p) {
                     array_push($aux, $authitem->getDescriptionByName($p->item_name)->description);
                 }
                 return join(', ', $aux);
             } else {
                 return "Não há permissões cadastradas";
             }
         } else {
             return null;
         }
     } else {
         return $this->cachePermissoes;
     }
 }
示例#13
0
 public function sendMailToAdmin($news, $subject)
 {
     $roles = \app\models\AuthAssignment::find()->where(['item_name' => 'admin'])->with('user')->all();
     if (!empty($roles)) {
         foreach ($roles as $role) {
             $emails[] = $role->user->email;
         }
         $body = sprintf('%s <br />
             Ссылка на новость - %s', $subject['admin'], $this->urlToNews($news->id));
         $this->sendMail($emails, $subject['admin'], $body);
     }
 }
示例#14
0
 public function getRole($id)
 {
     $data = AuthAssignment::findOne(['user_id' => $id]);
     return $data->item_name;
 }