Your IP : 10.10.0.253


Current Path : /var/www/components/com_yendifvideoshare/models/
Upload File :
Current File : /var/www/components/com_yendifvideoshare/models/video.php

<?php
/**
 * @version    1.2.9
 * @package    Com_YendifVideoShare
 * @author     PluginsWare Interactive Pvt. Ltd <admin@yendifplayer.com>
 * @copyright  Copyright (c) 2012 - 2021 PluginsWare Interactive Pvt. Ltd. All Rights Reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

// Prevent direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class YendifVideoShareModelVideo extends YendifVideoShareModel {
	
	public function getItem( $check_publishing_options ) {	
        $db = JFactory::getDbo();
		
        $query  = "SELECT * FROM #__yendifvideoshare_videos WHERE id=" . JFactory::getApplication()->input->getInt('id');		
		
		if ( YENDIF_VIDEO_SHARE_USERID == 0 ) {
			$query .= ' AND published=1';
			
			if ( $check_publishing_options ) {
				$date = JFactory::getDate();
				
				$nowDate  = $db->quote( $date->toSql() );
				$nullDate = $db->quote( $db->getNullDate() );
				
				$query .= " AND (published_up = " . $nullDate . " OR published_up <= " . $nowDate . ')';
				$query .= " AND (published_down = " . $nullDate . " OR published_down >= " . $nowDate . ')';
			}
		} else {
			$query .= " AND (published=1 OR userid=" . YENDIF_VIDEO_SHARE_USERID . ")";
		}
		  			 
        $db->setQuery( $query );
        $item = $db->loadObject();
		 
        return $item;		
	}
	
	public function getVideos( $limit, $catid, $filterby, $orderby, $check_publishing_options ) {	
		$app = JFactory::getApplication();
		$db = JFactory::getDbo();	 
		 
		$limit = $app->getUserStateFromRequest( 'global.list.limit', 'limit', $limit, 'int' );
		$limitstart = $app->input->get( 'limitstart', '0', 'INT' ); 
		$limitstart = $limit != 0 ? ( floor( $limitstart / $limit ) * $limit ) : 0;
 
		$this->setState( 'limit', $limit );
		$this->setState( 'limitstart', $limitstart );
		 
		$userid = $app->input->getInt( 'userid', 0 );

        $query  = "SELECT * FROM #__yendifvideoshare_videos WHERE id!=" . $app->input->getInt( 'id' );
		$query .= $userid > 0 ? " AND userid=" . $userid : " AND catid=" . (int) $catid . " AND published=1";
		 
		if ( $check_publishing_options && $userid == 0 ) {
			$date = JFactory::getDate();			
			
		 	$nowDate  = $db->quote( $date->toSql() );
			$nullDate = $db->quote( $db->getNullDate() );
			
		 	$query .= " AND ( published_up = " . $nullDate . " OR published_up <= " . $nowDate .')';
			$query .= " AND ( published_down = " . $nullDate . " OR published_down >= " . $nowDate .')';
		}
				 
		 if ( $filterby == 'featured' ) {
		 	$query .= ' AND featured=1';
		 }
		 
		 switch ( $orderby ) {
		 	case 'latest':
				$query .= ' ORDER BY created_date DESC';
				break;	
			case 'most_viewed':
				$query .= ' ORDER BY views DESC';
				break;
			case 'most_rated':
				$query .= ' ORDER BY rating DESC';
				break;
			case 'date_added':
				$query .= ' ORDER BY created_date ASC';
				break;
			case 'a_z':
				$query .= ' ORDER BY title ASC';
				break;
			case 'z_a':
				$query .= ' ORDER BY title DESC';
				break;
			case 'random':
				$query .= ' ORDER BY RAND()';
				break;
			case 'ordering':
				$query .= ' ORDER BY ordering';
				break;
			default:
				$query .= ' ORDER BY id DESC';
		}
		 
        $db->setQuery( $query, $limitstart, $limit );
        $items = $db->loadObjectList();
		 
		return $items;		 
	}
	
	public function getTotal( $catid, $filterby, $check_publishing_options ) {         
		$app = JFactory::getApplication();	
		$db = JFactory::getDbo();
		 
		$userid = $app->input->getInt( 'userid', 0 );

        $query  = "SELECT COUNT(id) FROM #__yendifvideoshare_videos WHERE id!=" . $app->input->getInt( 'id' );
		$query .= $userid > 0 ? " AND userid=" . $userid : " AND catid=" . (int) $catid . " AND published=1";
		 
		if ( $check_publishing_options && $userid == 0 ) {
			$date = JFactory::getDate();			
			
		 	$nowDate  = $db->quote( $date->toSql() );
			$nullDate = $db->quote( $db->getNullDate() );
			
		 	$query .= " AND ( published_up = " . $nullDate . " OR published_up <= " . $nowDate . ')';
			$query .= " AND ( published_down = " . $nullDate . " OR published_down >= " . $nowDate . ')';
		}		 	
		 
		if ( $filterby == 'featured' ) {
		 	$query .= ' AND featured=1';
		}
		
        $db->setQuery( $query );
        $count = $db->loadResult();
		 
		return $count;		
	}
	
	public function getPagination( $catid, $filterby, $check_publishing_options ) {	
    	jimport( 'joomla.html.pagination' );
		 
		$count = $this->getTotal( $catid, $filterby, $check_publishing_options ); 
		$pagination = new JPagination( $count, $this->getState( 'limitstart' ), $this->getState( 'limit' ) );
    	
		return $pagination;		
	}
	
	public function getCategory( $id ) {	
        $db = JFactory::getDbo();
		 
        $query = 'SELECT * FROM #__yendifvideoshare_categories WHERE published=1 AND id=' . (int) $id;
        $db->setQuery( $query );
        
		$item = $db->loadObject();
		 
        return $item;		 
	}
	
	public function getTotalRatedUsers() {	
		$db = JFactory::getDbo();
		 
    	$query = 'SELECT COUNT(id) FROM #__yendifvideoshare_ratings WHERE videoid=' . JFactory::getApplication()->input->getInt( 'id' );
        $db->setQuery( $query );
		
		return $db->loadResult();			
	}
		
}