public function execute()
 {
     $ratingId = 0;
     $user = $this->getUser();
     if (!isset($user)) {
         $this->logger->debug(__LINE__, 'User is empty');
         throw new Exception('User is empty');
     }
     $wikiId = (int) $this->getMain()->getVal('wikiId');
     $score = $this->getMain()->getVal('score');
     if (!is_int($wikiId)) {
         $this->logger->error(__LINE__, 'wikiId 格式不正确');
         $this->getResult()->addValue(null, $this->getModuleName(), array('isSuccess' => false, 'message' => 'wikiId 格式不正确'));
         return true;
     }
     $ratingController = new RatingController($ratingId, $wikiId, $user, $this->getRequest()->getIP());
     try {
         $result = $ratingController->rate($score);
         $this->getResult()->addValue(null, $this->getModuleName(), $result);
     } catch (Exception $ex) {
         $this->logger->error(__LINE__, 'Cannot get the rating score, wikiId %d', $wikiId);
         $this->getResult()->addValue(null, $this->getModuleName(), array('isSuccess' => false, 'message' => '服务器错误,请稍后再试'));
     }
     return true;
 }
Exemple #2
0
<?php

header('Content-type: application/json');
require_once "./RatingController.class.php";
require_once "./RatingService.class.php";
$ratingId = 0;
// The entrance
$ratingService = new RatingService();
$ratingService->setRatingId($ratingId);
$controller = new RatingController();
$controller->setRatingService($ratingService);
if ($_POST["action"] != null && $_POST["action"] === "rate") {
    $data = $controller->rate();
} elseif (isset($_GET["getscore"])) {
    $data = $controller->getScore();
} else {
    $data = $controller->actionError();
}
echo json_encode($data);