forked from MoeMoeFish/MoegirlRating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoegirlRating.MRRateApi.php
71 lines (53 loc) · 1.67 KB
/
MoegirlRating.MRRateApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
class MRRateApi extends ApiBase {
private $logger;
public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
parent::__construct( $mainModule, $moduleName, $modulePrefix );
$this->logger = new MRLogging( __FILE__ );
}
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' => 0,
'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' => 0,
'message' => '服务器错误,请稍后再试'
));
}
return true;
}
public function getDescription() {
}
public function getAllowedParams() {
return array(
'wikiId' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true
),
'score' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true)
);
}
public function getExample() {
}
}