/** * Generate settings form * * @param string $module * @param string $controller * @param string $action * @return \Application\Form\ApplicationCustomFormBuilder */ protected function settingsForm($module, $controller, $action) { $currentLanguage = LocalizationService::getCurrentLocalization()['language']; // get settings form $settingsForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Application\\Form\\ApplicationSetting'); // get settings list $settings = $this->getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationSettingAdministration'); if (false !== ($settingsList = $settings->getSettingsList($module, $currentLanguage))) { $settingsForm->addFormElements($settingsList); $request = $this->getRequest(); // validate the form if ($request->isPost()) { // fill the form with received values $settingsForm->getForm()->setData($request->getPost(), false); // save data if ($settingsForm->getForm()->isValid()) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $settingsForm->getForm(); } if (true === ($result = $settings->saveSettings($settingsList, $settingsForm->getForm()->getData(), $currentLanguage, $module))) { $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('Settings have been saved')); } else { $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result)); } $this->redirectTo($controller, $action); } } } return $settingsForm->getForm(); }
/** * Get current locale * * @return string */ public static function getLocale() { if (!self::$locale) { self::$locale = LocalizationService::getCurrentLocalization()['locale']; } return self::$locale; }
/** * Page 404 * * @return string|boolean */ public function __invoke() { $language = LocalizationService::getCurrentLocalization()['language']; $page404 = false; // get a custom 404 page's url if (true === DisableSiteUtility::isAllowedViewSite() && false !== ($page404 = $this->getView()->pageUrl(self::CUSTOM_404_PAGE, [], $language, true))) { $userRole = UserIdentityService::getCurrentUserIdentity()['role']; if (false == ($pageInfo = $this->getModel()->getActivePageInfo(self::CUSTOM_404_PAGE, $userRole, $language))) { return false; } // fire the page show event PageEvent::firePageShowEvent($pageInfo['slug'], $language); // check for redirect if ($pageInfo['redirect_url']) { $response = ServiceLocatorService::getServiceLocator()->get('Response'); $response->getHeaders()->addHeaderLine('Location', $pageInfo['redirect_url']); $response->setStatusCode(Response::STATUS_CODE_301); $response->sendHeaders(); return false; } // get the page's breadcrumb $breadcrumb = $this->getModel()->getActivePageParents($pageInfo['left_key'], $pageInfo['right_key'], $userRole, $language); return $this->getView()->partial($this->getModel()->getLayoutPath() . $pageInfo['layout'], ['page' => $pageInfo, 'breadcrumb' => $breadcrumb]); } return $page404; }
/** * Setup */ protected function setUp() { // get service manager $this->serviceLocator = PageBootstrap::getServiceLocator(); // get base model instance $this->model = $this->serviceLocator->get('Page\\Model\\PageNestedSet'); $this->language = current(LocalizationService::getLocalizations())['language']; }
/** * Get list of localizations * * @throws XmlRpc\Exception\XmlRpcActionDenied * @return array */ public function getLocalizations() { // check user permission if (!AclService::checkPermission('xmlrpc_get_localizations')) { throw new XmlRpcActionDenied(self::REQUEST_DENIED); } // fire the get localizations via XmlRpc event LocalizationEvent::fireGetLocalizationsViaXmlRpcEvent(); return LocalizationService::getLocalizations(); }
/** * Get all questions * * @return array */ public static function getAllQuestions() { if (null === self::$questions) { $questions = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Poll\\Model\\PollBase')->getAllQuestions(LocalizationService::getCurrentLocalization()['language']); // process questions self::$questions = []; foreach ($questions as $question) { self::$questions[$question->id] = $question->question; } } return self::$questions; }
/** * Get all categories * * @return array */ public static function getAllCategories() { if (null === self::$categories) { $categories = ServiceLocatorService::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('MiniPhotoGallery\\Model\\MiniPhotoGalleryBase')->getAllCategories(LocalizationService::getCurrentLocalization()['language']); // process categories self::$categories = []; foreach ($categories as $category) { self::$categories[$category->id] = $category->name; } } return self::$categories; }
/** * Page url * * @param string slug * @param array $privacyOptions * @param string $language * @param boolean $trustedPrivacyData * @param string|integer $objectId * @return string|boolean */ public function __invoke($slug = null, array $privacyOptions = [], $language = null, $trustedPrivacyData = false, $objectId = null) { if (!$slug) { $slug = $this->homePage; } if (!$language) { $language = LocalizationService::getCurrentLocalization()['language']; } $pageUrl = $this->getPageUrl($slug, $language, $privacyOptions, $trustedPrivacyData, $objectId); // compare the slug for the home page if ($this->homePage == $slug && false !== $pageUrl) { $pageUrl = null; } return $pageUrl; }
/** * Log an error * * @param string $errorMessage * @return boolean */ public static function log($errorMessage) { try { $writer = new LogWriterStream(ServiceLocatorService::getServiceLocator()->get('Config')['paths']['error_log']); $logger = new Logger(); $logger->addWriter($writer); $logger->err($errorMessage); // do we need send this error via email? if (null != ($errorEmail = SettingService::getSetting('application_errors_notification_email'))) { ApplicationEmailNotification::sendNotification($errorEmail, SettingService::getSetting('application_error_notification_title', LocalizationService::getDefaultLocalization()['language']), SettingService::getSetting('application_error_notification_message', LocalizationService::getDefaultLocalization()['language']), ['find' => ['ErrorDescription'], 'replace' => [$errorMessage]]); } } catch (Exception $e) { return false; } return true; }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (null != ($currentPage = PageService::getCurrentPage())) { $menuType = $this->getWidgetSetting('page_sidebar_menu_type'); $showDynamicPages = (int) $this->getWidgetSetting('page_sidebar_menu_show_dynamic'); $currentLanguage = LocalizationService::getCurrentLocalization()['language']; $pages = []; // collect sidebar menu items foreach ($this->getModel()->getPagesMap($currentLanguage) as $page) { // check the type of menu if ($page['parent'] != ($menuType == 'sidebar_menu_subpages' ? $currentPage['slug'] : $currentPage['parent_slug'])) { continue; } // get dynamic pages if (!empty($page['pages_provider'])) { if ($showDynamicPages) { if (null != ($dynamicPages = PageProviderUtility::getPages($page['pages_provider'], $currentLanguage))) { // process only the first pages level foreach ($dynamicPages as $dynamicPage) { // check received params if (!isset($dynamicPage['url_params'], $dynamicPage['url_title'])) { continue; } if (false !== ($pageUrl = $this->getView()->pageUrl($page['slug'], [], $currentLanguage, true))) { $pages[] = ['active' => !empty($dynamicPage['url_active']), 'url' => $pageUrl, 'title' => $dynamicPage['url_title'], 'params' => $dynamicPage['url_params']]; } } } } } else { // get a page url if (false === ($pageUrl = $this->getView()->pageUrl($page['slug']))) { continue; } $pages[] = ['active' => $currentPage['slug'] == $page['slug'], 'url' => $pageUrl, 'title' => $this->getView()->pageTitle($page)]; } } if ($pages) { return $this->getView()->partial('page/widget/sidebar-menu', ['pages' => $pages]); } } return false; }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (UserIdentityService::isGuest() && (int) $this->getSetting('user_allow_register')) { // get an user form $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones())->showCaptcha(true); // validate the form if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $userForm->getFormName()) { // make certain to merge the files info! $post = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); // fill the form with received values $userForm->getForm()->setData($post, false); // save data if ($userForm->getForm()->isValid()) { // add a new user with a particular status $status = (int) $this->getSetting('user_auto_confirm') ? true : false; $userInfo = $this->getModel()->addUser($userForm->getForm()->getData(), LocalizationService::getCurrentLocalization()['language'], $status, $this->getRequest()->getFiles()->avatar, true); // the user has been added if (is_array($userInfo)) { // check the user status if (!$status) { // get user activate url if (false !== ($activateUrl = $this->getView()->pageUrl('user-activate', ['user_id' => $userInfo['user_id']]))) { // send an email activate notification EmailNotificationUtility::sendNotification($userInfo['email'], $this->getSetting('user_email_confirmation_title'), $this->getSetting('user_email_confirmation_message'), ['find' => ['RealName', 'SiteName', 'ConfirmationLink', 'ConfCode'], 'replace' => [$userInfo['nick_name'], $this->getSetting('application_site_name'), $this->getView()->url('page', ['page_name' => $activateUrl, 'slug' => $userInfo['slug']], ['force_canonical' => true]), $userInfo['activation_code']]], true); $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('We sent a message with a confirmation code to your registration e-mail')); } else { $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your profile will be activated after checking')); } $this->reloadPage(); } else { // login and redirect the registered user return $this->loginUser($userInfo['user_id'], $userInfo['nick_name'], false); } } else { $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred')); } return $this->reloadPage(); } } return $this->getView()->partial('user/widget/register', ['user_form' => $userForm->getForm()]); } return false; }
/** * Log action * * @param integer $actionId * @param string $description * @param array $params * @return boolean|string */ public function logAction($actionId, $description, array $params = []) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $insert = $this->insert()->into('action_tracker_log')->values(['action_id' => $actionId, 'description' => $description, 'description_params' => serialize($params), 'registered' => time()]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // send an email notification about add the adding new action if (SettingService::getSetting('action_tracker_send_actions')) { $defaultLocalization = LocalizationService::getDefaultLocalization(); $actionDescription = vsprintf($this->serviceLocator->get('Translator')->translate($description, 'default', $defaultLocalization['locale']), $params); EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('action_tracker_title', $defaultLocalization['language']), SettingService::getSetting('action_tracker_message', $defaultLocalization['language']), ['find' => ['Action', 'Date'], 'replace' => [$actionDescription, $this->serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke(time(), [], $defaultLocalization['language'])]]); } return true; }
/** * Init view helpers */ public function getViewHelperConfig() { return ['invokables' => ['pageXmlSiteMap' => 'Page\\View\\Helper\\PageXmlSiteMap', 'page404' => 'Page\\View\\Helper\\Page404', 'pageBreadcrumb' => 'Page\\View\\Helper\\PageBreadcrumb', 'pageTitle' => 'Page\\View\\Helper\\PageTitle', 'pageWidgetTitle' => 'Page\\View\\Helper\\PageWidgetTitle', 'pagePosition' => 'Page\\View\\Helper\\PagePosition', 'pageHtmlWidget' => 'Page\\View\\Widget\\PageHtmlWidget', 'pageSiteMapWidget' => 'Page\\View\\Widget\\PageSiteMapWidget', 'pageContactFormWidget' => 'Page\\View\\Widget\\PageContactFormWidget', 'pageSidebarMenuWidget' => 'Page\\View\\Widget\\PageSidebarMenuWidget', 'pageShareButtonsWidget' => 'Page\\View\\Widget\\PageShareButtonsWidget', 'pageRssWidget' => 'Page\\View\\Widget\\PageRssWidget', 'pageRatingWidget' => 'Page\\View\\Widget\\PageRatingWidget'], 'factories' => ['pageTree' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageBase'); return new \Page\View\Helper\PageTree($model->getPagesTree(LocalizationService::getCurrentLocalization()['language'])); }, 'pageUserMenu' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageBase'); return new \Page\View\Helper\PageUserMenu($model->getUserMenu(LocalizationService::getCurrentLocalization()['language'])); }, 'pageFooterMenu' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageBase'); return new \Page\View\Helper\PageFooterMenu($model->getFooterMenu(LocalizationService::getCurrentLocalization()['language'])); }, 'pageMenu' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageBase'); return new \Page\View\Helper\PageMenu($model->getPagesTree(LocalizationService::getCurrentLocalization()['language'])); }, 'pageUrl' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageBase'); return new \Page\View\Helper\PageUrl($this->serviceLocator->get('Config')['home_page'], $model->getPagesMap()); }, 'pageInjectWidget' => function () { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageWidget'); return new \Page\View\Helper\PageInjectWidget($model->getWidgetsConnections(LocalizationService::getCurrentLocalization()['language'])); }]]; }
/** * Process action */ public function processAction() { // get the payment's type info if (null == ($payment = $this->getModel()->getPaymentTypeInfo($this->getSlug()))) { return $this->createHttpNotFoundModel($this->getResponse()); } // get the payment type instance $paymentInstance = $this->getServiceLocator()->get('Payment\\Type\\PaymentTypeManager')->getInstance($payment['handler']); // validate the payment if (false !== ($transactionInfo = $paymentInstance->validatePayment())) { if (true === ($result = $this->getModel()->activateTransaction($transactionInfo, $payment['id'], true, true))) { // send an email notification about the paid transaction if ((int) $this->applicationSetting('payment_transaction_paid_users')) { // get the user's info $userInfo = !empty($transactionInfo['user_id']) ? UserIdentityService::getUserInfo($transactionInfo['user_id']) : []; $notificationLanguage = !empty($userInfo['language']) ? $userInfo['language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($transactionInfo['email'], $this->applicationSetting('payment_transaction_paid_users_title', $notificationLanguage), $this->applicationSetting('payment_transaction_paid_users_message', $notificationLanguage), ['find' => ['Id', 'PaymentType'], 'replace' => [$transactionInfo['slug'], $this->getTranslator()->translate($payment['description'], 'default', LocalizationService::getLocalizations()[$notificationLanguage]['locale'])]]); } } } else { return $this->createHttpNotFoundModel($this->getResponse()); } return $this->getResponse(); }
/** * Clean expired memberships connections */ public function cleanExpiredMembershipsConnectionsAction() { $request = $this->getRequest(); $deletedConnections = 0; $notifiedConnections = 0; // get a list of expired memberships connections if (null != ($expiredConnections = $this->getModel()->getExpiredMembershipsConnections(self::ITEMS_LIMIT))) { // process expired memberships connections foreach ($expiredConnections as $connectionInfo) { // delete the connection if (false === ($deleteResult = $this->getModel()->deleteMembershipConnection($connectionInfo['id']))) { break; } // get a next membership connection $nextConnection = $this->getModel()->getMembershipConnectionFromQueue($connectionInfo['user_id']); $nextRoleId = $nextConnection ? $nextConnection['role_id'] : AclBaseModel::DEFAULT_ROLE_MEMBER; $nextRoleName = $nextConnection ? $nextConnection['role_name'] : AclBaseModel::DEFAULT_ROLE_MEMBER_NAME; // change the user's role if (true === ($result = $this->getUserModel()->editUserRole($connectionInfo['user_id'], $nextRoleId, $nextRoleName, $connectionInfo, true))) { // activate the next membership connection if ($nextConnection) { $this->getModel()->activateMembershipConnection($nextConnection['id']); } } $deletedConnections++; } } // get list of not notified memberships connections if ((int) $this->applicationSetting('membership_expiring_send')) { if (null != ($notNotifiedConnections = $this->getModel()->getNotNotifiedMembershipsConnections(self::ITEMS_LIMIT))) { // process not notified memberships connections foreach ($notNotifiedConnections as $connectionInfo) { if (false === ($markResult = $this->getModel()->markConnectionAsNotified($connectionInfo['id']))) { break; } // send a notification about membership expiring $notificationLanguage = $connectionInfo['language'] ? $connectionInfo['language'] : LocalizationService::getDefaultLocalization()['language']; $locale = LocalizationService::getLocalizations()[$notificationLanguage]['locale']; ApplicationEmailNotification::sendNotification($connectionInfo['email'], $this->applicationSetting('membership_expiring_send_title', $notificationLanguage), $this->applicationSetting('membership_expiring_send_message', $notificationLanguage), ['find' => ['RealName', 'Role', 'ExpireDate'], 'replace' => [$connectionInfo['nick_name'], ApplicationServiceLocatorService::getServiceLocator()->get('Translator')->translate($connectionInfo['role_name'], 'default', $locale), ApplicationServiceLocatorService::getServiceLocator()->get('viewhelpermanager')->get('applicationDate')->__invoke($connectionInfo['expire_date'], [], $locale)]]); $notifiedConnections++; } } } // delete not active empty connections $this->getModel()->deleteNotActiveEmptyConnections(); $verbose = $request->getParam('verbose'); if (!$verbose) { return 'All expired membership connections have been deleted.' . "\n"; } $result = $deletedConnections . ' membership connections have been deleted.' . "\n"; $result .= $notifiedConnections . ' membership connections have been notified.' . "\n"; return $result; }
/** * Get current language * * @return string */ protected function getCurrentLanguage() { return LocalizationService::getCurrentLocalization()['language']; }
/** * Get widget setting value * * @param string $name * @return string|array|boolean */ protected function getWidgetSetting($name) { $currentLanguage = LocalizationService::getCurrentLocalization()['language']; return $this->getWidgetSettingModel()->getWidgetSetting($this->pageId, $this->widgetConnectionId, $name, $currentLanguage); }
/** * Fire add comment event * * @param string $pageUrl * @param array $commentInfo * integer id * string comment * string name * string email * string registered_nickname * string registered_email * string registered_language * integer created * integer active * integer hidden * @param array $parentComment * integer id * string comment * string name * string email * string registered_nickname * string registered_email * string registered_language * integer created * integer active * integer hidden * @return void */ public static function fireAddCommentEvent($pageUrl, array $commentInfo, $parentComment = null) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Comment added by guest' : 'Event - Comment added by user'; $eventDescParams = UserIdentityService::isGuest() ? [$commentInfo['id']] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $commentInfo['id']]; self::fireEvent(self::ADD_COMMENT, $commentInfo['id'], UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); $serviceLocator = ServiceLocatorService::getServiceLocator(); // send an email notification about add the new comment if (SettingService::getSetting('comment_added_send')) { $defaultLocalization = LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('comment_added_title', $defaultLocalization), SettingService::getSetting('comment_added_message', $defaultLocalization), ['find' => ['PosterName', 'PosterEmail', 'CommentUrl', 'CommentId', 'Comment', 'Date'], 'replace' => [!empty($commentInfo['registered_nickname']) ? $commentInfo['registered_nickname'] : $commentInfo['name'], !empty($commentInfo['registered_email']) ? $commentInfo['registered_email'] : $commentInfo['email'], $pageUrl, $commentInfo['id'], $commentInfo['comment'], $serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke($commentInfo['created'], [], $defaultLocalization)]]); } // send a email notification about the new reply if ($parentComment && SettingService::getSetting('comment_reply_send')) { // don't send reply notifications if comments owners are equal if ($commentInfo['user_id'] != $parentComment['user_id'] || $commentInfo['email'] != $parentComment['email']) { // get notification language $notificationLanguage = $parentComment['registered_language'] ? $parentComment['registered_language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($parentComment['registered_email'] ? $parentComment['registered_email'] : $parentComment['email'], SettingService::getSetting('comment_reply_title', $notificationLanguage), SettingService::getSetting('comment_reply_message', $notificationLanguage), ['find' => ['PosterName', 'PosterEmail', 'Comment', 'ReplyUrl', 'ReplyId', 'Reply', 'Date'], 'replace' => [!empty($commentInfo['registered_nickname']) ? $commentInfo['registered_nickname'] : $commentInfo['name'], !empty($commentInfo['registered_email']) ? $commentInfo['registered_email'] : $commentInfo['email'], $parentComment['comment'], $pageUrl, $commentInfo['id'], $commentInfo['comment'], $serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke($commentInfo['created'], [], $notificationLanguage)]]); } } }
/** * Add a new user */ public function addUserAction() { // get an user form $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones()); $request = $this->getRequest(); // validate the form if ($request->isPost()) { // make certain to merge the files info! $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); // fill the form with received values $userForm->getForm()->setData($post, false); // save data if ($userForm->getForm()->isValid()) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $result; } // add a new user $result = $this->getModel()->addUser($userForm->getForm()->getData(), LocalizationService::getCurrentLocalization()['language'], true, $this->params()->fromFiles('avatar')); if (is_numeric($result)) { $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('User has been added')); } else { $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result)); } return $this->redirectTo('users-administration', 'add-user'); } } return new ViewModel(['user_form' => $userForm->getForm()]); }
/** * Get current localization * * @return array */ public function __invoke() { return LocalizationService::getCurrentLocalization(); }
/** * Init view helpers * * @return array */ public function getViewHelperConfig() { return ['factories' => ['localization' => function () { return new \Localization\View\Helper\Localization(LocalizationService::getCurrentLocalization(), LocalizationService::getLocalizations()); }]]; }
/** * Fire activate payment transaction event * * @param integer $transactionId * @param boolean $isSystemEvent * @param array $transactionInfo * string first_name * string last_name * string email * string id * @return void */ public static function fireActivatePaymentTransactionEvent($transactionId, $isSystemEvent = false, $transactionInfo = []) { // event's description $eventDesc = $isSystemEvent ? 'Event - Payment transaction activated by the system' : (UserIdentityService::isGuest() ? 'Event - Payment transaction activated by guest' : 'Event - Payment transaction activated by user'); $eventDescParams = $isSystemEvent ? [$transactionId] : (UserIdentityService::isGuest() ? [$transactionId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $transactionId]); self::fireEvent(self::ACTIVATE_PAYMENT_TRANSACTION, $transactionId, self::getUserId($isSystemEvent), $eventDesc, $eventDescParams); // send an email notification about the paid transaction if ($transactionInfo && (int) SettingService::getSetting('payment_transaction_paid')) { EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('payment_transaction_paid_title', LocalizationService::getDefaultLocalization()['language']), SettingService::getSetting('payment_transaction_paid_message', LocalizationService::getDefaultLocalization()['language']), ['find' => ['FirstName', 'LastName', 'Email', 'Id'], 'replace' => [$transactionInfo['first_name'], $transactionInfo['last_name'], $transactionInfo['email'], $transactionInfo['id']]]); } }
/** * Clear widgets settings cache * * @param integer $pageId * @param string $language * @return boolean */ public function clearWidgetsSettingsCache($pageId, $language = null) { // clear all caches if (!$language) { // get all localizations $localizations = LocalizationService::getLocalizations(); foreach ($localizations as $localization) { $cacheName = CacheUtility::getCacheName(self::CACHE_WIDGETS_SETTINGS_BY_PAGE . $pageId . '_' . $localization['language']); // clear a page's widgets settings cache if ($this->staticCacheInstance->hasItem($cacheName)) { if (false === ($result = $this->staticCacheInstance->removeItem($cacheName))) { return $result; } } } } else { $cacheName = CacheUtility::getCacheName(self::CACHE_WIDGETS_SETTINGS_BY_PAGE . $pageId . '_' . $language); if ($this->staticCacheInstance->hasItem($cacheName)) { if (false === ($result = $this->staticCacheInstance->removeItem($cacheName))) { return $result; } } } return true; }
/** * Fire edit role event * * @param array $user * string language * string email * string nick_name * integer user_id * @param string $roleName * @param boolean $isSystemEvent * @retun void */ public static function fireEditRoleEvent($user, $roleName, $isSystemEvent = false) { // event's description $eventDesc = $isSystemEvent ? 'Event - User\'s role edited by the system' : (UserIdentityService::isGuest() ? 'Event - User\'s role edited by guest' : 'Event - User\'s role edited by user'); $eventDescParams = $isSystemEvent ? [$user['user_id']] : (UserIdentityService::isGuest() ? [$user['user_id']] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $user['user_id']]); self::fireEvent(self::EDIT_ROLE, $user['user_id'], self::getUserId($isSystemEvent), $eventDesc, $eventDescParams); // send a notification if ((int) SettingService::getSetting('user_role_edited_send')) { $notificationLanguage = $user['language'] ? $user['language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($user['email'], SettingService::getSetting('user_role_edited_title', $notificationLanguage), SettingService::getSetting('user_role_edited_message', $notificationLanguage), ['find' => ['RealName', 'Role'], 'replace' => [$user['nick_name'], ServiceLocatorService::getServiceLocator()->get('Translator')->translate($roleName, 'default', LocalizationService::getLocalizations()[$notificationLanguage]['locale'])]]); } }
/** * Edit widget settings */ public function editWidgetSettingsAction() { $request = $this->getRequest(); // get a widget info if (null == ($widget = $this->getModel()->getWidgetConnectionInfo($this->getSlug(), true))) { return $this->redirectTo('pages-administration', 'list'); } $embedMode = $this->params()->fromQuery('embed_mode', null); $currentLanguage = LocalizationService::getCurrentLocalization()['language']; // get settings model $settings = $this->getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Page\\Model\\PageWidgetSetting'); // get settings form $settingsForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Page\\Form\\PageWidgetSetting')->showVisibilitySettings(!$widget['widget_forced_visibility'] && !$widget['widget_page_depend_connection_id'])->showCacheSettings($widget['widget_allow_cache'])->setModel($settings)->setWidgetDescription($this->getTranslator()->translate($widget['widget_description'])); // get settings list $settingsList = $settings->getSettingsList($widget['id'], $widget['widget_id'], $currentLanguage); if (false !== $settingsList) { // add extra settings on the form $settingsForm->addFormElements($settingsList); } // set default values $settingsForm->getForm()->setData(['title' => $widget['widget_title'], 'layout' => $widget['layout'], 'cache_ttl' => $widget['cache_ttl'], 'visibility_settings' => !empty($widget['visibility_settings']) ? $widget['visibility_settings'] : null]); // validate the form if ($request->isPost()) { // fill the form with received values $settingsForm->getForm()->setData($request->getPost(), false); // save data if ($settingsForm->getForm()->isValid()) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $result; } if (true === ($result = $this->getModel()->saveWidgetSettings($widget, $settingsList, $settingsForm->getForm()->getData(), $currentLanguage))) { $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('Settings have been saved')); } else { $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result)); } // redirect back return $this->redirectTo('pages-administration', 'widget-settings', [], true); } } $viewModel = new ViewModel(['settings_form' => $settingsForm->getForm(), 'page_info' => $this->getModel()->getStructurePageInfo($widget['page_id']), 'widget_info' => $widget]); // init embed mode if ($embedMode) { $this->layout('layout/blank'); $viewModel->setTemplate('page/page-administration/embed-edit-widget-settings'); } return $viewModel; }
/** * Get setting * * @param string $settingName * @param string $language * @return string|boolean */ public static function getSetting($settingName, $language = null) { $settingsModel = ApplicationServiceLocator::getServiceLocator()->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationSetting'); return $settingsModel->getSetting($settingName, $language ? $language : LocalizationService::getCurrentLocalization()['language']); }
/** * Get payment options * * @param float $itemsAmount * @param array $transactionInfo * integer id * string slug * integer user_id * string first_name * string last_name * string phone * string address * string email * integer currency * integer payment_type * integer discount_coupon * string currency_code * string payment_name * @return array */ public function getPaymentOptions($itemsAmount, array $transactionInfo) { return ['eshopId' => SettingService::getSetting('payment_rbk_eshop_id'), 'orderId' => $transactionInfo['slug'], 'successUrl' => $this->getSuccessUrl(), 'failUrl' => $this->getErrorUrl(), 'serviceName' => SettingService::getSetting('payment_rbk_money_title'), 'language' => LocalizationService::getCurrentLocalization()['language'], 'recipientAmount' => number_format($itemsAmount, 2), 'recipientCurrency' => $transactionInfo['currency_code'], 'user_email' => $transactionInfo['email']]; }
/** * Test setting by language */ public function testSettingsByLanguage() { // list of test settings $this->settingsNames = ['test language setting']; // get localization model $localization = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Localization\\Model\\LocalizationBase'); // list of settings values $settingValues = []; $settingValues[] = ['value' => 'base']; // process all registered localization foreach ($localization->getAllLocalizations() as $localizationInfo) { $settingValues[] = ['value' => $localizationInfo['locale'], 'language' => $localizationInfo['language']]; } // add test settings foreach ($this->settingsNames as $settingName) { $this->addSetting($settingName, $settingValues); } // get current language $currentLocalization = LocalizationService::getCurrentLocalization(); // check settings foreach ($this->settingsNames as $setting) { $this->assertEquals(SettingService::getSetting($setting), $currentLocalization['locale']); } }