update room number field to be an integer

This commit is contained in:
2016-06-28 13:12:55 +10:00
parent 1aa9f6cfbe
commit d5d45512c6
4 changed files with 62 additions and 2 deletions

View File

@@ -1657,6 +1657,43 @@ function _booking_room_email_summary($node) {
return implode("\n", $rows); return implode("\n", $rows);
} }
/**
* Helper function to create the mean, median, mode or average of an array
* @see http://www.phpsnips.com/45/Mean,-Median,-Mode,-Range-Of-An-Array
*/
function _booking_mmmr($array, $output = 'mean'){
if(!is_array($array)) {
return FALSE;
}
else {
switch($output){
case 'mean':
$count = count($array);
$sum = array_sum($array);
$total = $sum / $count;
break;
case 'median':
rsort($array);
$middle = round(count($array) / 2);
$total = $array[$middle-1];
break;
case 'mode':
$v = array_count_values($array);
arsort($v);
foreach($v as $k => $v){$total = $k; break;}
break;
case 'range':
sort($array);
$sml = $array[0];
rsort($array);
$lrg = $array[0];
$total = $lrg - $sml;
break;
}
return $total;
}
}
/** /**
* @brief Generates a Universally Unique IDentifier, version 4. * @brief Generates a Universally Unique IDentifier, version 4.
* *

View File

@@ -595,6 +595,16 @@ function booking_update_7238() {
_booking_node_create_mysqlview(); _booking_node_create_mysqlview();
} }
/**
* Change room number field in room definitions to integer
*/
function booking_update_7239() {
$spec = array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0);
db_change_field('booking_room_definition', 'booking_room_number', 'booking_room_number', $spec);
//update the view to match the new table definition
_booking_node_create_mysqlview();
}
/** /**
* Implementation of hook_install(). * Implementation of hook_install().
*/ */
@@ -926,7 +936,7 @@ function booking_schema() {
'fields' => array( 'fields' => array(
'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), 'rid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'),
'booking_room_location_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_location_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_number' => array('type' => 'varchar', 'length' => '500', 'not null' => FALSE), 'booking_room_number' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_singlebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_singlebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_doublebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_doublebeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),
'booking_room_queenbeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0), 'booking_room_queenbeds' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10', 'default' => 0),

View File

@@ -279,7 +279,8 @@ function booking_report_summary() {
)); ));
$output .= t("<h3>Ages</h3>"); $output .= t("<h3>Ages</h3>");
$output .= t("<p>The combined average age at the start of the week will be !average.<br />The male average age will be !maleaverage.<br />The female average age will be !femaleaverage.</p>", $output .= t("<p>The combined average age at the start of the week will be !average.<br />The male average age will be !maleaverage.<br />The female average age will be !femaleaverage.</p>",
array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start), '!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start), array('!average' => _booking_avg_age($dob_total, $male_count + $female_count, $event->booking_event_start),
'!maleaverage' => _booking_avg_age($male_dob_total, $male_count, $event->booking_event_start),
'!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start) '!femaleaverage' => _booking_avg_age($female_dob_total, $female_count, $event->booking_event_start)
)); ));
$output .= t("<h3>Finances</h3>"); $output .= t("<h3>Finances</h3>");

View File

@@ -425,6 +425,18 @@ function booking_rooms_definition_form($node, &$form_state, $create, $room_id =
} }
} }
/**
* Validate the form for adding room definitions
*/
function booking_rooms_definition_form_validate($form, $form_state) {
//make sure room number is numerical
$values = $form_state['input'];
if (! is_numeric($values['booking_room_number'])) {
form_set_error('booking_room_number', t('Room number must be numeric. If you need to use a more descriptive label, please use the room label field.'));
}
}
/** /**
* Process the form for adding room definitions * Process the form for adding room definitions
*/ */