Sindbad~EG File Manager
<?php
/**
* @package RSDirectory!
* @copyright (c) 2013 - 2021 RSJoomla!
* @link https://www.rsjoomla.com
* @license GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// No direct access.
defined('_JEXEC') or die('Restricted access');
/**
* Favorites model.
*/
class RSDirectoryModelFavorites extends JModelList
{
/**
* Constructor.
*
* @access public
*
* @param array An optional associative array of configuration settings.
*/
public function __construct( $config = array() )
{
if ( empty($config['filter_fields'] ) )
{
$config['filter_fields'] = array_merge(array('c.path', 'c.lft'), array_keys($this->getSortFields()));
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* @access protected
*
* @param string $ordering
* @param string $direction
*/
protected function populateState($ordering = null, $direction = null)
{
$params = JFactory::getApplication()->getParams();
$this->setState('params', $params);
list($order_field, $order_direction) = $this->splitOrdering($params->get('order_by', 'f.created_time-desc'));
// List state information.
parent::populateState($order_field, $order_direction);
}
/**
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
*
* @access protected
*
* @return object A JDatabaseQuery object to retrieve the data set.
*/
protected function getListQuery()
{
// Get DBO.
$db = JFactory::getDbo();
// Get the JUser object.
$user = JFactory::getUser();
// Get the menu item params.
$params = $this->state->params;
// Get entry author display info (name, username, email..).
$author = RSDirectoryConfig::getInstance()->get('entry_author', 'name');
$select = array(
$db->qn('e') . '.*',
$db->qn('ec') . '.*',
$db->qn('c.title', 'category_title'),
$db->qn('c.path', 'category_path'),
$db->qn('f.entry_id', 'faved'),
$db->qn("u.$author", 'author'),
' IF('.$db->qn("e.modified_time").' = '.$db->q('0000-00-00 00:00:00').', '.$db->qn("e.published_time").', '.$db->qn("e.modified_time").') as `modified_last`'
);
$query = $db->getQuery(true)
->select($select)
->from( $db->qn('#__rsdirectory_entries', 'e') )
->innerJoin( $db->qn('#__rsdirectory_entries_custom', 'ec') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('ec.entry_id') )
->innerJoin( $db->qn('#__rsdirectory_favorites', 'f') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('f.entry_id') )
->innerJoin( $db->qn('#__categories', 'c') . ' ON ' . $db->qn('e.category_id') . ' = ' . $db->qn('c.id') )
->innerJoin( $db->qn('#__users', 'u') . ' ON ' . $db->qn('e.user_id') . ' = ' . $db->qn('u.id') )
->where( '(' . $db->qn('e.expiry_time') . ' = ' . $db->q('0000-00-00 00:00:00') . ' OR ' . $db->qn('e.expiry_time') . ' >= ' . $db->q( JFactory::getDate()->toSql() ) . ')' )
->where( $db->qn('u.block') . ' = ' . $db->q(0) )
->where( $db->qn('f.user_id') . ' = ' . $db->q($user->id) );
// Process permissions.
if ( !RSDirectoryHelper::checkUserPermission('can_view_all_unpublished_entries') )
{
if ( RSDirectoryHelper::checkUserPermission('can_view_own_unpublished_entries') )
{
$cond1 = '(' . $db->qn('e.published') . ' = ' . $db->q(1) . ' AND ' . $db->qn('e.published_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) . ')';
$cond2 = $db->qn('u.id') . ' = ' . $db->q($user->id);
$query->where("($cond1 OR $cond2)");
}
else
{
$query->where( $db->qn('e.published') . ' = ' . $db->q(1) )
->where( $db->qn('e.published_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) );
}
}
$categories_ids = $this->getCategories();
if ( empty($categories_ids) )
{
$categories_ids = array(0);
}
$query->where( $db->qn('e.category_id') . ' IN (' . implode( ',', array_unique($categories_ids) ) . ')' );
// Initialize the order array.
$order = array();
switch ( $params->get('orderby_pri') )
{
case 'alpha':
$order[] = $db->qn('c.path');
break;
case 'ralpha':
$order[] = $db->qn('c.path') . ' DESC ';
break;
case 'order':
$order[] = $db->qn('c.lft');
break;
}
// set the fields and direction based on the users selection
list($order_field, $order_direction) = $this->splitOrdering();
if ($order_field == 'e.avg_rating') {
$order[] = $db->qn( $order_field ) . ' '.$db->escape( $order_direction ).', '.$db->qn('e.ratings_count') .' ' . $db->escape( $order_direction );
}
else {
$order[] = $db->qn( $order_field ) . ' ' . $db->escape( $order_direction );
}
// end setting the order
$query->order($order);
return $query;
}
/**
* Method to get a list of entries.
*
* @access public
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Get items.
$items = parent::getItems();
// Exit the function if there are no results.
if (!$items)
return;
return RSDirectoryHelper::getEntriesData($items);
}
protected function getSortFields() {
return array(
'f.created_time-asc' => JText::_('COM_RSDIRECTORY_CREATED_TIME_ASC'),
'f.created_time-desc' => JText::_('COM_RSDIRECTORY_CREATED_TIME_DESC'),
'e.price-asc' => JText::_('COM_RSDIRECTORY_PRICE_ASC'),
'e.price-desc' => JText::_('COM_RSDIRECTORY_PRICE_DESC'),
'e.published_time-asc' => JText::_('COM_RSDIRECTORY_PUBLISHED_TIME_ASC'),
'e.published_time-desc' => JText::_('COM_RSDIRECTORY_PUBLISHED_TIME_DESC'),
'modified_last-asc' => JText::_('COM_RSDIRECTORY_MODIFIED_LAST_ASC'),
'modified_last-desc' => JText::_('COM_RSDIRECTORY_MODIFIED_LAST_DESC'),
'e.expiry_time-asc' => JText::_('COM_RSDIRECTORY_EXPIRY_TIME_ASC'),
'e.expiry_time-desc' => JText::_('COM_RSDIRECTORY_EXPIRY_TIME_DESC'),
'e.title-asc' => JText::_('COM_RSDIRECTORY_TITLE_ASC'),
'e.title-desc' => JText::_('COM_RSDIRECTORY_TITLE_DESC'),
'e.big_subtitle-asc' => JText::_('COM_RSDIRECTORY_BIG_SUBTITLE_ASC'),
'e.big_subtitle-desc' => JText::_('COM_RSDIRECTORY_BIG_SUBTITLE_DESC'),
'e.small_subtitle-asc' => JText::_('COM_RSDIRECTORY_SMALL_SUBTITLE_ASC'),
'e.small_subtitle-desc' => JText::_('COM_RSDIRECTORY_SMALL_SUBTITLE_DESC'),
'author-asc' => JText::_('COM_RSDIRECTORY_AUTHOR_ASC'),
'author-desc' => JText::_('COM_RSDIRECTORY_AUTHOR_DESC'),
'e.hits-asc' => JText::_('COM_RSDIRECTORY_HITS_ASC'),
'e.hits-desc' => JText::_('COM_RSDIRECTORY_HITS_DESC'),
'e.ratings_count-asc' => JText::_('COM_RSDIRECTORY_RATINGS_COUNT_ASC'),
'e.ratings_count-desc' => JText::_('COM_RSDIRECTORY_RATINGS_COUNT_DESC'),
'e.avg_rating-asc' => JText::_('COM_RSDIRECTORY_AVG_RATING_ASC'),
'e.avg_rating-desc' => JText::_('COM_RSDIRECTORY_AVG_RATING_DESC')
);
}
protected function splitOrdering($value = null) {
if ($value === null) {
$value = $this->getState('list.ordering');
}
// format is 'column-direction'
$parts = explode('-', $value, 2);
// grab the column
$column = $parts[0];
// grab the direction
if (isset($parts[1])) {
$direction = $parts[1];
} else {
$direction = $this->getState('list.direction');
}
return array($column, $direction);
}
/**
* Method to get a select for the sorting options.
*
* @access public
*
* @return string
*/
public function getSortField()
{
$params = JFactory::getApplication()->getParams();
$fields = $this->getSortFields();
$options = array();
$options[] = JHtml::_('select.option', '', JText::_('COM_RSDIRECTORY_SORT_BY'));
foreach ($fields as $value => $text) {
$value = (string) $value;
$param = 'order_by_'.str_replace(array('f.', 'e.', '-asc', '-desc'), '', $value);
if ($params->get($param, 1)) {
$options[] = JHtml::_('select.option', $value, $text);
}
}
return JHtml::_( 'select.genericlist', $options, 'filter_order', ' class="input-medium '.RsdirectoryAdapterGrid::formSelect().' '.RsdirectoryAdapterGrid::float('right').'" onchange="adminForm.submit();"', 'value', 'text', $this->getState('list.ordering') );
}
protected function getCategories($id = 'root') {
$options = array(
'extension' => 'com_rsdirectory',
'table' => '#__rsdirectory_entries',
'field' => 'category_id',
'statefield' => 'published',
'countItems' => false
);
// Create a new JCategories object.
$categories = new JCategories($options);
if ($root = $categories->get($id)) {
if ($children = $root->getChildren()) {
return $this->getIds($children);
}
}
return array();
}
protected function getIds($categories) {
$ids = array();
foreach ($categories as $category) {
$ids[] = $category->id;
if ($category->hasChildren()) {
$ids = array_merge($ids, $this->getIds($category->getChildren()));
}
}
return $ids;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists