Пример #1
0
 /**
  * Get all settings
  *
  * @param integer $pageId
  * @param string $language
  * @return array
  */
 protected function getAllSettings($pageId, $language)
 {
     // get cache name
     $cacheName = CacheUtility::getCacheName(PageBaseModel::CACHE_WIDGETS_SETTINGS_BY_PAGE . $pageId . '_' . $language);
     // check data in cache
     if (null === ($settings = $this->staticCacheInstance->getItem($cacheName))) {
         // get default value
         $subQuery = $this->select();
         $subQuery->from(['i' => 'page_widget_setting_default_value'])->columns(['id'])->limit(1)->order('i.language desc')->where(['b.id' => new Expression('i.setting_id')])->where->and->equalTo('i.language', $language)->where->or->equalTo('b.id', new Expression('i.setting_id'))->and->isNull('i.language');
         $select = $this->select();
         $select->from(['a' => 'page_widget_connection'])->columns(['id'])->join(['b' => 'page_widget_setting'], 'a.widget_id = b.widget', ['name', 'type'])->join(['c' => 'page_widget_setting_value'], 'b.id = c.setting_id and a.id = c.widget_connection', ['value_id' => 'id', 'value'], 'left')->join(['d' => 'page_widget_setting_default_value'], new Expression('d.id = (' . $this->getSqlStringForSqlObject($subQuery) . ')'), ['default_value' => 'value'], 'left')->where(['page_id' => $pageId]);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         // convert strings
         $settings = [];
         foreach ($resultSet as $setting) {
             if (!empty($setting['value_id']) || !empty($setting['default_value'])) {
                 $settings[$setting['id']][$setting['name']] = $this->convertString($setting['type'], !empty($setting['value_id']) ? $setting['value'] : $setting['default_value']);
             }
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $settings);
         $this->staticCacheInstance->setTags($cacheName, [PageBaseModel::CACHE_PAGES_DATA_TAG]);
     }
     return $settings;
 }
Пример #2
0
 /**
  * Get menu
  *
  * @return array
  */
 public function getMenu()
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_ADMIN_MENU);
     // check data in cache
     if (null === ($menu = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from(['a' => 'application_admin_menu'])->columns(['name', 'controller', 'action'])->join(['b' => 'application_admin_menu_category'], 'a.category = b.id', ['category' => 'name', 'category_icon' => 'icon'])->join(['c' => 'application_admin_menu_part'], 'a.part = c.id', ['part' => 'name', 'part_icon' => 'icon'])->join(['d' => 'application_module'], new Expression('c.module = d.id and d.status = ?', [self::MODULE_STATUS_ACTIVE]), ['part_module' => 'name'])->join(['i' => 'application_module'], new Expression('b.module = i.id and i.status = ?', [self::MODULE_STATUS_ACTIVE]), ['category_module' => 'name'])->order('order');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         // process admin menu
         foreach ($resultSet as $menuItem) {
             if (!isset($menu[$menuItem['part']])) {
                 $menu[$menuItem['part']] = ['part' => $menuItem['part'], 'icon' => $menuItem['part_icon'], 'module' => $menuItem['part_module'], 'items' => [0 => ['name' => $menuItem['name'], 'controller' => $menuItem['controller'], 'action' => $menuItem['action'], 'category' => $menuItem['category'], 'category_icon' => $menuItem['category_icon'], 'category_module' => $menuItem['category_module']]]];
             } else {
                 $menu[$menuItem['part']]['items'][] = ['name' => $menuItem['name'], 'controller' => $menuItem['controller'], 'action' => $menuItem['action'], 'category' => $menuItem['category'], 'category_icon' => $menuItem['category_icon'], 'category_module' => $menuItem['category_module']];
             }
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $menu);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_ADMIN_MENU_DATA_TAG]);
     }
     return $menu;
 }
Пример #3
0
 /**
  * Get time zones
  *
  * @return array
  */
 public function getTimeZones()
 {
     // check data in a memory
     if (null !== self::$timeZones) {
         return self::$timeZones;
     }
     // generate a cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_TIME_ZONES);
     // check data in cache
     if (null === ($timeZones = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from('application_time_zone')->columns(['id', 'name'])->order('name');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         foreach ($resultSet as $timeZone) {
             $timeZones[$timeZone->id] = $timeZone->name;
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $timeZones);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_TIME_ZONES_DATA_TAG]);
     }
     self::$timeZones = $timeZones;
     return $timeZones;
 }
Пример #4
0
 /**
  * Call widget
  *
  * @param string $position
  * @param integer $pageId
  * @param integer $userRole
  * @param array $widgetInfo
  * @param boolean $useLayout
  * @throws Page\Exception\PageException
  * @return string|boolean
  */
 protected function callWidget($position, $pageId, $userRole, array $widgetInfo, $useLayout = true)
 {
     // don't call any widgets
     if (true === self::$widgetRedirected) {
         return false;
     }
     // check a widget visibility
     if ($userRole != AclBaseModel::DEFAULT_ROLE_ADMIN) {
         if (!empty($widgetInfo['hidden']) && in_array($userRole, $widgetInfo['hidden'])) {
             return false;
         }
     }
     // call the widget
     $widget = $this->getView()->{$widgetInfo['widget_name']}();
     // check the widget
     if (!$widget instanceof IPageWidget) {
         throw new PageException(sprintf($widgetInfo['widget_name'] . ' must be an object implementing IPageWidget'));
     }
     // init the widget
     $widget->setPageId($pageId)->setWidgetPosition($position)->setWidgetConnectionId($widgetInfo['widget_connection_id']);
     $widgetCacheName = null;
     if ((int) $widgetInfo['widget_cache_ttl']) {
         // generate a cache name
         $widgetCacheName = CacheUtility::getCacheName($widgetInfo['widget_name'], [$widgetInfo['widget_connection_id']]);
         // check the widget data in a cache
         if (null !== ($cachedWidgetData = $this->dynamicCache->getItem($widgetCacheName))) {
             // check a local widget lifetime
             if ($cachedWidgetData['widget_expire'] >= time()) {
                 // include widget's css and js files
                 if (false !== $cachedWidgetData['widget_content'] && !$this->request->isXmlHttpRequest()) {
                     $widget->includeJsCssFiles();
                 }
                 return $cachedWidgetData['widget_content'];
             }
             // clear cache
             $this->dynamicCache->removeItem($widgetCacheName);
         }
     }
     if (false !== ($widgetContent = $widget->getContent())) {
         self::$widgetRedirected = $widget->isWidgetRedirected();
         // include widget's css and js files
         if (!$this->request->isXmlHttpRequest()) {
             $widget->includeJsCssFiles();
         }
         // add the widget's layout
         if ($useLayout) {
             if (!empty($widgetInfo['widget_layout'])) {
                 $widgetContent = $this->getView()->partial($this->layoutPath . $widgetInfo['widget_layout'], ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
             } else {
                 $widgetContent = $this->getView()->partial($this->layoutPath . 'default', ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
             }
         }
     }
     // cache the widget data
     if ($widgetCacheName) {
         $this->dynamicCache->setItem($widgetCacheName, ['widget_content' => $widgetContent, 'widget_expire' => time() + $widgetInfo['widget_cache_ttl']]);
     }
     return $widgetContent;
 }
Пример #5
0
 /**
  * Retrieve the filesystem path to a view script
  *
  * @param  string $name
  * @param  null|Renderer $renderer
  * @throws \Zend\View\Exception\DomainException
  * @return string
  */
 public function resolve($name, Renderer $renderer = null)
 {
     if (!self::$currentLayoutId) {
         $activeLayouts = LayoutService::getCurrentLayouts();
         self::$currentLayoutId = end($activeLayouts)['name'];
     }
     // generate a cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_TEMPLATE_PATH, [$name, $renderer, self::$currentLayoutId]);
     // check data in cache
     if (null === ($templatePath = $this->dynamicCacheInstance->getItem($cacheName))) {
         if (false !== ($templatePath = parent::resolve($name, $renderer))) {
             // save data in cache
             $this->dynamicCacheInstance->setItem($cacheName, $templatePath);
         }
     }
     return $templatePath;
 }
Пример #6
0
 /**
  * Get all classes
  *
  * @return array
  */
 public function getClasses()
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_XMLRPC_CLASSES);
     // check data in cache
     if (null === ($classes = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from(['a' => 'xmlrpc_class'])->columns(['namespace', 'path', 'module'])->join(['b' => 'application_module'], new Expression('a.module = b.id and b.status = ?', [self::MODULE_STATUS_ACTIVE]), []);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $classes = $resultSet->toArray();
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $classes);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_XMLRPC_DATA_TAG]);
     }
     return $classes;
 }
Пример #7
0
 /**
  * Get resource's url
  *
  * @param string $fileName
  * @param string $type (possible values are: js, css and image)
  * @param string $module
  * @return string|false
  */
 public function __invoke($fileName, $type = 'js', $module = self::DEFAULT_MODULE)
 {
     if (!self::$currentLayoutId) {
         $activeLayouts = LayoutService::getCurrentLayouts();
         self::$currentLayoutId = end($activeLayouts)['name'];
     }
     // generate a dynamicCacheInstance name
     $dynamicCacheInstanceName = CacheUtility::getCacheName(self::CACHE_RESOURCE_PATH, [$fileName, $type, $module, self::$currentLayoutId]);
     if (null === ($resourcePath = $this->dynamicCacheInstance->getItem($dynamicCacheInstanceName))) {
         $baseResourcePath = $this->layoutPath;
         // get a resource url
         foreach ($this->layouts as $layout) {
             $checkResourcePath = $baseResourcePath . $layout['name'] . '/' . $module . '/' . $type . '/' . $fileName;
             if (file_exists($checkResourcePath)) {
                 $resourcePath = $this->layoutDir . '/' . $layout['name'] . '/' . $module . '/' . $type . '/' . $fileName;
                 // save data in dynamicCacheInstance
                 $this->dynamicCacheInstance->setItem($dynamicCacheInstanceName, $resourcePath);
             }
         }
     }
     return $resourcePath ? $resourcePath : false;
 }
Пример #8
0
 /**
  * Get default active layouts
  *
  * @return array
  */
 public function getDefaultActiveLayouts()
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_LAYOUTS_ACTIVE);
     // check data in cache
     if (null === ($layouts = $this->staticCacheInstance->getItem($cacheName))) {
         $defaultActiveCustomLayout = (int) SettingService::getSetting('layout_active');
         $select = $this->select();
         $select->from('layout_list')->columns(['name'])->order('type')->where(['type' => self::LAYOUT_TYPE_SYSTEM]);
         if ($defaultActiveCustomLayout) {
             $select->where->or->equalTo('id', $defaultActiveCustomLayout)->and->equalTo('type', self::LAYOUT_TYPE_CUSTOM);
         }
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $layouts = $resultSet->toArray();
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $layouts);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_LAYOUTS_DATA_TAG]);
     }
     return $layouts;
 }
Пример #9
0
 /**
  * Get all localizations
  *
  * @return array
  */
 public function getAllLocalizations()
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_LOCALIZATIONS);
     // check data in cache
     if (null === ($localizations = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from('localization_list')->columns(['language', 'locale', 'description', 'default', 'direction'])->order('default desc');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         // process localizations
         if ($resultSet) {
             foreach ($resultSet as $localization) {
                 $localizations[$localization['language']] = ['language' => $localization['language'], 'locale' => $localization['locale'], 'description' => $localization['description'], 'default' => $localization['default'], 'direction' => $localization['direction']];
             }
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $localizations);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_LOCALIZATIONS_DATA_TAG]);
     }
     return $localizations;
 }
 /**
  * Clear caches
  *
  * @param array $caches
  *      boolean setting optional
  *      boolean time_zone optional
  *      boolean admin_menu optional
  *      boolean js_cache optional
  *      boolean css_cache optional
  *      boolean layout optional
  *      boolean localization optional
  *      boolean page optional
  *      boolean user optional
  *      boolean xmlrpc optional
  * @return void
  */
 protected function clearCaches(array $caches = [])
 {
     // clear the modules and system config caches
     ApplicationCacheUtility::clearModuleCache();
     ApplicationCacheUtility::clearConfigCache();
     ApplicationCacheUtility::clearDynamicCache();
     foreach ($caches as $cacheName => $clear) {
         if (false === (bool) $clear) {
             continue;
         }
         switch ($cacheName) {
             case 'setting':
                 ApplicationCacheUtility::clearSettingCache();
                 break;
             case 'time_zone':
                 ApplicationCacheUtility::clearTimeZoneCache();
                 break;
             case 'admin_menu':
                 ApplicationCacheUtility::clearAdminMenuCache();
                 break;
             case 'js_cache':
                 ApplicationCacheUtility::clearJsCache();
                 break;
             case 'css_cache':
                 ApplicationCacheUtility::clearCssCache();
                 break;
             case 'layout':
                 LayoutCacheUtility::clearLayoutCache();
                 break;
             case 'localization':
                 LocalizationCacheUtility::clearLocalizationCache();
                 break;
             case 'page':
                 PageCacheUtility::clearPageCache();
                 break;
             case 'user':
                 UserCacheUtility::clearUserCache();
                 break;
             case 'xmlrpc':
                 XmlRpcCacheUtility::clearXmlRpcCache();
                 break;
         }
     }
 }
Пример #11
0
 /**
  * Test cache name generation
  */
 public function testCacheNameGeneration()
 {
     $this->assertEquals('599211e2143c831fa11c418e6c862baf', ApplicationCache::getCacheName('test', ['test' => 'test', 'value' => ['id' => 45]]));
     $this->assertEquals('098f6bcd4621d373cade4e832627b4f6', ApplicationCache::getCacheName('test'));
     $this->assertEquals('1d3ad489ae10c71f75b4bcd8d56e884e', ApplicationCache::getCacheName('test', ['name' => '1', 'value' => 0, 'role' => 'admin']));
 }
Пример #12
0
 /**
  * Get active modules list
  *
  * @return array
  */
 public function getActiveModulesList()
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_MODULES_ACTIVE);
     // check data in cache
     if (null === ($modulesList = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from('application_module')->columns(['id', 'name'])->where(['status' => self::MODULE_STATUS_ACTIVE])->order('id');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         foreach ($resultSet as $module) {
             $modulesList[$module->id] = $module->name;
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $modulesList);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_MODULES_DATA_TAG]);
     }
     return $modulesList;
 }
Пример #13
0
 /**
  * Init application
  *
  * @return void
  */
 public function initApplication()
 {
     // init php settings
     $this->initPhpSettings();
     // init a strict sql mode
     $this->initSqlStrictMode();
     // set the service manager
     ServiceLocatorService::setServiceLocator($this->serviceLocator);
     $request = $this->serviceLocator->get('Request');
     if (!$request instanceof ConsoleRequest) {
         // init session
         $this->initSession();
     }
     $eventManager = LocalizationEvent::getEventManager();
     $eventManager->attach(LocalizationEvent::UNINSTALL, function () {
         ApplicationCacheUtility::clearSettingCache();
     });
 }
 /**
  * Clear cache
  */
 public function clearCacheAction()
 {
     // get a cache form
     $cacheForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Application\\Form\\ApplicationClearCache');
     $request = $this->getRequest();
     // validate the form
     if ($request->isPost()) {
         // fill the form with received values
         $cacheForm->getForm()->setData($request->getPost(), false);
         // check the form validation
         if ($cacheForm->getForm()->isValid()) {
             if (null != ($caches = $cacheForm->getForm()->getData()['cache'])) {
                 // clear selected caches
                 foreach ($caches as $cache) {
                     // check the permission and increase permission's actions track
                     if (true !== ($result = $this->aclCheckPermission())) {
                         return $result;
                     }
                     $clearResult = false;
                     switch ($cache) {
                         case self::CACHE_STATIC:
                             $clearResult = CacheUtility::clearStaticCache();
                             break;
                         case self::CACHE_DYNAMIC:
                             $clearResult = CacheUtility::clearDynamicCache();
                             break;
                         case self::CACHE_CONFIG:
                             $clearResult = CacheUtility::clearConfigCache();
                             break;
                         case self::CACHE_JS:
                             $clearResult = CacheUtility::clearJsCache();
                             break;
                         case self::CACHE_CSS:
                             $clearResult = CacheUtility::clearCssCache();
                             break;
                     }
                     if (false === $clearResult) {
                         $this->flashMessenger()->setNamespace('error')->addMessage(sprintf($this->getTranslator()->translate('Error clearing caches'), $cache));
                         break;
                     }
                 }
                 if (true === $clearResult) {
                     ApplicationEvent::fireClearCacheEvent($cache);
                     $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('Selected caches have been cleared'));
                 }
                 return $this->redirectTo('settings-administration', 'clear-cache');
             }
         }
     }
     return new ViewModel(['cacheForm' => $cacheForm->getForm()]);
 }
Пример #15
0
 /**
  * Get all pages map
  * 
  * @return array
  */
 public function getAllPagesMap()
 {
     if (null !== self::$pagesMap) {
         return self::$pagesMap;
     }
     $cacheName = CacheUtility::getCacheName(self::CACHE_PAGES_MAP);
     // check data in a cache
     if (null === ($pagesMap = $this->staticCacheInstance->getItem($cacheName))) {
         // get all pages visibility
         $pagesVisibility = [];
         $select = $this->select();
         $select->from(['a' => 'page_visibility'])->columns(['page_id', 'hidden'])->join(['b' => 'page_structure'], 'b.id = a.page_id', ['slug']);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         // process pages visibility
         foreach ($resultSet as $pageVisibility) {
             $pagesVisibility[$pageVisibility->page_id][] = $pageVisibility->hidden;
         }
         // get all pages structure
         $select = $this->select();
         $select->from(['a' => 'page_structure'])->columns(['id', 'slug', 'title', 'level', 'active', 'site_map', 'xml_map', 'menu', 'type', 'language', 'date_edited', 'xml_map_update', 'xml_map_priority'])->join(['b' => 'page_system'], 'b.id = a.system_page', ['privacy', 'pages_provider', 'dynamic_page', 'system_title' => 'title'], 'left')->join(['c' => 'application_module'], 'c.id = a.module', ['module_status' => 'status'])->order('a.language, a.left_key');
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $language = null;
         $pagesMap = [];
         // process pages
         foreach ($resultSet as $page) {
             // check page's language
             if ($language != $page['language']) {
                 $language = $page['language'];
                 $levels = [];
             }
             $levels[$page->level] = $page->slug;
             $pagesMap[$page->language][$page->slug] = ['id' => $page->id, 'title' => $page->title, 'slug' => $page->slug, 'system_title' => $page->system_title, 'active' => $page->active, 'module_status' => $page->module_status, 'level' => $page->level, 'privacy' => $page->privacy, 'pages_provider' => $page->pages_provider, 'dynamic_page' => $page->dynamic_page, 'parent' => isset($levels[$page->level - 1]) ? $levels[$page->level - 1] : null, 'site_map' => $page->site_map, 'xml_map' => $page->xml_map, 'menu' => $page->menu, 'type' => $page->type, 'date_edited' => $page->date_edited, 'xml_map_update' => $page->xml_map_update, 'xml_map_priority' => $page->xml_map_priority, 'hidden' => isset($pagesVisibility[$page->id]) ? $pagesVisibility[$page->id] : []];
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $pagesMap);
         $this->staticCacheInstance->setTags($cacheName, [self::CACHE_PAGES_DATA_TAG]);
     }
     self::$pagesMap = $pagesMap;
     return $pagesMap;
 }
Пример #16
0
 /**
  * Get user info
  *
  * @param integer|string $userId
  * @param string $field
  * @return array
  */
 public function getUserInfo($userId, $field = self::USER_INFO_BY_ID)
 {
     // check data in a memory
     if (isset(self::$userInfo[$userId][$field])) {
         return self::$userInfo[$userId][$field];
     }
     // process a field name
     $field = in_array($field, $this->userInfoFields) ? $field : self::USER_INFO_BY_ID;
     // generate a cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_USER_INFO . $userId, [$field]);
     // check data in cache
     if (null === ($userInfo = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from(['a' => 'user_list'])->columns(['user_id', 'nick_name', 'slug', 'status', 'email', 'phone', 'first_name', 'last_name', 'address', 'role', 'language', 'time_zone', 'layout', 'api_key', 'api_secret', 'registered', 'activation_code', 'avatar'])->join(['b' => 'acl_role'], 'a.role = b.id', ['role_name' => 'name'], 'left')->join(['c' => 'application_time_zone'], 'a.time_zone = c.id', ['time_zone_name' => 'name'], 'left')->where([$field => $userId]);
         $statement = $this->prepareStatementForSqlObject($select);
         $resultSet = new ResultSet();
         $resultSet->initialize($statement->execute());
         $userInfo = $resultSet->current() ? (array) $resultSet->current() : [];
         // save data in cache
         if ($userInfo) {
             $this->staticCacheInstance->setItem($cacheName, $userInfo);
             $this->staticCacheInstance->setTags($cacheName, [self::CACHE_USER_DATA_TAG, self::CACHE_USER_SPECIFIC_DATA_TAG . $userInfo['user_id']]);
         }
     }
     self::$userInfo[$userId][$field] = $userInfo;
     return $userInfo;
 }
Пример #17
0
 /**
  * Get settings cache name
  *
  * @param string $language
  * @return string
  */
 protected function getSettingsCacheName($language)
 {
     // generate cache name
     return CacheUtility::getCacheName(self::CACHE_SETTINGS_BY_LANGUAGE . $language);
 }
Пример #18
0
 /**
  * Save widget settings
  *
  * @param array $widget
  *      string widget_name
  *      integer widget_id
  *      integer page_id
  *      integer id
  * @param array $settingsList
  * @param array $formData
  * @param string $currentlanguage
  * @return boolean|string
  */
 public function saveWidgetSettings(array $widget, array $settingsList, array $formData, $currentlanguage)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $widgetId = $widget['widget_id'];
         $pageId = $widget['page_id'];
         $widgetConnectionId = $widget['id'];
         $this->updateStructurePageEditedDate($pageId);
         // update primary widget settings
         $update = $this->update()->table('page_widget_connection')->set(['title' => !empty($formData['title']) ? $formData['title'] : null, 'layout' => !empty($formData['layout']) ? $formData['layout'] : null, 'cache_ttl' => !empty($formData['cache_ttl']) ? $formData['cache_ttl'] : 0])->where(['id' => $widgetConnectionId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // update extra widget settings
         foreach ($settingsList as $setting) {
             if (array_key_exists($setting['name'], $formData)) {
                 // remove previously value
                 $query = $this->delete('page_widget_setting_value')->where(['setting_id' => $setting['id'], 'widget_connection' => $widgetConnectionId]);
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
                 $value = is_array($formData[$setting['name']]) ? implode(PageWidgetSetting::SETTINGS_ARRAY_DEVIDER, $formData[$setting['name']]) : (null != $formData[$setting['name']] ? $formData[$setting['name']] : '');
                 $query = $this->insert('page_widget_setting_value')->values(['setting_id' => $setting['id'], 'value' => $value, 'widget_connection' => $widgetConnectionId]);
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
             }
         }
         // clear all widget old visibility settings
         $delete = $this->delete()->from('page_widget_visibility')->where(['widget_connection' => $widgetConnectionId]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $result = $statement->execute();
         // add new widget visibility settings
         if (!empty($formData['visibility_settings'])) {
             foreach ($formData['visibility_settings'] as $aclRoleId) {
                 $insert = $this->insert()->into('page_widget_visibility')->values(['widget_connection' => $widgetConnectionId, 'hidden' => $aclRoleId]);
                 $statement = $this->prepareStatementForSqlObject($insert);
                 $statement->execute();
             }
         }
         // clear caches
         $this->clearLanguageSensitivePageCaches();
         $this->clearWidgetsSettingsCache($pageId, $currentlanguage);
         $dynamicCache = $this->serviceLocator->get('Application\\Cache\\Dynamic');
         $widgetCacheName = CacheUtility::getCacheName($widget['widget_name'], [$widgetConnectionId]);
         if ($dynamicCache->hasItem($widgetCacheName)) {
             $dynamicCache->removeItem($widgetCacheName);
         }
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     PageEvent::fireEditWidgetSettingsEvent($widgetId, $pageId);
     return true;
 }
Пример #19
0
 /**
  * Clear layout caches
  *
  * @return void
  */
 public function clearLayoutCaches()
 {
     ApplicationCacheUtility::clearJsCache();
     ApplicationCacheUtility::clearCssCache();
     LayoutCacheUtility::clearLayoutCache();
     ApplicationCacheUtility::clearDynamicCache();
 }
 /**
  * Deactivate selected modules
  */
 public function deactivateAction()
 {
     $request = $this->getRequest();
     if ($request->isPost() && $this->applicationCsrf()->isTokenValid($request->getPost('csrf'))) {
         if (null !== ($modulesIds = $request->getPost('modules', null))) {
             // deactivate selected modules
             $deactivateResult = false;
             $deactivatedCount = 0;
             foreach ($modulesIds as $module) {
                 // get a module info
                 if (null != ($moduleInfo = $this->getModel()->getModuleInfo($module))) {
                     // check dependent modules and type of the module
                     if (count($this->getModel()->getDependentModules($module)) || $moduleInfo['type'] == ApplicationAbstractBaseModel::MODULE_TYPE_SYSTEM) {
                         continue;
                     }
                     // check the permission and increase permission's actions track
                     if (true !== ($result = $this->aclCheckPermission(null, true, false))) {
                         $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate('Access Denied'));
                         break;
                     }
                     // deactivate the module
                     if (true !== ($deactivateResult = $this->getModel()->setCustomModuleStatus($module, false))) {
                         $this->flashMessenger()->setNamespace('error')->addMessage($deactivateResult ? $this->getTranslator()->translate($deactivateResult) : $this->getTranslator()->translate('Error occurred'));
                         break;
                     }
                 }
                 $deactivatedCount++;
             }
             if (true === $deactivateResult) {
                 $message = $deactivatedCount > 1 ? 'Selected modules have been deactivated' : 'The selected module has been deactivated';
                 $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate($message));
             }
         }
     }
     ApplicationCacheUtility::clearDynamicCache();
     // redirect back
     return $this->redirectTo('modules-administration', 'list-installed', [], true);
 }
Пример #21
0
 /**
  * Get exchange rates
  *
  * @param boolean $excludePrimary
  * @return array
  */
 public function getExchangeRates($excludePrimary = true)
 {
     // generate cache name
     $cacheName = CacheUtility::getCacheName(self::CACHE_EXCHANGE_RATES, [$excludePrimary]);
     // check data in cache
     if (null === ($rates = $this->staticCacheInstance->getItem($cacheName))) {
         $select = $this->select();
         $select->from(['a' => 'payment_currency'])->columns(['id', 'code', 'name', 'primary_currency'])->join(['b' => 'payment_exchange_rate'], new Expression('a.id = b.currency'), ['rate'], 'left');
         if ($excludePrimary) {
             $select->where([new NotInPredicate('primary_currency', [self::PRIMARY_CURRENCY])]);
         }
         $statement = $this->prepareStatementForSqlObject($select);
         $result = $statement->execute();
         foreach ($result as $rate) {
             $rates[$rate['code']] = ['id' => $rate['id'], 'code' => $rate['code'], 'name' => $rate['name'], 'rate' => $rate['rate'], 'primary_currency' => $rate['primary_currency']];
         }
         // save data in cache
         $this->staticCacheInstance->setItem($cacheName, $rates);
     }
     return $rates;
 }