Subversion Repositories LCARS

Rev

Rev 193 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

1
<?php

require_once 'views/IndexView.php';
require_once 'models/mappers/SeriesMapper.php';

class IndexController extends \PointedEars\PHPX\Controller
{
  /**
   * Creates a new controller for the index view
   *
   * @see Controller::__construct()
   */

  public function __construct ()
  {
    parent::__construct('IndexView');
  }

  public function indexAction ()
  {
    require_once '../data.inc';

    $min_percentage = 100;
    $min_series = null;

    $data = array(
        'urns' => array(
            'wiki' => 'http://de.wikipedia.org/wiki/'
        )
    );

    $serien = SeriesMapper::getInstance()->getList($serien);

    foreach ($serien as $key => &$serie)
    {
      if ($serie->total > 0)
      {
        if (!$serie->ignore && $serie->percentage < $min_percentage)
        {
          $min_percentage = $serie->percentage;
          $min_series = $key;
        }
      }
    }

    $this->assign('serien', $serien);
    $this->assign('min_series', $min_series);
    $this->render();
  }

  private function oldIndexAction ()
  {
    require_once '../data.inc';

    $min_percentage = 100;
    $min_series = null;

    $data = array(
      'urns' => array(
        'wiki' => 'http://de.wikipedia.org/wiki/'
      ),
      'list' => &$serien
    );

    foreach ($serien as $key => &$serie)
    {
      $count = 0;
      $serie['coverage'] = array();

      if (isset($serie['seen']))
      {
        $count = count($serie['seen']);

        foreach ($serie['seen'] as $episode)
        {
          if (is_array($episode))
          {
            $count += $episode[1] - $episode[0];
            $serie['coverage'][] = $episode[0] . '&ndash;' . $episode[1];
          }
          else
          {
            $serie['coverage'][] = $episode;
          }
        }
      }

      $serie['count'] = $count;

      $serie['total'] = 0;
      if (isset($serie['seasons']) && is_array($serie['seasons']))
      {
        $serie['total'] = array_sum($serie['seasons']);

        $episode_count = 1;
        $serie['season_ranges'] = array();
        foreach ($serie['seasons'] as $season_key => $season_length)
        {
          if (is_int($season_key))
          {
            $serie['season_ranges'][$season_key + 1] = array($episode_count, $episode_count + $season_length - 1);
          }

          $episode_count += $season_length;
        }
      }
      else
      {
        $serie['total'] = max(array_keys($serie['episodes']));
      }

      $serie['percentage'] = 0;
      if ($serie['total'] > 0)
      {
        $serie['percentage'] = $count / $serie['total'] * 100;

        if ((!isset($serie['ignore']) || !$serie['ignore'])
             && $serie['percentage'] < $min_percentage)
        {
          $min_percentage = $serie['percentage'];
          $min_series = $key;
        }
      }

      if (isset($serie['episode_list']))
      {
        $episode_list =& $serie['episode_list'];
        foreach ($data['urns'] as $prefix => $urn)
        {
          if (preg_match("/^{$prefix}:/", $episode_list))
          {
            $episode_list = preg_replace("/^{$prefix}:/", $urn,
              str_replace(' ', '_', $episode_list));
          }
        }
      }
    }

    // var_dump($serien['<span class="alf">ALF</span>']);

    $this->assign('serien', $serien);
    $this->assign('min_series', $min_series);
    $this->render();
  }

//   public function importAction ()
//   {
//      require_once 'data.inc';
//      header('Content-Type: text/html; charset=UTF-8');
//      SeriesMapper::getInstance()->importAll($serien);
//   }
}