| 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 |
| 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( |
| 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'); |
| 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 |
| 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) { |
| 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) { |
| 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( |
| 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( |
| 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) { |
| 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; |
| 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) { |
| 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'], |
| 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, |
| 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 |
|
|