public function execute() { $ratingId = 0; $user = $this->getUser(); if (!isset($user)) { $this->logger->debug(__LINE__, "Can't get user"); throw new Exception('Can\'t get user'); } $wikiId = (int) $this->getMain()->getVal('wikiId'); 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->getScore(); $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; }
<?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);