| Current Path : /var/www/components/com_yendifvideoshare/models/ |
| Current File : /var/www/components/com_yendifvideoshare/models/search.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 YendifVideoShareModelSearch extends YendifVideoShareModel {
var $searchKey;
public function getItems( $limit, $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 v.* FROM #__yendifvideoshare_videos AS v';
$query .= ' LEFT JOIN #__yendifvideoshare_categories AS c ON v.catid=c.id';
$query .= ' WHERE v.published=1 AND c.published=1';
if ( $check_publishing_options ) {
$date = JFactory::getDate();
$nowDate = $db->quote( $date->toSql() );
$nullDate = $db->quote( $db->getNullDate() );
$query .= " AND ( v.published_up = " . $nullDate . " OR v.published_up <= " . $nowDate . ' )';
$query .= " AND ( v.published_down = " . $nullDate . " OR v.published_down >= " . $nowDate . ' )';
}
$this->searchKey = $app->getUserStateFromRequest( 'yendif.search.public', 'search', '', 'string' );
$this->searchKey = JString::strtolower( $this->searchKey );
$searchKey = $db->quote( '%' . $db->escape( $this->searchKey, true ) . '%', false );
$query .= ' AND (CONCAT(v.title,v.description,v.meta_keywords,v.meta_description) LIKE ' . $searchKey . ' OR c.name LIKE ' . $searchKey . ')';
$query.= ' ORDER BY v.id DESC';
$db->setQuery( $query, $limitstart, $limit );
$items = $db->loadObjectList();
return $items;
}
public function getTotal( $check_publishing_options ) {
$app = JFactory::getApplication();
$db = JFactory::getDbo();
$query = 'SELECT COUNT(v.id) FROM #__yendifvideoshare_videos AS v';
$query .= ' LEFT JOIN #__yendifvideoshare_categories AS c ON v.catid=c.id';
$query .= ' WHERE v.published=1 AND c.published=1';
if ( $check_publishing_options ) {
$date = JFactory::getDate();
$nowDate = $db->quote( $date->toSql() );
$nullDate = $db->quote( $db->getNullDate() );
$query .= " AND ( v.published_up = " . $nullDate . " OR v.published_up <= " . $nowDate . ' )';
$query .= " AND ( v.published_down = " . $nullDate . " OR v.published_down >= " . $nowDate . ' )';
}
$this->searchKey = $app->getUserStateFromRequest( 'yendif.search.public', 'search', '', 'string' );
$this->searchKey = JString::strtolower( $this->searchKey );
$searchKey = $db->quote( '%' . $db->escape( $this->searchKey, true ) . '%', false );
$query .= ' AND (CONCAT(v.title,v.description,v.meta_keywords,v.meta_description) LIKE ' . $searchKey . ' OR c.name LIKE ' . $searchKey . ')';
$query.= ' ORDER BY v.id DESC';
$db->setQuery( $query );
$count = $db->loadResult();
return $count;
}
public function getPagination( $check_publishing_options ) {
jimport( 'joomla.html.pagination' );
$count = $this->getTotal( $check_publishing_options );
$pageination = new JPagination( $count, $this->getState( 'limitstart' ), $this->getState( 'limit' ) );
return $pageination;
}
}