Пример #1
0
 public static function loadFixtures(TBGScope $scope)
 {
     $scope_id = $scope->getID();
     $admin_group = new TBGGroup();
     $admin_group->setName('Administrators');
     $admin_group->setScope($scope);
     $admin_group->save();
     TBGSettings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id);
     $user_group = new TBGGroup();
     $user_group->setName('Regular users');
     $user_group->setScope($scope);
     $user_group->save();
     TBGSettings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id);
     $guest_group = new TBGGroup();
     $guest_group->setName('Guests');
     $guest_group->setScope($scope);
     $guest_group->save();
     // Set up initial users, and their permissions
     if ($scope->isDefault()) {
         list($guestuser_id, $adminuser_id) = TBGUser::loadFixtures($scope, $admin_group, $user_group, $guest_group);
         TBGUserScopesTable::getTable()->addUserToScope($guestuser_id, $scope->getID(), $guest_group->getID(), true);
         TBGUserScopesTable::getTable()->addUserToScope($adminuser_id, $scope->getID(), $admin_group->getID(), true);
     } else {
         $default_scope_id = TBGSettings::getDefaultScopeID();
         $default_user_id = (int) TBGSettings::get(TBGSettings::SETTING_DEFAULT_USER_ID, 'core', $default_scope_id);
         TBGUserScopesTable::getTable()->addUserToScope($default_user_id, $scope->getID(), $user_group->getID(), true);
         TBGUserScopesTable::getTable()->addUserToScope(1, $scope->getID(), $admin_group->getID());
         TBGSettings::saveSetting(TBGSettings::SETTING_DEFAULT_USER_ID, $default_user_id, 'core', $scope->getID());
     }
     TBGPermissionsTable::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID());
 }
Пример #2
0
 public static function loadFixtures(TBGScope $scope)
 {
     $scope_id = $scope->getID();
     $admin_group = new TBGGroup();
     $admin_group->setName('Administrators');
     $admin_group->setScope($scope);
     $admin_group->save();
     TBGSettings::saveSetting('admingroup', $admin_group->getID(), 'core', $scope_id);
     $user_group = new TBGGroup();
     $user_group->setName('Regular users');
     $user_group->setScope($scope);
     $user_group->save();
     TBGSettings::saveSetting('defaultgroup', $user_group->getID(), 'core', $scope_id);
     $guest_group = new TBGGroup();
     $guest_group->setName('Guests');
     $guest_group->setScope($scope);
     $guest_group->save();
     // Set up initial users, and their permissions
     TBGUser::loadFixtures($scope, $admin_group, $user_group, $guest_group);
     TBGPermissionsTable::getTable()->loadFixtures($scope, $admin_group->getID(), $guest_group->getID());
 }
Пример #3
0
 public function runAddGroup(TBGRequest $request)
 {
     try {
         $mode = $request->getParameter('mode');
         if ($group_name = $request->getParameter('group_name')) {
             if ($mode == 'clone') {
                 try {
                     $old_group = TBGContext::factory()->TBGGroup($request->getParameter('group_id'));
                 } catch (Exception $e) {
                 }
                 if (!$old_group instanceof TBGGroup) {
                     throw new Exception(TBGContext::getI18n()->__("You cannot clone this group"));
                 }
             }
             if (TBGGroup::doesGroupNameExist(trim($group_name))) {
                 throw new Exception(TBGContext::getI18n()->__("Please enter a group name that doesn't already exist"));
             }
             $group = new TBGGroup();
             $group->setName($group_name);
             $group->save();
             if ($mode == 'clone') {
                 if ($request->getParameter('clone_permissions')) {
                     TBGPermissionsTable::getTable()->cloneGroupPermissions($old_group->getID(), $group->getID());
                 }
                 $message = TBGContext::getI18n()->__('The group was cloned');
             } else {
                 $message = TBGContext::getI18n()->__('The group was added');
             }
             return $this->renderJSON(array('failed' => false, 'message' => $message, 'content' => $this->getTemplateHTML('configuration/groupbox', array('group' => $group))));
         } else {
             throw new Exception(TBGContext::getI18n()->__('Please enter a group name'));
         }
     } catch (Exception $e) {
         $this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }