/** * 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; if (in_array($ratingmode, array("like_dislike", "stars"))) { $info['rating'] = $this->ratingRepository->findRatingInfos($filter, $ratingmode)[0]; if ($ratingmode == "like_dislike") { if ($info['rating']['likes'] > 0) { $info['rating']['likes_percent'] = round($info['rating']['likes'] / $info['rating']['count'] * 100); } if ($info['rating']['dislikes'] > 0) { $info['rating']['dislikes_percent'] = round($info['rating']['dislikes'] / $info['rating']['count'] * 100); } } if ($extended) { $infosPerRating = $this->ratingRepository->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 ($ratingmode == "stars" && !$info['rating']['average']) { $info['rating']['average'] = 0; } if ($extended) { $info['rating']['extended'] = $extendedInfo; } if (TRUE === empty($as)) { return $info; } else { $this->templateVariableContainer->add($as, $info); } }
/** * action show * * @param array $filter filter * @param string $settings settings * @return void */ public function showAction($filter = [], $settings = NULL) { // init action arrays and booleans $messages = []; $errors = []; $info = []; $isModerator = false; $isViewable = false; $isRateable = false; $isUnrateable = false; // overwrite settings $this->settings = $this->helperService->overwriteSettings($this->settings, $settings); // get configuration if (isset($filter['uid_foreign']) && is_numeric($filter['uid_foreign']) && $filter['uid_foreign'] > 0 && isset($filter['tablenames']) && $filter['tablenames'] != "") { $configuration = ["uid_foreign" => $filter['uid_foreign'], "tablenames" => $filter['tablenames']]; } else { $configuration = $this->helperService->getConfiguration("rating"); } // check and get logged in user if (TRUE === $this->accessControllService->hasLoggedInFrontendUser()) { $feUser = $this->frontendUserRepository->findByUid($this->accessControllService->getFrontendUserUid()); } if (!$this->settings['onlyLoggedInUsersCanSeeRatings'] || $this->settings['onlyLoggedInUsersCanSeeRatings'] && is_object($feUser)) { $isViewable = true; } if (!$this->settings['onlyLoggedInUsersCanRate'] || $this->settings['onlyLoggedInUsersCanRate'] && $feUser) { $isRateable = true; if ($configuration && $this->settings['allowOnlyOneRatingPerUserIfPossible'] && is_object($feUser)) { $items = $this->ratingRepository->findByFilter(['uid_foreign' => $configuration['uid_foreign'], 'tablenames' => $configuration['tablenames'], 'feUser' => $feUser->getUid()], NULL, NULL, NULL, "all"); if ($items->count() > 0) { $isRateable = false; $rating = $items->getFirst(); if (is_object($rating) && $this->settings['usersCanDeleteOrRerateOwnRatings']) { $isUnrateable = true; } } } } // if configuration is valid if ($configuration && $isViewable) { // if user is logged in if ($feUser) { $this->view->assign('feUser', $feUser); } else { $this->view->assign('feUser', NULL); } $filter['uid_foreign'] = $configuration['uid_foreign']; $filter['tablenames'] = $configuration['tablenames']; // get item count //$count = $this->ratingRepository->findByFilter($filter,$orderings,NULL,NULL,"all")->count(); // get rating info if (in_array($this->settings['ratingMode'], ["like_dislike", "stars"])) { $info['rating'] = $this->ratingRepository->findRatingInfos(["uid_foreign" => $configuration['uid_foreign'], "tablenames" => $configuration['tablenames']], $this->settings['ratingMode'])[0]; if ($this->settings['ratingMode'] == "like_dislike") { if ($info['rating']['likes'] > 0) { $info['rating']['likes_percent'] = round($info['rating']['likes'] / $info['rating']['count'] * 100); } if ($info['rating']['dislikes'] > 0) { $info['rating']['dislikes_percent'] = round($info['rating']['dislikes'] / $info['rating']['count'] * 100); } } } if ($this->settings['ratingMode'] == "stars" && !$info['rating']['average']) { $info['rating']['average'] = 0; } $this->view->assign('configuration', $configuration); $this->view->assign('fields', $this->fields); $this->view->assign('info', $info); $this->view->assign('rating', $rating); $this->view->assign('uri', $this->uriBuilder->getRequest()->getRequestUri()); $this->view->assign('ajaxSettings', $this->helperService->encrypt(json_encode($this->settings))); $this->view->assign('isViewable', $isViewable); $this->view->assign('isRateable', $isRateable); $this->view->assign('isUnrateable', $isUnrateable); $this->view->assign('settings', $this->settings); $this->view->assign('action', 'show'); } else { $this->view = NULL; } }