Your IP : 10.10.0.253


Current Path : /var/www/components/com_yendifvideoshare/models/
Upload File :
Current File : /var/www/components/com_yendifvideoshare/models/category.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 YendifVideoShareModelCategory extends YendifVideoShareModel {

	public function getItem() {	
        $db = JFactory::getDbo();	
		 	
        $query = "SELECT * FROM #__yendifvideoshare_categories WHERE published=1 AND id=" . JFactory::getApplication()->input->getInt( 'id' );
       
		$db->setQuery( $query );
        $item = $db->loadObject();
		 
        return $item;		 
	}
	
	public function getVideos( $limit, $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 );
		 
        $query  = 'SELECT * FROM #__yendifvideoshare_videos WHERE published=1 AND catid=' . $app->input->getInt( 'id' );

		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 . ' )';		
		}			 				 
		 
		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( $filterby, $check_publishing_options ) {	
		$app = JFactory::getApplication();	
        $db = JFactory::getDbo();

        $query = 'SELECT COUNT(id) FROM #__yendifvideoshare_videos WHERE published=1 AND catid=' . $app->input->getInt( 'id' );
		 
		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 . ' )';
		}
		 
		if ( $filterby == 'featured' ) {
		 	$query .= ' AND featured=1';
		}
		 
        $db->setQuery( $query );
        $count = $db->loadResult();
		 
		return $count;		
	}
	
	public function getPagination( $filterby, $check_publishing_options ) {	
    	jimport( 'joomla.html.pagination' );	
		 	 
		$count = $this->getTotal( $filterby, $check_publishing_options );
		$pagination = new JPagination( $count, $this->getState( 'limitstart' ), $this->getState( 'limit' ) );
        
		return $pagination;		 
	}
	
	public function getCategories( $orderby ) {	
        $db = JFactory::getDbo();
		 
        $query = 'SELECT * FROM #__yendifvideoshare_categories WHERE published=1 AND parent=' . JFactory::getApplication()->input->getInt( 'id' );
		 
		switch ( $orderby ) {		 	
			case 'data_added':
				$query .= ' ORDER BY id ASC';
				break;
			case 'a_z':
				$query .= ' ORDER BY name ASC';
				break;
			case 'z_a':
				$query .= ' ORDER BY name 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 );
        $items = $db->loadObjectList();
		 
        return $items;		 
	}
	
}