Пример #1
0
 /**
  * action rate
  *
  * @param array $rate form data
  * @param bool $ajax is ajax request?
  * @param string $settings settings
  * @return void
  */
 public function rateAction($rate = NULL, $ajax = FALSE, $settings = NULL)
 {
     // init action arrays and booleans
     $messages = [];
     $errors = [];
     // overwrite settings
     $this->settings = $this->helperService->overwriteSettings($this->settings, $settings);
     // check and get logged in user
     if (TRUE === $this->accessControllService->hasLoggedInFrontendUser()) {
         $feUser = $this->frontendUserRepository->findByUid($this->accessControllService->getFrontendUserUid());
     }
     // no errors -> add rating
     if (!count($errors)) {
         // set item values
         $item = $this->objectManager->get('DCNGmbH\\MooxComment\\Domain\\Model\\Rating');
         $item->setUidForeign($rate['uid_foreign']);
         $item->setTitleForeign($rate['title_foreign']);
         $item->setUrlForeign($rate['url_foreign']);
         $item->setTablenames($rate['tablenames']);
         if ($feUser) {
             $item->setFeUser($feUser);
         }
         $item->setConfirmed(time());
         $item->setTitle($rate['title_foreign'] . " | Rating: " . trim($rate['rating']));
         $item->setRating(trim($rate['rating']));
         // set pid (bugfix ignoring global setting);
         if (!$item->getPid()) {
             $item->setPid($this->settings['storagePid']);
         }
         // save item to database and reload
         $this->ratingRepository->add($item);
         $this->persistenceManager->persistAll();
         $item->setCrdate($GLOBALS['EXEC_TIME']);
         // add message
         $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi2.action_rate', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi2.action_rate.success', $this->extensionName), "type" => FlashMessage::OK];
     }
     // unset register object
     unset($rate);
     // end request
     if ($ajax) {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
             header("HTTP/1.0 200 Ok");
             exit;
         }
     } else {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
         }
     }
 }
Пример #2
0
 /**
  * action add
  *
  * @param array $add form data
  * @param bool $ajax is ajax request?
  * @param string $settings settings
  * @return void
  */
 public function addAction($add = NULL, $ajax = FALSE, $settings = NULL)
 {
     // init action arrays and booleans
     $messages = [];
     $errors = [];
     $moderators = [];
     $confirmed = false;
     $isModerator = false;
     $isConfirmable = false;
     // overwrite settings
     $this->settings = $this->helperService->overwriteSettings($this->settings, $settings);
     // get moderators
     if ($this->settings['feGroupsAdmin']) {
         $feGroupsAdmin = explode(",", $this->settings['feGroupsAdmin']);
         if (count($feGroupsAdmin)) {
             $usergroups = [];
             foreach ($this->frontendUserGroupRepository->findByUidList($feGroupsAdmin) as $usergroup) {
                 $usergroups[] = $usergroup;
             }
             $moderators = $this->frontendUserRepository->findByUsergroups($usergroups);
         }
     }
     // check and get logged in user
     if (TRUE === $this->accessControllService->hasLoggedInFrontendUser()) {
         $feUser = $this->frontendUserRepository->findByUid($this->accessControllService->getFrontendUserUid());
         if (is_object($feUser) && count($moderators)) {
             // check if user is moderator
             foreach ($moderators as $moderator) {
                 if ($feUser->getUid() == $moderator->getUid()) {
                     $isModerator = true;
                     $isConfirmable = true;
                     break;
                 }
             }
         }
     }
     // check fields
     $this->helperService->checkFields($this->fields, $add, $messages, $errors);
     // no errors -> add comment
     if (!count($errors)) {
         // set item values
         $item = $this->objectManager->get('DCNGmbH\\MooxComment\\Domain\\Model\\Comment');
         $item->setUidForeign($add['uid_foreign']);
         $item->setTitleForeign($add['title_foreign']);
         $item->setUrlForeign($add['url_foreign']);
         $item->setTablenames($add['tablenames']);
         if (!$feUser) {
             $item->setName(trim($add['name']));
             $item->setEmail(trim($add['email']));
             if ($this->settings['autoConfirmPublicUsers']) {
                 $item->setConfirmed(time());
                 $confirmed = true;
             }
         } else {
             $item->setName($feUser->getName());
             $item->setEmail($feUser->getEmail());
             $item->setFeUser($feUser);
             if ($this->settings['autoConfirmLoggedInUsers'] || $isConfirmable) {
                 $item->setConfirmed(time());
                 $confirmed = true;
             }
         }
         $item->setTitle(trim($add['title']));
         $item->setComment(trim($add['comment']));
         // set pid (bugfix ignoring global setting);
         if (!$item->getPid()) {
             $item->setPid($this->settings['storagePid']);
         }
         // save item to database and reload
         $this->commentRepository->add($item);
         $this->persistenceManager->persistAll();
         $item->setCrdate($GLOBALS['EXEC_TIME']);
         // need to send notifications?
         if (!$isConfirmable && count($moderators) && $this->settings['newEntryEmailTemplate'] > 0) {
             // load mail template
             $template = $this->templateRepository->findByUid($this->settings['newEntryEmailTemplate']);
             // if mail template exists
             if ($template) {
                 // set user mail field
                 if ($feUser) {
                     $user = [];
                     foreach (["username", "first_name", "last_name", "auto_name", "email", "gender"] as $fieldname) {
                         $getMethod = "get" . GeneralUtility::underscoredToUpperCamelCase($fieldname);
                         if (method_exists($feUser, $getMethod)) {
                             $user[$fieldname] = $feUser->{$getMethod}();
                         }
                     }
                 } else {
                     $user['auto_name'] = $item->getName();
                     $user['email'] = $item->getEmail();
                 }
                 $subject = $this->helperService->prepareMailSubject($template->getSubject(), $user);
                 $deleteUrl = $this->uriBuilder->reset()->setNoCache(true)->setTargetPageUid($GLOBALS["TSFE"]->id)->setCreateAbsoluteUri(TRUE)->uriFor('delete', array("uid" => $item->getUid(), "hash" => $item->getHash()), 'Pi1', 'MooxComment', 'Pi1');
                 if (!$item->getConfirmed()) {
                     $confirmUrl = $this->uriBuilder->reset()->setNoCache(true)->setTargetPageUid($GLOBALS["TSFE"]->id)->setCreateAbsoluteUri(TRUE)->uriFor('confirm', array("uid" => $item->getUid(), "hash" => $item->getHash()), 'Pi1', 'MooxComment', 'Pi1');
                 }
                 foreach ($moderators as $moderator) {
                     if ($moderator->getEmail() != "") {
                         // set user mail field
                         $receiver = [];
                         foreach (["username", "first_name", "last_name", "auto_name", "email", "gender"] as $fieldname) {
                             $getMethod = "get" . GeneralUtility::underscoredToUpperCamelCase($fieldname);
                             if (method_exists($moderator, $getMethod)) {
                                 $receiver[$fieldname] = $moderator->{$getMethod}();
                             }
                         }
                         // set info mail array
                         $mail = ['sender_name' => $this->settings['notificationsSenderName'], 'sender_address' => $this->settings['notificationsSenderAddress'], 'receiver_name' => $moderator->getFirstName() != "" ? $moderator->getFirstName() . " " . $moderator->getLastName() : $moderator->getLastName(), 'receiver_address' => $moderator->getEmail(), 'subject' => $subject, 'pid' => $GLOBALS["TSFE"]->id, 'confirm-url' => $confirmUrl, 'delete-url' => $deleteUrl, 'user' => $user, 'receiver' => $receiver, 'item' => ['name' => $item->getName(), 'email' => $item->getEmail(), 'title' => $item->getTitle(), 'comment' => $item->getComment()], 'target' => ['type' => $item->getTablenames(), 'uid' => $item->getUidForeign(), 'title' => $item->getTitleForeign(), 'url' => $item->getUrlForeign()]];
                         // set mail body
                         $mail['body'] = $this->helperService->prepareMailBody($template, $mail);
                         // send mail
                         $this->helperService->sendMail($mail);
                     }
                 }
             } else {
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-warning-sign icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.error.no_template', $this->extensionName), "type" => FlashMessage::ERROR];
             }
         }
         // add message
         if ($confirmed) {
             $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.success', $this->extensionName), "type" => FlashMessage::OK];
         } else {
             $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi1.action_add.success_moderated', $this->extensionName), "type" => FlashMessage::OK];
         }
     }
     // unset register object
     unset($add);
     // end request
     if ($ajax) {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
             header("HTTP/1.0 200 Ok");
             exit;
         }
     } else {
         if (count($messages)) {
             // set flash messages
             $this->helperService->setFlashMessages($this, $messages);
         } else {
             $this->view = NULL;
         }
     }
 }