/**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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();
 }
 /**
  * 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']]]);
     }
 }
Exemplo n.º 5
0
 /**
  * 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'])]]);
     }
 }
 /**
  * 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;
 }
 /**
  * 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)]]);
         }
     }
 }