/**
  * Gets full details of an inbound filter
  * @param int $filterId ID of filter to fetch
  * @return string JSON response
  * @version 2011071101
  * @since 2011071101
  */
 private function getFilterDetails($filterId)
 {
     $inboundFilter = $this->filterDAO->getFilterById($filterId);
     // Account must exist within system
     if (!is_object($inboundFilter)) {
         throw new MoodletxtAJAXException(get_string('errorinvalidaccountid', 'block_moodletxt'), MoodletxtAJAXException::$ERROR_CODE_BAD_ACCOUNT_ID, null, false);
     }
     return $this->buildResponse($inboundFilter);
 }
Exemplo n.º 2
0
$formData = $filterForm->get_data();
// Form processing
if ($formData != null) {
    $formData = $filterForm->cleanupFormData($formData);
    $usersOnFilter = array();
    // Run over the users selected for the filter and ensure they
    // are ready for saving
    if (isset($formData->usersOnFilter) && is_array($formData->usersOnFilter)) {
        $usersOnFilter = $userDAO->getUsersById($formData->usersOnFilter);
    }
    // Create or fetch filter object
    if ($formData->newKeywordFilter != '' || $formData->newPhoneNumberFilter != '') {
        $type = $formData->newKeywordFilter != '' ? MoodletxtInboundFilter::$FILTER_TYPE_KEYWORD : MoodletxtInboundFilter::$FILTER_TYPE_PHONE_NUMBER;
        $value = $formData->newKeywordFilter != '' ? $formData->newKeywordFilter : $formData->newPhoneNumberFilter;
        $filter = new MoodletxtInboundFilter($formData->filterAccountList, $type, $value);
    } else {
        $filterId = $formData->existingKeywordFilterList > 0 ? $formData->existingKeywordFilterList : $formData->existingPhoneNumberFilterList;
        $filter = $filterDAO->getFilterById($filterId);
    }
    // The easiest way of doing the filter links, rather than my old method
    // of finding the ones to remove and the ones to add, is simply to drop
    // them all and replace them with what's in the form. So let's do that!
    $filter->clearDestinationUsers();
    $filter->setDestinationUsers($usersOnFilter);
    $filterDAO->saveFilter($filter);
}
$output = $PAGE->get_renderer('block_moodletxt');
// Chuck the page out and go home
echo $output->header();
$filterForm->display();
echo $output->footer();