示例#1
0
 public function __construct(Curry_Backend_Page $backend, PageRevision $pageRevision, $langcode = "")
 {
     $this->pageRevision = $pageRevision;
     $this->langcode = $langcode;
     parent::__construct('PageModule', array('title' => 'Content', 'maxPerPage' => 0, 'columns' => array('name' => array('sortable' => false, 'action' => 'edit', 'callback' => function ($wrapper) {
         return $wrapper->getName();
     }), 'target' => array('sortable' => false, 'callback' => function ($wrapper) {
         return $wrapper->getTarget();
     }), 'type' => array('sortable' => false, 'escape' => false, 'callback' => function ($wrapper) {
         return Html::tag('span', array('title' => $wrapper->getClassName()), basename(str_replace('_', '/', $wrapper->getClassName())));
     })), 'addDefaultActions' => false, 'actions' => array('edit' => array('single' => true, 'class' => 'inline', 'action' => array($this, 'showEdit'))), 'sortable' => array($this, 'sortItems')));
     $user = User::getUser();
     $this->pagePermission = $backend->getPagePermission($pageRevision->getPage());
     if ($user->hasAccess('Curry_Backend_Template')) {
         $this->addColumn('template', array('sortable' => false, 'escape' => false, 'callback' => function ($wrapper) {
             if (!$wrapper->getTemplate()) {
                 return 'None';
             }
             $templateUrl = url('', array('module' => 'Curry_Backend_Template', 'view' => 'Edit', 'file' => $wrapper->getTemplate()));
             return Html::tag('a', array('href' => $templateUrl, 'title' => $wrapper->getTemplate()), basename($wrapper->getTemplate()));
         }));
     }
     if ($this->pagePermission[PageAccessPeer::PERM_MODULES]) {
         $this->addColumn('info', array('sortable' => false, 'escape' => false, 'callback' => array($this, 'getInfo'), 'order' => 1));
         $this->addAction('properties', array('single' => true, 'class' => 'dialog', 'action' => array($this, 'showProperties')));
         $this->addAction('inheritance', array('label' => 'Inheritance details', 'general' => true, 'class' => 'dialog', 'action' => array($this, 'showInheritance')));
     }
     if ($this->pagePermission[PageAccessPeer::PERM_CREATE_MODULE]) {
         $this->addAction('new', array('general' => true, 'label' => 'New content', 'class' => 'dialog', 'href' => (string) url('', array('module' => 'Curry_Backend_Page', 'page_id' => $this->pageRevision->getPageId(), 'view' => 'NewModule'))));
         $this->addAction('delete', array('single' => true, 'class' => 'inline modelview-delete', 'action' => array($this, 'showDelete')));
     }
 }
示例#2
0
 /**
  * Get page permission table row.
  *
  * @param Page $page
  * @param string $name
  * @param User|null $user
  * @param UserRole|null $role
  * @return string
  */
 protected static function getPagePermissionRow(Page $page, $name, User $user = null, UserRole $role = null)
 {
     $inheritPermission = $page->getPageAccess($user, $role ? $role : ($user ? $user->getUserRole() : null));
     $userPermission = Curry_Backend_Page::getPagePermission($page);
     $access = PageAccessQuery::create()->filterByPage($page)->filterByUserAndRole($user, $role)->findOne();
     $row = '';
     foreach (PageAccess::getPermissionTypes() as $colName => $phpName) {
         $fieldName = $name . '[' . $colName . ']';
         $val = $access ? $access->{'get' . $phpName}() : null;
         if ($colName == PageAccessPeer::PERM_SUBPAGES) {
             if ($val === null) {
                 $val = $inheritPermission[$colName];
             }
             $row .= '<td><input type="hidden" name="' . $fieldName . '" value="no" /><input type="checkbox" name="' . $fieldName . '" value="yes" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . ($val ? 'checked="checked" ' : '') . '/></td>';
             continue;
         }
         $options = array('' => '(inherited)', 'yes' => 'Yes', 'no' => 'No');
         if ($val === null) {
             $options[''] = ($inheritPermission[$colName] ? 'Yes ' : 'No ') . $options[''];
         }
         $val = $val === null ? '' : ($val ? 'yes' : 'no');
         $selectedColor = 'black';
         $opts = '';
         foreach ($options as $optionValue => $optionLabel) {
             $attr = array('value' => $optionValue);
             $color = $optionValue ? $optionValue == 'yes' ? 'green' : 'red' : '#aaa';
             $attr['style'] = 'color:' . $color;
             if ($optionValue === $val) {
                 $selectedColor = $color;
                 $attr['selected'] = 'selected';
             }
             $opts .= Html::tag('option', $attr, $optionLabel);
         }
         $row .= '<td><select name="' . $fieldName . '" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . 'style="color:' . $selectedColor . '" onchange="this.style.color = this.options[this.selectedIndex].style.color">';
         $row .= $opts;
         $row .= '</select></td>';
     }
     return $row;
 }