// Notice that the your lists response is returned as a Response object display_response($response, 'Example #6: Get the details from your first list (object-oriented)'); /** * Example #7: Make an object oriented request to get all the contacts that belong to a particular list * Call the .contacts method() in a List object */ // Let's get all your lists $lists = contactList::all(); // Let's get the contacts that belong to your first list // Notice that items is an array of List objects $response = $lists->items[0]->contacts(); // Notice that the items of the response are returned as a Contact object display_response($response, 'Example #7: Make an object oriented request to get all the contacts that belong to a particular list'); /** * Example #8: Make an object oriented request to create a contact in a particular list * Call the .create_contact method() in a List object */ // Let's get all your lists $lists = contactList::all(); // Let's get the contacts that belong to your first list // Notice that items is an array of List objects $response = $lists->items[0]->create_contact(array('email' => 'contact_list' . time() . '3' . '@verticalresponse.com')); // Notice that the the response is returned as a Contact object display_response($response, 'Example #8: Make an object oriented request to create a contact in a particular list'); function display_response($response, $title) { // Let's print the title followed by a empty line echo '<br/>' . $title . '<br/><br/>'; echo print_r($response); echo '<br/><br/>End of ' . $title . '<br/>'; }
// Notice that the $response variable is a Response object // And the items is an array of Contact objects display_response($response, 'Example #3: Make an object oriented request to get all of your contacts'); /** * Example #4: Get the details from your first contact in your contact list (object-oriented) * Use the .details method defined in the Contact class */ // Let's use the $response object from the last example // Get the first contact of the $response object $contact = $response->items[0]; // Let's print the details of the contact display_response($contact->details(), 'Example #4: Get the details from your first contact in your contact list (object-oriented)'); /** * Example #5: Make an object oriented request to get your contact list with pagination * To use pagination, simply specifify the index and limit parameters in the call */ // Let's get you contact list paginated $response = contact::all(array('index' => 2, 'limit' => 5)); display_response($response, 'Example #5: Make an object oriented request to get your contact list with pagination'); /** * Example #6: Make an object oriented request to create a contact */ $response = contact::create(array('email' => 'test_contact_2' . time() . '@verticalresponse.com')); display_response($response, 'Example #6: Make an object oriented request to create a contact'); function display_response($response, $title) { // Let's print the title followed by a empty line echo '<br/>' . $title . '<br/><br/>'; echo print_r($response); echo '<br/><br/>End of ' . $title . '<br/>'; }
/** * Render the querstion as required for displaying results and feedback to the user * @param array $extra [description] */ public function render_feedback($extra = array()) { global $string; // Make sure data is arrays not encoded if (!is_array($this->useranswer)) { $this->useranswer = json_decode($this->useranswer, true); } if (!is_array($this->settings)) { $this->settings = json_decode($this->settings, true); } if (isset($this->useranswer['vars'])) { $varname = array_keys($this->useranswer['vars']); $varvalue = array_values($this->useranswer['vars']); } else { $varname = array('$A', '$B', '$C', '$D', '$E', '$F', '$G', '$H', '$I', '$J', '$K'); $varvalue = array_fill(0, 11, '<span class="var_error"><img src="../artwork/small_yellow_warning_icon.gif" width="12" height="11" alt="!"> ERROR</span>'); } $leadin = str_ireplace($varname, $varvalue, $this->leadin); // Deal with the failed variables if ($this->scenario != '') { echo "<p>" . $this->scenario . "</p>\n"; } if ($this->q_media != '') { echo "<p align=\"center\">" . display_media($this->q_media, $this->q_media_width, $this->q_media_height, '') . "</p>\n"; } echo_content($leadin); if (!isset($this->useranswer['uans']) or $this->useranswer['uans'] == '') { if ($extra['hide_if_unanswered'] == 1) { $extra['tmp_display_correct_answer'] = 0; $extra['tmp_display_students_response'] = '0'; $extra['tmp_display_feedback'] = '0'; $extra['tmp_display_question_mark'] = '0'; } } $saved_response = ''; $saved_response_clean = ''; if (isset($this->useranswer['uans'])) { $saved_response = $this->useranswer['uans']; $saved_response_clean = preg_replace('([^0-9\\.\\-])', '', $saved_response); } $part_id = 1; $tmp_fback = $this->correct_fback; echo "<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\"><tr>"; if ($extra['tmp_display_correct_answer'] == '1') { echo '<td>'; if (isset($this->std[0])) { echo display_std($this->std[0]); } echo '</td>'; } else { echo '<td></td>'; } $marked = true; if ($saved_response_clean == '') { echo '<td>'; if ($extra['tmp_exclude'] == '1') { echo '<span class="exclude">'; } echo display_response($extra['tmp_display_students_response'], 'blank') . "<input type=\"text\" style=\"color:#808080; text-align:right\" name=\"q'" . $extra['question'] . "'\" size=\"10\" value=\"" . $string['unanswered'] . "\" />"; } else { echo '<td>'; if ($extra['tmp_exclude'] == '1') { echo '<span class="exclude">'; } if (isset($this->useranswer['status']['overall']) and ($this->useranswer['status']['overall'] == Q_MARKING_EXACT or $this->useranswer['status']['overall'] == Q_MARKING_FULL_TOL)) { echo display_response($extra['tmp_display_students_response'], 'tick'); } elseif (isset($this->useranswer['status']['overall']) and $this->useranswer['status']['overall'] == Q_MARKING_PART_TOL) { echo display_response($extra['tmp_display_students_response'], 'half'); } elseif (isset($this->useranswer['status']['overall']) and $this->useranswer['status']['overall'] == Q_MARKING_WRONG) { echo display_response($extra['tmp_display_students_response'], 'cross'); } else { echo display_response($extra['tmp_display_students_response'], 'unmarked'); $marked = false; } if ($marked) { echo '<input type="text" style="text-align:right" name="q' . $extra['question'] . '" size="10" value="' . $this->useranswer['uansnumb'] . ' ' . $this->useranswer['uansunit'] . '" />'; } } if ($marked) { if ($this->useranswer['ans']['units_used'] == '') { $display_units = ''; } else { $display_units = ' ' . $this->useranswer['ans']['units_used']; } } if ($extra['tmp_display_correct_answer'] == '1') { if (!isset($this->useranswer['status'])) { echo ' <strong><span class="err">' . $string['unmarked'] . '</span></strong>'; } elseif (!isset($this->useranswer['cans'])) { echo ' <strong><span class="err">' . $string['EnhancedCalcCorrectError'] . '</span></strong>'; } else { echo ' <strong>' . $this->useranswer['cans'] . $display_units . '</strong>'; } } else { echo ' '; } if (isset($this->useranswer['cans'])) { if (isset($this->useranswer['status']['overall']) and $this->useranswer['status']['overall'] == Q_MARKING_FULL_TOL) { echo ' ' . $string['withatoleranceof'] . ' ' . $this->settings['tolerance_full'] . str_replace('#', '', $this->settings['fulltoltyp']); echo ' (' . $this->useranswer['ans']['tolerance_fullansneg'] . $display_units . ' - ' . $this->useranswer['ans']['tolerance_fullans'] . $display_units . ')'; } if (isset($this->useranswer['status']['overall']) and $this->useranswer['status']['overall'] == Q_MARKING_PART_TOL) { echo ' ' . $string['withatoleranceof'] . ' ' . $this->settings['tolerance_partial'] . str_replace('#', '', $this->settings['parttoltyp']); echo ' (' . $this->useranswer['ans']['tolerance_partialansneg'] . $display_units . ' - ' . $this->useranswer['ans']['tolerance_partialans'] . $display_units . ')'; } } if ($extra['tmp_exclude'] == '1') { echo '</span>'; } echo "</td></tr>\n</table>\n"; if ($tmp_fback != '' and $extra['tmp_display_feedback'] == '1') { foreach ($varname as $individual_varname) { $tmp_fback = str_replace($individual_varname, $this->useranswer['vars'][$individual_varname], $tmp_fback); } echo "<br /><div class=\"fback\">" . nl2br($tmp_fback) . "</div>\n"; } }
// Let's get the details of one of your contacts $contact = $contacts->items[0]; $details = VerticalResponse\API\Test::get_contact_details($contact); display_response($details, 'Get the details of one of your contacts'); // Let's create a list $list = VerticalResponse\API\Test::create_list(array('name' => 'Dummy list' . time())); display_response($list, 'Create a list'); // Let's see all your lists $lists = VerticalResponse\API\Test::get_lists(); display_response($lists, 'Get your lists'); // Let's see the details of one of your lists // Let's use the lists object of the previous example ($lists) $list = $lists->items[0]; $details = VerticalResponse\API\Test::list_details($list); display_response($details, 'Get details of one of your lists'); // Let's see the contacts that belong to one of your lists // Let's use the list object of the previous example ($list) $contacts = VerticalResponse\API\Test::get_lists_contacts($list); display_response($contacts, 'Get the contacts of one of your lists'); // Let's create a new contact in one of your lists // Let's use the list object of the previous example ($list) $contact = VerticalResponse\API\Test::create_list_contact(array('email' => 'dummy_list_contact_' . time() . '@verticalresponse.com'), $list); display_response($contact, 'Create a contact in a list'); // This method is used to format the output of the examples above function display_response($response, $title) { // Let's print the title followed by a empty line echo '<br/>' . $title . '<br/><br/>'; echo print_r($response); echo '<br/><br/>End of ' . $title . '<br/>'; }