Exemplo n.º 1
0
 public function showRoles()
 {
     if (!$this->hasPermission(self::PERMISSION_ROLES)) {
         throw new Exception('You dont have permission to access this view.');
     }
     $this->addMenu();
     $user = User::getUser();
     $backendModules = Curry_Backend::getBackendList();
     $disable = array();
     $backend = array("*" => "All");
     if (!$user->hasAccess('*')) {
         $disable[] = '*';
     }
     foreach ($backendModules as $backendClass => $backendName) {
         $backend[$backendClass] = $backendName;
         $permissions = method_exists($backendClass, 'getPermissions') ? call_user_func(array($backendClass, 'getPermissions')) : array();
         foreach ($permissions as $permission) {
             $backend[$backendClass . "/" . $permission] = Curry_Core::SELECT_TREE_PREFIX . $permission;
             if (!$user->hasAccess($backendClass . "/" . $permission)) {
                 $disable[] = $backendClass . "/" . $permission;
             }
         }
         if (!$user->hasAccess($backendClass)) {
             $disable[] = $backendClass;
         }
     }
     $content = array();
     $contentAccess = array("*" => "All") + Curry_Module::getModuleList();
     $allContentAccess = $user->hasAccess('Curry_Backend_Content/*');
     foreach ($contentAccess as $k => $v) {
         $content['Curry_Backend_Content/' . $k] = $v;
         if (!$allContentAccess && !$user->hasAccess('Curry_Backend_Content/' . $k)) {
             $disable[] = 'Curry_Backend_Content/' . $k;
         }
     }
     $form = new Curry_ModelView_Form('UserRole', array('elements' => array('backend' => array('multiselect', array('label' => 'Backend access', 'multiOptions' => $backend, 'size' => 10, 'order' => 1, 'disable' => $disable, 'validators' => array(array('InArray', true, array(array_diff(array_keys($backend), $disable)))))), 'content' => array('multiselect', array('label' => 'Content access', 'multiOptions' => $content, 'size' => 10, 'order' => 2, 'disable' => $disable, 'validators' => array(array('InArray', true, array(array_diff(array_keys($content), $disable))))))), 'onFillForm' => function (UserRole $role, $form) {
         $access = UserRoleAccessQuery::create()->filterByUserRole($role)->select('Module')->find()->getArrayCopy();
         $form->backend->setValue($access);
         $form->content->setValue($access);
     }, 'onFillModel' => function (UserRole $role, $form, $values) {
         $access = array_merge((array) $values['backend'], (array) $values['content']);
         $collection = new PropelObjectCollection();
         $collection->setModel('UserRoleAccess');
         foreach ($access as $a) {
             $ura = new UserRoleAccess();
             $ura->setModule($a);
             $collection->append($ura);
         }
         $role->setUserRoleAccesss($collection);
     }));
     $q = UserRoleQuery::create();
     $list = new Curry_ModelView_List($q, array('modelForm' => $form));
     $list->addAction('file_permissions', array('action' => $this->getFileAccessList(), 'class' => 'inline', 'single' => true));
     $list->show($this);
 }
Exemplo n.º 2
0
 /**
  * Show revisions for page.
  *
  */
 public function showPageRevisions()
 {
     $page = self::getPage(PageAccessPeer::PERM_REVISIONS);
     $ses = new \Zend\Session\Container(__CLASS__);
     $ses->pageView = 'PageRevisions';
     $this->addPageMenu($page);
     $query = PageRevisionQuery::create()->filterByPage($page);
     $list = new Curry_ModelView_List($query, array('columns' => array('template' => false, 'description' => array('escape' => false, 'callback' => function ($pageRevision) {
         $page = $pageRevision->getPage();
         $icon = '';
         if ($page->getActivePageRevision() === $pageRevision) {
             $icon .= ' <i class="icon-bolt" title="Active revision" />';
         }
         if ($page->getWorkingPageRevision() === $pageRevision) {
             $icon .= ' <i class="icon-wrench" title="Working revision"></i>';
         }
         return htmlspecialchars($pageRevision->getDescription()) . $icon;
     })), 'actions' => array('edit' => false, 'new' => array('href' => (string) url('', array("module", "page_id" => $page->getPageId(), "view" => "CreateRevision"))), 'make_working' => array('label' => 'Switch to working', 'single' => true, 'class' => 'post', 'action' => function ($revision, $backend) use($page) {
         if (isPost()) {
             $page->setWorkingPageRevision($revision);
             $page->save();
             $backend->createModelUpdateEvent('Page', $page->getPrimaryKey(), 'update');
             $backend->createModelUpdateEvent('PageRevision', $revision->getPrimaryKey(), 'update');
         }
     }))));
     if (self::getPagePermission($page, PageAccessPeer::PERM_PUBLISH)) {
         $list->addAction('publish_date', array('label' => 'Set publish date', 'single' => true, 'class' => 'inline', 'href' => (string) url('', array('module', 'view' => 'SetPublishDate'))));
         $list->addAction('publish', array('single' => true, 'class' => 'post', 'action' => function ($revision, Curry_Backend_Page $backend) use($page) {
             if (isPost()) {
                 $backend->publishRevision($revision);
                 $backend->createModelUpdateEvent('Page', $page->getPrimaryKey(), 'update');
                 $backend->createModelUpdateEvent('PageRevision', $revision->getPrimaryKey(), 'update');
             }
         }));
     }
     $this->addMainContent($list);
 }