<?php
require_once 'lib/vod/vod_genres_screen.php';

class MyPlugIN_VodGenresScreen extends VodGenresScreen
	implements UserInputHandler
{
    public static function get_media_url_str()
    {
        return MediaURL::encode(array('screen_id' => self::ID));
    }
    private $vod;

    public function __construct(Vod $vod)
    {
        $this->vod = $vod;
        parent::__construct($vod);
        UserInputHandlerRegistry::get_instance()->register_handler($this);
    }
    ///////////////////////////////////////////////////////////////////////


    public function get_all_folder_items(MediaURL $media_url, &$plugin_cookies)
    {
        $this->vod->folder_entered($media_url, $plugin_cookies);
        $this->vod->ensure_genres_loaded($plugin_cookies);
        $genre_ids = $this->vod->get_genre_ids();
        $items = array();
        foreach ($genre_ids as $genre_id)
        {
            $caption = $this->vod->get_genre_caption($genre_id);
            $media_url_str = $this->vod->get_genre_media_url_str($genre_id);
            $icon_url = $this->vod->get_genre_icon_url($genre_id);

            $items[] = array
            (
                PluginRegularFolderItem::media_url => $media_url_str,
                PluginRegularFolderItem::caption => $this->mb_ucfirst($caption),
                PluginRegularFolderItem::view_item_params => array
                (
                    ViewItemParams::icon_path => $icon_url,
                )
            );
        }

        return $items;
    }
    
	private function mb_ucfirst($str, $encoding='UTF-8')
    {
        $str = mb_ereg_replace('^[\ ]+', '', $str);
        $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding).
               mb_substr($str, 1, mb_strlen($str), $encoding);
        return $str;
    }
    #public function get_archive(MediaURL $media_url)
    #{
    #    return $this->session->get_archive();
    #}
}

?>
