Ejemplo n.º 1
0
 /**
  * action delete
  *
  * @param int $uid uid
  * @param string $hash hash
  * @param bool $ajax is ajax request?
  * @param string $settings settings
  * @return void
  */
 public function deleteAction($uid = 0, $hash = "", $ajax = FALSE, $settings = NULL)
 {
     if ($uid > 0) {
         $item = $this->reviewRepository->findByUid($uid);
         if (is_object($item)) {
             if ($hash == $item->getHash()) {
                 $redirectUri = $item->getUrlForeign() . "#reviewform";
                 // remove item from database
                 $this->reviewRepository->remove($item);
                 $this->persistenceManager->persistAll();
                 // add message
                 $messages[] = ["icon" => '<span class="glyphicon glyphicon-ok icon-alert" aria-hidden="true"></span>', "title" => LocalizationUtility::translate(self::LLPATH . 'pi3.action_delete', $this->extensionName), "text" => LocalizationUtility::translate(self::LLPATH . 'pi3.action_delete.success', $this->extensionName), "type" => FlashMessage::OK];
                 // set flash messages
                 $this->helperService->setFlashMessages($this, $messages);
                 // end request
                 if (!$ajax) {
                     // redirect to target url
                     $this->redirectToUri($redirectUri);
                 }
             }
         } else {
             $this->view = NULL;
         }
     } else {
         $this->view = NULL;
     }
 }
 /**
  * Get Info
  *
  * @param int $uid
  * @param string $tablenames
  * @param string $ratingmode
  * @param bool $extended
  * @param string $as output variable	
  * @return array info
  */
 public function render($uid, $tablenames, $ratingmode = "like_dislike", $extended = FALSE, $as = NULL)
 {
     $info = [];
     $extendedInfo = [];
     $filter['uid_foreign'] = $uid;
     $filter['tablenames'] = $tablenames;
     $filter['confirmed'] = true;
     // get items
     $items = $this->reviewRepository->findByFilter($filter, NULL, NULL, NULL, "all");
     if (in_array($ratingmode, ["like_dislike", "stars"])) {
         $info['rating'] = $this->reviewRepository->findRatingInfos($filter, $ratingmode)[0];
         if ($ratingmode == "like_dislike") {
             if ($info['rating']['likes'] > 0) {
                 $info['rating']['likes_percent'] = round($info['rating']['count'] / $info['rating']['likes'] * 100);
             }
             if ($info['rating']['dislikes'] > 0) {
                 $info['rating']['dislikes_percent'] = round($info['rating']['count'] / $info['rating']['dislikes'] * 100);
             }
         }
         if ($extended) {
             $infosPerRating = $this->reviewRepository->findInfosPerRating($filter, $ratingmode);
             if (is_array($infosPerRating)) {
                 foreach ($infosPerRating as $infoPerRating) {
                     $extendedInfo[] = ["rating" => $infoPerRating['rating'], "count" => $infoPerRating['count'], "percent" => round($infoPerRating['count'] / $info['rating']['count'] * 100)];
                 }
             }
         }
     }
     if (!$info['rating']['average']) {
         $info['rating']['average'] = 0;
     }
     if ($extended) {
         $info['rating']['extended'] = $extendedInfo;
     }
     $info['count'] = $items->count();
     if (TRUE === empty($as)) {
         return $info;
     } else {
         $this->templateVariableContainer->add($as, $info);
     }
 }