Drupal Tutorials

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

You should have read part one.
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.
  1. 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
  2. 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.
  3. 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.
  4. 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.

Commenting on this Tutorial is closed.

Categories:

Comments (24)

droople's picture

Hey admin,

Happy New Year.

Any news on Part 3?

DrupalSN's picture

Thanks Droople, same to you!!

Funny you should ask, i started looking at this again yesterday (i got half way through before xmas), so it’s in the pipeline.
I’ll try and finish it for next week.

Cheers
Tom

DrupalSN's picture

Scrap that i’ve just put up part 3: http://drupalsn.com/learn-drupal/drupal-tutorials/events-listing-system-...

Hope you like it, tried to make it more advanced
Tom

4 Ace Technologies's picture

i want to make calender block and when i create any event it these event should show in calender block.tell me how it is posible?

I need to know how to do this as well.
cd rates

calender making should not be that much difficult. pregnancy ultrasounds

4 Ace Technologies's picture

I have created a calender block using cck it shows the events on date but when i click on this date it shows the bigger calender but its not showing the events detail.

4 Ace Technologies's picture

Hi ,
Thanks admin to give us such a nice tutorial.
I want to ask you one thing i was trying to show only event time there dont want to show date than how can i do this? i have spent lots of time there ….

Thanks in Advance

DrupalSN's picture

Hi,

You should be able to alter the event start and end dates to show just the time by editing the the start and end date fields.
Near the bottom of the form you should see a “Default Display” fieldset and then in the “*Custom display format:” textfield enter “h:i a” which will output a 10:30pm like time.

Hopefully that will help get you going
Tom

4 Ace Technologies's picture

Hi,
Thanks to reply me ,
i did not find “Default Display” fieldset on the views page can you please tell me where is it and where i can find custom display format textfield ?

Thanks again for your reply

DrupalSN's picture

Hi,

The “Default Display” fieldset is in your event content type.

Go to Administer > Content Management > Content Types and click the “manage fields” link next to your event content type.
Then from there click “configure” link next to the start and end date fields and on the next page you should see the “Default Display” fieldset.

Hope that helps
Tom

4 Ace Technologies's picture

Thanks Tom , Its really help me,
views module is amazing and i also use views module in drupal 6 it is also a soooooper module. I love this.
Thanks for your help.
If you will be there we can learn a lot from you .
Thanks again
Azhar

4 Ace Technologies's picture

Hi again,
I want to ask from where i can find the full tutorial on views and cck module in drupal 6 or drupal 5 ?

I am setting up the view and I don’t see datestamp as an option to choose from the group dropdown when setting up the fields. I see content: start and end dates. I also don’t see datestamp for filters.

When I defined the content type I did use datestamp for end and start dates. What am I missing?

I also want to ask from same thing where i can find the full tutorial on views and cck module in drupal 6 or drupal 5 ?

P90X

I am really following all your tutorials. its really good instead of full tutorial. easy to understand.

Miele Vacuum Cleaners

As a learner it was nice to know these things exist thank you very much for the post…...

Brighton dentists

I learn a lot from this post too. I also want to say Thanks to the author for sharing.

karate gispla

Hello Admin,

Nice tutorial. I am new to drupal and found your article. Its good one for beginner like me. When i tried this tutorial than Part 1 was easily set up but for Part 2 in View i did face lot of problem as i am using drupal 6. Also version of views module is different which you used. So is it possible that you can post new article or update this article with current version ? do let me know please. i want to complete this tutorial part 2 in my website.

Thank you.

Thanks you for help.

Now i have one question. We have generated evenets and listing but how can i get that which user has signup for this event ? sorry if my question is silly but i am newbie to drupal so not getting clear idea.

Thank you.

DrupalSN's picture

You should check out the sign up module: http://drupal.org/project/signup
Thanks

What all events can be listed using this method?

Thanks for sharing.

//Datestamp: End Date – Date | Operator = greater than or equal to | Option = now//

I am not able to follow this action. I am using D6.

Please advise.