Rev 194 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 194 | Rev 200 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | require_once 'application/models/databases/seriometer/tables/SeriesTable.php'; |
3 | require_once 'models/databases/seriometer/tables/SeriesTable.php'; |
4 | 4 | ||
5 | class Series extends \PointedEars\PHPX\Model |
5 | class Series extends \PointedEars\PHPX\Model |
6 | {
|
6 | {
|
7 | /**
|
7 | /**
|
8 | * (non-PHPdoc)
|
8 | * (non-PHPdoc)
|
9 | * @see \PointedEars\PHPX\Model::$_persistentTable
|
9 | * @see \PointedEars\PHPX\Model::$_persistentTable
|
10 | */
|
10 | */
|
11 | protected static $_persistentTable = 'SeriesTable'; |
11 | protected static $_persistentTable = 'SeriesTable'; |
12 | 12 | ||
13 | /**
|
13 | /**
|
14 | * (non-PHPdoc)
|
14 | * (non-PHPdoc)
|
15 | * @see \PointedEars\PHPX\Model::$_persistentId
|
15 | * @see \PointedEars\PHPX\Model::$_persistentId
|
16 | */
|
16 | */
|
17 | protected static $_persistentId = 'series_id'; |
17 | protected static $_persistentId = 'series_id'; |
18 | 18 | ||
19 | /**
|
19 | /**
|
20 | * (non-PHPdoc)
|
20 | * (non-PHPdoc)
|
21 | * @see \PointedEars\PHPX\Model::$_persistentProperties
|
21 | * @see \PointedEars\PHPX\Model::$_persistentProperties
|
22 | */
|
22 | */
|
23 | protected static $_persistentProperties = array( |
23 | protected static $_persistentProperties = array( |
24 | 'title', |
24 | 'title', |
25 | 'ignore', |
25 | 'ignore', |
26 | 'channel_id', |
26 | 'channel_id', |
27 | 'last_seen', |
27 | 'last_seen', |
28 | 'seasons', |
28 | 'seasons', |
29 | 'showtimes', |
29 | 'showtimes', |
30 | 'url'
|
30 | 'url'
|
31 | ); |
31 | ); |
32 | 32 | ||
33 | protected static $_urns = array( |
33 | protected static $_urns = array( |
34 | 'wiki' => 'http://de.wikipedia.org/wiki/' |
34 | 'wiki' => 'http://de.wikipedia.org/wiki/' |
35 | ); |
35 | ); |
36 | 36 | ||
37 | /**
|
37 | /**
|
38 | * @var int
|
38 | * @var int
|
39 | */
|
39 | */
|
40 | protected $_series_id; |
40 | protected $_series_id; |
41 | 41 | ||
42 | /**
|
42 | /**
|
43 | * @var string
|
43 | * @var string
|
44 | */
|
44 | */
|
45 | protected $_title; |
45 | protected $_title; |
46 | 46 | ||
47 | /**
|
47 | /**
|
48 | * @var bool
|
48 | * @var bool
|
49 | */
|
49 | */
|
50 | protected $_ignore = false; |
50 | protected $_ignore = false; |
51 | 51 | ||
52 | /**
|
52 | /**
|
53 | * @var string
|
53 | * @var string
|
54 | */
|
54 | */
|
55 | protected $_channel; |
55 | protected $_channel; |
56 | 56 | ||
57 | /**
|
57 | /**
|
58 | * @var string
|
58 | * @var string
|
59 | */
|
59 | */
|
60 | protected $_showtimes; |
60 | protected $_showtimes; |
61 | 61 | ||
62 | /**
|
62 | /**
|
63 | * @var array
|
63 | * @var array
|
64 | */
|
64 | */
|
65 | protected $_seen; |
65 | protected $_seen; |
66 | 66 | ||
67 | /**
|
67 | /**
|
68 | * @var int
|
68 | * @var int
|
69 | */
|
69 | */
|
70 | protected $_last_seen; |
70 | protected $_last_seen; |
71 | 71 | ||
72 | /**
|
72 | /**
|
73 | * @var array[string]
|
73 | * @var array[string]
|
74 | */
|
74 | */
|
75 | protected $_seasons; |
75 | protected $_seasons; |
76 | 76 | ||
77 | /**
|
77 | /**
|
78 | * @var string
|
78 | * @var string
|
79 | */
|
79 | */
|
80 | protected $_episode_list; |
80 | protected $_episode_list; |
81 | 81 | ||
82 | /**
|
82 | /**
|
83 | * @var array
|
83 | * @var array
|
84 | */
|
84 | */
|
85 | protected $_episodes; |
85 | protected $_episodes; |
86 | 86 | ||
87 | /**
|
87 | /**
|
88 | * @var string
|
88 | * @var string
|
89 | */
|
89 | */
|
90 | protected $_url; |
90 | protected $_url; |
91 | 91 | ||
92 | /* Computed properties */
|
92 | /* Computed properties */
|
93 | 93 | ||
94 | /**
|
94 | /**
|
95 | * Number of seen episodes
|
95 | * Number of seen episodes
|
96 | * @var int
|
96 | * @var int
|
97 | */
|
97 | */
|
98 | protected $_count; |
98 | protected $_count; |
99 | 99 | ||
100 | /**
|
100 | /**
|
101 | * The total number of episodes of this series
|
101 | * The total number of episodes of this series
|
102 | * @var int
|
102 | * @var int
|
103 | */
|
103 | */
|
104 | protected $_total; |
104 | protected $_total; |
105 | 105 | ||
106 | /**
|
106 | /**
|
107 | * The percentage of seen episodes
|
107 | * The percentage of seen episodes
|
108 | * @var double
|
108 | * @var double
|
109 | */
|
109 | */
|
110 | protected $_percentage; |
110 | protected $_percentage; |
111 | 111 | ||
112 | /**
|
112 | /**
|
113 | * Season ranges, consisting of arrays of the number of
|
113 | * Season ranges, consisting of arrays of the number of
|
114 | * the first and last episode of a season.
|
114 | * the first and last episode of a season.
|
115 | * @var array
|
115 | * @var array
|
116 | */
|
116 | */
|
117 | protected $_season_ranges; |
117 | protected $_season_ranges; |
118 | 118 | ||
119 | public function setSeries_id ($value) |
119 | public function setSeries_id ($value) |
120 | {
|
120 | {
|
121 | $this->_series_id = (int) $value; |
121 | $this->_series_id = (int) $value; |
122 | return $this; |
122 | return $this; |
123 | }
|
123 | }
|
124 | 124 | ||
125 | public function setTitle ($value) |
125 | public function setTitle ($value) |
126 | {
|
126 | {
|
127 | $this->_title = trim((string) $value); |
127 | $this->_title = trim((string) $value); |
128 | return $this; |
128 | return $this; |
129 | }
|
129 | }
|
130 | 130 | ||
131 | public function setIgnore ($value) |
131 | public function setIgnore ($value) |
132 | {
|
132 | {
|
133 | $this->_ignore = (bool) $value; |
133 | $this->_ignore = (bool) $value; |
134 | return $this; |
134 | return $this; |
135 | }
|
135 | }
|
136 | 136 | ||
137 | public function setChannel ($value) |
137 | public function setChannel ($value) |
138 | {
|
138 | {
|
139 | $this->_channel = trim((string) $value); |
139 | $this->_channel = trim((string) $value); |
140 | return $this; |
140 | return $this; |
141 | }
|
141 | }
|
142 | 142 | ||
143 | public function setShowtimes ($value) |
143 | public function setShowtimes ($value) |
144 | {
|
144 | {
|
145 | $this->_showtimes = trim((string) $value); |
145 | $this->_showtimes = trim((string) $value); |
146 | return $this; |
146 | return $this; |
147 | }
|
147 | }
|
148 | 148 | ||
149 | public function setLast_seen ($value) |
149 | public function setLast_seen ($value) |
150 | {
|
150 | {
|
151 | $this->_last_seen = ($value === null |
151 | $this->_last_seen = ($value === null |
152 | ? $value
|
152 | ? $value
|
153 | : (($time = strtotime($value . ' GMT')) !== false ? $time : null)); |
153 | : (($time = strtotime($value . ' GMT')) !== false ? $time : null)); |
154 | return $this; |
154 | return $this; |
155 | }
|
155 | }
|
156 | 156 | ||
157 | public function setSeasons ($value) |
157 | public function setSeasons ($value) |
158 | {
|
158 | {
|
159 | $this->_seasons = is_array($value) ? $value : explode(',', $value); |
159 | $this->_seasons = is_array($value) ? $value : explode(',', $value); |
160 | return $this; |
160 | return $this; |
161 | }
|
161 | }
|
162 | 162 | ||
163 | public function setEpisode_list ($value) |
163 | public function setEpisode_list ($value) |
164 | {
|
164 | {
|
165 | $episode_list = (string) $value; |
165 | $episode_list = (string) $value; |
166 | 166 | ||
167 | if ($episode_list !== null) |
167 | if ($episode_list !== null) |
168 | {
|
168 | {
|
169 | foreach (self::$_urns as $prefix => $urn) |
169 | foreach (self::$_urns as $prefix => $urn) |
170 | {
|
170 | {
|
171 | if (preg_match("/^{$prefix}:/", $episode_list)) |
171 | if (preg_match("/^{$prefix}:/", $episode_list)) |
172 | {
|
172 | {
|
173 | $episode_list = preg_replace("/^{$prefix}:/", $urn, |
173 | $episode_list = preg_replace("/^{$prefix}:/", $urn, |
174 | str_replace(' ', '_', $episode_list)); |
174 | str_replace(' ', '_', $episode_list)); |
175 | }
|
175 | }
|
176 | }
|
176 | }
|
177 | }
|
177 | }
|
178 | 178 | ||
179 | $this->_episode_list = $episode_list; |
179 | $this->_episode_list = $episode_list; |
180 | 180 | ||
181 | return $this; |
181 | return $this; |
182 | }
|
182 | }
|
183 | 183 | ||
184 | public function setEpisodes ($value) |
184 | public function setEpisodes ($value) |
185 | {
|
185 | {
|
186 | $this->_episodes = is_array($value) ? $value : null; |
186 | $this->_episodes = is_array($value) ? $value : null; |
187 | return $this; |
187 | return $this; |
188 | }
|
188 | }
|
189 | 189 | ||
190 | public function setUrl ($value) |
190 | public function setUrl ($value) |
191 | {
|
191 | {
|
192 | $this->_url = (string) $value; |
192 | $this->_url = (string) $value; |
193 | return $this; |
193 | return $this; |
194 | }
|
194 | }
|
195 | 195 | ||
196 | public function getCount () |
196 | public function getCount () |
197 | {
|
197 | {
|
198 | if ($this->_count === null) |
198 | if ($this->_count === null) |
199 | {
|
199 | {
|
200 | $count = 0; |
200 | $count = 0; |
201 | $seen = $this->seen; |
201 | $seen = $this->seen; |
202 | 202 | ||
203 | if (is_array($seen)) |
203 | if (is_array($seen)) |
204 | {
|
204 | {
|
205 | $count = count($seen); |
205 | $count = count($seen); |
206 | 206 | ||
207 | foreach ($seen as $episode_or_range) |
207 | foreach ($seen as $episode_or_range) |
208 | {
|
208 | {
|
209 | if (is_array($episode_or_range)) |
209 | if (is_array($episode_or_range)) |
210 | {
|
210 | {
|
211 | $count += $episode_or_range[1] - $episode_or_range[0]; |
211 | $count += $episode_or_range[1] - $episode_or_range[0]; |
212 | }
|
212 | }
|
213 | }
|
213 | }
|
214 | }
|
214 | }
|
215 | 215 | ||
216 | $this->_count = $count; |
216 | $this->_count = $count; |
217 | }
|
217 | }
|
218 | 218 | ||
219 | return $this->_count; |
219 | return $this->_count; |
220 | }
|
220 | }
|
221 | 221 | ||
222 | /**
|
222 | /**
|
223 | * Returns the number of episodes of this series,
|
223 | * Returns the number of episodes of this series,
|
224 | * based on the season or episodes data, preferring the former.
|
224 | * based on the season or episodes data, preferring the former.
|
225 | *
|
225 | *
|
226 | * @return int
|
226 | * @return int
|
227 | */
|
227 | */
|
228 | public function getTotal () |
228 | public function getTotal () |
229 | {
|
229 | {
|
230 | if ($this->_total === null) |
230 | if ($this->_total === null) |
231 | {
|
231 | {
|
232 | if (is_array($this->seasons)) |
232 | if (is_array($this->seasons)) |
233 | {
|
233 | {
|
234 | $total = array_sum($this->seasons); |
234 | $total = array_sum($this->seasons); |
235 | $episode_count = 1; |
235 | $episode_count = 1; |
236 | $this->_season_ranges = array(); |
236 | $this->_season_ranges = array(); |
237 | 237 | ||
238 | foreach ($this->seasons as $season_key => $season_length) |
238 | foreach ($this->seasons as $season_key => $season_length) |
239 | {
|
239 | {
|
240 | if (is_int($season_key)) |
240 | if (is_int($season_key)) |
241 | {
|
241 | {
|
242 | $this->_season_ranges[$season_key + 1] = |
242 | $this->_season_ranges[$season_key + 1] = |
243 | array($episode_count, $episode_count + $season_length - 1); |
243 | array($episode_count, $episode_count + $season_length - 1); |
244 | }
|
244 | }
|
245 | 245 | ||
246 | $episode_count += $season_length; |
246 | $episode_count += $season_length; |
247 | }
|
247 | }
|
248 | }
|
248 | }
|
249 | else
|
249 | else
|
250 | {
|
250 | {
|
251 | $total = max(array_keys($this->episodes)); |
251 | $total = max(array_keys($this->episodes)); |
252 | }
|
252 | }
|
253 | 253 | ||
254 | $this->_total = $total; |
254 | $this->_total = $total; |
255 | }
|
255 | }
|
256 | 256 | ||
257 | return $this->_total; |
257 | return $this->_total; |
258 | }
|
258 | }
|
259 | 259 | ||
260 | /**
|
260 | /**
|
261 | * Returns the percentage of seen episodes
|
261 | * Returns the percentage of seen episodes
|
262 | * @return double
|
262 | * @return double
|
263 | */
|
263 | */
|
264 | public function getPercentage () |
264 | public function getPercentage () |
265 | {
|
265 | {
|
266 | if ($this->_percentage === null) |
266 | if ($this->_percentage === null) |
267 | {
|
267 | {
|
268 | $this->_percentage = $this->count / $this->total * 100; |
268 | $this->_percentage = $this->count / $this->total * 100; |
269 | }
|
269 | }
|
270 | 270 | ||
271 | return $this->_percentage; |
271 | return $this->_percentage; |
272 | }
|
272 | }
|
273 | }
|
273 | }
|
274 | 274 |