• Home
  • How-To
  • Add a UDF to the Mobile My Bookings List

How-To

Add a UDF to the Mobile My Bookings List

This How-To shows the steps to showing a UDF on the mobile customer app's My Bookings list screen.

To support an unlimited number of UDFs, the UDF data cannot be stored in the booking, it must be stored in a separate table where each row is one UDF's values. If you join the booking table to the udf_values table and you have say 3 UDFs defined, you will get 3 copies of each booking row, one for each UDF.
The only way around this is to use some fancy SQL aggregating and grouping. 

You will need to:

  1. Modify the query that pulls booking data
  2. Modify the JQuery Mobile screen to display the UDF data 

 

1. Modify the query 

You will need to modify the get_mybookings() function in the JSON server.
Edit File:
\components\com_rsappt_pro2\controllers\json_x.php

Around line 1328 look for:

// now get their details and order by startdattime
$sql = "SELECT #__sv_apptpro2_requests.id_requests as id, #__sv_apptpro2_requests.name, #__sv_apptpro2_requests.email, #__sv_apptpro2_requests.phone,".
"#__sv_apptpro2_requests.request_status, #__sv_apptpro2_requests.payment_status, #__sv_apptpro2_requests.cancellation_id,".
"#__sv_apptpro2_resources.resource_admins, ".
"#__sv_apptpro2_resources.name as resname, #__sv_apptpro2_services.name AS ServiceName, ".
"CONCAT(#__sv_apptpro2_requests.startdate, ' ',#__sv_apptpro2_requests.starttime) as startdatetime, ".
"DATE_FORMAT(#__sv_apptpro2_requests.startdate, '%a %b %e ') as display_startdate, ".
"CONCAT(DATE_FORMAT(#__sv_apptpro2_requests.starttime, '%H:%i'), '/', DATE_FORMAT(#__sv_apptpro2_requests.endtime, '%H:%i')) as display_starttime ".
"FROM ( ".
"#__sv_apptpro2_requests LEFT JOIN ".
"#__sv_apptpro2_resources ON #__sv_apptpro2_requests.resource = ".
"#__sv_apptpro2_resources.id_resources LEFT JOIN ".
"#__sv_apptpro2_services ON #__sv_apptpro2_requests.service = ".
"#__sv_apptpro2_services.id_services ) ".
" WHERE ";
if($auth_result >0){
    $sql .= " (#__sv_apptpro2_requests.id_requests IN (".$booking_ids. ") OR #__sv_apptpro2_requests.cancellation_id IN (".$cancel_codes. ") OR user_id=".$auth_result.") ";
} else {
    if($cc != "-1"){
      $sql .= " #__sv_apptpro2_requests.cancellation_id IN (".$cancel_codes. ") ";
    } else {
      $sql .= " #__sv_apptpro2_requests.id_requests IN (".$booking_ids. ") ";
    }
}
$sql .= " AND #__sv_apptpro2_requests.startdate >= CURDATE() ".
" ORDER BY startdatetime asc";

 

 

Add in the red code:

// now get their details and order by startdattime
$sql = "SELECT #__sv_apptpro2_requests.id_requests as id, #__sv_apptpro2_requests.name, #__sv_apptpro2_requests.email, #__sv_apptpro2_requests.phone,".
"#__sv_apptpro2_requests.request_status, #__sv_apptpro2_requests.payment_status, #__sv_apptpro2_requests.cancellation_id,".
"#__sv_apptpro2_resources.resource_admins, ".
"GROUP_CONCAT(CASE #__sv_apptpro2_udfvalues.udf_id WHEN 3 THEN #__sv_apptpro2_udfvalues.udf_value END) as Fruit, ".
"#__sv_apptpro2_resources.name as resname, #__sv_apptpro2_services.name AS ServiceName, ".
"CONCAT(#__sv_apptpro2_requests.startdate, ' ',#__sv_apptpro2_requests.starttime) as startdatetime, ".
"DATE_FORMAT(#__sv_apptpro2_requests.startdate, '%a %b %e ') as display_startdate, ".
"CONCAT(DATE_FORMAT(#__sv_apptpro2_requests.starttime, '%H:%i'), '/', DATE_FORMAT(#__sv_apptpro2_requests.endtime, '%H:%i')) as display_starttime ".
"FROM ( ".
"#__sv_apptpro2_requests LEFT JOIN ".
"#__sv_apptpro2_resources ON #__sv_apptpro2_requests.resource = ".
"#__sv_apptpro2_resources.id_resources LEFT JOIN ".
"#__sv_apptpro2_services ON #__sv_apptpro2_requests.service = ".
"#__sv_apptpro2_services.id_services ". //) ".  // note, move the closing ) to the new line below.
'LEFT JOIN #__sv_apptpro2_udfvalues ON request_id = #__sv_apptpro2_requests.id_requests )'.
" WHERE ";
if($auth_result >0){
    $sql .= " (#__sv_apptpro2_requests.id_requests IN (".$booking_ids. ") OR #__sv_apptpro2_requests.cancellation_id IN (".$cancel_codes. ") OR user_id=".$auth_result.") ";
} else {
    if($cc != "-1"){
        $sql .= " #__sv_apptpro2_requests.cancellation_id IN (".$cancel_codes. ") ";
    } else {
        $sql .= " #__sv_apptpro2_requests.id_requests IN (".$booking_ids. ") ";
    }
}
$sql .= " AND #__sv_apptpro2_requests.startdate >= CURDATE() ".
" GROUP BY #__sv_apptpro2_requests.id_requests ".
" ORDER BY startdatetime asc";

 

In the above example I am grabbing UDF id 3 and naming it Fruit in the resulting data set.

 

2. Modify the View 

A work of caution here, in JQuery Mobile the entire app becomes a single JavaScript document in the device browser.
A typo or code error in one area can break the entire app or manifest itself as an error in a seemingly unrelated part of the mobile app.

Edit Mobile App file: scripts.js

Around line 924 look for:

list.append('<li><a href="/mybookings_detail.html" onclick="setSelectedBooking(\''+mb_data[i].cancellation_id+'\');"><h3>'
+ mb_data[i].resname + '</h3> <p>' + mb_data[i].display_startdate + ' ' + mb_data[i].display_starttime
+ ' ('+ status_span + translate_status(mb_data[i].request_status)+status_span_end+')'
 + '<br/>' +mb_data[i].ServiceName + '</p></li>');

 

Below I changed the ServiceName line to show the UDF selected in the above query.

list.append('<li><a href="/mybookings_detail.html" onclick="setSelectedBooking(\''+mb_data[i].cancellation_id+'\');"><h3>'
+ mb_data[i].resname + '</h3> <p>' + mb_data[i].display_startdate + ' ' + mb_data[i].display_starttime
+ ' ('+ status_span + translate_status(mb_data[i].request_status)+status_span_end+')'
+ '<br/>Favourite Fruit: ' + mb_data[i].Fruit + '</p></li>');