I'm trying to get event.module to show the date of each event in the sidebar, rather than it currently showing the days remaining. I can't figure it out since I don't understand php or whatever code this is written in. Could someone tell me just what variable I need to change in this file to make this happen?

CommentFileSizeAuthor
#8 event-34271.patch4.86 KBcafuego
#7 event-date-patch.txt3.7 KBcafuego

Comments

killes@www.drop.org’s picture

Status: Active » Fixed

There is no such variable. You can only limit the number of events shown.

seaneffel’s picture

So how can I modify this module to display what I want it to? Its not very useful to have a countdown of days on a calendar. Thanks for your help.

Sean
http://www.squarefour.org

seaneffel’s picture

Who says there is no such variable? Some random shots in the dark and I fixed it. I don't speak this php language so I'm just lucky - or a good reverse engineer.

I changed this line in events.theme from this:

/**
 * Format an individual upcoming event block item
 *
 * @param node
 *   The node to render as an upcoming event
 */
function theme_event_upcoming_item($node) {
  return l($node->title, "node/$node->nid", array('title' => $node->title)). '<span class="event-nodetype">('. $node->typename .')</span>       <span class="event-timeleft">('. $node->timeleft .')</span>';
}

To this. The change is in the last bit there where it says "event-timeleft":

/**
 * Format an individual upcoming event block item
 *
 * @param node
 *   The node to render as an upcoming event
 */
function theme_event_upcoming_item($node) {
  return l($node->title, "node/$node->nid", array('title' => $node->title)). '<span class="event-nodetype">('. $node->typename .')</span> <span class="event-timeleft">'. gmdate('m/d/Y', $node->event_start) .'</span>';
}
nicgal’s picture

Well, I did something similar as well, just edit the event.module and look for the upcoming event block just change it for this, and even you will have a nice feature saying days to event, Im not an php expert myself but some lucky changes and here it is.... Im copying the entire block so you can copy and paste easily...

/**
* Creates a block that contains upcoming events.
*
* @ingroup event_block
* @param $limit The number of events that can be displayed in the block.
* @return A string containing the fully themed block.
*/
function event_block_upcoming($limit = 6) {
  global $user;
  // For two hours, we display "NOW"
  $time = time() - (2 * 60 * 60);
  $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.type, n.status, n.moderate, e.event_start FROM {node} n INNER JOIN {event} e USING (nid) WHERE n.status = 1 AND n.moderate = 0 AND e.event_start >= %d ORDER BY event_start"), $time);

  while (($node = db_fetch_object($result)) && $limit) {

    //call the event_edit_upcoming hook in all modules.  note that modules can prevent display of a node by setting
    //it's status to 0 here.
    foreach (module_implements('event_edit_upcoming') as $module) {
      $function = $module .'_event_edit_upcoming';
      $function($node);
    }
    $minutesleft = floor(($node->event_start - time()) / 60);

    if ($minutesleft < 0) {
      $timeleft = t('NOW');
    }
    else if ($minutesleft < 60) {
      $timeleft = format_plural($minutesleft, '1 minute', '%count minutes');
    }
    else if ($minutesleft >= 60 && $minutesleft < (24 * 60)) {
      $timeleft = format_plural(floor($minutesleft / 60), '1 hour', '%count hours');
    }
    else if ($minutesleft >= (24 * 60)) {
      $days = floor($minutesleft / (24 * 60));
      // hours remainder
      $hours = ($minutesleft % (24 * 60)) / 60;
      // hours left in the day
      $hours_left = ((time() / 60) % (24 * 60)) / 60;
      // see if the remainder of hours on the event date is greater than the hours left in today, if so increase the days by one so that the days remaining mimics the date rather than how many 24 hour periods there are between now and then.
      if ($hours>$hours_left) {
        $days++;
      }
      $timeleft = format_plural($days, '1 day', '%count days');
    }
//To get the start date of the event displayed along the title.
    else { $timeleft = 'today'; }
$day = _event_date('j', $node->event_start);
$month = _event_date('M', $node->event_start);
$shortdate = $month. " ". $day. ": ". $node->title;
$items[] = l($shortdate, "node/$node->nid", array("title" => $node->title)). t('  Days to event: ') . " ($timeleft)";
}

  $output = theme("event_upcoming_block", $items);
  $output .= theme('event_ical_link', 'event/ical');
  $output .= theme('event_more_link', 'event');

  return $output;
}
Anonymous’s picture

Status: Fixed » Closed (fixed)
alxp’s picture

I was having trouble getting the time zone to display correctly, but finally was able to show a list of upcoming events including full date and time, formatted according to site settings, like this:

in 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 ((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, 'small', '', $node->start_offset) .')</span>';
  
  return $output;
}
cafuego’s picture

Version: 4.6.x-1.x-dev » 6.x-2.x-dev
Assigned: Unassigned » cafuego
Category: support » feature
Status: Closed (fixed) » Needs review
StatusFileSize
new3.7 KB

I've made a small patch for the 6.x module that allows you to choose whether or not to show the node type in the Upcoming block and how to format the date.

It defaults to the number of minutes, hours or days, but allows the user to specify a PHP date() format as well.

This adds two items to the Site Configuration > Event > Events Overview page.

cafuego’s picture

Assigned: cafuego » Unassigned
StatusFileSize
new4.86 KB

I've modified the patch slightly, so the new variables are removed in _uninstall.

File name updated as per submission guidelines.

frank ralf’s picture

Thanks for the patch! Will try it ASAP.

Just for the record, see also this related issue:

Customize upcoming list view
http://drupal.org/node/326409

Cheers,
Frank

JirkaRybka’s picture

This issue is yet another proof, that there's a lot of demand for this feature, so it should be considered.

Otherwise, I see two problems with the patch:
- Having settings on administrative pages is frowned upon (although I would support this way), the module maintainer said something along the lines that this is a theming issue (correct me if I misunderstood)
- Just like many other patches and snippets for this purpose, it's likely to fail for some timezones settings (because $node->event_start is NOT adjusted as required).

I have another patch waiting in the queue: #78271: Upcoming Events to optionally show event dates instead of countdown - that one makes the time theming into a template, and provides all the necessary variables. I tested that for all settings I can think of.

cafuego’s picture

Handling this via theming works, but only if whoever needs to change this format has access to the template, which isn't the use case I'm dealing with.

JirkaRybka’s picture

Honestly, I would prefer a simple setting somewhere on administrative pages, too (and I already posted such a patch in the past). But it seems like the maintainer of Event module doesn't like tha idea (despite the requests being numerous) - I can remember these:

#177624: Upcoming block: Plain date/time option - comment #2:

Gerhard Killesreiter: ....I think if you need to have a different block you can just put it into your site specific module

-> Won't fix (November 8, 2007)

#78271: Upcoming Events to optionally show event dates instead of countdown - comment #15:

killes@www.drop.org: this can be easily done through theming.

-> Won't fix (December 2007)

My patch here [EDIT: on the other issue] is an attempt on a different approach, in hope we can just agree on *something* usable for all, and get it in.

frank ralf’s picture

Just an idea: Would it be possible to make your patch a sub-module of Event?

BTW Here's another one for your list: #326409: customize upcoming list view

Cheers,
Frank

JirkaRybka’s picture

I've also seen a few more threads (in the Forum too), but I don't have the links saved.

I'm not sure how much work it might be, but I'm not going to maintain any modules myself due to variety of reasons (including, but not limited to, lack of time) - especially not modules which are in fact just bugfixes for other code (yes, I consider this an usability bug; feel free to disagree). Having that disclaimer said - without the proposed changes in event module itself (theming of the block refactored, or some other way to slip the data in cleanly without hacking event.module from outside, as well as abstraction of the date/timezone viewing code from hook_nodeapi() into a separate function), there'll be quite large code duplication. Unless I missed something, the hypothetical new module needs to have a verbatim of large code segment from hook_nodeapi() just to obtain correct date across all settings, and a verbatim of the whole block builder (unless we ship this part as a theme function to be copy-pasted into themes, making the whole thing hackish and denying further plug-and-play themability). Maybe I missed something on quick read, but it seems to me like we would need to re-write the block pretty much from scratch, just to be able to slip in a small change.

Certainly, this is NOT "easy to do through theming", because the theme layer currently doesn't have the needed date/time information, and it's not that easy to obtain (which leads to *many* buggy snippets posted all over the place - if one just grabs event-start somewhere in database or in node object, then it breaks on certain timezone settings, possibly only after the timezone is changed due to DST or something, i.e. it breaks later, in production - these are nasty situations; once I had to remove a Views-made block of events, because even the Views 1.6 handler didn't do this correctly; once DST kicked in, all events were one hour off! So I would say don't rely on people figuring this out themselves in a theme function.)

I think, we really need some word from the maintainer now, to reach some decision which way to go. The options are:
- Add simple administrative setting, and integrate both the date/time and countdown displays into the block. Pros: Everyone get the feature without further struggle, just like all these timezone settings etc. Cons: One more administrative setting.
- Refactor theming layer (template, plus provide the start/end date/time variables - my latest patch is over at #78271: Upcoming Events to optionally show event dates instead of countdown), to allow for doing this from theme easily. Pros: No extra administrative settings, possibly better control over the display (only date / only time / end date, and the like). Cons: A small impact on performance (to provide all the variables for theming, both code segments need to always run), difficult for new/unexperienced users (and therefore) further income of support requests.
- Extra module. Pros: No changes to event.module itself. Cons: Large code duplication, module is difficult to find for some users, someone would need to maintain that (keeping all the copied code in sync with original too).
- Repeat the "Won't fix" scenario. Pros: ??? Cons: It's going to be re-opened again and again. People need this...

frank ralf’s picture

JFTR to get all arguments together:

There was a IMO related discussion over in #336161: Display an event node without a time. whether it would be better to use the Date API for date and time handling of the event module.

seaneffel’s picture

Many of you want the Event module to perform all these new tricks that IMHO could be done with CCK, Date API and Views. Especially when it comes to making new date formats (like "12/1/09 - 1:30PM" vs "1-12-2009 - 13:30") with Date API. At some point you have to stop fighting the module and move to one that gives you the flexibility you need.

Or as it was pointed out above, if you need more from a module then write your own companion module and publish it. If the maintainer doesn't want to include your features then your next bet is to override it.

JirkaRybka’s picture

Except that this is a tiny, frequently needed change, unsolvable from outside without duplicating A LOT of code. Definitely in-scope for event.module, IMO.

Dubber Dan’s picture

Is there a D5 version of this patch at all?

frank ralf’s picture

Try the code from http://drupal.org/node/326409#comment-1095759 which doesn't change the module code but works with a template.php file.

hth
Frank

Dubber Dan’s picture

Thanks Frank, just tried adding that code to the bottom of my template.php file of my theme but it don't work. I've tried it with and without the two small PHP references either side of it but still no joy.

It changes the days remaining all to 31 Dez | Mi. and throws up a series of errors:

* warning: preg_match() expects parameter 2 to be string, array given in /home/.krone/dubber/test06.lightbeingcreations.org/includes/bootstrap.inc on line 708.
* warning: preg_match() expects parameter 2 to be string, array given in /home/.krone/dubber/test06.lightbeingcreations.org/includes/bootstrap.inc on line 708.
* warning: preg_match() expects parameter 2 to be string, array given in /home/.krone/dubber/test06.lightbeingcreations.org/includes/bootstrap.inc on line 708.
* warning: preg_match() expects parameter 2 to be string, array given in /home/.krone/dubber/test06.lightbeingcreations.org/includes/bootstrap.inc on line 708.

http://test06.lightbeingcreations.org/event/2009/08/01/month/all/all using D5 and Event 5.x.1.0

Dubber Dan’s picture

Got it working using the code in comment 24 of this thread (http://drupal.org/node/78271) but it's not quite there yet.

Still would make sense to be in the event module admin section

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.