--- office_hours.module 2008-03-03 09:35:50.000000000 +0200 +++ office_hours.module 2008-03-12 08:01:27.000000000 +0200 @@ -6,8 +6,7 @@ * Creates a field and widget for inserting working or office hours per day * * - *TODO: allow for more than one 'block' of hours per day, or merge them if the day is identical. - + * /** * implementation of hook_menu. @@ -90,7 +89,7 @@ function office_hours_field_settings($op '#type' => 'select', '#title' => t('Limit hours start'), '#options' => $options, - '#default_value' => $field['limitstart']? $field['limitstart'] : FALSE, // $options['None'], + '#default_value' => $field['limitstart']? $field['limitstart'] : FALSE, '#required' => FALSE, '#description' => t('Set the allowed start hours. Note: if you just changed the clock format, please submit before changing this.'), ); @@ -98,7 +97,7 @@ function office_hours_field_settings($op '#type' => 'select', '#title' => t('Limit hours end'), '#options' => $options, - '#default_value' => $field['limitend'] ? $field['limitend'] : FALSE, // $options['None'], + '#default_value' => $field['limitend'] ? $field['limitend'] : FALSE, '#required' => FALSE, '#description' => t('Set the allowed end hours. Note: if you just changed the clock format, please submit before changing this'), ); @@ -112,7 +111,7 @@ function office_hours_field_settings($op return $form; case 'save': - return array('hoursformat', 'granularity', 'limitstart', 'limitend'); + return array('hoursformat', 'granularity', 'limitstart', 'limitend', 'valhrs'); case 'database columns': $columns = array( @@ -129,12 +128,10 @@ function office_hours_field_settings($op case 'tables': $tables = content_views_field_tables($field); - // whatever additions / modifications needed on the default definitions return $tables; case 'arguments': $arguments = content_views_field_arguments($field); - // whatever additions / modifications needed on the default definitions return $arguments; case 'filters': @@ -259,8 +256,6 @@ function office_hours_field_formatter($f } $count++; $lastday=$item['day']; - - if (isset($item['day'])) { $daykey= check_plain($item['day']); @@ -277,13 +272,11 @@ function office_hours_field_formatter($f $strhrs=convert_to_ampm($strhrs); } - switch ($formatter) { default: return theme('oh_formatter_display', $day, $strhrs, $endhrs, $display); } - } @@ -493,14 +486,14 @@ function office_hours_widget($op, &$node /** * helper function to create hours array. - * items are saved in 24 hours string format (i.e '18:00'). the logic of this function could be better. + * items are saved in 24 hours string format (i.e '18:00'). */ function _create_hours_arr($field, $limit = TRUE) { $fl1= $field['limitstart']; $fl2= $field['limitend']; $gran= ($field['granularity']== 0) ? 60 : $field['granularity']; - $limst=0; $limend=23; $mins='00'; + $limst=0; $limend=23; $mins='00'; $mine=60; if ($limit === TRUE) { if ($fl1 != 'none') { @@ -514,10 +507,10 @@ function _create_hours_arr($field, $limi if ($field['hoursformat'] == 1) { //12-hour clock foreach (range($limst,$limend) as $i) { - $mincounter= ($i==$limst && $mins!=0 ) ? $mins : 0; - for(; $mincounter<=45; $mincounter=$mincounter+$gran) { - if (!($i==$limend && $mincounter>$minend)) { - $mincounter= ($mincounter==0)? '00' : $mincounter; + $mincounter= ($i==$limst) ? $mins : 0; //in the first iteration, start the count according to limst. if not, begin from 0 + for(; $mincounter<=45; $mincounter=$mincounter+$gran) { + if (!($i==$limend && $mincounter>$mine)) { //last iteration + $mincounter= ($mincounter==0)? '00' : $mincounter; //preparing the mincounter for use in a string $hr=$i.':'.$mincounter; $ophours[$hr]=convert_to_ampm($hr); } @@ -527,9 +520,9 @@ function _create_hours_arr($field, $limi else { //24-hour clock foreach (range($limst,$limend) as $i) { - $mincounter= ($i==$limst && $mins!=0 ) ? $mins : 0; + $mincounter= ($i==$limst) ? $mins : 0; for(; $mincounter<=45; $mincounter=$mincounter+$gran) { - if (!($i==$limend && $mincounter>$minend)) { + if (!($i==$limend && $mincounter>$mine)) { $mincounter= ($mincounter==0)? '00' : $mincounter; $hr=$i.':'.$mincounter; $ophours[$hr]=$hr; @@ -546,19 +539,18 @@ function _create_hours_arr($field, $limi */ function convert_to_ampm($hour) { list($hr, $min)= explode(":",$hour); - if ($hr== '0') { //midnight + if ($hr== '0') { // midnight $hr=12; $ampm= ' AM'; } - elseif ($hr== 12) { + elseif ($hr== 12) { // noon $hr=12; $ampm= ' PM'; } - elseif ($hr>=12 && $hr<24) { // a pm time + elseif ($hr>12 && $hr<24) { // a pm time $hr= $hr-12; $ampm= ' PM'; } - else { $ampm=' AM'; }