Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Datetime filter NOT WORKING in generated component 09 Jan 2014 07:26 #11947

I'm sorry to say this, but to be honest I always found the datetime filter a bit buggy and it never really worked to me (but maybe it was due to my settings in the jcook builder, not using the default values.), so I always tried to avoid to use it, now that I'm in need of it, I had to take a look on it.
By the way the datetime filter doesn't filter anything with my configuration, because the filter value is not converted to unixtime in the model list.

jcook Scenario:
- datetime filed with unixtime selected and format d-m-Y H:i:s
- filter "from date" - "to date" added in grid view
- submit on change, selected


generated component:
- UI perfectly working
- model list doesn't submit the unixtime to the DB query


bug caused by:
ROOT\administrator\components\com_mycomponent\models\myitemslist.php
		//Define the filterable fields
		$this->set('filter_vars', array(
			'creation_date_from' => 'cmd',
			'creation_date_to' => 'cmd',
			'sortTable' => 'cmd',
			'directionTable' => 'cmd',
			'limit' => 'cmd'
				));
with that code the function getUserStateFromRequest doesn't return the correct value for the datetime, so nothing can work.


fix:
		//Define the filterable fields
		$this->set('filter_vars', array(
			'creation_date_from' => 'string', /* hack */
			'creation_date_to' => 'string', /* hack */
			'sortTable' => 'cmd',
			'directionTable' => 'cmd',
			'limit' => 'cmd'
				));


then in the same file:
//WHERE - FILTER : Creation date
if($this->getState('filter.creation_date_from') !== null)
	$this->addWhere("a.creation_date >= " . (int)JformsHelperDates::getUnixTimestamp($this->getState('filter.creation_date_from')));

//WHERE - FILTER : Creation date
if($this->getState('filter.creation_date_to') !== null)
	$this->addWhere("a.creation_date <= " . (int)JformsHelperDates::getUnixTimestamp($this->getState('filter.creation_date_to')));
the FORMAT of the datetime is missing, so the getUnixTimestamp will return an empty value


fix:
//WHERE - FILTER : Creation date
if($this->getState('filter.creation_date_from') !== null)
	$this->addWhere("a.creation_date >= " . (int)JformsHelperDates::getUnixTimestamp($this->getState('filter.creation_date_from'),array('d-m-Y H:i:s'))); /* hack */

//WHERE - FILTER : Creation date
if($this->getState('filter.creation_date_to') !== null)
	$this->addWhere("a.creation_date <= " . (int)JformsHelperDates::getUnixTimestamp($this->getState('filter.creation_date_to'),array('d-m-Y H:i:s'))); /* hack */
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

Last edit: by Tomaselli.

Datetime filter NOT WORKING in generated component 17 May 2015 10:11 #13014

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Fixed now.

Thank you very much for this good catch.
K+
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.071 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started