Welcome, Guest
Username: Password: Remember me

TOPIC: [ tutorial | how make your own filter ]

[ tutorial | how make your own filter ] 10 Oct 2011 17:33 #186

  • doob
  • doob's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 2
  • Karma: 5
Change 'com_calendar' and 'events' for your names...

You need those files:

MODEL :
(M1) - components/com_calendar/models/events.php

HELPER :
(H1) - administrator/components/com_calendar/helpers/helper.php

VIEW :
(V1) - components/com_calendar/views/events/tmpl/default_filters.php
(V2) - components/com_calendar/views/events/view.html.php

CONTROLLER :
(C1) - components/com_calendar/controllers/events.php


(M1)
class CalendarModelEvents extends CalendarModelList
{
...
function _buildQueryWhere()
	{
		$where = array();

		$app = &JFactory::getApplication();
		$db=& JFactory::getDBO();
		$option	= JRequest::getCmd('option');
		$view	= JRequest::getCmd('view');
		$layout	= JRequest::getCmd('layout', 'default');

		$baseUserState = $option . '_' . $view . '.' . $layout . '.';

		if ($this->_active['filter'])
		{
			$filter_type = $this->getState('filter_type');
			if ($filter_type != '')	$where[] = "a.type = " . $db->Quote($filter_type);

			$filter_category = $this->getState('filter_category');
			if ($filter_category != '')	$where[] = "a.category = " . $db->Quote($filter_category);
>>> JUST ADD THOSE CODE ( CHANGE ANY DATE FOR YOUR FIELD NAME )
>>>			$filter_date = $this->getState('filter_date');
>>>			if ($filter_date != '')	$where[] = "a.date = " . $db->Quote($filter_date);
>>> END
		}


(H1)
class CalendarHelper
{
 ...
>>> ADD THOSE CODE ( CHANGE ANY DATE FOR YOUR FIELD NAME )
	function dbList($ctrl, $fieldName)
	{
		$db =& JFactory::getDBO();
		$query = 'SELECT *,'. $fieldName .' FROM #__' . 'calendar_'.$ctrl;

		$db->setQuery( $query );

		$list = $db->loadObjectList();

		$lists[$ctrl][$fieldName] = array();
		$id = 1;
		foreach($list as $l ){
			$lists[$ctrl][$fieldName][$id] = array("value" => $l->date, "text" => $l->date);
			$id++;
		}	

		return $lists[$ctrl][$fieldName]; 

	}

>>> ....


(V1)
...
<script language="javascript" type="text/javascript">
<!--

function resetFilters()
{
	if ($('filter_type') != null)
	    $('filter_type').value='';
	if ($('filter_category') != null)
	    $('filter_category').value='';
>>>>>>>>>>>>>>>>>>>>
>>>	if ($('filter_date') != null)
>>>	    $('filter_date').value='';
>>>>>>>>>>>>>>>>>>>>

....

window.addEvent('domready', function()
{
	//Reset broken filter (if selected value is not anymore available)
	if (  !checkFilter('filter_type', ("<?php echo($this->filters['type']->value); ?>" == ''))
		|| !checkFilter('filter_category', ("<?php echo($this->filters['category']->value); ?>" == ''))

>>>>>
	>>>	|| !checkFilter('filter_date', ("<?php echo($this->filters['date']->value); ?>" == '')))

>>>>>
....
<legend onclick="toggle_div('filters_wrapper');"><?php echo JText::_( "JSEARCH_FILTER_LABEL" ); ?></legend>
>>>>>
>>> <!-- SELECT : Datee  -->

	<div class='filter filter_date'>
			<label for="filter_date"><?php echo(JText::_("CALENDAR_JSEARCH_DATE")); ?> :</label>			
			<?php echo JHTML::_('select.genericlist',  $this->filters['date']->list, 'filter_date', " onchange = 'this.form.submit()'", 'value', 'text', $this->filters['date']->value);?>

		</div>

>>>>>>>> 

....



(V2)
class CalendarViewEvents extends JView
{
	function display($tpl = null)
	{

....
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_________HERE......
	$statesVars = array('limit', 'limitstart', 'filter_order', 'filter_order_Dir', 'filter_date', 'filter_type', 'filter_category');

.... 

function display_default($tpl = null)
{
.....
// table ordering
		$lists['order'] = $model->getState('filter_order');
		$lists['order_Dir'] = $model->getState('filter_order_Dir');

	>>>>	$lists['enum']['events.date'] = CalendarHelper::dbList('events', 'date');

.....

		//Filters
		//Date
		$this->filters['date'] = new stdClass();
		$this->filters['date']->list = $lists['enum']['events.date'];
		array_unshift($this->filters['date']->list, array("value"=>"", "text" => JText::_("CALENDAR_FILTER_NULL_DATE")));
		$this->filters['date']->value = $app->getUserState( $option . "_events.default.filter_date");

.....







(C1)
class CalendarControllerEvents extends CalendarController
{
	var $ctrl = 'events';
	var $singular = 'event';

	function __construct($config = array())
	{

		parent::__construct($config);

		$app = &JFactory::getApplication();


		// Register the filtering request variables
		$app->getUserStateFromRequest( $this->namespace . 'filter_type',		'filter_type',		'',	'varchar' );
		$app->getUserStateFromRequest( $this->namespace . 'filter_category',	'filter_category',	'',	'varchar' );
	>>>>>	$app->getUserStateFromRequest( $this->namespace . 'filter_date',		'filter_date',		'',	'date' );


....

		//Predefine fields depending on filters values
		$get = array();
		$app = &JFactory::getApplication();

>>>		//Date
>>>		$filter_date = $app->getUserState( $this->namespace . "filter_date");
>>>		if ($filter_date) $get[] = "filter_date=" . $filter_date;                
                
		//Type
		$filter_type = $app->getUserState( $this->namespace . "filter_type");
		if ($filter_type) $get[] = "filter_type=" . $filter_type;

Last Edit: 12 Oct 2011 06:29 by doob.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.059 seconds

Get Started