コード例 #1
0
 /**
  *
  * @param type $resource_id
  * @param type $role_id
  * @param type $values
  */
 public function set($resource_id, $role_id, $values)
 {
     $model = $this->find('`role_id`=:role_id AND `resource_id`=:resource_id', array(':role_id' => $role_id, ':resource_id' => $resource_id));
     if ($model === NULL) {
         $model = new UserRolesOnResources();
         $model->resource_id = $resource_id;
         $model->role_id = $role_id;
     }
     foreach ($values as $key => $val) {
         $model->{$key} = (int) $val;
     }
     if ($model->save()) {
         return TRUE;
     }
     return FALSE;
 }
コード例 #2
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     Acl::hasPrivilege($this->privileges, $this->resource, Acl::ACTION_VIEW);
     $model = UserRoles::model()->loadModel($id);
     $this->pageTitle = $model->name;
     $this->showPageTitle = TRUE;
     $this->pageDescription = $model->description;
     $forbidden_resources = Acl::getForbiddenResources(UserLevels::LEVEL_ENGINEER);
     $resources = UserResources::model()->getResources($forbidden_resources);
     if (isset($_POST['RolesOnResources'])) {
         $roles_on_resources = $_POST['RolesOnResources'];
         foreach ($roles_on_resources as $key => $rr) {
             UserRolesOnResources::model()->set($key, $id, $rr);
         }
         Yii::app()->user->setFlash('success', Lang::t('SUCCESS_MESSAGE'));
         $this->refresh();
     }
     $this->render('view', array('model' => $model, 'resources' => $resources));
 }
コード例 #3
0
ファイル: Acl.php プロジェクト: wanyos2005/hsbf
 /**
  * Gets system-wide privileges of a user;
  * @param type $user_id
  */
 public static function getPrivileges($user_id = NULL)
 {
     /*
      * 1. get all the resources
      * 2. get user_type & role
      * 3. for each resources check whether it is forbidden
      * 4.If user type =system_engineer or super_admin return true
      * 5.Check if the role has privilege
      */
     if (empty($user_id)) {
         $user_id = Yii::app()->user->id;
     }
     //get all resources
     $resources = UserResources::model()->getResources();
     $user_model = Users::model()->loadModel($user_id);
     $forbidden_resources = self::getForbiddenResources($user_model->user_level);
     $role_on_resources = UserRolesOnResources::model()->getData('*', '`role_id`=:t1', array(':t1' => $user_model->role_id));
     return self::check($resources, $user_model, $forbidden_resources, $role_on_resources);
 }
コード例 #4
0
ファイル: view.php プロジェクト: wanyos2005/hsbf
N/A<?php 
    }
    ?>
</td><td><?php 
    if (UserResources::model()->get($r['id'], 'updateable') == 1) {
        echo CHtml::hiddenField('RolesOnResources[' . $r['id'] . '][update]', 0);
        echo CHtml::checkBox('RolesOnResources[' . $r['id'] . '][update]', UserRolesOnResources::model()->getValue($r['id'], $model->id, 'update'), array('class' => 'my-roles-checkbox'));
    } else {
        ?>
N/A<?php 
    }
    ?>
</td><td><?php 
    if (UserResources::model()->get($r['id'], 'deleteable') == 1) {
        echo CHtml::hiddenField('RolesOnResources[' . $r['id'] . '][delete]', 0);
        echo CHtml::checkBox('RolesOnResources[' . $r['id'] . '][delete]', UserRolesOnResources::model()->getValue($r['id'], $model->id, 'delete'), array('class' => 'my-roles-checkbox'));
    } else {
        ?>
N/A<?php 
    }
    ?>
</td></tr>
                                        <?php 
}
?>
                                </tbody>
                        </table>
                </div>
                <?php 
echo CHtml::endForm();
?>