Events listing system using Date, CCK and Views modules – Part 2

Events listing system using Date, CCK and Views modules – Part 2

This is part 2 of “Events listing system using Date, CCK and Views modules”, if you missed part one you can find it here.

In part one we set up our event CCK node type so now we’re going to look at setting up a view to list our events.
Views Setup
Lets not waste time and get stuck in to make our events view.
Go to yoursite.com/admin/build/views, click the “Add” tab and input the following details:

Basic Information fieldset
Name: events
Page fieldset
Provide Page View: Check the box

URL: events
View Type: Table View
Title: Events Listing
Use Pager: Check the box
Nodes per Page: Up to you I’m using 20
Click the “Save and edit” button and scroll down to the Fields fieldset and select the following fields:

Node: Title
Datestamp: Start Date and input “Start Date” as the label
Datestamp: End Date and input “End Date” as the label

These are the fields that will show in our events table.
Click the “Save and edit” button again and scroll down the Filters fieldset and add the following filters:

Node: Type | Operator = Is One Of | Value = Event
Node: Published | Value = Yes
Datestamp: End Date – Date | Operator = greater than or equal to | Option = now

Here we are narrowing down which nodes our view should select by adding criteria.
We’re using the End Date filter to only select events that haven’t already happened by saying only select events where the events end date is greater than or equal to now ie. the end date hasn’t already passed.
Click the “Save and edit” button yet again and scroll down to the Sort Criteria fieldset and select:

Datestamp: Start Date | Order = Ascending
Datestamp: End Date | Order = Ascending

This will ensure our events our ordered as they are happening ie. the events happening first are at the top.

That’s it you should now have a basic events system up and running.

Here’s the exported views code from our events view
$view = new stdClass();
$view->name = ‘events’;
$view->description = ”;
$view->access = array (
);
$view->view_args_php = ”;
$view->page = TRUE;
$view->page_title = ‘Upcoming Events’;
$view->page_header = ”;
$view->page_header_format = ‘1’;
$view->page_footer = ”;
$view->page_footer_format = ‘1’;
$view->page_empty = ”;
$view->page_empty_format = ‘1’;
$view->page_type = ‘table’;
$view->url = ‘events’;
$view->use_pager = TRUE;
$view->nodes_per_page = ’30’;
$view->sort = array (
array (
‘tablename’ => ‘node_data_field_start_date’,
‘field’ => ‘field_start_date_value’,
‘sortorder’ => ‘ASC’,
‘options’ => ”,
),
array (
‘tablename’ => ‘node_data_field_end_date’,
‘field’ => ‘field_end_date_value’,
‘sortorder’ => ‘ASC’,
‘options’ => ”,
),
);
$view->argument = array (
);
$view->field = array (
array (
‘tablename’ => ‘node’,
‘field’ => ‘title’,
‘label’ => ”,
‘handler’ => ‘views_handler_field_nodelink’,
‘options’ => ‘link’,
),
array (
‘tablename’ => ‘node_data_field_start_date’,
‘field’ => ‘field_start_date_value’,
‘label’ => ‘Start Time’,
‘handler’ => ‘content_views_field_handler_group’,
‘options’ => ‘medium’,
),
array (
‘tablename’ => ‘node_data_field_end_date’,
‘field’ => ‘field_end_date_value’,
‘label’ => ‘End Time’,
‘handler’ => ‘content_views_field_handler_group’,
‘options’ => ‘medium’,
),
);
$view->filter = array (
array (
‘tablename’ => ‘node’,
‘field’ => ‘type’,
‘operator’ => ‘OR’,
‘options’ => ”,
‘value’ => array (

0 => ‘event’,
),
),
array (
‘tablename’ => ‘node’,
‘field’ => ‘status’,
‘operator’ => ‘=’,
‘options’ => ”,
‘value’ => ‘1’,
),
array (
‘tablename’ => ‘node_data_field_end_date’,
‘field’ => ‘field_end_date_value_default’,
‘operator’ => ‘>=’,
‘options’ => ‘now’,
‘value’ => ”,
),
);
$view->exposed_filter = array (
);
$view->requires = array(node_data_field_start_date, node_data_field_end_date, node);
$views[$view->name] = $view;

In the final part I’ll look at possible ways you could improve this events system and take it further.

Leave a Reply

Your email address will not be published.