The Upcoming Events block should besides showing the countdown by days and hours for events also offer the possibility of showing the date of the event, the site admin can then decide which format he/she prefers (date or countdown).

CommentFileSizeAuthor
#32 event-upcoming-tpl.patch8.66 KBJirkaRybka

Comments

gtcaz’s picture

I vote for this as well. I hacked the PHP to display things differently, but then blew it away when I rsynced with the current 4.7 cvs branch. I'd rather not have to maintain this by hand. I better option would be to add a configuration option in the events setting page.

gtcaz’s picture

Here's an example of how I changed the display format. If I upgrade I have to re-edit the file. It'd be nice to have a control panel option.

File: event.theme

/**
 * Format an individual upcoming event block item
 *
 * @param node
 *   The node to render as an upcoming event
 */
function theme_event_upcoming_item($node) {
  $output = l($node->title, "node/$node->nid", array('title' => $node->title));
if ((event_get_types('all') + event_get_types('solo')) > 1) {
  //$output .= '<span class="event-nodetype">'. t("($node->typename)") .'</span>';
  $output .= '<span class="event-timeleft">'. gmdate('D, F j, Y', $node->event_start) .'</span>';
}
  return $output;
}
gtcaz’s picture

Actually, should probably move that outside the if statement.

gtcaz’s picture

Sorry to keep following-up my own posts, but I thought I'd add that I with the above hack I need to add a manual timezone offset on my production server, while my XAMPP test install doesn't need this.

solipsist’s picture

Excellent! Thanks for sharing. We have by now already made the necessary modifications.

Any chance the module maintainer or someone can produce a patch that also includes the configuration option to choose between the two display formats, which can eventually by committed to CVS?

solipsist’s picture

This is our code, and it takes the user's time zone into consideration, 24 hr format below:

function theme_event_upcoming_item($node) {
  $output = l($node->title, "node/$node->nid", array('title' => $node->title));
  if ((event_get_types('all') + event_get_types('solo')) > 1) {
    $output .= '<span class="event-nodetype">'. t("($node->typename)") .'</span>';
  }
   $output .= '<span class="event-timeleft">on '. format_date($node->event_start, 'custom', 'j/m - G:i') .'</span>';
  return $output;
}
gtcaz’s picture

No one is interested in this change? I think showing the date of an event should be preferred to "(54 days)". Also, showing "(event)" is just plain ugly.

fraew’s picture

i'm a big fan of this - actually grouping events in the block by the day would be even better...

billl4’s picture

Thanks for this. I'm a newbie, so this really helped me out. I couldn't stand the way (13 hours)(event) looked. I changed it to a slightly different format to include Day, Month & Date & start time (on Wed Mar 7 @ 8:30am). I think I did it correctly

$output .= '<span class="event-timeleft">on '. format_date($node->event_start, 'custom', 'D M j @ G:ia') .'</span>';

Cheers,
Bill

gtaylor’s picture

Big agreement. I would like to see the start date and do NOT want to see the content type (event).

I also found this post on the site today: http://drupal.org/node/118413 so I know quite a few want it. Making this change will also allow cache to remain valid longer. I can't imagine why somebody would NOT want this enhancement. recommend a simple change - losing old behavior altogether.

Anecdote for Enhancement Need
I built a website for my dad and all he could do in the acceptance meeting was complain about the #days. He said his customers would be confused thinking that the conference was 10 days long vs. taking place in 10 days. I'm sure he's right for at least some users. It took me 10 mins. to get off this subject before he would see all the other cool things Drupal and Events did for him.

I plan to upgrade my dad's website to 5.1 sometime within the next month or two, so I hope this enhancement makes it to 4.7x & 5.1x

(Despite what dad says :-) awesome module! Thnx for supporting it.

cookiesunshinex’s picture

Thanks for this information. It helped quite significantly. I chose to use a better International Date format Day, Number Month @ Time: EX: Fri, 30 March @ 11:00PM, but I also wanted to include the number of days left to be more clear.

I used this code:

function theme_event_upcoming_item($node) {
  $output = l($node->title, "node/$node->nid", array('title' => $node->title));
  if ((count(event_get_types('all')) + count(event_get_types('solo'))) > 1) {
    $output .= '<span class="event-nodetype">'. t("($node->typename)") .'</span>';
  }
  $output .= '<span class="event-timeleft"> '. format_date($node->event_start, 'custom', 'D j M @ G:ia') .'</span>';
  $output .= '<span class="event-timeleft">('. $node->timeleft .')</span>';
  return $output;
}

How would I change it so that the date is formatted on the left hand column, the event title is listed (on the same line), and then (number of days left) is formatted on the far right.

Currently, it's title of event on the left, then on the next line/right colum date, then next line right column number of days left.

Thanks.

mattjabs’s picture

I am in full support of this addition to the module. I run a corporate website & the president doesn't like the "days countdown" either. He would much prefer a date & maybe a time as well. This should be an option.

I have tried all the code here on this page & although it does format it differently on my page, it does not bring the correct dates onto the block. Instead of my actual event date showing up, all my events list the same date (on Wed Dec 31 @ 20:33pm). Every event in the Upcoming events block lists that date, no matter what the actual date is.

Module maintainer, I love this module, and thank you for your hard work. Please add this feature, it would be SOOO much appreciated.

I do know that using the Event Views module, you can create a custom block, but the Views module still has my head swimming so I don't understand how to do this yet.

Please help. Let it be noted that I'm using Drupal 5.1 and Event.module version 5.x-2.x-dev

Matthew Jabs

fm’s picture

I agree. This feature should be added into an official release. Most people use dates, not countdowns, to schedule their activities.

mattjabs’s picture

Is there any update on this feature, I will kiss you if there is! ;-)

For everyone out there waiting for the developers to update this module (you devs are "da bomb"), what I'm doing in the meantime, that has proved to be a viable "work around" is to put the date of the event in the title.

Ex. Here's the title I use:

"Utility Billing and the Internet - 7/25/2007"

If you do this, you will see the date, and the countdown in the Upcoming Events block...which I kind of like. That way I have the date & the countdown...

killes@www.drop.org’s picture

Status: Active » Closed (won't fix)

this can be easily done through theming.

solipsist’s picture

Yes it can but apparently it's too complicated for many users who do not need or want to learn theming. The theming solution has been available for over a year but people are still requesting a proper feature. The response here is evidence enough that this is something a lot of people want and need.

If you don't want to spend the time to do it, I can submit a patch. Ok with that?

killes@www.drop.org’s picture

Version: 4.7.x-1.x-dev » 5.x-2.x-dev
Status: Closed (won't fix) » Needs work

Oh, well, if this is really so often needed, I won't say no to a patch against event 5.2

solipsist’s picture

Awesome! :)

Jim Ruby’s picture

Hi, I hope this is the right place to post and ask for help, but I am using the views module and I want to get a block to show something like:
event title
start date and time - end date and time
number of days till event

I've been working with the views module to ad least get the first two lines displayed, but I've having no luck at all and about ready to give up.
Any help out there? Sorry if I am asking in the wrong spot, but it looked like there was talk about this so just replied to the thred.

Thank you

aezalpha’s picture

mattjabs - I updated the event.theme file to include the date & time in the title of the upcoming event. This may help in not having to manually put those into the title for recurring events.

function theme_event_upcoming_item($node) {
$event_start_date = format_date($node->event_start, 'custom', ' - m/d (g:ia)');
$output = l("$node->title $event_start_date", "node/$node->nid", array('title' => $node->title));
if ((count(event_get_types('all')) + count(event_get_types('solo'))) > 1) {
$output .= ''. t("($node->typename)") .'';
}
return $output;
}

fm’s picture

Oh, well, if this is really so often needed, I won't say no to a patch against event 5.2

Has this patch been added to the Event 5.2 release? Or are we required to patch it ourselves?

solipsist’s picture

Unfortunately I haven't had the time to do it yet. If someone else wants to, be my guest. It would just be nice to get it done, help out some people who aren't that theming-savvy.

mnoyes’s picture

Work around?

I created a new view titled "upcoming events" with fields for "title" and "start time."

Added filters for "node: published" (yes), "node:type" (event), and "event: start date" (greater than or equals to now).

Doesn't solve the problem, which should be as simple as a checkbox on the events administration page, but any reason not to use this?

jmcclelland’s picture

I took the following steps to implement this idea. I didn't touch any of the event module code or files. I was using the chameleon theme that shipped with Drupal 5.

  1. Copied the chameleon theme from the /themes directory to my sites/default/themes directory
  2. Renamed the directory dreamschool.
  3. Removed the marvin sub-directory
  4. Renamed the file chameleon.theme to dreamschool.theme.
  5. Did a search/replace in dreamschool.theme replacing all instances of chameleon with dreamschool.
  6. Enabled the new dreamschool theme in the admin themes section
  7. Edited the dreamschool.theme file adding the following function:
    <?php
    function dreamschool_event_upcoming_item($node) {
            $output = l($node->title, "node/$node->nid", array('title' => $node->title));
            if ((event_get_types('all') + event_get_types('solo')) > 1) {
                    $output .= '<span class="event-timeleft">'. format_date($node->event_start,'small') .'</span>';
            }       
            return $output;
    } 
    ?>
    

This function will display the date in the appropriate format given the format chosen in Settings / Dates and Times.

agerson’s picture

Is there a drupal 6 version of this?

shashi_lo’s picture

Here is the code for Drupal 6

function theme_event_upcoming_item($node, $types = array()) {
  $output = l($node->title, "node/$node->nid", array('attributes' => array('title' => $node->title)));
  if (count($types) > 1) {
    $output .= '<span class="event-nodetype">('. $node->event['node_type'] .')</span>';
  }
  $output .= '<span class="event-timeleft">'. event_format_date($node->event_start, 'custom', "D, F j, Y") .'</span>';
  return $output;
}
Morn’s picture

Another Code example for Drupal 6 - Countdown and date - Table like - German only (am instead of "at the")

function theme_event_upcoming_item($node, $types = array()) {
  $output = '<table style="table-layout:fixed"><tr><td style="width:50%; border:thin solid">';
  $output .= l($node->title, "node/$node->nid", array('attributes' => array('title' => $node->title)));
  $output .= '</td>';
  $output .= '<td style="width:36%; border:thin solid">&nbsp;'. $node->event['timeleft'] .',&nbsp;';
  $output .= 'am &nbsp;'. event_format_date($node->event_start, 'custom', 'd. F Y') .'</td>';
  if (count($types) > 1) {
    $output .= '<td style="width:10%; border:thin solid">'. $node->event['node_type'] .'</td>';
  }
  $output .= '</tr></table>';
  return $output;
}
dattas’s picture

Component: User interface » API

I need patch code for event to be convarted into marathi.

gtaylor’s picture

Bump. Is this enhancement going into 6?

Any idea when 6 will be production ready? I love this module and we really need it for a new site planning to go live in late Oct / early Nov.

dcoffee’s picture

Thanks everyone for your help on this. I definitely would love a control panel option.

JirkaRybka’s picture

+1 for the feature. I'm another one thinking, that the countdown display makes no sense in some cases (if not all cases), and that opinion was also supported by users' reactions on my site in the old days, when I ran event module in its original form. I also think, that this is a content-of-the block issue, not theming.

I'm still on 5.x, so I've no idea how this looks on 6.x, but I'm maintaining my own hack (for years now), and I posted another issue a while back: #177624: Upcoming block: Plain date/time option - so most probably either that or this is duplicate, but the linked issue have a patch. I see that someone even RTBC'ed that patch, but that all happened a year (!) ago, and I have no time to go through it again today, to ensure it's up-to-date. It would be great, if someone else took over that.

Code-wise, I was long using a hack very similar to the snippets earlier in this thread here (also seen in my initial patch in the other issue), but later I discovered serious problems with the time being one-hour-off after timezone-changes (emulating Daylight Saving Time), revealing that simple approach being incompatible with the various timezone-options available. The latest patch (on the other issue) uses a code, that is more-or-less verbatim from the full-node-view, ensuring the same times being shown everywhere for a given event.

By the way - I also tried to build an Event block through Views (a category-restricted block for a specific page), early in the 5.x era of my website, but after users' complaints I had to remove it completely, because the Views output for events date/time suffered from the same problem (being not timezone-stuff aware, and therefore one-hour-off after switching Daylight Saving Time). That turned out to be - more or less - unsolvable for me (due to Views bypassing the event module's time-formatting code, as far as I remember), so unless something changed in the last year or so, I don't consider Views an usable replacement for the Upcoming events block.

Really, another great feature would be a "fixed time" for events, showing just plainly what the node author entered, with no timezone-translations whatsoever. My site's audience is all local, so the whole timezones' stuff is just trouble here.

JirkaRybka’s picture

Version: 5.x-2.x-dev » 6.x-2.x-dev
Component: API » Code
Status: Needs work » Needs review
StatusFileSize
new8.66 KB

OK, I took another look into the 6.x-2.x-dev version.
Although I don't really feel like this belongs into theming layer, I can still accept this approach (since I see it's, like, preferred here), but then I think the following concerns should be addressed:

- Theming of the item must be a template. A themable function is far too complicated for a lot of users "just wanting to switch from countdown to something more friendly". Template is better (although it's still a nightmare, if compared to a setting on administrative pages). (TODO: If going in this direction, consider providing an alternative template with start date/time already implemented, to be enabled by just renaming files.)

- The appropriate variables must be available. As of previous hints to use themability, the existing 'event_start' property (taken directly from DB) is insufficient, because it: 1) Is NOT formatted along site settings of date/time format, and, 2) Is NOT adjusted for timezones, per event-view settings.

I've created a new patch for 6.x-2.x-dev, doing the following:
- Turning the 'event_upcoming_item' theme function into a template event-upcoming-item.tpl.php
- Providing all the variables as in event_nodeapi.tpl.php (partially by re-using its preprocess function), including all sorts of formatted/unformatted start/end dates/times
- Providing also variables needed/useful in the default implementation, i.e. $node_title, $node_link, $timeleft, and $node_types (for the already-existing check only).

Just like in my previous 5.x patch, there's a bit of new code inside _event_block_upcoming() to obtain correct (timezone-settings aware) start/end dates/times. This is basically taken from event_nodeapi() case 'load' and 'view' (because I don't think it's a good idea to do a full node_load() here, but still we need to re-use some of its functionality). The code in 'view' (formatting the various variables for theme layer) is now abstracted to a separate function _event_prepare_start_end($node), without any changes, to avoid code duplication. From the code in 'load', only the needed part is reproduced. (It might be possible to merge it into the original query somehow, but these huge DB-type specific queries are quite scary, so I gave up on that. With block caching in core, I don't think 6 queries are too big deal.)

Testing this is also affected by #260355: Timezone handling settings not saved, you might need to write variables in database by hand, to change the event-viewing timezone settings.

JirkaRybka’s picture

Related issue, with a bit different patch: #34271: Display date of event rather than days until event

Dubber Dan’s picture

Have used the code in comment 24 which is a great improvement, but how do I further edit this so that only the date is shown and not the start time too?

I'd also like to add my voice to requesting this to be a switch within the Event module admin section. Would make sense to simply be able to decide what to display in the block, seeing as the block is provided by the module

japerry’s picture

Status: Needs review » Closed (outdated)

Event for Drupal 8 is unrelated to older versions. If an issue similar to this one exists, please open a new issue with the 8.x branch.