Subversion Repositories LCARS

Rev

Rev 193 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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