Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| SuggestionList | |
0.00% |
0 / 42 |
|
0.00% |
0 / 12 |
506 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
72 | |||
| newFromRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDisplayNameMessage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getInfo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOwner | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| isPublic | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStartTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEndTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace ContentTranslation; |
| 4 | |
| 5 | use MediaWiki\Context\IContextSource; |
| 6 | use MediaWiki\Language\RawMessage; |
| 7 | use MediaWiki\Message\Message; |
| 8 | use MediaWiki\Title\Title; |
| 9 | |
| 10 | class SuggestionList { |
| 11 | // List types. Make sure to add them in ext.cx.suggestionlist.js to |
| 12 | // achieve wanted display order. |
| 13 | public const TYPE_DEFAULT = 0; |
| 14 | public const TYPE_FEATURED = 1; |
| 15 | public const TYPE_DISCARDED = 2; |
| 16 | public const TYPE_FAVORITE = 3; |
| 17 | public const TYPE_CATEGORY = 4; |
| 18 | |
| 19 | /** @var int|null */ |
| 20 | protected $id; |
| 21 | /** @var string */ |
| 22 | protected $name; |
| 23 | /** @var string|null */ |
| 24 | protected $info; |
| 25 | /** @var int|null */ |
| 26 | protected $owner; |
| 27 | /** @var string|null */ |
| 28 | protected $startTime; |
| 29 | /** @var string|null */ |
| 30 | protected $endTime; |
| 31 | /** @var int|null */ |
| 32 | protected $type; |
| 33 | /** @var bool|null */ |
| 34 | protected $public; |
| 35 | |
| 36 | public function __construct( array $params ) { |
| 37 | if ( isset( $params['id'] ) ) { |
| 38 | $this->id = (int)$params['id']; |
| 39 | } |
| 40 | |
| 41 | $this->name = (string)$params['name']; |
| 42 | |
| 43 | if ( isset( $params['info'] ) ) { |
| 44 | $this->info = (string)$params['info']; |
| 45 | } |
| 46 | |
| 47 | if ( isset( $params['owner'] ) ) { |
| 48 | $this->owner = (int)$params['owner']; |
| 49 | } |
| 50 | |
| 51 | if ( isset( $params['public'] ) ) { |
| 52 | $this->public = (bool)$params['public']; |
| 53 | } |
| 54 | |
| 55 | if ( isset( $params['startTime'] ) ) { |
| 56 | $this->startTime = $params['startTime']; |
| 57 | } |
| 58 | |
| 59 | if ( isset( $params['endTime'] ) ) { |
| 60 | $this->endTime = $params['endTime']; |
| 61 | } |
| 62 | |
| 63 | if ( isset( $params['type'] ) ) { |
| 64 | $this->type = $params['type']; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param \stdClass $row |
| 70 | * @return self |
| 71 | */ |
| 72 | public static function newFromRow( $row ) { |
| 73 | $params = [ |
| 74 | 'id' => $row->cxl_id, |
| 75 | 'name' => $row->cxl_name, |
| 76 | 'info' => $row->cxl_info, |
| 77 | 'owner' => $row->cxl_owner, |
| 78 | 'startTime' => $row->cxl_start_time, |
| 79 | 'endTime' => $row->cxl_end_time, |
| 80 | 'type' => $row->cxl_type, |
| 81 | ]; |
| 82 | |
| 83 | return new self( $params ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return int|null |
| 88 | */ |
| 89 | public function getId() { |
| 90 | return $this->id; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return string|null |
| 95 | */ |
| 96 | public function getName() { |
| 97 | return $this->name; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param IContextSource $context |
| 102 | * @return Message |
| 103 | */ |
| 104 | public function getDisplayNameMessage( IContextSource $context ) { |
| 105 | $message = $context->msg( $this->getName() ); |
| 106 | if ( $message->exists() ) { |
| 107 | return $message; |
| 108 | } else { |
| 109 | return new RawMessage( Title::newFromText( $this->getName() )->getText() ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @return string|null |
| 115 | */ |
| 116 | public function getInfo() { |
| 117 | return $this->info; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @return int |
| 122 | */ |
| 123 | public function getOwner() { |
| 124 | if ( $this->owner ) { |
| 125 | return $this->owner; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @return bool |
| 133 | */ |
| 134 | public function isPublic() { |
| 135 | return (bool)$this->public; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * @return string|null |
| 140 | */ |
| 141 | public function getStartTime() { |
| 142 | return $this->startTime; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @return string|null |
| 147 | */ |
| 148 | public function getEndTime() { |
| 149 | return $this->endTime; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * @return int |
| 154 | */ |
| 155 | public function getType() { |
| 156 | if ( $this->type === null ) { |
| 157 | return self::TYPE_DEFAULT; |
| 158 | } |
| 159 | |
| 160 | return (int)$this->type; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @return string |
| 165 | */ |
| 166 | public function __toString() { |
| 167 | return $this->name; |
| 168 | } |
| 169 | } |