Example #1
0
 /**
  * Initialize form.
  *
  * @return void
  */
 public function initialize()
 {
     $this->setDescription('This menu item will be available under menu or parent menu item.');
     $content = $this->addContentFieldSet()->addText('title')->addSelect('target', 'Target', 'Link type', [null => 'Default link', MenuItem::ITEM_TARGET_BLANK => 'Opens the linked document in a new window or tab', MenuItem::ITEM_TARGET_PARENT => 'Opens the linked document in the parent frame', MenuItem::ITEM_TARGET_TOP => 'Opens the linked document in the full body of the window'])->addRadio('url_type', 'Select url type', null, [0 => 'Url', 1 => 'System page'])->addText('url', 'Url', 'Do not type url with starting slash... Example: "somepage/url/to?param=1"')->addText('page', 'Page', 'Start typing to see pages variants.', null, [], ['data-link' => $this->getDI()->getUrl()->get('admin/pages/suggest'), 'data-target' => '#page_id', 'data-widget' => 'autocomplete', 'autocomplete' => 'off'])->addTextArea('onclick', 'OnClick', 'Type JS action that will be performed when this menu item is selected.')->addCkEditor('tooltip')->addSelect('tooltip_position', 'Tooltip position', null, [MenuItem::ITEM_TOOLTIP_POSITION_TOP => 'Top', MenuItem::ITEM_TOOLTIP_POSITION_BOTTOM => 'Bottom', MenuItem::ITEM_TOOLTIP_POSITION_LEFT => 'Left', MenuItem::ITEM_TOOLTIP_POSITION_RIGHT => 'Right'])->addRemoteFile('icon', 'Select icon')->addSelect('icon_position', 'Icon position', null, [MenuItem::ITEM_ICON_POSITION_LEFT => 'Left', MenuItem::ITEM_ICON_POSITION_RIGHT => 'Right'])->addMultiSelect('languages', 'Languages', 'Choose the language in which the menu item will be displayed.
                 If no one selected - will be displayed at all.', Language::find(), null, ['using' => ['language', 'name']])->addMultiSelect('roles', 'Roles', 'If no value is selected, will be allowed to all (also as all selected).', Role::find(), null, ['using' => ['id', 'name']])->addCheckbox('is_enabled', 'Is enabled', null, 1, true, false)->addHidden('page_id')->addHidden('menu_id')->addHidden('parent_id');
     $this->_setValidation($content);
 }
Example #2
0
 /**
  * Add elements to form.
  *
  * @return void
  */
 public function initialize()
 {
     $this->setTitle('User Creation')->setDescription('Create new user.')->setAttribute('autocomplete', 'off');
     $content = $this->addContentFieldSet()->addText('username', null, null, null, [], ['autocomplete' => 'off'])->addPassword('password', null, null, [], ['autocomplete' => 'off'])->addText('email', null, null, null, [], ['autocomplete' => 'off'])->addSelect('role_id', 'Role', 'Select user role', Role::find(), null, ['using' => ['id', 'name']]);
     $this->addFooterFieldSet()->addButton('create')->addButtonLink('cancel', 'Cancel', ['for' => 'admin-users']);
     $this->_setValidation($content);
 }
Example #3
0
 /**
  * Initialize form.
  *
  * @return void
  */
 public function initialize()
 {
     $this->setTitle('Page Creation')->setDescription('Create new page.');
     $content = $this->addContentFieldSet()->addText('title')->addText('url', 'Url', 'Page will be available under http://' . $_SERVER['HTTP_HOST'] . '/page/[URL NAME]')->addTextArea('description')->addTextArea('keywords')->addTextArea('controller', 'Controller', 'Controller and action name that will handle this page. Example: NameController->someAction', null, ['emptyAllowed' => true, 'escape' => false])->addMultiSelect('roles', 'Roles', 'If no value is selected, will be allowed to all (also as all selected).', Role::find(), null, ['using' => ['id', 'name']]);
     $this->addFooterFieldSet()->addButton('create')->addButtonLink('cancel', 'Cancel', ['for' => 'admin-pages']);
     $this->_setValidation($content);
 }
Example #4
0
 /**
  * Initialize grid columns.
  *
  * @return array
  */
 protected function _initColumns()
 {
     $this->addTextColumn('u.id', 'ID', [self::COLUMN_PARAM_TYPE => Column::BIND_PARAM_INT, self::COLUMN_PARAM_OUTPUT_LOGIC => function (GridItem $item, $di) {
         $url = $di->get('url')->get(['for' => 'admin-users-view', 'id' => $item['u.id']]);
         return sprintf('<a href="%s">%s</a>', $url, $item['u.id']);
     }])->addTextColumn('u.username', 'Username')->addTextColumn('u.email', 'Email')->addSelectColumn('r.name', 'Role', ['hasEmptyValue' => true, 'using' => ['name', 'name'], 'elementOptions' => Role::find()], [self::COLUMN_PARAM_USE_HAVING => false, self::COLUMN_PARAM_USE_LIKE => false, self::COLUMN_PARAM_OUTPUT_LOGIC => function (GridItem $item) {
         return $item['name'];
     }])->addTextColumn('u.creation_date', 'Creation Date');
 }
Example #5
0
 /**
  * Edit access.
  *
  * @param int $id Identity.
  *
  * @return ResponseInterface|mixed|void
  *
  * @Route("/edit/{id:[a-zA-Z_-]+}", methods={"GET", "POST"}, name="admin-access-edit")
  */
 public function editAction($id)
 {
     // Normalize id.
     $urlId = $id;
     $id = str_replace('_', '\\', $id);
     // Check current role change request.
     $changeRole = $this->request->get('role');
     if ($changeRole !== null) {
         $this->session->set('admin-current-role', $changeRole);
         return $this->response->redirect(['for' => 'admin-access-edit', 'id' => $urlId]);
     }
     $resources = $this->core->acl()->getResources();
     $resourceFound = false;
     foreach ($resources as $resource) {
         if ($resource->getName() == $id) {
             $resourceFound = true;
             break;
         }
     }
     if (!$resourceFound) {
         return $this->response->redirect(['for' => 'admin-access']);
     }
     // get all roles and current
     $roles = Role::find();
     $currentRole = $this->session->get('admin-current-role');
     $currentRole = Role::findFirst($currentRole);
     if (!$currentRole) {
         $currentRole = Role::getRoleByType(Acl::DEFAULT_ROLE_ADMIN);
     }
     $objectAcl = $this->core->acl()->getObject($id);
     $form = $this->_getForm($objectAcl, $currentRole);
     $this->view->currentObject = $id;
     $this->view->form = $form;
     $this->view->roles = $roles;
     $this->view->currentRole = $currentRole;
     if (!$this->request->isPost() || !$form->isValid()) {
         return;
     }
     $data = $form->getValues();
     // save actions
     foreach ($objectAcl->actions as $action) {
         $result = Access::findFirst(["conditions" => "object = ?1 AND action = ?2 AND role_id = ?3", "bind" => [1 => $id, 2 => $action, 3 => $currentRole->id]]);
         if (!$result) {
             $result = new Access();
             $result->object = $id;
             $result->action = $action;
             $result->role_id = $currentRole->id;
         }
         if (empty($data[$action])) {
             $result->value = 'deny';
         } else {
             $result->value = 'allow';
         }
         $result->save();
     }
     //save options
     foreach ($objectAcl->options as $options) {
         $result = Access::findFirst(["conditions" => "object = ?1 AND action = ?2 AND role_id = ?3", "bind" => [1 => $id, 2 => $options, 3 => $currentRole->id]]);
         if (!$result) {
             $result = new Access();
             $result->object = $id;
             $result->action = $options;
             $result->role_id = $currentRole->id;
         }
         if (empty($data[$options])) {
             $data[$options] = null;
         }
         $result->value = $data[$options];
         $result->save();
     }
     $this->core->acl()->clearAcl();
     $this->flash->success('Settings saved!');
 }
Example #6
0
 /**
  * Widget options.
  *
  * @return void
  *
  * @Route("/widget-options", methods={"GET", "POST"}, name="admin-pages-widget-options")
  */
 public function widgetOptionsAction()
 {
     $widgetIndex = $this->request->get('widget_index', 'int', -1);
     if ($widgetIndex != '0' && intval($widgetIndex) == 0) {
         $widgetIndex = -1;
     }
     $currentPageWidgets = $this->session->get('admin-pages-manage', []);
     if ($widgetIndex == -1) {
         $widgetIndex = $this->session->get('admin-pages-widget-index');
         $currentPageWidgets[$widgetIndex] = ['widget_index' => $widgetIndex, 'id' => 0, 'layout' => $this->request->get('layout', 'string', 'middle'), 'widget_id' => $this->request->get('widget_id', 'int'), 'params' => []];
     }
     if (empty($currentPageWidgets[$widgetIndex])) {
         return;
     }
     $widgetData = $currentPageWidgets[$widgetIndex];
     $id = $widgetData['id'];
     $widgetParams = $widgetData['params'];
     $widgetParams['content_id'] = $id;
     $widget_id = $widgetData['widget_id'];
     $widgetMetadata = Widget::findFirstById($widget_id);
     $form = new CoreForm();
     // building widget form
     $adminForm = $widgetMetadata->admin_form;
     if (empty($adminForm)) {
         $form->addText('title');
     } elseif ($adminForm == 'action') {
         $widgetName = $widgetMetadata->name;
         if ($widgetMetadata->module !== null) {
             $widgetClass = '\\' . ucfirst($widgetMetadata->module) . '\\Widget\\' . $widgetName . '\\Controller';
         } else {
             $widgetClass = '\\Widget\\' . $widgetName . '\\Controller';
         }
         $widgetController = new $widgetClass();
         $widgetController->setDefaults($widgetName, ucfirst($widgetMetadata->module), $widgetParams);
         $widgetController->prepare();
         $form = $widgetController->adminAction();
     } else {
         $form = new $adminForm();
     }
     if ($widgetMetadata->is_paginated == 1) {
         $form->addText('count', 'Items count', null, 10);
         $form->setOrder('count', 1000);
     }
     if ($widgetMetadata->is_acl_controlled == 1) {
         $form->addMultiSelect('roles', 'Roles', null, Role::find(), null, ['using' => ['id', 'name']]);
         $form->setOrder('roles[]', 1001);
     }
     // set form values
     if (!empty($widgetParams)) {
         $form->setValues($widgetParams);
     }
     if (!$this->request->isPost() || !$form->isValid()) {
         $this->view->form = $form;
         $this->view->id = $id;
         $this->view->name = $widgetMetadata->name;
         return;
     }
     $currentPageWidgets[$widgetIndex]['params'] = $form->getValues();
     $this->resolveModal(['hide' => true, 'customJs' => 'setEditedWidgetIndex(' . $widgetIndex . ');']);
     $this->session->set('admin-pages-manage', $currentPageWidgets);
     $this->session->set('admin-pages-widget-index', ++$widgetIndex);
 }