コード例 #1
0
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
define('AJAX_SCRIPT', true);
/**
 *
 * @package mod-dialogue
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once $CFG->dirroot . '/mod/dialogue/locallib.php';
// course module identifier
$id = required_param('id', PARAM_INT);
// search text
$q = required_param('q', PARAM_RAW);
// check access.
if (!isloggedin()) {
    print_error('mustbeloggedin');
}
// check session
if (!confirm_sesskey()) {
    print_error('invalidsesskey');
}
$cm = get_coursemodule_from_id('dialogue', $id, 0, false, MUST_EXIST);
$PAGE->set_cm($cm);
list($receivers, $matches, $pagesize) = dialogue_search_potentials(new \mod_dialogue\dialogue($cm), $q);
$return = array();
$return['results'] = array_values($receivers);
$return['matches'] = $matches;
$return['pagesize'] = $pagesize;
header('Content-type: application/json; charset=utf-8');
echo json_encode($return);
exit;
コード例 #2
0
 /**
  *
  * @return boolean
  */
 public function definition_after_data()
 {
     global $PAGE;
     $mform = $this->_form;
     $q = optional_param('p_query', '', PARAM_TEXT);
     if (!empty($q)) {
         $dialogue = new \mod_dialogue\dialogue($PAGE->cm, $PAGE->course, $PAGE->activityrecord);
         $results = dialogue_search_potentials($dialogue, $q);
         if (empty($results[0])) {
             $people = array(get_string('nomatchingpeople', 'dialogue', $q) => array(''));
         } else {
             $options = array();
             foreach ($results[0] as $person) {
                 $options[$person->id] = fullname($person);
             }
             $people = array(get_string('matchingpeople', 'dialogue', count($options)) => $options);
             if ($mform->getElement('p_select')->getMultiple()) {
                 $selected = optional_param_array('p_select', array(), PARAM_INT);
             } else {
                 $selected = optional_param('p_select', array(), PARAM_INT);
             }
             $this->update_selectgroup('p_select', $people, $selected);
         }
     }
     // Clear out query string and selectgroup form data
     if (optional_param('p_clear', false, PARAM_BOOL)) {
         $mform = $this->_form;
         $pquery = $mform->getElement('p_query');
         $pquery->setValue('');
         $this->update_selectgroup('p_select', array(get_string('usesearch', 'dialogue') => array('' => '')));
     }
     return true;
 }