Skip to content

Survey Interface Implementation

Myeong Lee edited this page Jun 8, 2018 · 2 revisions

Survey Interfaces

This page is a survey interfact that is shown to organizations for filling out the forms (the source of our data).

Public Survey (http://www.opendataimpactmap.org/survey)

  • The layout of the public survey interface is implemented at /templates/survey/tp_survey.php
  • http://www.opendataimpactmap.org/survey calls survey/start function in the index.php file using the Slim framework.

/start/ function

  1. It has following two queries:
    1. retrieve max object id from the org_surveys table
    2. Insert a new object id with id as maxId + 1 into org_surveys table
    3. Pass the last inserted survey id to survey/:surveyId/form where surveyId is the passed surveyId
  2. :surveyId/form function calls survey/tp_survey.php file
  3. When a user submits the form, survey/tp_survey.php calls survey/2du/:surveyId function in index.php
  4. All the insertion of data using MySQL queries is done in 2du/:surveyId function. It first prepare data based on the data passed from the form, and insert to each table one by one.

/2du/:surveyId Function

  1. All the database operations for the input data provided by user in the form is done in this function.
  2. Checks whether org_hq_country_locode is already registered in the org_country_info table. If so, get the country_id from the table. This table follows ISO2 standard from the World Bank. If not found here, that means the country code is not available from the list (so will be remain as null).
  3. Checks org_locations_info table whether the location data (e.g., city and province) is already registered. If not, insert the location data into the table.
  4. Insert information into org_profiles table along with profile id as survey id of the form and location_id.
  5. Insert into org_contact table all survey_contact related data along with profile id as survey id
  6. Insert into data_applications table based on "applications" data.
  7. Insert int org_data_use table. i. First, retrieve country information for each data_use case. If available, it links to the country_id. ii. The followings deal with data_type when some values are available or null.
  8. After all the DB operations, it redirects to /survey/submitted/:surveyId/ function, then, calls survey/:surveyId/thankyou function.
  9. All survey related information along with profile id is passed to survey/tp_thankyou.php from /:surveyId/thankyou function

Internal Survey (http://www.opendataimpactmap.org/survey/start/internal/add/)

  • This interface is used by the internal researcher in ODE (not by an outside guest). E.g., A researcher interviews an organization and puts the organization data by himself/herself (rather than the organization's person does the survey).
  • The interface calls /:surveyId/form/internal/add/ function in index.php file using the Slim framework.
  • The layout of the internal survey interface is implemented at /templates/survey/tp_survey_less_req.php
  • The rest of the operations are same to the public one.

Survey Edit

  • survey/edit/:profile_id is called from /survey/tp_thankyou.php file or a pop-up menu from the map visualization.

/edit/:profile_id function

  1. It first retrieves org_name from the org_profiles table using profile id
  2. Calls survey/tp_profile_edit_msg.php file and passes org_name information.
  3. survey/tp_profile_edit_msg.php file calls survey/edit/:profileId/form function from index.php file

/edit/:profile_id/form function

  1. Retrieve all information from org_profiles table based on profile id, and join org_locations, org_country_info, and data_applications tables.
  2. Retrieve org_data_use based on profile id.
  3. Insert into org_surveys with a new survey_id.
  4. Sends all retrieved information to survey/tp_profile_edit.php file along with a new profile_id
  5. In survey/tp_profile_edit.php file, it displays all information received from /edit/:profile_id/form function
  6. After submission of the edited form, it calls survey/2du/:surveyId function and process all information as described above for /2du/:surveyId function.

Adding a New Language

Update languages by adding a new language

Requirements

  • gettext installed on server, development environment

Create files

  • Create directory for language files in Locale directory
cd odesurvey
mkdir -p html/map/survey/Locale/[language]/LC_MESSAGES
touch html/map/survey/Locale/[language]/LC_MESSAGES/messages.po
  • Copy content from Hackpad (or other source) into ../[language]/LC_MESSAGES/messages.po

Generate messages.mo file

  • Test format of messages.po is correct and generate the file (use sudo if necessary)
cd odesurvey/html/map/survey/Locale/de_DE/LC_MESSAGES
/usr/local/Cellar/gettext/0.19.4/bin/msgfmt messages.po

Example

[vagrant@odesurvey LC_MESSAGES]$ cd /var/www/html/map/survey/Locale/de_DE/LC_MESSAGES
[vagrant@odesurvey LC_MESSAGES]$ msgfmt messages.po 
messages.po:511: end-of-line within string
msgfmt: found 1 fatal error
[vagrant@odesurvey LC_MESSAGES]$ msgfmt messages.po 
msgfmt: error while opening "messages.mo" for writing: Permission denied
[vagrant@odesurvey LC_MESSAGES]$ sudo msgfmt messages.po 
[vagrant@odesurvey LC_MESSAGES]$ 

Add language to PHP templates

  • Add language entry to $langs array in PHP template files html/map/survey/templates/survey/tp_survey.php and html/map/survey/templates/survey/tp_survey_gettext.php
$langs = array('es_MX' => 'Español', 'fr_FR' => 'Français', 'de_DE' => 'German', 'ru_RU' => 'Russkiy');

Commit to repo

  • Commit to repo
  • Push repo

Upload to servers

  • See update_website.md

Restart Apache servers

  • Login into target server
  • Run the following commands
sudo service apache2 restart

Clone this wiki locally