Exemplo n.º 1
0
    /**
     * 
     * @param PCRequest $request
     */
    public function userAction($request) {
        $param = $request->getParams();
        if (isset($param['id']) == FALSE)
            throw new PCExceptionController("Page not found", 404);

        $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $param['id'], NULL, TRUE);

        if (isset($user) == FALSE)
            throw new PCExceptionController("Page not found", 404);


        $result = array();

        $user_identifier = $user->getIdentifier();
        $user_name = $user->getUsername();
        $result['user_id'] = $user_identifier;
        $result['userName'] = $user_name;
        $result['userFrom'] = $user->getCreation_date()->format("Y-m-d H:i");
        
        
        $avgTotReviews = PCMapperReview::getUserAverageAndCount($user_identifier);
        $result['averageVote'] = sprintf("%.1f",$avgTotReviews['avg']);
        $result['votesCount'] = $avgTotReviews['tot'];
        $result['reliability'] = $avgTotReviews['reliability'];
        $result['contents'] = $avgTotReviews['contents'];
        $result['usability'] = $avgTotReviews['usability'];

        $reviewsList = array();
        $reviews = PCMapperReview::getReviewsWithUserIdentifier($user_identifier, 0); 

        foreach ($reviews as $r) {
            $reviewArray = array();

            $site = PCModelManager::fetchObjectWithIdentifier(PCModelWebsite::getMapper(), $r->getSiteIdentifier(), NULL, TRUE);

            $reviewArray["vote"] = sprintf("%.1f",$r->getVote());
            $reviewArray["site"] = $site->getUrl();
            $reviewArray["date_added"] = $r->getDate_added()->format("Y-m-d");
            $reviewArray["comment"] = $r->getComment();
            $reviewArray["siteId"] = $site->getIdentifier();
            $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 - " . $user_name;
        return PCRendererHTML::rendererForView('host', $result);
    }
Exemplo n.º 2
0
    /**
     * Restituisce le recensioni legate ad un sito oppure ad un utente
     * @param PCRequest $request
     */
    public function getSiteReviewsAction($request) {
        $params = $request->getParams();
        
        if( isset($params['offset']) == FALSE) return new PCRendererJSON(array("error" => "missing param 'offset'"), 400);
        
        $offset = $params['offset'];
        
        if( isset($params['site_id'])){
            $site_id = $params['site_id'];
            
            $result = array();
            
            $reviews = PCMapperReview::getReviewsWithSiteIdentifier($site_id, $offset);
           
            foreach ($reviews as $r) {
                $tmp = array();
                $tmp["vote"] = sprintf("%.1f", $r->getVote());
                //XXX pensare ad un modo più efficente per risolvere gli identificativi
                $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $r->getUserIdentifier(), NULL, TRUE);
                $tmp["user"] = $user->getUsername();
                $tmp["date_added"] = $r->getDate_added()->format("Y-m-d");
                $tmp["comment"] = $r->getComment();
                $tmp["reviewId"] = $r->getIdentifier();
                $tmp["userId"] = $user->getIdentifier();
                $tmp['reliability'] = sprintf("%.1f", $r->getReliabilityVote());
                $tmp['contents'] = sprintf("%.1f", $r->getContentsVote());
                $tmp['usability'] = sprintf("%.1f", $r->getUsabilityVote());
                $result[] = $tmp;
            }
            return new PCRendererJSON($result);
        }
        
        if (isset($params['user_id'])) {
            $user_id = $params['user_id'];
            $result = array();

            $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $user_id, NULL, TRUE);
            if (!isset($user))
                new PCRendererJSON(array("error" => "wrong user identifier"), 400);

           // $user_name = $user->getUsername();

            $reviews = PCMapperReview::getReviewsWithUserIdentifier($user_id, $offset);
           
            foreach ($reviews as $r) {
                $tmp = array();
                
                //XXX pensare ad un modo più efficente per risolvere gli identificativi
                $site = PCModelManager::fetchObjectWithIdentifier(PCModelWebsite::getMapper(), $r->getSiteIdentifier(), NULL, TRUE);

                $tmp["vote"] = sprintf("%.1f",$r->getVote());
                $tmp["site"] = $site->getDomain();
                $tmp["date_added"] = $r->getDate_added()->format("Y-m-d");
                $tmp["comment"] = $r->getComment();
                $tmp["reviewId"] = $r->getIdentifier();
                $tmp["siteId"] = $site->getIdentifier();
                $tmp['reliability'] = sprintf("%.1f",$r->getReliabilityVote());
                $tmp['contents'] = sprintf("%.1f",$r->getContentsVote());
                $tmp['usability'] = sprintf("%.1f",$r->getUsabilityVote());
                $result[] = $tmp;
            }
            return new PCRendererJSON($result);
        }

        return new PCRendererJSON(array("error" => "missing param 'site_id' or 'user_id"), 400);
    }