/** * 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; }