Hi everyone,
I'm somewhat a newbie to drupal and PHP but I've been learning fast!
I've been charged with the task of creating an online daily notices system for our school which staff can add to, and after extensive searching on the web I decided upon Drupal with the event module. I've actually got it to the point where it is functioning, but there are a few wrinkles to iron out.
How it works is that notices are submitted via the drupal site and the output is obtained by pointing an RSS to HTML script at the RSS feed (this one here if you're interested: http://www.feedforall.com/free-php-script.htm). This is important because the notices are printed each morning for staff to read out in class, and it needs to be one notice per line or it doesn't fit on one page.
I've successfully added a piece of code to event.module which truncates the $body tag (in order to get each notice on one line), however the next issue is somewhat more complex. The problem is that the RSS feed only displays notices that are in the future, ie if a notice is set to end at 8am, someone reading the notices at 9am will not see it. One solution would be to instruct staff to make sure they set notices to end late in the day, however I would rather get the module to display all notices from the current day.
The function I've been modifying is event_calendar_rss, and at first I thought I would simply be able to modify the $stamp variable, however that appears to only take into account days anyway, and ignores hours and minutes. Thus I believe the line I need to modify is this one:$result = db_query(db_rewrite_sql('SELECT n.nid, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND ((e.event_start > %d AND e.event_start < %d) OR (e.event_end > %d AND e.event_end < %d) OR (e.event_start < %d AND e.event_end > %d)) ORDER BY event_start '), $stamp, $endstamp, $stamp, $endstamp, $stamp, $endstamp);
However that is where my understanding ends. First of all I don't know what the "%d" variable means, and any changes I make seem to break the code, including adding another OR statement which says: (e.event_start < %d AND e.event_end < %d).
Adding that results in an XML parsing error when I try to view the feed directly:warning: sprintf(): Too few arguments in D:\htdocs\home\includes\database.inc on line 154. user error: Query was empty
Here is the line with the extra OR statement inserted (that causes the error):$result = db_query(db_rewrite_sql('SELECT n.nid, e.event_start FROM {node} n INNER JOIN {event} e ON n.nid = e.nid WHERE n.status = 1 AND ((e.event_start > %d AND e.event_start < %d) OR (e.event_end > %d AND e.event_end < %d) OR (e.event_start < %d AND e.event_end > %d) OR (e.event_start < %d AND e.event_end < %d)) ORDER BY event_start '), $stamp, $endstamp, $stamp, $endstamp, $stamp, $endstamp);
This confuses me, because all I have done is added another OR condition? Therefore shouldn't the query be more inclusive than before? Thank you for taking the time to read this, any help would be greatly appreciated!
Comments
Hi Alexf, It seems that
Hi Alexf,
It seems that every %d represents one of the variables, in order, $stamp, $endstamp, $stamp, etc. etc.
So, the first time the system encounters a %d, it looks at the first variable in the list (which would be $stamp). The next time it encounters a %d, it looks at the next variable in the list (which would be $endstamp).
If you're trying to insert an OR (%d, ... %d...) statement, you need to make sure the list of variables there has the same number of %d.
Ah, that makes sense, thanks
Ah, that makes sense, thanks for clearing that up. Adding $stamp, $endstamp to the list at the end of the line fixed the error, however it had the undesired effect of including all notices from the past and not just the current day. Which is obvious now that I look at my logic (or lack of).
Thanks again for the quick response, I have more work to do. :)