<?php 
/*
 * @package Joomla 3.0
 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @component XMovie Component
 * @copyright Copyright (C) Dana Harris optikool.com
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.model');

if (!class_exists('JModelLegacy')) {
    class_alias('JModel', 'JModelLegacy');
}

class XMovieModelSingle extends JModelLegacy
{
    
    protected $_item;
    protected $_category;
        
    public function getItem() 
    {
        $movie_id = JRequest::getInt('id');
        $cfgParams =  JComponentHelper::getParams('com_xmovie');       
                
        $row = JTable::getInstance('movie', 'XMovieTable');
        $row->load($movie_id);
        $row->hit($movie_id);
        
        // Deprecated
        if ($cfgParams->get('display_layout') == "shadowbox") {
            $row->embed = MovieHelper::getShadowboxCode($row);
        } else {
            $row->embed = MovieHelper::getEmbedCode($row);
        }
        
        $user = JFactory::getUser($row->user_id);
        $row->submitter = $user->username;
        $this->_item = $row;
        $this->_category = $this->getCategory();
        
        return $row;
    }
    
    /** 
     * Gets the parent category information and sets the _category protected var.
     * @return $_category The parent category information.
     */
    public function getCategory() 
    {
        if (!$this->_category) {
            $db = $this->getDbo();
            $query = $db->getQuery(true);
            
            $query->select('*');
            $query->from('#__categories');
            $query->where("id = '{$this->_item->catid}' AND extension = 'com_xmovie' AND published = '1'");
            
            $db->setQuery($query);
            $this->_category = $db->loadObject();
        }
        
        return $this->_category;    
    }
    
    public function getConfigParams() 
    {
        $cfgParams =  JComponentHelper::getParams('com_xmovie');
        
        return $cfgParams;
    }
}
?>

