Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php |
— | — | @@ -0,0 +1,114 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to delete objects stored by the Education Program extension. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiRefreshEducation.php |
| 10 | + * @ingroup Education Program |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiDeleteEducation extends ApiBase { |
| 17 | + |
| 18 | + /** |
| 19 | + * Maps class names to values for the type parameter. |
| 20 | + * |
| 21 | + * @since 0.1 |
| 22 | + * |
| 23 | + * @var array |
| 24 | + */ |
| 25 | + protected static $typeMap = array( |
| 26 | + 'org' => 'EPOrg', |
| 27 | + 'course' => 'EPCourse', |
| 28 | + 'term' => 'EPTerm', |
| 29 | + 'student' => 'EPStudent', |
| 30 | + ); |
| 31 | + |
| 32 | + public function execute() { |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + |
| 35 | + if ( $this->getUser()->isBlocked() ) { |
| 36 | + $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
| 37 | + } |
| 38 | + |
| 39 | + $c = self::$typeMap[$params['type']]; |
| 40 | + $c::updateSummaryFields( null, array( 'id' => $params['ids'] ) ); |
| 41 | + |
| 42 | + $this->getResult()->addValue( |
| 43 | + null, |
| 44 | + 'success', |
| 45 | + true |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Get the User being used for this instance. |
| 51 | + * ApiBase extends ContextSource as of 1.19. |
| 52 | + * |
| 53 | + * @since 0.1 |
| 54 | + * |
| 55 | + * @return User |
| 56 | + */ |
| 57 | + public function getUser() { |
| 58 | + return method_exists( 'ApiBase', 'getUser' ) ? parent::getUser() : $GLOBALS['wgUser']; |
| 59 | + } |
| 60 | + |
| 61 | + public function needsToken() { |
| 62 | + return true; |
| 63 | + } |
| 64 | + |
| 65 | + public function mustBePosted() { |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + public function getAllowedParams() { |
| 70 | + return array( |
| 71 | + 'ids' => array( |
| 72 | + ApiBase::PARAM_TYPE => 'integer', |
| 73 | + ApiBase::PARAM_REQUIRED => true, |
| 74 | + ApiBase::PARAM_ISMULTI => true, |
| 75 | + ), |
| 76 | + 'type' => array( |
| 77 | + ApiBase::PARAM_TYPE => array_keys( self::$typeMap ), |
| 78 | + ApiBase::PARAM_REQUIRED => true, |
| 79 | + ApiBase::PARAM_ISMULTI => false, |
| 80 | + ), |
| 81 | + 'token' => null, |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getParamDescription() { |
| 86 | + return array( |
| 87 | + 'ids' => 'The IDs of the reviews to refresh', |
| 88 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 89 | + 'type' => 'Type of object to delete.', |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + public function getDescription() { |
| 94 | + return array( |
| 95 | + 'API module for refreshing (rebuilding) summary data of objects parts of the Education Program extension.' |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + public function getPossibleErrors() { |
| 100 | + return array_merge( parent::getPossibleErrors(), array( |
| 101 | + ) ); |
| 102 | + } |
| 103 | + |
| 104 | + protected function getExamples() { |
| 105 | + return array( |
| 106 | + 'api.php?action=refresheducation&ids=42&type=course', |
| 107 | + 'api.php?action=refresheducation&ids=4|2&type=student', |
| 108 | + ); |
| 109 | + } |
| 110 | + |
| 111 | + public function getVersion() { |
| 112 | + return __CLASS__ . ': $Id$'; |
| 113 | + } |
| 114 | + |
| 115 | +} |
Property changes on: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 116 | + native |
Added: svn:keywords |
2 | 117 | + Id |