Many of the module that use the Date API allow for filtering content based on the dates. Example, filter all content that occurs in the future, or between these dates.

For this module, I would like to be able to filter on things such as is the node open today, currently (the current time is between the open and close times), or will be opening/closing in the next 'x' hours.

CommentFileSizeAuthor
#23 office_hours_readme_txt.PNG20.96 KBKanat Ospanov
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnv’s picture

Title: Request: Advanced Date Filters in Views » Request: Views Filters for Open/Closed today/now/soon
Status: Active » Closed (duplicate)
johnv’s picture

Title: Request: Views Filters for Open/Closed today/now/soon » Add Views Filters for Open/Closed (today/now/soon)
Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (duplicate) » Needs work

Re-opening this issue, since the issue mentioned in #1 refers to 'showing' not 'selecting' the status.

Latest -dev version contains Views 3 support.
The 2 Filter-handlers in the /includes directory are not converted yet, and should be able to perform this task.
(ATM they are disabled by commenting the out in the .info file.)

Patches are welcome.

johnv’s picture

Title: Add Views Filters for Open/Closed (today/now/soon) » Views 3: Add Filters for Open/Closed (today/now/soon)
adelka’s picture

subscribe

alayham’s picture

I am achieving "now open" filter in views using a views_php filter with the following code

$node=node_load($data->nid);
foreach($node->field_working_hours['und'] as $day){
	$d = (int)$day['day'];
	$s = (int)$day['starthours']/100;
	$e = (int)$day['endhours']/100;
    $start=strtotime('-1 sunday + ' . $d  . ' days + ' . $s/100  . ' hours');
    if($s>=$e)
		$d=$d+1;
    $end=strtotime('-1 sunday + ' . $d  . ' days + ' . $e/100  . ' hours');
 
   if(microtime()>=$start && microtime()<=$end) return true;
}
return false;

If you use minutes, you need to add them to the code.

FuXXz’s picture

Issue summary: View changes

Any plans to implement an open now / closed now Exposed filter in views?

Or is there a other way to get this function? Can the result from the views_php module exposed? Or can any other moudel read it? Maybe Rules? So is it possible to unpublish or fill a other field if the views_php filter return false?

johnv’s picture

Status: Needs work » Fixed

This commit adds a filter with options: closed/open now/open today.

FuXXz’s picture

Thank you for the commit.
If i try to add filter i get an Ajax error:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: ../admin/structure/views/ajax/add-item/navigation/default/filter
StatusText: Internal Server Error
ResponseText:

In addition there is an error in the log:
Notice: Undefined index: aliases in office_hours_field_views_data_alter() (Zeile 22 von ../sites/all/modules/office_hours/office_hours.views.inc).

  • johnv committed fd4fd9a on
    Issue #728026: Added Views Filter for Open/Closed (today/now/closed)
    
johnv’s picture

Above commit is a new try.

FuXXz’s picture

This johnv is awesome.
It works better, i can add the filter now but it can only filter the "open" nodes.
The closed dont work.
Bothe Filter display Error:

Notice: Undefined index: und in office_hours_handler_filter_open->post_execute() (line 115 of .../sites/all/modules/office_hours/includes/office_hours_handler_filter_open.inc).
Warning: Invalid argument supplied for foreach() in office_hours_handler_filter_open->post_execute() (line 115 of .../sites/all/modules/office_hours/includes/office_hours_handler_filter_open.inc).
Notice: Undefined index: und in office_hours_handler_filter_open->post_execute() (line 115 of .../sites/all/modules/office_hours/includes/office_hours_handler_filter_open.inc).
Warning: Invalid argument supplied for foreach() in office_hours_handler_filter_open->post_execute() (line 115 of .../sites/all/modules/office_hours/includes/office_hours_handler_filter_open.inc).

johnv’s picture

Yeah, the current version is very basic:
- you must use nodes. Not other entites, not revisions.
- you must not translate the field (hence the 'und') Please check the database which language you use. Do you use translation? Content Translation? Entity Translation?

I'll see what I can do. Please answer the above questions.

FuXXz’s picture

I installed the module and did no translation to it, but i use german language in the frontend. English for backend / Admin.
The vies show only node.
But i can't follow you which language my database is, where should i look ?

Now i deactivated locale module, deinstall it, reinstall office hours, create new contenttype, new office hour field, created a new view for nodes only. Now there is no error.
BUT the closed nodes still not visible if the filter is selected.

  • johnv committed 72bf039 on 7.x-1.x
    Issue #728026: Added Views Filter for Open/Closed (today/now/closed) -2-
    
johnv’s picture

Title: Views 3: Add Filters for Open/Closed (today/now/soon) » Add Views Filter handler for Open/Closed (today/now/soon)
Version: 7.x-1.x-dev » 7.x-1.3

Try the next update. It fixes the language problem and the selection problem.

johnv’s picture

FuXXz’s picture

Same Error, closed nodes not displayed. I will trie again a fresh Drupal

johnv’s picture

REmoving and re-adding the filter from your view might help (save inbetween)

FuXXz’s picture

No Change :( Same Error and behavior with 7.x-1.3+16-dev

FuXXz’s picture

7.x-1.3+17-dev works. I will try with locale and l10update etc.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sunil khan’s picture

Hello guys,
I have a problem

i have created new content type for tenders with following fields:
Title,
Files,
start date,
close date,
status ( open/close)
In view i want to apply following filter.
Between open and close date status will be open and i want to change status to close at closing date.

Kanat Ospanov’s picture

FileSize
20.96 KB

Hi,
Exposed filter does not work with open now \ closed now.
Drupal 7.64 Office hours 1.8

I see readme.txt, when will it be possible?