Esempio n. 1
0
 public function actionRights()
 {
     $Users = User::model()->findAllByAttributes(['company_id' => Yii::app()->getUser()->getProfile()->company_id]);
     if (isset($_POST['save'])) {
         foreach ($Users as $User) {
             UserRights::model()->deleteAllByAttributes(['user_id' => $User->id]);
         }
         if (!empty($_POST['rights'])) {
             foreach ($_POST['rights'] as $userId => $rights) {
                 $User = User::model()->findByPK($userId);
                 if ($User->company_id != Yii::app()->getUser()->getProfile()->company_id) {
                     break;
                 }
                 //TODO переработать обновление
                 foreach ($rights as $right => $status) {
                     $UserRights = new UserRights();
                     $UserRights->user_id = $User->id;
                     $UserRights->right = $right;
                     $UserRights->save();
                 }
             }
         }
     }
     $this->render('rights', ['Users' => $Users]);
 }