Hi,
I made some small additions/ changes to this really nice module so that I could use it for my website.
Now I wonder if they could be useful for the original module...? (I'm not a big developer, so please forgive my dilettante efforts.) ;o)
I attached my modified version of scheduler.module as a text file.
1.) First of all, I added a basic validation function with two helper functions to make sure that
- publication and expiration date aren't in the past,
- the expiration date lies ahead of the publication date and
- the dates entered are valid.
/**
* Implementation of hook_form_validate()
* Validate the input of the publish and unpublish date fields. Uses the helper function 'timediff_date' (or alternatively 'timediff_timestamp') to make sure that the actual or a future date is entered.
*/
function _scheduler_form_validate($form_id, $form_values) {
$publishtime ='';
$unpublishtime = '';
if (is_array($form_values) && isset($form_values['publish_on'])) {
$publishtime = strtotime($form_values['publish_on']);
$timediff_pub = timediff_date($form_values['publish_on']);
if ($publishtime === false) {
form_set_error('publish_on', t('The entered publication date is invalid.'));
}
else if ($timediff_pub < 0) {
form_set_error('publish_on', t('The entered publication date occurs in the past.'));
}
}
if (is_array($form_values) && isset($form_values['unpublish_on'])) {
$unpublishtime = strtotime($form_values['unpublish_on']);
$timediff_unpub = timediff_date($form_values['unpublish_on']);
if ($unpublishtime === false) {
form_set_error('unpublish_on', t('The entered expiration date is invalid.'));
}
else if ($timediff_unpub < 0) {
form_set_error('unpublish_on', t('The entered expiration date occurs in the past.'));
}
else if (isset($form_values['publish_on']) && $unpublishtime < $publishtime) {
form_set_error('unpublish_on', t('The expiration date can\'t lie ahead of the publication date.'));
}
}
}
/**
* Function checks the time difference between a specified date to now in days.
* @param $date
* @return Positive value for number of days in the future, negative value for number of days in the past.
* A date in standard english format 'Y-m-d'.
*/
function timediff_date($date){
$date_diff = round( (strtotime($date)-strtotime(date('Y-m-d'))) / 86400, 0 );
return $date_diff;
}
/**
* Function checks the time difference between a specified timestamp to now in days.
* @param $date
* @return Positive value for number of days in the future, negative value for number of days in the past.
* A timestamp.
*/
function timediff_timestamp($timestamp){
$date_diff = round( ($timestamp-strtotime(date('Y-m-d'))) / 86400, 0 );
return $date_diff;
}
2.) I also added three jscalender properties to the form_alter function so I could change the format of the date display (I didn't want the time to be displayed)
'#jscalendar_ifFormat' => $jscalendar ? '%d.%m.%Y' : array(),
// Don't show time.
'#jscalendar_showsTime' => $jscalendar ? 'false' : array(),
// Show 24-hour clock.
'#jscalendar_timeFormat' => $jscalendar ? '24' : '',
| Comment | File | Size | Author |
|---|---|---|---|
| scheduler.module.modified.txt | 14.26 KB | olio |
Comments
Comment #1
AjK commentedYou attached the entire module, you need to send a patch, see http://drupal.org/patch
Comment #2
eric-alexander schaefer commentedNo response from the original poster for 31 weeks. Most of it is fixed now anyways.
Comment #3
eric-alexander schaefer commented