This repository was archived by the owner on Mar 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathModel.php
More file actions
167 lines (140 loc) · 3.87 KB
/
Model.php
File metadata and controls
167 lines (140 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
declare( strict_types = 1 );
namespace App\Model;
use App\Repository\Repository;
use Exception;
/**
* A model is any domain-side entity to be represented in the application.
* Models know nothing of persistence, transport, or presentation.
*/
abstract class Model {
/**
* Below are the class properties. Some subclasses may not use all of these.
*/
/** @var Repository The corresponding repository for this model. */
protected Repository $repository;
/** @var Project The project. */
protected Project $project;
/** @var User|null The user. */
protected ?User $user;
/** @var Page|null the page associated with this edit */
protected ?Page $page = null;
/** @var int|string Which namespace we are querying for. 'all' for all namespaces. */
protected int|string $namespace;
/** @var false|int Start of time period as Unix timestamp. */
protected false|int $start;
/** @var false|int End of time period as Unix timestamp. */
protected false|int $end;
/** @var false|int Unix timestamp to offset results which acts as a substitute for $end */
protected false|int $offset = false;
/** @var int|null Number of rows to fetch. */
protected ?int $limit = null;
/**
* Set this model's data repository.
* @param Repository $repository
* @return Model
*/
public function setRepository( Repository $repository ): Model {
$this->repository = $repository;
return $this;
}
/**
* Get this model's repository.
* @return Repository A subclass of Repository.
* @throws Exception If the repository hasn't been set yet.
*/
public function getRepository(): Repository {
if ( !isset( $this->repository ) ) {
// Untestable, Model cannot be directly instantiated and all subclasses set it in __construct.
// @codeCoverageIgnoreStart
$msg = sprintf( 'The $repository property for class %s must be set before using.', static::class );
throw new Exception( $msg );
// @codeCoverageIgnoreEnd
}
return $this->repository;
}
/**
* Get the associated Project.
* @return Project
*/
public function getProject(): Project {
return $this->project;
}
/**
* Get the associated User.
* @return User|null
*/
public function getUser(): ?User {
return $this->user;
}
/**
* Get the associated Page.
* @return Page|null
*/
public function getPage(): ?Page {
return $this->page;
}
/**
* Get the associated namespace.
* @return int|string Namespace ID or 'all' for all namespaces.
*/
public function getNamespace() {
return $this->namespace;
}
/**
* Get date opening date range as Unix timestamp.
* @return false|int
*/
public function getStart() {
return $this->start;
}
/**
* Get date opening date range, formatted as this is used in the views.
* @return string Blank if no value exists.
*/
public function getStartDate(): string {
return is_int( $this->start ) ? date( 'Y-m-d', $this->start ) : '';
}
/**
* Get date closing date range as Unix timestamp.
* @return false|int
*/
public function getEnd() {
return $this->end;
}
/**
* Get date closing date range, formatted as this is used in the views.
* @return string Blank if no value exists.
*/
public function getEndDate(): string {
return is_int( $this->end ) ? date( 'Y-m-d', $this->end ) : '';
}
/**
* Has date range?
* @return bool
*/
public function hasDateRange(): bool {
return $this->start || $this->end;
}
/**
* Get the limit set on number of rows to fetch.
* @return int|null
*/
public function getLimit(): ?int {
return $this->limit;
}
/**
* Get the offset timestamp as Unix timestamp. Used for pagination.
* @return false|int
*/
public function getOffset(): false|int {
return $this->offset;
}
/**
* Get the offset timestamp as a formatted ISO timestamp.
* @return null|string
*/
public function getOffsetISO(): ?string {
return is_int( $this->offset ) ? date( 'Y-m-d\TH:i:s', $this->offset ) : null;
}
}