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'; |
||
193 | 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( |
||
193 | PointedEar | 26 | 'urns' => array( |
27 | 'wiki' => 'http://de.wikipedia.org/wiki/' |
||
28 | ) |
||
29 | ); |
||
30 | |||
31 | $serien = SeriesMapper::getInstance()->getList($serien); |
||
32 | |||
33 | foreach ($serien as $key => &$serie) |
||
34 | { |
||
35 | if ($serie->total > 0) |
||
36 | { |
||
37 | if (!$serie->ignore && $serie->percentage < $min_percentage) |
||
38 | { |
||
39 | $min_percentage = $serie->percentage; |
||
40 | $min_series = $key; |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | |||
45 | $this->assign('serien', $serien); |
||
46 | $this->assign('min_series', $min_series); |
||
47 | $this->render(); |
||
48 | } |
||
49 | |||
50 | private function oldIndexAction () |
||
51 | { |
||
52 | require_once 'data.inc'; |
||
53 | |||
54 | $min_percentage = 100; |
||
55 | $min_series = null; |
||
56 | |||
57 | $data = array( |
||
173 | PointedEar | 58 | 'urns' => array( |
59 | 'wiki' => 'http://de.wikipedia.org/wiki/' |
||
60 | ), |
||
61 | 'list' => &$serien |
||
62 | ); |
||
63 | |||
64 | foreach ($serien as $key => &$serie) |
||
65 | { |
||
66 | $count = 0; |
||
67 | $serie['coverage'] = array(); |
||
68 | |||
69 | if (isset($serie['seen'])) |
||
70 | { |
||
71 | $count = count($serie['seen']); |
||
72 | |||
73 | foreach ($serie['seen'] as $episode) |
||
74 | { |
||
75 | if (is_array($episode)) |
||
76 | { |
||
77 | $count += $episode[1] - $episode[0]; |
||
78 | $serie['coverage'][] = $episode[0] . '–' . $episode[1]; |
||
79 | } |
||
80 | else |
||
81 | { |
||
82 | $serie['coverage'][] = $episode; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | |||
87 | $serie['count'] = $count; |
||
88 | |||
89 | $serie['total'] = 0; |
||
90 | if (isset($serie['seasons']) && is_array($serie['seasons'])) |
||
91 | { |
||
92 | $serie['total'] = array_sum($serie['seasons']); |
||
93 | |||
94 | $episode_count = 1; |
||
95 | $serie['season_ranges'] = array(); |
||
96 | foreach ($serie['seasons'] as $season_key => $season_length) |
||
97 | { |
||
98 | if (is_int($season_key)) |
||
99 | { |
||
100 | $serie['season_ranges'][$season_key + 1] = array($episode_count, $episode_count + $season_length - 1); |
||
101 | } |
||
102 | |||
103 | $episode_count += $season_length; |
||
104 | } |
||
105 | } |
||
106 | else |
||
107 | { |
||
108 | $serie['total'] = max(array_keys($serie['episodes'])); |
||
109 | } |
||
110 | |||
111 | $serie['percentage'] = 0; |
||
112 | if ($serie['total'] > 0) |
||
113 | { |
||
114 | $serie['percentage'] = $count / $serie['total'] * 100; |
||
115 | |||
116 | if ((!isset($serie['ignore']) || !$serie['ignore']) |
||
117 | && $serie['percentage'] < $min_percentage) |
||
118 | { |
||
119 | $min_percentage = $serie['percentage']; |
||
120 | $min_series = $key; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | if (isset($serie['episode_list'])) |
||
125 | { |
||
126 | $episode_list =& $serie['episode_list']; |
||
127 | foreach ($data['urns'] as $prefix => $urn) |
||
128 | { |
||
129 | if (preg_match("/^{$prefix}:/", $episode_list)) |
||
130 | { |
||
131 | $episode_list = preg_replace("/^{$prefix}:/", $urn, |
||
132 | str_replace(' ', '_', $episode_list)); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | // var_dump($serien['<span class="alf">ALF</span>']); |
||
139 | |||
140 | $this->assign('serien', $serien); |
||
141 | $this->assign('min_series', $min_series); |
||
142 | $this->render(); |
||
143 | } |
||
186 | PointedEar | 144 | |
145 | // public function importAction () |
||
146 | // { |
||
147 | // require_once 'data.inc'; |
||
148 | // header('Content-Type: text/html; charset=UTF-8'); |
||
149 | // SeriesMapper::getInstance()->importAll($serien); |
||
150 | // } |
||
173 | PointedEar | 151 | } |