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 | protected $id; |
20 | protected $name; |
21 | protected $info; |
22 | protected $owner; |
23 | protected $startTime; |
24 | protected $endTime; |
25 | protected $type; |
26 | protected $public; |
27 | |
28 | public function __construct( array $params ) { |
29 | if ( isset( $params['id'] ) ) { |
30 | $this->id = (int)$params['id']; |
31 | } |
32 | |
33 | $this->name = (string)$params['name']; |
34 | |
35 | if ( isset( $params['info'] ) ) { |
36 | $this->info = (string)$params['info']; |
37 | } |
38 | |
39 | if ( isset( $params['owner'] ) ) { |
40 | $this->owner = (int)$params['owner']; |
41 | } |
42 | |
43 | if ( isset( $params['public'] ) ) { |
44 | $this->public = (bool)$params['public']; |
45 | } |
46 | |
47 | if ( isset( $params['startTime'] ) ) { |
48 | $this->startTime = $params['startTime']; |
49 | } |
50 | |
51 | if ( isset( $params['endTime'] ) ) { |
52 | $this->endTime = $params['endTime']; |
53 | } |
54 | |
55 | if ( isset( $params['type'] ) ) { |
56 | $this->type = $params['type']; |
57 | } |
58 | } |
59 | |
60 | /** |
61 | * @param \stdClass $row |
62 | * @return SuggestionList |
63 | */ |
64 | public static function newFromRow( $row ) { |
65 | $params = [ |
66 | 'id' => $row->cxl_id, |
67 | 'name' => $row->cxl_name, |
68 | 'info' => $row->cxl_info, |
69 | 'owner' => $row->cxl_owner, |
70 | 'startTime' => $row->cxl_start_time, |
71 | 'endTime' => $row->cxl_end_time, |
72 | 'type' => $row->cxl_type, |
73 | ]; |
74 | |
75 | return new SuggestionList( $params ); |
76 | } |
77 | |
78 | public function getId() { |
79 | return $this->id; |
80 | } |
81 | |
82 | public function getName() { |
83 | return $this->name; |
84 | } |
85 | |
86 | /** |
87 | * @param IContextSource $context |
88 | * @return Message |
89 | */ |
90 | public function getDisplayNameMessage( IContextSource $context ) { |
91 | $message = $context->msg( $this->getName() ); |
92 | if ( $message->exists() ) { |
93 | return $message; |
94 | } else { |
95 | return new RawMessage( Title::newFromText( $this->getName() )->getText() ); |
96 | } |
97 | } |
98 | |
99 | public function getInfo() { |
100 | return $this->info; |
101 | } |
102 | |
103 | public function getOwner() { |
104 | if ( $this->owner ) { |
105 | return $this->owner; |
106 | } |
107 | |
108 | return 0; |
109 | } |
110 | |
111 | public function isPublic() { |
112 | return (bool)$this->public; |
113 | } |
114 | |
115 | public function getStartTime() { |
116 | return $this->startTime; |
117 | } |
118 | |
119 | public function getEndTime() { |
120 | return $this->endTime; |
121 | } |
122 | |
123 | public function getType() { |
124 | if ( $this->type === null ) { |
125 | return self::TYPE_DEFAULT; |
126 | } |
127 | |
128 | return (int)$this->type; |
129 | } |
130 | |
131 | /** |
132 | * @return string |
133 | */ |
134 | public function __toString() { |
135 | return $this->name; |
136 | } |
137 | } |