/[drupal]/contributions/modules/office_hours/office_hours.module
ViewVC logotype

Diff of /contributions/modules/office_hours/office_hours.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.1.2.9, Sat Jun 27 17:48:58 2009 UTC revision 1.1.2.1.2.10, Sat Aug 29 07:49:16 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: office_hours.module,v 1.1.2.1.2.8 2009/05/02 09:51:28 ozeuss Exp $  // $Id: office_hours.module,v 1.1.2.1.2.9 2009/06/27 17:48:58 ozeuss Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 11  Line 11 
11   */   */
12  function office_hours_theme() {  function office_hours_theme() {
13    return array(    return array(
14      'office_hours_formatter_default' => array (      'office_hours_formatter_default' => array(
15          'arguments' => array ('element' => NULL),        'arguments' => array('element' => NULL),
16        'file' => 'office_hours.theme.inc',        'file' => 'office_hours.theme.inc',
17      ),      ),
18      'office_hours' => array (      'office_hours' => array(
19          'arguments' => array ('element' => NULL),        'arguments' => array('element' => NULL),
20        'file' => 'office_hours.theme.inc',        'file' => 'office_hours.theme.inc',
21      ),      ),
22      'office_hours_multiple_values' => array(      'office_hours_multiple_values' => array(
# Line 30  function office_hours_theme() { Line 30  function office_hours_theme() {
30    );    );
31  }  }
32    
33    /**
34     * Implementation of hook_form_alter().
35     */
36  function office_hours_form_alter(&$form, &$form_state, $form_id) {  function office_hours_form_alter(&$form, &$form_state, $form_id) {
37  if ($form_id == 'content_field_edit_form') {  if ($form_id == 'content_field_edit_form') {
38                  if($form['#field']['type'] == 'office_hours') {      if($form['#field']['type'] == 'office_hours') {
39                          $description = t('Number of field that will show.');        $description = t('Number of field that will show.');
40                          $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>';        $description .= '<br/><strong>'. t('Warning! Changing this setting after data has been created could result in the loss of data!') .'</strong>';
41                          $form['field']['multiple'] = array(          $form['field']['multiple'] = array(
42                          '#type' => 'select',            '#type' => 'select',
43                          '#title' => t('Number of values'),            '#title' => t('Number of values'),
44                          '#options' => drupal_map_assoc(array(7,14)),            '#options' => drupal_map_assoc(array(7,14)),
45                          '#default_value' => isset($form['field']['multiple']) ? $form['field']['multiple'] : 7,            '#default_value' => isset($form['field']['multiple']) ? $form['field']['multiple'] : 7,
46                          '#description' => $description,            '#description' => $description,
47                          );          );
48                  }      }
49          }    }
50          if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
51                  $type = content_types($form['#node']->type);      $type = content_types($form['#node']->type);
52                  foreach ($type['fields'] as $field) {      foreach ($type['fields'] as $field) {
53                          if ($field['type'] == 'office_hours') {        if ($field['type'] == 'office_hours') {
54                                  $form[$field['field_name']]['#theme'] = 'office_hours_multiple_values';          $form[$field['field_name']]['#theme'] = 'office_hours_multiple_values';
55                          }        }
56                  }      }
57          }    }
58  }  }
59    
60  /**  /**
61   * implementation of hook_init.   * Implementation of hook_init().
62   */   */
63  function office_hours_init () {  function office_hours_init () {
64      drupal_add_css(drupal_get_path('module', 'office_hours') .'/office_hours.css');      drupal_add_css(drupal_get_path('module', 'office_hours') .'/office_hours.css');
# Line 73  function office_hours_content_is_empty($ Line 76  function office_hours_content_is_empty($
76  }  }
77    
78  /**  /**
79   * Implementation of hook_field_info   * Implementation of hook_field_info().
80   *   *
81   * @return   * @return
82   *   An array keyed by field type name. Each element of the array is an associative   *   An array keyed by field type name. Each element of the array is an associative
# Line 83  function office_hours_content_is_empty($ Line 86  function office_hours_content_is_empty($
86  function office_hours_field_info() {  function office_hours_field_info() {
87    return array(    return array(
88      'office_hours' => array(      'office_hours' => array(
89          'label' => 'Office Hours',        'label' => 'Office Hours',
90          'description' => t('Store office or opening hours in the database.'),        'description' => t('Store office or opening hours in the database.'),
91          'callbacks'=> array (        'callbacks'=> array (
92          'tables'=> CONTENT_CALLBACK_DEFAULT,        'tables'=> CONTENT_CALLBACK_DEFAULT,
93          'arguments'=> CONTENT_CALLBACK_DEFAULT,        'arguments'=> CONTENT_CALLBACK_DEFAULT,
94          ),        ),
95       ),       ),
96    );    );
97  }  }
98    
99  /**  /**
100   * implementation of hook_field_settings   * Implementation of hook_field_settings().
101     *
102   * Handle the parameters for a field.   * Handle the parameters for a field.
103   */   */
104  function office_hours_field_settings($op, $field) {  function office_hours_field_settings($op, $field) {
# Line 188  function office_hours_field_settings($op Line 192  function office_hours_field_settings($op
192          $data[$table_alias][$field['field_name'] .'_starthours']['filter']['handler'] = 'office_hours_handler_filter_hours';          $data[$table_alias][$field['field_name'] .'_starthours']['filter']['handler'] = 'office_hours_handler_filter_hours';
193          $data[$table_alias][$field['field_name'] .'_endhours']['filter']['handler'] = 'content_handler_handler_filter_hours';          $data[$table_alias][$field['field_name'] .'_endhours']['filter']['handler'] = 'content_handler_handler_filter_hours';
194          return $data;          return $data;
195                          break;        break;
196    }    }
197  }  }
198    
199  /**  /**
200   * implementation of hook_field   * Implementation of hook_field().
201   *   *
202   */   */
203   function office_hours_field($op, &$node, $field, &$items, $teaser, $page) {   function office_hours_field($op, &$node, $field, &$items, $teaser, $page) {
# Line 220  function office_hours_field_settings($op Line 224  function office_hours_field_settings($op
224  }  }
225    
226  /**  /**
227   * Declare information about a formatter.   * Implementation of hook_field_formatter_info().
228   */   */
229  function office_hours_field_formatter_info() {  function office_hours_field_formatter_info() {
230    return array(    return array(
# Line 232  function office_hours_field_formatter_in Line 236  function office_hours_field_formatter_in
236    );    );
237  }  }
238    
239    /**
240     * Implementation of hook_widget_info().
241     */
242  function office_hours_widget_info() {  function office_hours_widget_info() {
243    return array(    return array(
244      'office_hours' => array(      'office_hours' => array(
# Line 313  function _office_hours_convert_to_ampm($ Line 320  function _office_hours_convert_to_ampm($
320    if (!strstr($hour, ":")) {    if (!strstr($hour, ":")) {
321      $hour = _office_hours_mil_to_tf($hour);      $hour = _office_hours_mil_to_tf($hour);
322    }    }
323    list($hr, $min)= explode(":",$hour);    list($hr, $min) = explode(":", $hour);
324    if ($hr== '0') { // midnight    if ($hr== '0') { // midnight
325      $hr = 12;      $hr = 12;
326      $ampm = ' AM';      $ampm = ' AM';
327     }    }
328     elseif ($hr== 12) { // noon    elseif ($hr == 12) { // noon
329      $hr=12;      $hr = 12;
330      $ampm = ' PM';      $ampm = ' PM';
331     }    }
332     elseif ($hr>12 && $hr<24) { // a pm time    elseif ($hr > 12 && $hr < 24) { // a pm time
333      $hr = $hr-12;      $hr = $hr - 12;
334      $ampm = ' PM';      $ampm = ' PM';
335     }    }
336     else {    else {
337      $ampm =' AM';      $ampm =' AM';
338     }    }
339  return $hr.':'.$min.$ampm ;    return $hr . ':' . $min . $ampm;
340  }  }
341    
342  function _office_hours_tf_to_mil($hour) {  function _office_hours_tf_to_mil($hour) {
343    if (strstr($hour,':') == FALSE || is_null($hour)) return $hour;    if (strstr($hour,':') == FALSE || is_null($hour)) {
344    list($hr, $min) = explode(":",$hour);      return $hour;
345    $hr = $hr*60+$min;    }
346      list($hr, $min) = explode(":", $hour);
347      $hr = $hr * 60 + $min;
348    return $hr;    return $hr;
349  }  }
350    
351  function _office_hours_mil_to_tf ($time = ''){  function _office_hours_mil_to_tf($time = '') {
352  $hour = (substr($time,0,-2)) ? substr($time,0,-2): '0';    $hour = (substr($time,0,-2)) ? substr($time,0,-2): '0';
353  $min = (substr($time,-2)) ? substr($time,-2): '00';    $min = (substr($time,-2)) ? substr($time,-2): '00';
354  return $hour.":".$min;    return $hour . ":" . $min;
355  }  }
356    
357  function _office_hours_set_weight($items) {  function _office_hours_set_weight($items) {
# Line 351  function _office_hours_set_weight($items Line 360  function _office_hours_set_weight($items
360      if (!is_null($item['day'])) {      if (!is_null($item['day'])) {
361        $sortkey= (int) $item['day'];        $sortkey= (int) $item['day'];
362        if (count($items) == 14) {        if (count($items) == 14) {
363          $sortkey = $sortkey*2;          $sortkey = $sortkey * 2;
364        }        }
365        if (is_array($sorted[$sortkey])) {        if (is_array($sorted[$sortkey])) {
366          $sorted[$sortkey+1] = $item;          $sorted[$sortkey+1] = $item;
# Line 364  function _office_hours_set_weight($items Line 373  function _office_hours_set_weight($items
373    //now fill the empty spaces with null values    //now fill the empty spaces with null values
374    foreach (range(0,count($items)-1) as $value) {    foreach (range(0,count($items)-1) as $value) {
375      if (!is_array($sorted[$value])) {      if (!is_array($sorted[$value])) {
376        $sorted[$value] = array('day'=>NULL, 'starthours' =>NULL, 'endhours'=>NULL);        $sorted[$value] = array('day' => NULL, 'starthours' => NULL, 'endhours'=> NULL);
377      }      }
378    }    }
379    return $sorted;    return $sorted;
380  }  }
381   /**  
382    /**
383   * Adding all table field into $data in hook_views_data.   * Adding all table field into $data in hook_views_data.
384   */   */
385  function _office_hours_views_field_views_data($field) {  function _office_hours_views_field_views_data($field) {
# Line 434  function _office_hours_views_field_views Line 444  function _office_hours_views_field_views
444  $i=0;  $i=0;
445      // Ensure all columns are retrieved,      // Ensure all columns are retrieved,
446      $additional_fields = drupal_map_assoc($columns);      $additional_fields = drupal_map_assoc($columns);
447                  foreach($columns as $key => $column) {      foreach($columns as $key => $column) {
448      list(,,$field_type) =explode('_',$column);      list(,,$field_type) =explode('_',$column);
449      $data[$column] = array(      $data[$column] = array(
450        'group' => t('Content'),        'group' => t('Content'),
451        'title' => t($field_types[$field['type']]['label']) .': '. t($field['widget']['label']) . ' ('. $field['field_name'].' '.$field_type .')',        'title' => t($field_types[$field['type']]['label']) . ': ' . t($field['widget']['label']) . ' (' . $field['field_name'].' '.$field_type . ')',
452        'help' =>  t($field_types[$field['type']]['label']) .' - '. t('Appears in: @types', array('@types' => implode(', ', $types))),        'help' =>  t($field_types[$field['type']]['label']) . ' - ' . t('Appears in: @types', array('@types' => implode(', ', $types))),
453        'field' => array(        'field' => array(
454          'field' => $column,          'field' => $column,
455          'table' => $db_info['table'],          'table' => $db_info['table'],
# Line 465  $i=0; Line 475  $i=0;
475        ),        ),
476        'filter' => array(        'filter' => array(
477          'field' => $column,          'field' => $column,
478          'title' => t($field['widget']['label']).': '.$field_type ,          'title' => t($field['widget']['label']) . ': ' . $field_type ,
479          'table' => $db_info['table'],          'table' => $db_info['table'],
480          'handler' => $filters[$i],          'handler' => $filters[$i],
481          //'additional fields' => $additional_fields,          //'additional fields' => $additional_fields,
# Line 490  $i=0; Line 500  $i=0;
500      // TODO: provide automatic filters, sorts, and arguments for each column, not just the first?      // TODO: provide automatic filters, sorts, and arguments for each column, not just the first?
501      return array($table_alias => $data);      return array($table_alias => $data);
502  }  }
503    

Legend:
Removed from v.1.1.2.1.2.9  
changed lines
  Added in v.1.1.2.1.2.10

  ViewVC Help
Powered by ViewVC 1.1.2