Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
SuggestionList
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 12
506
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
72
 newFromRow
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDisplayNameMessage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getOwner
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 isPublic
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStartTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEndTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getType
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 __toString
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace ContentTranslation;
4
5use MediaWiki\Context\IContextSource;
6use MediaWiki\Language\RawMessage;
7use MediaWiki\Message\Message;
8use MediaWiki\Title\Title;
9
10class 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 SuggestionList
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 SuggestionList( $params );
84    }
85
86    public function getId() {
87        return $this->id;
88    }
89
90    public function getName() {
91        return $this->name;
92    }
93
94    /**
95     * @param IContextSource $context
96     * @return Message
97     */
98    public function getDisplayNameMessage( IContextSource $context ) {
99        $message = $context->msg( $this->getName() );
100        if ( $message->exists() ) {
101            return $message;
102        } else {
103            return new RawMessage( Title::newFromText( $this->getName() )->getText() );
104        }
105    }
106
107    public function getInfo() {
108        return $this->info;
109    }
110
111    public function getOwner() {
112        if ( $this->owner ) {
113            return $this->owner;
114        }
115
116        return 0;
117    }
118
119    public function isPublic() {
120        return (bool)$this->public;
121    }
122
123    public function getStartTime() {
124        return $this->startTime;
125    }
126
127    public function getEndTime() {
128        return $this->endTime;
129    }
130
131    public function getType() {
132        if ( $this->type === null ) {
133            return self::TYPE_DEFAULT;
134        }
135
136        return (int)$this->type;
137    }
138
139    /**
140     * @return string
141     */
142    public function __toString() {
143        return $this->name;
144    }
145}