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