Hello there!

Im having some trouble getting Views and a Date integrated with my custom module and came here for some help.

So I have a custom module (project name "Tracky") that saves "any kinds of tracker data" (sports activities, repeats of some sort etc, just name it) into a database table. For example, when I save my workout in the system, it saves one row to a database. The data columns saved are id, date, value and all kinds of extra information (for example type of sports etc). I have already integrated this with Views so that I can get the saved rows into a views list and it works well. Filtering works mostly too, however, I am having problems with date values. What I want to achieve is:

- When user goes to URL mydrupalsite.com/summary/[DATE], he sees a filtered list of activities, not all. I have not been able to get the date filtering/arguments to work.
- The [DATE] value can be YYYY-MM (2016-03) or YYYY-\WWW (2016-W07). So basicly there will be only one date argument and it should filter the Views rows so that for example if certain month is given, the rows include all activities from that month. This isn't the problem though.

The problem is, when I add arguments to the view, I just can't get stuff working. When using date_views_argument_handler as the argument handler, I can add the argument but my date field is not listed in the "Date field(s)" section in the argument window so I can't choose it there. Only values there are user related fields. So am I missing some integration that would tell my date field is really a date and should be listed there too?

When using date_views_argument_handler_simple the "Date field(s)" select list is not in the window so I don't have to choose anything there, but after adding the argument and testing it, any date format argument just makes the views list completely empty.

Here's the essential part of the tracky.views.inc:

<?php
function tracky_views_data () {
	
	$data = array();
	
	$data['tracky_activities']['table']['group'] = t('Tracky | Activities');
	$data['tracky_activities']['table']['base'] = array(
		'field'         => 'aid',
		'title'         => t('Tracky | Activities'),
	);
	$data['tracky_activities']['started'] = array(
		'title'         => t('Started'),
		'field'         => array(
			'title'             => t('Started'),
			'handler'           => 'views_handler_field_date',
			'click sortable'    => true,
			'is date' 			=> TRUE,
		),
		'sort'          => array(
			'handler'   => 'views_handler_sort_date',
			'is date' 	=> TRUE,
		),
		'argument' => array(
			'handler' 	=> 'date_views_argument_handler',
			'is date' 	=> TRUE,
		),
	);
	$data['tracky_activities']['value'] = array(
		'title'         => t('Value'),
		'field'         => array(
			'title'             => t('Value'),
			'click sortable'    => true,
		),
		'sort'          => array(
			'handler'   => 'views_handler_sort',
		),
	);
	$data['tracky_activities']['notes']['field'] = array(
		'title'         => t('Notes'),
	);
	$data['tracky_activities']['actions'] = array(
		'title'         => t('Actions'),
		'field'         => array(
			'title'             => t('Actions'),
			'handler'           => 'tracky_views_handler_field_activity_actions',
		),
	);
	
	/* ...more code here... */
	
	return $data;
	
}
?>

I used to use custom views field handler for the started-field too but reverted it back to basics (views_handler_field_date) just to see that is not the problem. Also didn't originally have the 'is date' = TRUE in the code so added it but it had no effect.

I don't think this is any kind of huge problem to get fixed, but I am quite new to views integration myself and just don't know what to search for anymore. Or even if it is views or date related problem.

Comments

phonkala’s picture

Anyone able to help me a bit with this? Still have no solution.