Example #1
0
 /**
  * Displays the assignments for the user with the given id.
  * @param string $id the user id.
  */
 public function actionView($id)
 {
     $formModel = new AddAuthItemForm();
     /* @var $am CAuthManager|AuthBehavior */
     $am = Yii::app()->getAuthManager();
     if (isset($_POST['AddAuthItemForm'])) {
         $formModel->attributes = $_POST['AddAuthItemForm'];
         if ($formModel->validate()) {
             if (!$am->isAssigned($formModel->items, $id)) {
                 $am->assign($formModel->items, $id);
                 if ($am instanceof CPhpAuthManager) {
                     $am->save();
                 }
                 if ($am instanceof ICachedAuthManager) {
                     $am->flushAccess($formModel->items, $id);
                 }
             }
         }
     }
     $model = CActiveRecord::model($this->module->userClass)->findByPk($id);
     $assignments = $am->getAuthAssignments($id);
     $authItems = $am->getItemsPermissions(array_keys($assignments));
     $authItemDp = new AuthItemDataProvider();
     $authItemDp->setAuthItems($authItems);
     $assignmentOptions = $this->getAssignmentOptions($id);
     if (!empty($assignmentOptions)) {
         $assignmentOptions = array_merge(array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $assignmentOptions);
     }
     $this->render('view', array('model' => $model, 'authItemDp' => $authItemDp, 'formModel' => $formModel, 'assignmentOptions' => $assignmentOptions));
 }
Example #2
0
 /**
  * Displays the item with the given name.
  * @param string $name name of the item.
  */
 public function actionView($name)
 {
     Yii::app()->user->checkAccess('comment.*', Yii::app()->user->id);
     $formModel = new AddAuthItemForm();
     /* @var $am CAuthManager|AuthBehavior */
     $am = Yii::app()->getAuthManager();
     if (isset($_POST['AddAuthItemForm'])) {
         $formModel->attributes = $_POST['AddAuthItemForm'];
         if ($formModel->validate()) {
             if (!$am->hasItemChild($name, $formModel->items)) {
                 $am->addItemChild($name, $formModel->items);
                 if ($am instanceof CPhpAuthManager) {
                     $am->save();
                 }
             }
         }
     }
     $item = $am->getAuthItem($name);
     $dpConfig = array('pagination' => false, 'sort' => array('defaultOrder' => 'depth asc'));
     $ancestors = $am->getAncestors($name);
     $ancestorDp = new PermissionDataProvider(array_values($ancestors), $dpConfig);
     $descendants = $am->getDescendants($name);
     $descendantDp = new PermissionDataProvider(array_values($descendants), $dpConfig);
     $childOptions = $this->getItemChildOptions($item->name);
     if (!empty($childOptions)) {
         $childOptions = array_merge(array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $childOptions);
     }
     $this->render('view', array('item' => $item, 'ancestorDp' => $ancestorDp, 'descendantDp' => $descendantDp, 'formModel' => $formModel, 'childOptions' => $childOptions));
 }
Example #3
0
 /**
  * Displays the item with the given name.
  * @param string $name name of the item.
  */
 public function actionView($name)
 {
     $formModel = new AddAuthItemForm();
     /* @var $am CAuthManager|AuthBehavior */
     $am = Yii::app()->getAuthManager();
     $item = $am->getAuthItem($name);
     $childOptions = $this->getItemChildOptions($item->name);
     if (isset($_POST['AddAuthItemForm'])) {
         $formModel->attributes = $_POST['AddAuthItemForm'];
         if ($formModel->validate()) {
             $descendants = $am->getDescendants($name);
             foreach ($descendants as $childName => $_) {
                 $am->removeItemChild($name, $childName);
             }
             $this->addItemChild($name, $formModel->items);
             $this->redirect(array('view', 'name' => $name));
         }
     }
     $dpConfig = array('pagination' => false, 'sort' => array('defaultOrder' => 'depth asc'));
     $ancestors = $am->getAncestors($name);
     $ancestorDp = new PermissionDataProvider(array_values($ancestors), $dpConfig);
     $descendants = $am->getDescendants($name);
     $descendantDp = new PermissionDataProvider(array_values($descendants), $dpConfig);
     if (!empty($childOptions)) {
         $childOptions = array_merge(array('' => Yii::t('AuthModule.main', 'Select item') . ' ...'), $childOptions);
     }
     $this->render('view', array('item' => $item, 'ancestorDp' => $ancestorDp, 'descendantDp' => $descendantDp, 'formModel' => $formModel, 'childOptions' => $childOptions, 'descendantsTree' => $this->getDescendantsTree($descendants), 'ancestorsTree' => $this->getAncestorsTree($ancestors)));
 }