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');
require_once dirname(__FILE__).'/entries.php';
/**
* My Entries model.
*/
class RSDirectoryModelMyEntries extends RSDirectoryModelEntries
{
/**
* 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 JInput object.
$jinput = JFactory::getApplication()->input;
// 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('#__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') )
->leftJoin( $db->qn('#__rsdirectory_favorites', 'f') . ' ON ' . $db->qn('e.id') . ' = ' . $db->qn('f.entry_id') . ' AND ' . $db->qn('f.user_id') . ' = ' . $db->q($user->id) )
->where( $db->qn('e.user_id') . ' = ' . $db->q($user->id) );
// Initialize the featured categories array.
$featured_categories = array();
// Get categories filter.
$categories = $jinput->get('categories', array(), 'array');
// Get a single category.
$category = $jinput->getInt('category');
if ($category) {
$categories[] = $category;
}
if (!empty($categories)) {
$featured_categories = RSDirectoryHelper::arrayInt($categories);
}
// Get the featured categories from the module settings if there were no categories filters.
if (!$featured_categories)
{
$featured_categories = RSDirectoryHelper::arrayInt( $params->get('featured_categories') );
}
if (!empty($featured_categories) && !in_array(0, $featured_categories)) {
// Let's see if the featured categories we've selected are accessible
if ($categories_filtered_ids = array_intersect($featured_categories, $this->getCategories())) {
$categories_ids = array();
foreach ($categories_filtered_ids as $id) {
$categories_ids[] = $id;
$categories_ids = array_merge($categories_ids, $this->getCategories($id));
}
}
} else {
$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) ) . ')' );
$statuses = $jinput->get( 'status', array(0, 1), 'status' );
$status_conditions = array();
if ( in_array(0, $statuses) )
{
$status_conditions[] = '(' . $db->qn('e.published') . ' = ' . $db->q(0) . ' OR ' . $db->qn('e.expiry_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) . ')';
}
if ( in_array(1, $statuses) )
{
$status_conditions[] = '((' . $db->qn('e.published') . ' = ' . $db->q(1) . ' AND ' . $db->qn('e.published_time') . ' <= ' . $db->q( JFactory::getDate()->toSql() ) . ') AND (' . $db->qn('e.expiry_time') . ' = ' . $db->q('0000-00-00 00:00:00') . ' OR ' . $db->qn('e.expiry_time') . ' >= ' . $db->q( JFactory::getDate()->toSql() ) . '))';
}
if ($status_conditions)
{
$query->where( '(' . implode(' OR ', $status_conditions) . ')' );
}
if ($f = $jinput->get('f', array(), 'array')) {
if ($jinput->getInt('filter')) {
$fields = RSDirectoryHelper::getFilterFields($featured_categories);
RSDirectoryHelper::buildEntriesFilteringQuery($fields, $f, $query);
} // Process "Categories from Field Values".
else {
$fields = RSDirectoryHelper::getFormFields(null, true, true);
if ($fields) {
foreach ($f as $form_field_name => $values) {
if (is_string($values) && $values === '')
continue;
$field = RSDirectoryHelper::findElements(array('form_field_name' => $form_field_name), $fields);
if (!$field)
continue;
$table = $field->create_column ? 'ec' : 'e';
$column_name = $db->qn("$table.$field->column_name");
// Initialize the condition array.
$cond = array();
if (!is_array($values)) {
$values = (array)$values;
}
foreach ($values as $value) {
if (is_string($value) && $value === '')
continue;
$cond[] = $column_name . ' LIKE ' . $db->q('%' . $db->escape($value, true) . '%');
}
if ($cond) {
$query->where('(' . implode(' OR ', $cond) . ')');
}
}
}
}
}
// 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;
}
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