/**
  * Save settings
  *
  * @param array $settingsList
  * @param array $settingsValues
  * @param string $currentlanguage
  * @param string $module
  * @return boolean|string
  */
 public function saveSettings(array $settingsList, array $settingsValues, $currentlanguage, $module)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         // save settings
         foreach ($settingsList as $setting) {
             if (array_key_exists($setting['name'], $settingsValues)) {
                 // remove previously value
                 $query = $this->delete('application_setting_value')->where(['setting_id' => $setting['id']])->where(!$setting['language_sensitive'] ? 'language is null' : ['language' => $currentlanguage]);
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
                 // insert new value
                 $extraValues = $setting['language_sensitive'] ? ['language' => $currentlanguage] : [];
                 $value = is_array($settingsValues[$setting['name']]) ? implode(self::SETTINGS_ARRAY_DIVIDER, $settingsValues[$setting['name']]) : (null != $settingsValues[$setting['name']] ? $settingsValues[$setting['name']] : '');
                 $query = $this->insert('application_setting_value')->values(array_merge(['setting_id' => $setting['id'], 'value' => $value], $extraValues));
                 $statement = $this->prepareStatementForSqlObject($query);
                 $statement->execute();
             }
         }
         // clear cache
         $this->removeSettingsCache($currentlanguage);
         self::$settings = null;
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the change settings event
     ApplicationEvent::fireChangeSettingsEvent($module);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Init layout
  */
 protected function initlayout()
 {
     try {
         // get a custom template path resolver
         $templatePathResolver = $this->serviceLocator->get('Layout\\View\\Resolver\\TemplatePathStack');
         // replace the default template path stack resolver with one
         $aggregateResolver = $this->serviceLocator->get('Zend\\View\\Resolver\\AggregateResolver');
         $aggregateResolver->attach($templatePathResolver)->getIterator()->remove($this->serviceLocator->get('Zend\\View\\Resolver\\TemplatePathStack'));
         $layout = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Layout\\Model\\LayoutBase');
         $request = $this->serviceLocator->get('Request');
         // get a layout from cookies
         $allowSelectLayouts = (int) SettingService::getSetting('layout_select');
         $cookieLayout = isset($request->getCookie()->{self::LAYOUT_COOKIE}) && $allowSelectLayouts ? (int) $request->getCookie()->{self::LAYOUT_COOKIE} : null;
         // init a user selected layout
         if ($cookieLayout) {
             $activeLayouts = $layout->getLayoutsById($cookieLayout);
         } else {
             $activeLayouts = !empty(UserIdentityService::getCurrentUserIdentity()['layout']) && $allowSelectLayouts ? $layout->getLayoutsById(UserIdentityService::getCurrentUserIdentity()['layout']) : $layout->getDefaultActiveLayouts();
         }
         // add layouts paths for each module
         foreach ($this->moduleManager->getModules() as $module) {
             foreach ($activeLayouts as $layoutInfo) {
                 $templatePathResolver->addPath('module/' . $module . '/view/' . $layoutInfo['name']);
             }
         }
         LayoutService::setCurrentLayouts($activeLayouts);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
 }
Ejemplo n.º 3
0
 /**
  * Clear user cache
  *
  * @return boolean
  */
 public static function clearUserCache()
 {
     try {
         return ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Static')->clearByTags([UserBaseModel::CACHE_USER_DATA_TAG]);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Clear localization cache
  *
  * @return boolean
  */
 public static function clearLocalizationCache()
 {
     try {
         return ServiceLocatorService::getServiceLocator()->get('Application\\Cache\\Static')->clearByTags([LocalizationBaseModel::CACHE_LOCALIZATIONS_DATA_TAG]);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Create message
  *
  * @param string $email
  * @param string $title
  * @param string $message
  * @return boolean|string
  */
 public function createMessage($email, $title, $message)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $insert = $this->insert()->into('application_email_queue')->values(['email' => $email, 'title' => $title, 'message' => $message, 'created' => 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();
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Mark service as processed
  *
  * @param integer $serviceId
  * @return boolean|string
  */
 protected function markServiceProcessed($serviceId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $update = $this->update()->table('application_delete_content_service')->set(['processed' => time()])->where(['id' => $serviceId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * Add answer vote
  *
  * @param integer $questionId
  * @param integer $answerId
  * @return string|boolean
  */
 public function addAnswerVote($questionId, $answerId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $remote = new RemoteAddress();
         $remote->setUseProxy(true);
         // add a track info
         $insert = $this->insert()->into('poll_answer_track')->values(['question_id' => $questionId, 'answer_id' => $answerId, 'ip' => inet_pton($remote->getIpAddress()), 'created' => 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();
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Set user time zone
  *
  * @param integer $userId
  * @param string $userName
  * @param integer $timeZoneId
  * @return boolean|string
  */
 public function setUserTimeZone($userId, $userName, $timeZoneId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $update = $this->update()->table('user_list')->set(['time_zone' => $timeZoneId, 'date_edited' => date('Y-m-d')])->where(['user_id' => $userId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // remove user cache
         $this->removeUserCache($userId);
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire set user's time zone via XmlRpc event
     UserEvent::fireSetTimezoneViaXmlRpcEvent($userId, $userName);
     return true;
 }
 /**
  * Immediately send notification
  *
  * @param string $email
  * @param string $title
  * @param string $messageDesc
  * @return boolean|string
  */
 public static function immediatelySendNotification($email, $title, $messageDesc)
 {
     try {
         // fire the send email notification event
         ApplicationEvent::fireSendEmailNotificationEvent($email, $title);
         // add the mime type
         $message = new MimePart($messageDesc);
         $message->type = 'text/html';
         $body = new MimeMessage();
         $body->setParts([$message]);
         $messageInstance = new Message();
         $messageInstance->addFrom(ApplicationSettingService::getSetting('application_notification_from'))->addTo($email)->setSubject($title)->setBody($body)->setEncoding('UTF-8');
         self::getMessageTransport()->send($messageInstance);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         return 'Error: ' . $e->getMessage() . "\n";
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Select layout
  * 
  * @param integer $layoutId
  * @param integer $userId
  * @return boolean|string
  */
 public function selectLayout($layoutId, $userId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $update = $this->update()->table('user_list')->set(['layout' => $layoutId])->where(['user_id' => $userId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // clear a cache
         $this->removeUserCache($userId);
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the edit user event
     UserEvent::fireUserEditEvent($userId, true);
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Generate a new activation code
  *
  * @param array $userInfo
  * @return boolean|string
  */
 public function generateActivationCode(array $userInfo)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $activationCode = $this->generateRandString();
         $update = $this->update()->table('user_list')->set(['activation_code' => $activationCode, 'date_edited' => date('Y-m-d')])->where(['user_id' => $userInfo['user_id']]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // clear a cache
         $this->removeUserCache($userInfo['user_id']);
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the user password reset request event
     UserEvent::fireUserPasswordResetRequestEvent($userInfo['user_id'], $userInfo, $activationCode);
     return true;
 }
 /**
  * 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;
 }
Ejemplo n.º 13
0
 /**
  * Init user localization
  *
  * @param \Zend\Mvc\MvcEvent $e
  * @return void
  */
 public function initUserLocalization(MvcEvent $e)
 {
     try {
         // get a router
         $router = $this->serviceLocator->get('router');
         $matches = $e->getRouteMatch();
         if (!$matches->getParam('language') || !array_key_exists($matches->getParam('language'), $this->localizations)) {
             if (!$matches->getParam('language')) {
                 // set default language
                 $router->setDefaultParam('language', $this->defaultLocalization['language']);
                 // remember user's chose language
                 $this->setUserLanguage($this->defaultLocalization['language']);
                 return;
             }
             // show a 404 page
             $matches->setParam('action', 'not-found');
             return;
         }
         // init an user localization
         if ($this->defaultLocalization['language'] != $matches->getParam('language')) {
             $this->serviceLocator->get('translator')->setLocale($this->localizations[$matches->getParam('language')]['locale']);
             LocalizationService::setCurrentLocalization($this->localizations[$matches->getParam('language')]);
         }
         Locale::setDefault($this->localizations[$matches->getParam('language')]['locale']);
         $router->setDefaultParam('language', $matches->getParam('language'));
         // remember user's choose language
         $this->setUserLanguage($matches->getParam('language'));
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
 }
 /**
  * Edit answer
  *
  * @param integer $answerId
  * @param array $formData
  *      string answer
  *      integer order
  * @return boolean|string
  */
 public function editAnswer($answerId, array $formData)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $update = $this->update()->table('poll_answer')->set($formData)->where(['id' => $answerId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the edit answer event
     PollEvent::fireEditAnswerEvent($answerId);
     return true;
 }
Ejemplo n.º 15
0
 /**
  * Add page rating
  *
  * @param integer $pageId
  * @param integer $widgetConnectionId
  * @param float $ratingValue
  * @param string $slug
  * @return string|float
  */
 public function addPageRating($pageId, $widgetConnectionId, $ratingValue, $slug = null)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $pageRatingId = 0;
         $remote = new RemoteAddress();
         $remote->setUseProxy(true);
         $visitorIp = inet_pton($remote->getIpAddress());
         // check the page's rating existing
         if (null == ($pageRateInfo = $this->getPageRatingInfo($pageId, $slug))) {
             // create a new page rating
             $insert = $this->insert()->into('page_rating')->values(['page_id' => $pageId, 'widget_connection' => $widgetConnectionId, 'slug' => $slug, 'total_rating' => $ratingValue, 'total_count' => 1]);
             $statement = $this->prepareStatementForSqlObject($insert);
             $statement->execute();
             $pageRatingId = $this->adapter->getDriver()->getLastGeneratedValue();
         } else {
             // update the existing page's rating
             $update = $this->update()->table('page_rating')->set(['total_rating' => new Expression('total_rating + ?', [$ratingValue]), 'total_count' => new Expression('total_count + 1')])->where(['page_id' => $pageId, 'slug' => $slug]);
             $statement = $this->prepareStatementForSqlObject($update);
             $statement->execute();
         }
         // add a track info
         $insert = $this->insert()->into('page_rating_track')->values(['rating_id' => !empty($pageRateInfo['id']) ? $pageRateInfo['id'] : $pageRatingId, 'ip' => $visitorIp, 'rating' => $ratingValue, 'created' => 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();
     }
     return !empty($pageRateInfo) ? ($pageRateInfo['total_rating'] + $ratingValue) / ($pageRateInfo['total_count'] + 1) : $ratingValue;
 }
 /**
  * Upload custom module
  *
  * @param array $formData
  *      string login required
  *      string password required
  *      array module required
  * @param string $host
  * @return boolean|string
  */
 public function uploadCustomModule(array $formData, $host)
 {
     $uploadResult = true;
     try {
         // create a tmp dir
         $tmpDirName = $this->generateTmpDir();
         ApplicationFileSystemUtility::createDir($tmpDirName);
         // unzip a custom module into the tmp dir
         $this->unzipFiles($formData['module']['tmp_name'], $tmpDirName);
         // check the module's config
         if (!file_exists($tmpDirName . '/config.php')) {
             throw new ApplicationException('Cannot define the module\'s config file');
         }
         // get the module's config
         $moduleConfig = (include $tmpDirName . '/config.php');
         // get the module's path
         $modulePath = !empty($moduleConfig['module_path']) ? $tmpDirName . '/' . $moduleConfig['module_path'] : null;
         // check the module existing
         if (!$modulePath || !file_exists($modulePath) || !is_dir($modulePath)) {
             throw new ApplicationException('Cannot define the module\'s path into the config file');
         }
         if (!file_exists($modulePath . '/' . $this->moduleInstallConfig) || !file_exists($modulePath . '/' . $this->moduleConfig)) {
             throw new ApplicationException('Module not found');
         }
         // check the module layout existing
         $moduleLayoutPath = null;
         if (!empty($moduleConfig['layout_path'])) {
             $moduleLayoutPath = $tmpDirName . '/' . $moduleConfig['layout_path'];
             if (!file_exists($moduleLayoutPath) || !is_dir($moduleLayoutPath)) {
                 throw new ApplicationException('Cannot define the module\'s layout path into the config file');
             }
         }
         // check the module existing into modules and layouts dirs
         $moduleName = basename($modulePath);
         $globalModulePath = ApplicationService::getModulePath(false) . '/' . $moduleName;
         $moduleLayoutName = $moduleLayoutPath ? basename($moduleLayoutPath) : null;
         $localModulePath = APPLICATION_ROOT . '/' . $globalModulePath;
         $localModuleLayout = $moduleLayoutName ? ApplicationService::getBaseLayoutPath() . '/' . $moduleLayoutName : null;
         if (file_exists($localModulePath) || $localModuleLayout && file_exists($localModuleLayout)) {
             throw new ApplicationException('Module already uploaded');
         }
         // upload the module via FTP
         $ftp = new ApplicationFtpUtility($host, $formData['login'], $formData['password']);
         $ftp->createDirectory($globalModulePath);
         $ftp->copyDirectory($modulePath, $globalModulePath);
         // upload the module's layout
         if ($moduleLayoutPath) {
             $globalModuleLayoutPath = basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getBaseLayoutPath(false) . '/' . $moduleLayoutName;
             $ftp->createDirectory($globalModuleLayoutPath);
             $ftp->copyDirectory($moduleLayoutPath, $globalModuleLayoutPath);
         }
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         $uploadResult = $e->getMessage();
     }
     // remove the tmp dir
     if (file_exists($tmpDirName)) {
         ApplicationFileSystemUtility::deleteFiles($tmpDirName, [], false, true);
     }
     // fire the upload custom module event
     if (true === $uploadResult) {
         ApplicationEvent::fireUploadCustomModuleEvent($moduleName);
     }
     return $uploadResult;
 }
Ejemplo n.º 17
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;
 }
 /**
  * Delete an image
  *
  * @param array $imageInfo
  *      integer id
  *      string name
  *      string description
  *      integer category_id
  *      string image
  *      string url
  *      integer created
  * @throws \Slideshow\Exception\SlideshowException
  * @return boolean|string
  */
 public function deleteImage(array $imageInfo)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $delete = $this->delete()->from('slideshow_image')->where(['id' => $imageInfo['id']]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $result = $statement->execute();
         // delete an image
         if (true !== ($imageDeleteResult = $this->deleteSlideShowImage($imageInfo['image']))) {
             throw new SlideshowException('Image deleting failed');
         }
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     $result = $result->count() ? true : false;
     // fire the delete image event
     if ($result) {
         SlideshowEvent::fireDeleteImageEvent($imageInfo['id']);
     }
     return $result;
 }
Ejemplo n.º 19
0
 /**
  * Clear css cache
  *
  * @return boolean
  */
 public static function clearCssCache()
 {
     try {
         return ApplicationFileSystem::deleteFiles(LayoutService::getLayoutCachePath());
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
Ejemplo n.º 20
0
 /**
  * Init guest identity
  *
  * @param object $authService
  * @return void
  */
 protected function initGuestIdentity($authService)
 {
     try {
         $this->userIdentity = [];
         $this->userIdentity['role'] = AclBaseModel::DEFAULT_ROLE_GUEST;
         $this->userIdentity['user_id'] = UserBaseModel::DEFAULT_GUEST_ID;
         $request = $this->serviceLocator->get('Request');
         // get language from cookie
         if (!$request instanceof ConsoleRequest) {
             $this->userIdentity['language'] = isset($request->getCookie()->{LocalizationModule::LOCALIZATION_COOKIE}) ? $request->getCookie()->{LocalizationModule::LOCALIZATION_COOKIE} : null;
         }
         $authService->getStorage()->write($this->userIdentity);
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
 }
 /**
  * Delete not active empty connections
  *
  * @return boolean|string
  */
 public function deleteNotActiveEmptyConnections()
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $predicate = new Predicate();
         $delete = $this->delete()->from('membership_level_connection')->where(['active' => self::MEMBERSHIP_LEVEL_CONNECTION_NOT_ACTIVE, $predicate->isNull('membership_id')]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return true;
 }
 /**
  * Edit role
  *
  * @param array $roleInfo
  * @param array $formData
  *      integer role_id - required
  *      integer cost - required
  *      integer lifetime - required
  *      string description - required
  *      string image - required
  * @param array $image
  * @return boolean|string
  */
 public function editRole($roleInfo, array $formData, array $image)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         if (empty($formData['active'])) {
             $formData['active'] = self::MEMBERSHIP_LEVEL_STATUS_NOT_ACTIVE;
         }
         $update = $this->update()->table('membership_level')->set($formData)->where(['id' => $roleInfo['id']]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         $this->uploadImage($roleInfo['id'], $image, $roleInfo['image']);
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the edit membership role event
     MembershipEvent::fireEditMembershipRoleEvent($roleInfo['id']);
     return true;
 }
Ejemplo n.º 23
0
 /**
  * Uninnstall custom layout
  *
  * @param array $layout
  *      integer id
  *      string name
  *      string type 
  *      string version 
  *      string vendor 
  *      string vendor_email 
  * @return boolean|string
  */
 public function uninstallCustomLayout(array $layout)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         // clear caches
         $this->clearLayoutCaches();
         $query = $this->delete('layout_list')->where(['id' => $layout['id']]);
         $statement = $this->prepareStatementForSqlObject($query);
         $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the uninstall custom layout event
     LayoutEvent::fireUninstallCustomLayoutEvent($layout['name']);
     return true;
 }
Ejemplo n.º 24
0
 /**
  * Delete role
  *
  * @param integer $roleId
  * @return boolean|string
  */
 public function deleteRole($roleId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $delete = $this->delete()->from('acl_role')->where(['type' => self::ROLE_TYPE_CUSTOM, 'id' => $roleId]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $result = $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the delete acl role event
     AclEvent::fireDeleteAclRoleEvent($roleId);
     return $result->count() ? true : false;
 }
 /**
  * Add a new category
  *
  * @param array $categoryInfo
  *      string name
  * @return boolean|string
  */
 public function addCategory(array $categoryInfo)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $insert = $this->insert()->into('miniphotogallery_category')->values(array_merge($categoryInfo, ['language' => $this->getCurrentLanguage()]));
         $statement = $this->prepareStatementForSqlObject($insert);
         $statement->execute();
         $insertId = $this->adapter->getDriver()->getLastGeneratedValue();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the add category event
     MiniPhotoGalleryEvent::fireAddCategoryEvent($insertId);
     return true;
 }
Ejemplo n.º 26
0
 /**
  * Set user's language
  *
  * @param integer $userId
  * @param string $language
  * @return boolean|string
  */
 public function setUserLanguage($userId, $language)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $update = $this->update()->table('user_list')->set(['language' => $language, 'date_edited' => date('Y-m-d')])->where(['user_id' => $userId]);
         $statement = $this->prepareStatementForSqlObject($update);
         $statement->execute();
         // clear a cache
         $this->removeUserCache($userId);
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return true;
 }
 /**
  * Edit comment
  *
  * @param array $commentInfo
  *  integer id
  *  integer page_id
  *  integer left_key
  *  integer right_key
  *  string slug
  * @param array $basicData
  *      integer active
  *      string comment
  *      string name optional
  *      string email optional
  * @return array|string
  */
 public function editComment($commentInfo, array $basicData)
 {
     try {
         $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         $hideSiblings = false;
         if ($basicData['active'] != self::COMMENT_STATUS_ACTIVE) {
             $hideSiblings = true;
             $basicData = array_merge($basicData, ['hidden' => self::COMMENT_STATUS_HIDDEN]);
         }
         $this->tableGateway->update($basicData, [$this->nodeId => $commentInfo['id']]);
         // add the hidden flag for all siblings comments
         if ($hideSiblings) {
             $filter = ['page_id' => $commentInfo['page_id'], 'slug' => $commentInfo['slug']];
             $result = $this->updateSiblingsNodes(['hidden' => self::COMMENT_STATUS_HIDDEN], $commentInfo[$this->left], $commentInfo[$this->right], null, $filter, false);
             if (true !== $result) {
                 $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
                 return $result;
             }
         }
         $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     $commentInfo = $this->getCommentInfo($commentInfo['id'], $commentInfo['page_id'], $commentInfo['slug']);
     // fire the edit comment event
     CommentEvent::fireEditCommentEvent($commentInfo['id']);
     return $commentInfo;
 }
 /**
  * Edit exchange rates
  *
  * @param array $exchangeRatesInfo
  *      integer id
  *      string code
  *      sting name
  *      float rate
  * @param array $exchangeRates
  *      float rate
  * @param integer $currencyId
  * @return boolean|string
  */
 public function editExchangeRates(array $exchangeRatesInfo, array $exchangeRates, $currencyId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         // delete old rates
         $this->clearExchangeRates();
         // insert new rates
         foreach ($exchangeRates as $code => $rate) {
             // skip empty values
             if (!(double) $rate) {
                 continue;
             }
             $insert = $this->insert()->into('payment_exchange_rate')->values(['rate' => $rate, 'currency' => $exchangeRatesInfo[$code]['id']]);
             $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();
     }
     // fire the edit exchange rates event
     PaymentEvent::fireEditExchangeRatesEvent($currencyId);
     return true;
 }
 /**
  * Update siblings nodes
  *
  * @param array $data
  * @param integer $leftKey
  * @param integer $rightKey
  * @param integer $level
  * @param array $filter
  * @param boolean $useTransaction
  * @return boolean|string
  */
 public function updateSiblingsNodes(array $data, $leftKey, $rightKey, $level = null, array $filter = [], $useTransaction = true)
 {
     try {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         }
         $baseFilter = array_merge([(new Predicate())->greaterThan($this->left, $leftKey), (new Predicate())->lessThan($this->right, $rightKey)], $filter);
         if ($level) {
             $baseFilter[$this->level] = $level;
         }
         $this->tableGateway->update($data, $baseFilter);
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         }
     } catch (Exception $e) {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         }
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return true;
 }
 /**
  * Delete action log
  *
  * @param integer $actionId
  * @return boolean|string
  */
 public function deleteActionLog($actionId)
 {
     try {
         $this->adapter->getDriver()->getConnection()->beginTransaction();
         $delete = $this->delete()->from('action_tracker_log')->where(['id' => $actionId]);
         $statement = $this->prepareStatementForSqlObject($delete);
         $result = $statement->execute();
         $this->adapter->getDriver()->getConnection()->commit();
     } catch (Exception $e) {
         $this->adapter->getDriver()->getConnection()->rollback();
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     // fire the delete action log event
     ActionTrackerEvent::fireDeleteActionEvent($actionId);
     return $result->count() ? true : false;
 }