/** * * @param PCRequest $request */ public function siteAction($request) { $param = $request->getParams(); $hostName = $request->dequeuePathComponent(); if (isset($hostName)) { $site = PCMapperWebsite::getSiteWithDomain($hostName); if (isset($site) == FALSE) { throw new PCExceptionController("Page not found", 404); } $identifier = $site->getIdentifier(); throw new PCExceptionRedirection("/sites/site?id=$identifier"); } if (isset($param['id']) == FALSE) throw new PCExceptionController("Page not found", 404); /** @value PCModelWebsite $site */ $site = PCModelManager::fetchObjectWithIdentifier(PCModelWebsite::getMapper(), $param['id'], NULL, TRUE); if (!isset($site)) { throw new PCExceptionController("Page not found", 404); } if ($site->cacheIsExpired()) { $site = PCMapperWebsite::recacheSiteReview($site); if (isset($site) == FALSE) { throw new PCExceptionController('Error caching', 500); } } $result = array(); $result['siteCategory'] = PCMapperCategory::nameFromIdentifier($site->getCategory()); $result['site_id'] = $site->getIdentifier(); $result['siteHost'] = $site->getUrl(); $result['reliability'] = $site->getReliability(); $result['contents'] = $site->getContents(); $result['usability'] = $site->getUsability(); $result['averageVote'] = $site->getVote(); $result['votesCount'] = $site->getNumber_of_votes(); $result['dateAdded'] = $site->getDate_added()->format("Y-m-d"); $reviews = PCMapperReview::getReviewsWithSiteIdentifier($site->getIdentifier(), 0); $reviewsList = array(); foreach ($reviews as $r) { $reviewArray = array(); $reviewArray["vote"] = sprintf("%.1f", $r->getVote()); $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $r->getUserIdentifier(), NULL, TRUE); $reviewArray["user"] = $user->getUsername(); $reviewArray["date_added"] = $r->getDate_added()->format("Y-m-d"); $reviewArray["comment"] = $r->getComment(); $reviewArray["reviewId"] = $r->getIdentifier(); $reviewArray["userId"] = $r->getUserIdentifier(); $reviewArray['reliability'] = sprintf("%.1f", $r->getReliabilityVote()); $reviewArray['contents'] = sprintf("%.1f", $r->getContentsVote()); $reviewArray['usability'] = sprintf("%.1f", $r->getUsabilityVote()); $reviewsList[] = $reviewArray; } $result['reviews'] = $reviewsList; $result['title'] = "WebSherpa - " . $site->getUrl(); return PCRendererHTML::rendererForView('host', $result); }
/** * * @param PCRequest $request * @return PCRouterRoute */ private function getRouteForRequest($request) { $itemTmp = $request->dequeuePathComponent(); $item = strtolower($itemTmp); foreach ($this->typesRegexes as $key => $value) { if (preg_match($value, $request->getDomainName()) === 1) { $routes = $this->routes[$key]; //if(strcmp($item, "")==0) $item = "home"; //else $item = strtolower($item); return $routes[$item]; } } }