/**
  * Get form instance
  *
  * @return object
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // add extra options for the title
         $this->formElements['title']['description_params'] = [$this->widgetDescription];
         // add extra options for the cache ttl
         if ($this->showCacheSettings) {
             $this->formElements['cache_ttl']['description_params'] = [(int) SettingService::getSetting('application_dynamic_cache_life_time')];
             // add extra validators
             $this->formElements['cache_ttl']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateCacheTtl'], 'message' => 'Enter a correct value']]];
         } else {
             unset($this->formElements['cache_ttl']);
         }
         // add extra options for the visibility settings
         if ($this->showVisibilitySettings) {
             // add visibility settings
             $this->formElements['visibility_settings']['values'] = AclService::getAclRoles(false, true);
         } else {
             unset($this->formElements['visibility_settings']);
         }
         // fill the form with default values
         $this->formElements['layout']['values'] = $this->model->getWidgetLayouts();
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
Beispiel #2
0
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // fill the form with default values
         $this->formElements['role']['values'] = AclService::getAclRoles();
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // get list of all ACL roles
         $aclRoles = [];
         foreach (AclService::getAclRoles() as $roleId => $roleName) {
             // skip all system ACL roles
             if (in_array($roleId, [AclBaseModel::DEFAULT_ROLE_ADMIN, AclBaseModel::DEFAULT_ROLE_GUEST, AclBaseModel::DEFAULT_ROLE_MEMBER])) {
                 continue;
             }
             $aclRoles[$roleId] = $roleName;
         }
         // get list of acl roles
         $this->formElements['role']['values'] = $aclRoles;
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Edit the user's role
  */
 public function editRoleAction()
 {
     // get the user info
     if (null == ($user = $this->getModel()->getUserInfo($this->getSlug())) || $user['user_id'] == UserAdministrationModel::DEFAULT_USER_ID) {
         return $this->createHttpNotFoundModel($this->getResponse());
     }
     // get a role form
     $roleForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\UserRole');
     // fill the form with default values
     $roleForm->getForm()->setData($user);
     $request = $this->getRequest();
     // validate the form
     if ($request->isPost()) {
         // fill the form with received values
         $roleForm->getForm()->setData($request->getPost(), false);
         // save data
         if ($roleForm->getForm()->isValid()) {
             // check the permission and increase permission's actions track
             if (true !== ($result = $this->aclCheckPermission())) {
                 return $result;
             }
             // get the role name
             $roleName = AclService::getAclRoles()[$roleForm->getForm()->getData()['role']];
             if (true === ($result = $this->getModel()->editUserRole($user['user_id'], $roleForm->getForm()->getData()['role'], $roleName, (array) $user))) {
                 $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('User\'s role has been edited'));
             } else {
                 $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result));
             }
             return $this->redirectTo('users-administration', 'edit-role', ['slug' => $user['user_id']]);
         }
     }
     return new ViewModel(['csrf_token' => $this->applicationCsrf()->getToken(), 'role_form' => $roleForm->getForm(), 'user' => $user]);
 }
 /**
  * Get system pages map
  *
  * @param array $pagesIds
  * @param array $dependentPagesFilter
  * @param integer $order
  * @return array
  */
 protected function getDependentSystemPages(array $pagesIds, array $dependentPagesFilter = [], $order = 0)
 {
     // we need to get recursively all selected pages and their dependent pages
     $pages = [];
     // get selected system pages
     $select = $this->select();
     $select->from(['a' => 'page_system'])->columns(['id', 'slug', 'module', 'disable_user_menu', 'disable_menu', 'disable_site_map', 'disable_footer_menu', 'disable_xml_map', 'dynamic_page', 'forced_visibility'])->join(['d' => 'page_structure'], new Expression('a.slug = d.slug and d.language = ?', [$this->getCurrentLanguage()]), [], 'left')->join(['i' => 'application_module'], new Expression('i.id = a.module and i.status = ?', [self::MODULE_STATUS_ACTIVE]), [])->where->in('a.id', $pagesIds)->where->isNull('d.id');
     $statement = $this->prepareStatementForSqlObject($select);
     $resultSet = new ResultSet();
     $resultSet->initialize($statement->execute());
     // get home page
     $homePage = $this->serviceLocator->get('Config')['home_page'];
     // get default values
     $defaultPageLayout = $this->getPageLayout(SettingService::getSetting('page_new_pages_layout'));
     $defaultWidgetLayout = SettingService::getSetting('page_new_widgets_layout');
     $defaultShowInMainMenu = (int) SettingService::getSetting('page_new_pages_in_main_menu');
     $defaultShowInSiteMap = (int) SettingService::getSetting('page_new_pages_in_site_map');
     $defaultShowInFooterMenu = (int) SettingService::getSetting('page_new_pages_in_footer_menu');
     $defaultShowInUserMenu = (int) SettingService::getSetting('page_new_pages_in_user_menu');
     $defaultShowInXmlMap = (int) SettingService::getSetting('page_new_pages_in_xml_map');
     $defaultPageVisibility = SettingService::getSetting('page_new_pages_hidden_for');
     // check the roles
     if ($defaultPageVisibility) {
         // get all ACL roles
         $aclRoles = AclService::getAclRoles(false, true);
         // compare them with a setting value
         foreach ($defaultPageVisibility as $index => $roleId) {
             if (!array_key_exists($roleId, $aclRoles)) {
                 unset($defaultPageVisibility[$index]);
             }
         }
     }
     foreach ($resultSet as $page) {
         $dependentPagesFilter[] = $page->id;
         $pages[$page->id] = ['slug' => $page->slug, 'module' => $page->module, 'visibility_settings' => !$page->forced_visibility && $defaultPageVisibility ? $defaultPageVisibility : null, 'user_menu' => !$page->disable_user_menu && $defaultShowInUserMenu ? 1 : null, 'user_menu_order' => (int) SettingService::getSetting('page_new_pages_user_menu_order'), 'menu' => !$page->disable_menu && $defaultShowInMainMenu || $page->slug == $homePage ? 1 : null, 'site_map' => !$page->disable_site_map && $defaultShowInSiteMap || $page->slug == $homePage ? 1 : null, 'xml_map' => !$page->disable_xml_map && $defaultShowInXmlMap ? 1 : null, 'xml_map_update' => SettingService::getSetting('page_new_pages_xml_map_update'), 'xml_map_priority' => SettingService::getSetting('page_new_pages_xml_map_priority'), 'footer_menu' => !$page->disable_footer_menu && $defaultShowInFooterMenu ? 1 : null, 'footer_menu_order' => (int) SettingService::getSetting('page_new_pages_footer_menu_order'), 'layout' => !empty($defaultPageLayout['id']) ? $defaultPageLayout['id'] : null, 'layout_default_position' => !empty($defaultPageLayout['default_position']) ? $defaultPageLayout['default_position'] : null, 'widget_default_layout' => $defaultWidgetLayout ? $defaultWidgetLayout : null, 'order' => $order, 'system_page' => $page->id, 'dynamic_page' => $page->dynamic_page, 'active' => (int) SettingService::getSetting('page_new_pages_active') ? PageNestedSet::PAGE_STATUS_ACTIVE : null];
     }
     // check dependent pages
     if ($pages) {
         $select = $this->select();
         $select->from(['a' => 'page_system_page_depend'])->columns([])->join(['b' => 'page_system'], 'a.depend_page_id = b.id', ['id'])->join(['c' => 'page_structure'], new Expression('b.slug = c.slug and c.language = ?', [$this->getCurrentLanguage()]), [], 'left')->group('b.id')->where->in('a.page_id', array_keys($pages))->where->isNull('c.id');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $dependentPagesIds = [];
         foreach ($resultSet as $page) {
             if (in_array($page->id, $dependentPagesFilter)) {
                 continue;
             }
             $dependentPagesIds[] = $page->id;
         }
         // get dependent pages
         if ($dependentPagesIds) {
             $pages = $pages + $this->getDependentSystemPages($dependentPagesIds, $dependentPagesFilter, $order + 1);
         }
     }
     return $pages;
 }
Beispiel #6
0
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // set default values
         $this->formElements['active']['value'] = (int) SettingService::getSetting('page_new_pages_active');
         $this->formElements['layout']['value'] = (int) SettingService::getSetting('page_new_pages_layout');
         $this->formElements['menu']['value'] = (int) SettingService::getSetting('page_new_pages_in_main_menu');
         $this->formElements['site_map']['value'] = (int) SettingService::getSetting('page_new_pages_in_site_map');
         $this->formElements['footer_menu']['value'] = (int) SettingService::getSetting('page_new_pages_in_footer_menu');
         $this->formElements['footer_menu_order']['value'] = (int) SettingService::getSetting('page_new_pages_footer_menu_order');
         $this->formElements['user_menu']['value'] = (int) SettingService::getSetting('page_new_pages_in_user_menu');
         $this->formElements['user_menu_order']['value'] = (int) SettingService::getSetting('page_new_pages_user_menu_order');
         $this->formElements['xml_map']['value'] = (int) SettingService::getSetting('page_new_pages_in_xml_map');
         $this->formElements['xml_map_update']['value'] = SettingService::getSetting('page_new_pages_xml_map_update');
         $this->formElements['xml_map_priority']['value'] = (double) SettingService::getSetting('page_new_pages_xml_map_priority');
         $this->formElements['visibility_settings']['value'] = SettingService::getSetting('page_new_pages_hidden_for');
         if ($this->isSystemPage) {
             $this->formElements['title']['description'] = 'The page uses the system default title';
             $this->formElements['title']['required'] = false;
             // add descriptions params
             $this->formElements['title']['description_params'] = [$this->systemTitle];
             unset($this->formElements['slug']);
         }
         if (!$this->showMainMenu) {
             unset($this->formElements['menu']);
         }
         if (!$this->showSiteMap) {
             unset($this->formElements['site_map']);
         }
         if (!$this->showXmlMap) {
             unset($this->formElements['xml_map']);
             unset($this->formElements['xml_map_update']);
             unset($this->formElements['xml_map_priority']);
         }
         if (!$this->showFooterMenu) {
             unset($this->formElements['footer_menu']);
             unset($this->formElements['footer_menu_order']);
         }
         if (!$this->showUserMenu) {
             unset($this->formElements['user_menu']);
             unset($this->formElements['user_menu_order']);
         }
         if (!$this->showVisibilitySettings) {
             unset($this->formElements['visibility_settings']);
         }
         if (!$this->showSeo) {
             unset($this->formElements['meta_keywords']);
             unset($this->formElements['meta_description']);
         }
         if (!$this->isSystemPage) {
             // add extra validators
             $this->formElements['slug']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateSlug'], 'message' => 'Display name already used']]];
         }
         if ($this->pageInfo) {
             // add extra validators
             $this->formElements['custom_validate']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validatePage'], 'message' => 'You cannot move the page into self or into its child pages']]];
         }
         if ($this->showXmlMap) {
             $this->formElements['xml_map_priority']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateXmlMapPriority'], 'message' => 'Enter a correct priority value']]];
         }
         // fill the form with default values
         $this->formElements['layout']['values'] = $this->model->getPageLayouts();
         if ($this->showVisibilitySettings) {
             $this->formElements['visibility_settings']['values'] = AclService::getAclRoles(false, true);
         }
         if (null != ($pages = $this->getPages())) {
             $this->formElements['page']['values'] = $pages;
         } else {
             unset($this->formElements['page']);
             unset($this->formElements['page_direction']);
         }
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }
 /**
  * Get form instance
  *
  * @return \Application\Form\ApplicationCustomFormBuilder
  */
 public function getForm()
 {
     // get form builder
     if (!$this->form) {
         // get list of all ACL roles
         $aclRoles = [];
         foreach (AclService::getAclRoles() as $roleId => $roleName) {
             // skip all system ACL roles
             if (in_array($roleId, [AclBaseModel::DEFAULT_ROLE_ADMIN, AclBaseModel::DEFAULT_ROLE_GUEST, AclBaseModel::DEFAULT_ROLE_MEMBER])) {
                 continue;
             }
             $aclRoles[$roleId] = $roleName;
         }
         $this->formElements['role_id']['values'] = $aclRoles;
         // add preview for the image
         if ($this->image) {
             $this->formElements['image']['required'] = false;
             $this->formElements['image']['extra_options']['preview'] = true;
             $this->formElements['image']['extra_options']['file_url'] = ApplicationService::getResourcesUrl() . MembershipBaseModel::getImagesDir() . $this->image;
         }
         // add extra validators
         $this->formElements['expiration_notification']['validators'] = [['name' => 'callback', 'options' => ['callback' => [$this, 'validateExpirationNotification'], 'message' => 'The expiration notification value  must be less than role\'s lifetime']]];
         $this->form = new ApplicationCustomFormBuilder($this->formName, $this->formElements, $this->translator, $this->ignoredElements, $this->notValidatedElements, $this->method);
     }
     return $this->form;
 }