/** * Adds a contact to the group * @param MoodletxtAddressbookRecipient $contact Contact to add * @version 2012092501 * @since 2011102601 */ public function addContact(MoodletxtAddressbookRecipient $contact) { if (!is_array($this->contacts)) { $this->contacts = array(); } $this->contacts[$contact->getContactId()] = $contact; }
/** * Converts a higher-level contact object into a standard * object class for writing to the database * @param MoodletxtAddressbookRecipient $contact Full-fat data object * @return object Object ready for DB * @version 2012091301 * @since 2012090501 */ private function convertContactBeanToStandardClass(MoodletxtAddressbookRecipient $contact) { $dbObj = new object(); $dbObj->addressbook = $contact->getAddressbookId(); $dbObj->firstname = $contact->getFirstName(); $dbObj->lastname = $contact->getLastName(); $dbObj->company = $contact->getCompanyName(); $dbObj->phoneno = $contact->getRecipientNumber()->getPhoneNumber(); if ($contact->getContactId() > 0) { $dbObj->id = $contact->getContactId(); } return $dbObj; }
$initialFormData = array('course' => $courseId, 'instance' => $instanceId, 'addressbook' => $addressbook->getId()); $customFormData = array('potentialGroups' => array()); $groupList = $addressbookDAO->getAddressbookGroupsForUser($USER->id, $addressbook->getId()); foreach ($groupList as $group) { $customFormData['potentialGroups'][$group->getId()] = $group->getName(); } $GLOBALS['_HTML_QuickForm_default_renderer'] = new QuickFormRendererWithSlides(); // Override renderer for multi-select $contactForm = new MoodletxtContactAddForm(null, $customFormData); $notifications = ''; // POST PROCESSING $formData = $contactForm->get_data(); if ($formData != null) { $formData = $contactForm->cleanupFormData($formData); // Create contact, add groups, save to DB $newContact = new MoodletxtAddressbookRecipient(new MoodletxtPhoneNumber($formData->phoneNumber), $formData->firstName, $formData->lastName, $formData->company, 0, $addressbook->getId()); foreach ($formData->groups as $groupId) { $newContact->addGroup($addressbookDAO->getAddressbookGroupById($formData->addressbook, $groupId)); } $addressbookDAO->saveContact($newContact); // Based on which button was pressed, we either send the // user back to the addressbook or clear the form if ($formData->submitButton == get_string('buttoncontactaddreturn', 'block_moodletxt')) { $addressbookPageUrl = new moodle_url('/blocks/moodletxt/addressbook_view.php', array('course' => $courseId, 'instance' => $instanceId, 'addressbook' => $addressbookId)); redirect($addressbookPageUrl, get_string('redirectcontactadded', 'block_moodletxt')); } else { if ($formData->submitButton == get_string('buttoncontactadd', 'block_moodletxt')) { $contactForm->clearSubmittedValues(); $notifications .= $output->notification(get_string('notifycontactadded', 'block_moodletxt'), 'notifysuccess'); } }
/** * Build JSON response structure for an updated contact * @param MoodletxtAddressbookRecipient $contact Updated contact * @return string Constructed JSON * @version 2012090501 * @since 2012090501 */ private function buildResponse(MoodletxtAddressbookRecipient $contact) { // Copy template down $response = $this->responseTemplate; $contactArray = array('contactId' => $contact->getContactId(), 'firstName' => $contact->getFirstName(), 'lastName' => $contact->getLastName(), 'company' => $contact->getCompanyName(), 'phoneNo' => $contact->getRecipientNumber()->getPhoneNumber()); array_push($response['contacts'], $contactArray); return json_encode($response); }
/** * Adds a single contact to this addressbook * @param MoodletxtAddressbookRecipient $contact Contact to add * @version 2012080701 * @since 2012080701 */ public function addContact(MoodletxtAddressbookRecipient $contact) { $this->contacts[$contact->getContactId()] = $contact; }