| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Model; |
| 4 |
|
| 5 |
use InvalidArgumentException; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
use stdClass; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class TargetPage extends AbstractEntity { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $title = false; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
protected $pageId; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
protected $event; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
protected $eventId; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
protected $eventType; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
protected function __construct() { |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static function create( Title $title, Event $event ) { |
| 55 |
|
| 56 |
if ( !$title->getArticleID() ) { |
| 57 |
return null; |
| 58 |
} |
| 59 |
$obj = new self(); |
| 60 |
$obj->event = $event; |
| 61 |
$obj->eventId = $event->getId(); |
| 62 |
$obj->eventType = $event->getType(); |
| 63 |
$obj->title = $title; |
| 64 |
$obj->pageId = $title->getArticleID(); |
| 65 |
|
| 66 |
return $obj; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public static function newFromRow( $row ) { |
| 76 |
$requiredFields = [ |
| 77 |
'etp_page', |
| 78 |
'etp_event' |
| 79 |
]; |
| 80 |
foreach ( $requiredFields as $field ) { |
| 81 |
if ( !isset( $row->$field ) || !$row->$field ) { |
| 82 |
throw new InvalidArgumentException( $field . ' is not set in the row!' ); |
| 83 |
} |
| 84 |
} |
| 85 |
$obj = new self(); |
| 86 |
$obj->pageId = $row->etp_page; |
| 87 |
$obj->eventId = $row->etp_event; |
| 88 |
if ( isset( $row->event_type ) ) { |
| 89 |
$obj->eventType = $row->event_type; |
| 90 |
} |
| 91 |
|
| 92 |
return $obj; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function getTitle() { |
| 99 |
if ( $this->title === false ) { |
| 100 |
$this->title = Title::newFromID( $this->pageId ); |
| 101 |
} |
| 102 |
|
| 103 |
return $this->title; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public function getPageId() { |
| 110 |
return $this->pageId; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public function getEvent() { |
| 117 |
if ( !$this->event ) { |
| 118 |
$this->event = Event::newFromID( $this->eventId ); |
| 119 |
} |
| 120 |
|
| 121 |
return $this->event; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public function getEventId() { |
| 128 |
return $this->eventId; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function getEventType() { |
| 135 |
if ( !$this->eventType ) { |
| 136 |
$this->eventType = $this->getEvent()->getType(); |
| 137 |
} |
| 138 |
|
| 139 |
return $this->eventType; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public function toDbArray() { |
| 147 |
return [ |
| 148 |
'etp_page' => $this->pageId, |
| 149 |
'etp_event' => $this->eventId |
| 150 |
]; |
| 151 |
} |
| 152 |
} |