%PDF-
%PDF-
Mini Shell
Mini Shell
<?php
/**
* @version CVS: 1.0.0
* @package Com_Projectmanager
* @author Sandeep <>
* @copyright Copyright (C) 2016. All rights reserved.
* @license
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
* Methods supporting a list of Projectmanager records.
*
* @since 1.6
*/
class ProjectmanagerModelProjects extends JModelList
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'name', 'a.name',
'start_date', 'a.start_date',
'finish_date', 'a.finish_date',
'description', 'a.description',
'long_description', 'a.long_description',
'main_image', 'a.main_image',
'sliderimage1', 'a.sliderimage1',
'sliderimage2', 'a.sliderimage2',
'sliderimage3', 'a.sliderimage3',
'sliderimage4', 'a.sliderimage4',
'state', 'a.state',
'ordering', 'a.ordering',
'created_by', 'a.created_by',
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering Elements order
* @param string $direction Order direction
*
* @return void
*
* @throws Exception
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication();
// List state information
//$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'));
//echo "Limit=".$limit; die;
$limit = 100;
$this->setState('list.limit', $limit);
//$this->setState('list.limit', 0);
$limitstart = $app->getUserStateFromRequest('limitstart', 'limitstart', 0);
$this->setState('list.start', $limitstart);
if ($list = $app->getUserStateFromRequest($this->context . '.list', 'list', array(), 'array'))
{
foreach ($list as $name => $value)
{
// Extra validations
switch ($name)
{
case 'fullordering':
$orderingParts = explode(' ', $value);
if (count($orderingParts) >= 2)
{
// Latest part will be considered the direction
$fullDirection = end($orderingParts);
if (in_array(strtoupper($fullDirection), array('ASC', 'DESC', '')))
{
$this->setState('list.direction', $fullDirection);
}
unset($orderingParts[count($orderingParts) - 1]);
// The rest will be the ordering
$fullOrdering = implode(' ', $orderingParts);
if (in_array($fullOrdering, $this->filter_fields))
{
$this->setState('list.ordering', $fullOrdering);
}
}
else
{
$this->setState('list.ordering', $ordering);
$this->setState('list.direction', $direction);
}
break;
case 'ordering':
if (!in_array($value, $this->filter_fields))
{
$value = $ordering;
}
break;
case 'direction':
if (!in_array(strtoupper($value), array('ASC', 'DESC', '')))
{
$value = $direction;
}
break;
case 'limit':
$limit = $value;
break;
// Just to keep the default case
default:
$value = $value;
break;
}
$this->setState('list.' . $name, $value);
}
}
// Receive & set filters
if ($filters = $app->getUserStateFromRequest($this->context . '.filter', 'filter', array(), 'array'))
{
foreach ($filters as $name => $value)
{
$this->setState('filter.' . $name, $value);
}
}
$ordering = $app->input->get('filter_order');
if (!empty($ordering))
{
$list = $app->getUserState($this->context . '.list');
$list['ordering'] = $app->input->get('filter_order');
$app->setUserState($this->context . '.list', $list);
}
$orderingDirection = $app->input->get('filter_order_Dir');
if (!empty($orderingDirection))
{
$list = $app->getUserState($this->context . '.list');
$list['direction'] = $app->input->get('filter_order_Dir');
$app->setUserState($this->context . '.list', $list);
}
$list = $app->getUserState($this->context . '.list');
if (empty($list['ordering']))
{
$list['ordering'] = 'ordering';
}
if (empty($list['direction']))
{
$list['direction'] = 'asc';
}
if (isset($list['ordering']))
{
$this->setState('list.ordering', $list['ordering']);
}
if (isset($list['direction']))
{
$this->setState('list.direction', $list['direction']);
}
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query
->select(
$this->getState(
'list.select', 'DISTINCT a.*'
)
);
$query->from('`#__projectmanager_projects` AS a');
// Join over the created by field 'created_by'
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
if (!JFactory::getUser()->authorise('core.edit.state', 'com_projectmanager'))
{
$query->where('a.state = 1');
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->Quote('%' . $db->escape($search, true) . '%');
}
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol && $orderDirn)
{
$query->order($db->escape($orderCol . ' ' . $orderDirn));
}
return $query;
}
/**
* Method to get an array of data items
*
* @return mixed An array of data on success, false on failure.
*/
public function getItems()
{
$items = parent::getItems();
return $items;
}
/**
* Overrides the default function to check Date fields format, identified by
* "_dateformat" suffix, and erases the field if it's not correct.
*
* @return void
*/
protected function loadFormData()
{
$app = JFactory::getApplication();
$filters = $app->getUserState($this->context . '.filter', array());
$error_dateformat = false;
foreach ($filters as $key => $value)
{
if (strpos($key, '_dateformat') && !empty($value) && $this->isValidDate($value) == null)
{
$filters[$key] = '';
$error_dateformat = true;
}
}
if ($error_dateformat)
{
$app->enqueueMessage(JText::_("COM_PROJECTMANAGER_SEARCH_FILTER_DATE_FORMAT"), "warning");
$app->setUserState($this->context . '.filter', $filters);
}
return parent::loadFormData();
}
/**
* Checks if a given date is valid and in a specified format (YYYY-MM-DD)
*
* @param string $date Date to be checked
*
* @return bool
*/
private function isValidDate($date)
{
$date = str_replace('/', '-', $date);
return (date_create($date)) ? JFactory::getDate($date)->format("Y-m-d") : null;
}
}
Zerion Mini Shell 1.0