Rev 173 | Rev 193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
173 | PointedEar | 1 | <?php |
2 | |||
3 | require_once 'application/views/IndexView.php'; |
||
186 | PointedEar | 4 | // require_once 'application/models/mappers/SeriesMapper.php'; |
173 | PointedEar | 5 | |
186 | PointedEar | 6 | class IndexController extends \PointedEars\PHPX\Controller |
173 | PointedEar | 7 | { |
8 | /** |
||
9 | * Creates a new controller for the index view |
||
10 | * |
||
11 | * @see Controller::__construct() |
||
12 | */ |
||
13 | public function __construct () |
||
14 | { |
||
15 | parent::__construct('IndexView'); |
||
16 | } |
||
17 | |||
18 | public function indexAction () |
||
19 | { |
||
20 | require_once 'data.inc'; |
||
21 | |||
22 | $min_percentage = 100; |
||
23 | $min_series = null; |
||
24 | |||
25 | $data = array( |
||
26 | 'urns' => array( |
||
27 | 'wiki' => 'http://de.wikipedia.org/wiki/' |
||
28 | ), |
||
29 | 'list' => &$serien |
||
30 | ); |
||
31 | |||
32 | foreach ($serien as $key => &$serie) |
||
33 | { |
||
34 | $count = 0; |
||
35 | $serie['coverage'] = array(); |
||
36 | |||
37 | if (isset($serie['seen'])) |
||
38 | { |
||
39 | $count = count($serie['seen']); |
||
40 | |||
41 | foreach ($serie['seen'] as $episode) |
||
42 | { |
||
43 | if (is_array($episode)) |
||
44 | { |
||
45 | $count += $episode[1] - $episode[0]; |
||
46 | $serie['coverage'][] = $episode[0] . '–' . $episode[1]; |
||
47 | } |
||
48 | else |
||
49 | { |
||
50 | $serie['coverage'][] = $episode; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | |||
55 | $serie['count'] = $count; |
||
56 | |||
57 | $serie['total'] = 0; |
||
58 | if (isset($serie['seasons']) && is_array($serie['seasons'])) |
||
59 | { |
||
60 | $serie['total'] = array_sum($serie['seasons']); |
||
61 | |||
62 | $episode_count = 1; |
||
63 | $serie['season_ranges'] = array(); |
||
64 | foreach ($serie['seasons'] as $season_key => $season_length) |
||
65 | { |
||
66 | if (is_int($season_key)) |
||
67 | { |
||
68 | $serie['season_ranges'][$season_key + 1] = array($episode_count, $episode_count + $season_length - 1); |
||
69 | } |
||
70 | |||
71 | $episode_count += $season_length; |
||
72 | } |
||
73 | } |
||
74 | else |
||
75 | { |
||
76 | $serie['total'] = max(array_keys($serie['episodes'])); |
||
77 | } |
||
78 | |||
79 | $serie['percentage'] = 0; |
||
80 | if ($serie['total'] > 0) |
||
81 | { |
||
82 | $serie['percentage'] = $count / $serie['total'] * 100; |
||
83 | |||
84 | if ((!isset($serie['ignore']) || !$serie['ignore']) |
||
85 | && $serie['percentage'] < $min_percentage) |
||
86 | { |
||
87 | $min_percentage = $serie['percentage']; |
||
88 | $min_series = $key; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | if (isset($serie['episode_list'])) |
||
93 | { |
||
94 | $episode_list =& $serie['episode_list']; |
||
95 | foreach ($data['urns'] as $prefix => $urn) |
||
96 | { |
||
97 | if (preg_match("/^{$prefix}:/", $episode_list)) |
||
98 | { |
||
99 | $episode_list = preg_replace("/^{$prefix}:/", $urn, |
||
100 | str_replace(' ', '_', $episode_list)); |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | |||
106 | // var_dump($serien['<span class="alf">ALF</span>']); |
||
107 | |||
108 | $this->assign('serien', $serien); |
||
109 | $this->assign('min_series', $min_series); |
||
110 | $this->render(); |
||
111 | } |
||
186 | PointedEar | 112 | |
113 | // public function importAction () |
||
114 | // { |
||
115 | // require_once 'data.inc'; |
||
116 | // header('Content-Type: text/html; charset=UTF-8'); |
||
117 | // SeriesMapper::getInstance()->importAll($serien); |
||
118 | // } |
||
173 | PointedEar | 119 | } |