unset($customFormData['existingGroups'][$deleteData->groupToDelete]); if ($nukeContacts) { $customFormData['potentialContacts'] = array(); // Flattens existing data $contactList = $addressbookDAO->getAddressbookContactsForUser($USER->id, $addressbook->getId()); foreach ($contactList as $contact) { $customFormData['potentialContacts'][$contact->getContactId()] = $contact->getFullNameForDisplay(); } } } // POST PROCESSING FOR EDIT FORM $editForm = new MoodletxtGroupEditForm(null, $customFormData); $editData = $editForm->get_data(); if ($editData != null) { $editData = $editForm->cleanupFormData($editData); $groupObject = $addressbookDAO->getAddressbookGroupById($addressbook->getId(), $editData->editExistingGroup); if ($groupObject != null) { // Make sure collection is initialised, but empty $groupObject->setContacts(array()); foreach ($editData->editGroupMembers as $contactId) { $groupObject->addContact($addressbookDAO->getAddressbookContactById($addressbook->getId(), $contactId)); } $addressbookDAO->saveGroup($groupObject); $editForm->clearSubmittedValues(); $notifications .= $output->notification(get_string('notifygroupupdated', 'block_moodletxt'), 'notifysuccess'); } } // Populate group-contact associations // after all updates are complete $groupAssociationList = $addressbookDAO->getAddressbookGroupsForUser($USER->id, $addressbook->getId(), true); foreach ($groupAssociationList as $group) {
$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'); } } } // Initialise form defaults