process names fields to always be Title Case

This commit is contained in:
2017-09-12 08:44:21 +10:00
parent 9910b523c6
commit 557b99966d
4 changed files with 52 additions and 30 deletions

View File

@@ -72,6 +72,21 @@ function _booking_remove_emoji($text) {
*/
}
/**
* Helper function to convert text of any case to Title Case, specifically for names
* Taken from http://php.net/manual/en/function.ucwords.php
*/
function _booking_ucname($string) {
$string = ucwords(strtolower($string));
foreach (array('-', '\'') as $delimiter) {
if (strpos($string, $delimiter)!==false) {
$string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
}
}
return $string;
}
/**
* Helper function to perform some validity checking of email addresses
@@ -108,26 +123,25 @@ function _valid_email_address($email) {
function _valid_medicare_number($input) {
//strip any whitespace
$medicare = preg_replace( '/\s+/', '', $input );
if (is_numeric($medicare) && strlen($medicare) >= 9 && $medicare > 0)
{
//for testing, use the fake medicare number 111111110
if (is_numeric($medicare) && strlen($medicare) >= 9 && $medicare > 0) {
$check_digit = $medicare[0] + (3 * $medicare[1]) + (7 * $medicare[2]) + (9 * $medicare[3])
+ $medicare[4] + (3 * $medicare[5]) + (7 * $medicare[6]) + (9 * $medicare[7]);
if (($check_digit % 10) == $medicare[8])
{
if (($check_digit % 10) == $medicare[8]) {
watchdog('booking', 'Medicare number (!mca) validates since check digit !check matches remainder from !remainder',
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
return TRUE;
}
else
{
else {
watchdog('booking', 'Medicare number (!mca) does not validate since check digit !check does not match remainder from !remainder',
array('!mca' => $input, '!check' => $medicare[8], '!remainder' => $check_digit));
return FALSE;
}
}
else
{
else {
watchdog('booking', 'Medicare number (!mca) does not validate since it is either non-numeric or too short',
array('!mca' => $input));
return FALSE;

View File

@@ -917,7 +917,7 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
if (variable_get('booking_enable_roommate', 0) == 1) {
$form['misc-areas']['booking_room_mate1'] = array(
'#type' => 'textfield',
'#title' => t('List up to two people you would like to share a room with (subject to availability).'),
'#title' => t('List up to two people you would like to share a room with (subject to availability)'),
'#maxlength' => 200,
'#required' => FALSE,
'#default_value' => !empty($data->booking_room_mate1) ? $data->booking_room_mate1 : ''
@@ -935,7 +935,7 @@ function booking_form($node, &$form_state, $inserting = FALSE, $early_access_all
if (variable_get('booking_enable_songchoice', 0) == 1) {
$form['misc-areas']['booking_song_choice'] = array(
'#type' => 'textfield',
'#title' => t("Let us know if there's a song you'd love to sing during the week."),
'#title' => t("Let us know if there's a song you'd love to sing during the week"),
'#maxlength' => 200,
'#required' => TRUE,
'#default_value' => !empty($data->booking_song_choice) ? $data->booking_song_choice : ''
@@ -1216,6 +1216,11 @@ function booking_form_submit($form, &$form_state)
$values = $form_state['input'];
//do some preprocessing on input
//convert names from whatever case they're in to Title Case
$values['booking_firstname'] = _booking_ucname($values['booking_firstname']);
$values['booking_lastname'] = _booking_ucname($values['booking_lastname']);
//strip any emojis from user input
if (variable_get('booking_enable_emoji_removal', 1) == 1) {
foreach ($values as $key => $value) {

View File

@@ -7,7 +7,7 @@ function booking_node_presave($node) {
if($node->type == 'booking') {
$title = t('!event registration: !name', array(
'!event' => $event->booking_eventname,
'!name' => $node->booking_firstname . ' ' . $node->booking_lastname,
'!name' => _booking_ucname($node->booking_firstname . ' ' . $node->booking_lastname),
));
//strip any emojis from user input if that feature is enabled
@@ -448,6 +448,11 @@ function booking_update($node) {
}
}
}
//make sure the name is the correct case
$data['booking_firstname'] = _booking_ucname($data['booking_firstname']);
$data['booking_lastname'] = _booking_ucname($data['booking_lastname']);
watchdog('booking', 'Updating node: @info', array('@info' => var_export($data, TRUE)));
db_update('booking_person')->fields($data)->condition('nid', $node->nid)->execute();
/*

View File

@@ -148,12 +148,10 @@ function booking_report_summary() {
$amount_owing = _booking_amount_owing($person, 0, FALSE);
//calculate the travel link
if ($person->tid > 0)
{
if ($person->tid > 0) {
$travel_link = l(t('Travel'), t('node/!id/edit', array('!id' => $person->tid)));
}
else
{
else {
$travel_link = t('N/A');
}