本文整理汇总了PHP中optional_param_array函数的典型用法代码示例。如果您正苦于以下问题:PHP optional_param_array函数的具体用法?PHP optional_param_array怎么用?PHP optional_param_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了optional_param_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: no_submit_button_pressed
/**
* Checks if button pressed is not for submitting the form
*
* This overrides moodleform, and is a hack to fix the issue where recurring element buttons
* will be stored as an array, rather than a single item, in the url which causes a warning and causes our tests to fail
*
* Most of the code was copied from moodleform, with the addition of the in_array check
*
*
* @staticvar bool $nosubmit keeps track of no submit button
* @return bool
*/
function no_submit_button_pressed()
{
static $nosubmit = null;
// one check is enough
if (!is_null($nosubmit)) {
return $nosubmit;
}
$mform =& $this->_form;
$nosubmit = false;
if (!$this->is_submitted()) {
return false;
}
foreach ($mform->_noSubmitButtons as $nosubmitbutton) {
// Need to handle this specially, since will be an array
if (in_array($nosubmitbutton, $this->_recurring_nosubmit_buttons)) {
if (optional_param_array($nosubmitbutton, 0, PARAM_RAW)) {
$nosubmit = true;
break;
}
} else {
if (optional_param($nosubmitbutton, 0, PARAM_RAW)) {
$nosubmit = true;
break;
}
}
}
return $nosubmit;
}
示例2: data_preprocessing
public function data_preprocessing($question)
{
$question = parent::data_preprocessing($question);
$question = $this->data_preprocessing_combined_feedback($question, true);
$question = $this->data_preprocessing_hints($question, true, true);
$dragids = array();
// drag no -> dragid
if (!empty($question->options)) {
$question->shuffleanswers = $question->options->shuffleanswers;
$question->drags = array();
foreach ($question->options->drags as $drag) {
$dragindex = $drag->no - 1;
$question->drags[$dragindex] = array();
$question->drags[$dragindex]['draglabel'] = $drag->label;
$question->drags[$dragindex]['infinite'] = $drag->infinite;
$question->drags[$dragindex]['draggroup'] = $drag->draggroup;
$dragids[$dragindex] = $drag->id;
}
$question->drops = array();
foreach ($question->options->drops as $drop) {
$question->drops[$drop->no - 1] = array();
$question->drops[$drop->no - 1]['choice'] = $drop->choice;
$question->drops[$drop->no - 1]['droplabel'] = $drop->label;
$question->drops[$drop->no - 1]['xleft'] = $drop->xleft;
$question->drops[$drop->no - 1]['ytop'] = $drop->ytop;
}
}
//initialise file picker for bgimage
$draftitemid = file_get_submitted_draft_itemid('bgimage');
file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'bgimage', !empty($question->id) ? (int) $question->id : null, self::file_picker_options());
$question->bgimage = $draftitemid;
//initialise file picker for dragimages
list(, $imagerepeats) = $this->get_drag_item_repeats();
$draftitemids = optional_param_array('dragitem', array(), PARAM_INT);
for ($imageindex = 0; $imageindex < $imagerepeats; $imageindex++) {
$draftitemid = isset($draftitemids[$imageindex]) ? $draftitemids[$imageindex] : 0;
//numbers not allowed in filearea name
$itemid = isset($dragids[$imageindex]) ? $dragids[$imageindex] : null;
file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'dragimage', $itemid, self::file_picker_options());
$question->dragitem[$imageindex] = $draftitemid;
}
if (!empty($question->options)) {
foreach ($question->options->drags as $drag) {
$dragindex = $drag->no - 1;
if (!isset($question->dragitem[$dragindex])) {
$fileexists = false;
} else {
$fileexists = self::file_uploaded($question->dragitem[$dragindex]);
}
$labelexists = trim($question->drags[$dragindex]['draglabel']) != '';
if ($labelexists && !$fileexists) {
$question->dragitemtype[$dragindex] = 'word';
} else {
$question->dragitemtype[$dragindex] = 'image';
}
}
}
$this->js_call();
return $question;
}
示例3: __construct
/**
* Constructor
*
* @param \mod_grouptool\output\sortlist $sortlist Sortlist to be used without
*/
public function __construct(sortlist &$sortlist)
{
global $SESSION;
$this->sortlist = $sortlist;
$classes = optional_param_array('classes', array(0), \PARAM_INT);
$action = optional_param('class_action', 0, \PARAM_ALPHA);
$gobutton = optional_param('do_class_action', 0, \PARAM_BOOL);
if (!empty($gobutton) && $classes != null && count($classes) != 0 && !empty($action)) {
$keys = array();
$groups = array();
foreach ($classes as $groupingid) {
$groups = array_merge($groups, groups_get_all_groups($this->sortlist->cm->course, 0, $groupingid));
}
foreach ($groups as $current) {
switch ($action) {
case 'select':
$this->sortlist->selected[$current->id] = 1;
break;
case 'deselect':
$this->sortlist->selected[$current->id] = 0;
break;
case 'toggle':
$next = empty($this->sortlist->selected[$current->id]) ? 1 : 0;
$this->sortlist->selected[$current->id] = $next;
break;
}
}
// Update SESSION!
$SESSION->sortlist->selected = $this->sortlist->selected;
}
}
示例4: preferences_update
/**
* Save as CSV value
*/
public function preferences_update($data)
{
$raw = optional_param_array($this->name, '', PARAM_RAW);
if (!empty($raw) and !empty($data->{$this->name})) {
$data->{$this->name} = implode(',', $data->{$this->name});
} else {
$data->{$this->name} = '';
}
return parent::preferences_update($data);
}
示例5: upload
/**
* Process uploaded file
* @return array|bool
*/
public function upload($saveas_filename, $maxbytes)
{
global $CFG;
$types = optional_param_array('accepted_types', '*', PARAM_RAW);
$savepath = optional_param('savepath', '/', PARAM_PATH);
$itemid = optional_param('itemid', 0, PARAM_INT);
$license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT);
$author = optional_param('author', '', PARAM_TEXT);
return $this->process_upload($saveas_filename, $maxbytes, $types, $savepath, $itemid, $license, $author);
}
示例6: upload
/**
* Process uploaded file
* @return array|bool
*/
public function upload($saveas_filename, $maxbytes)
{
global $CFG;
$types = optional_param_array('accepted_types', '*', PARAM_RAW);
$savepath = optional_param('savepath', '/', PARAM_PATH);
$itemid = optional_param('itemid', 0, PARAM_INT);
$license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT);
$author = optional_param('author', '', PARAM_TEXT);
$areamaxbytes = optional_param('areamaxbytes', FILE_AREA_MAX_BYTES_UNLIMITED, PARAM_INT);
$overwriteexisting = optional_param('overwrite', false, PARAM_BOOL);
return $this->process_upload($saveas_filename, $maxbytes, $types, $savepath, $itemid, $license, $author, $overwriteexisting, $areamaxbytes);
}
示例7: process_form
public function process_form()
{
$tag = optional_param('tag', '', PARAM_TAG);
$fs = get_file_storage();
$storedfile = $fs->get_file($this->context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $this->image);
$image = new lightboxgallery_image($storedfile, $this->gallery, $this->cm);
if ($tag) {
$image->add_tag($tag);
} else {
if (optional_param('delete', 0, PARAM_INT)) {
if ($deletes = optional_param_array('deletetags', array(), PARAM_RAW)) {
foreach ($deletes as $delete) {
$image->delete_tag(clean_param($delete, PARAM_INT));
}
}
}
}
}
示例8: filter_input
/**
* Filter and load input parameters
*
* @throws \coding_exception
*/
protected function filter_input()
{
// Type specifc
$this->content_id = optional_param('content_id', 0, PARAM_INT);
// Used to handle pagination
$this->offset = optional_param('offset', 0, PARAM_INT);
// Max number of items to display on one page
$this->limit = optional_param('limit', 20, PARAM_INT);
if ($this->limit > 100) {
// Avoid wrong usage
throw new \coding_exception('limit to high');
}
// Field to order by
$this->orderBy = optional_param('sortBy', 0, PARAM_INT);
// Direction to order in
$this->orderDir = optional_param('sortDir', 0, PARAM_INT);
// List of fields to filter results on
$this->filters = optional_param_array('filters', array(), PARAM_RAW_TRIMMED);
}
示例9: execute
function execute($finalelements, $data) {
global $CFG;
if ($this->report->type != 'sql')
return $finalelements;
if ($CFG->version < 2011120100) {
$filter_starttime = optional_param('filter_starttime', 0, PARAM_RAW);
$filter_endtime = optional_param('filter_endtime', 0, PARAM_RAW);
} else {
$filter_starttime = optional_param_array('filter_starttime', 0, PARAM_RAW);
$filter_endtime = optional_param_array('filter_endtime', 0, PARAM_RAW);
}
if (!$filter_starttime || !$filter_endtime)
return $finalelements;
$filter_starttime = make_timestamp($filter_starttime['year'], $filter_starttime['month'], $filter_starttime['day'], $filter_starttime['hour'], $filter_starttime['minute']);
$filter_endtime = make_timestamp($filter_endtime['year'], $filter_endtime['month'], $filter_endtime['day'], $filter_endtime['hour'], $filter_endtime['minute']);
$operators = array('<', '>', '<=', '>=');
if (preg_match("/%%FILTER_STARTTIME:([^%]+)%%/i", $finalelements, $output)) {
list($field, $operator) = preg_split('/:/', $output[1]);
if (!in_array($operator, $operators))
print_error('nosuchoperator');
$replace = ' AND ' . $field . ' ' . $operator . ' ' . $filter_starttime;
$finalelements = str_replace('%%FILTER_STARTTIME:' . $output[1] . '%%', $replace, $finalelements);
}
if (preg_match("/%%FILTER_ENDTIME:([^%]+)%%/i", $finalelements, $output)) {
list($field, $operator) = preg_split('/:/', $output[1]);
if (!in_array($operator, $operators))
print_error('nosuchoperator');
$replace = ' AND ' . $field . ' ' . $operator . ' ' . $filter_endtime;
$finalelements = str_replace('%%FILTER_ENDTIME:' . $output[1] . '%%', $replace, $finalelements);
}
$finalelements = str_replace('%STARTTIME%%', $filter_starttime, $finalelements);
$finalelements = str_replace('%ENDTIME%%', $filter_endtime, $finalelements);
return $finalelements;
}
示例10: __construct
public function __construct()
{
global $PAGE;
global $CFG;
if ($CFG->debug) {
$PAGE->requires->yui_module('moodle-local_searchbytags-allowmultiple', 'M.local_searchbytags.allowmultiple.init');
}
$this->tags = optional_param_array('tags', array(), PARAM_TEXT);
if (!empty($this->tags) && $this->tags[0] == null) {
array_shift($this->tags);
}
$this->nottags = optional_param_array('nottags', array(), PARAM_TEXT);
if (!empty($this->nottags) && $this->nottags[0] == null) {
array_shift($this->nottags);
}
if (!empty($this->tags) || !empty($this->nottags)) {
$this->init();
}
}
示例11: __construct
public function __construct($submiturl, $question, $category, $contexts, $formeditable = true)
{
$this->regenerate = true;
$this->question = $question;
$this->qtypeobj = question_bank::get_qtype($this->question->qtype);
// Get the dataset definitions for this question.
// Coming here everytime even when using a NoSubmitButton.
// This will only set the values to the actual question database content
// which is not what we want, so this should be removed from here.
// Get priority to paramdatasets.
$this->reload = optional_param('reload', false, PARAM_BOOL);
if (!$this->reload) {
// Use database data as this is first pass
// Question->id == 0 so no stored datasets.
if (!empty($question->id)) {
$this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
if (!empty($this->datasetdefs)) {
foreach ($this->datasetdefs as $defid => $datasetdef) {
// First get the items in case their number does not correspond to itemcount.
if (isset($datasetdef->id)) {
$this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
if ($this->datasetdefs[$defid]->items != '') {
$datasetdef->itemcount = count($this->datasetdefs[$defid]->items);
} else {
$datasetdef->itemcount = 0;
}
}
// Get maxnumber.
if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
$this->maxnumber = $datasetdef->itemcount;
}
}
}
$i = 0;
foreach ($this->question->options->answers as $answer) {
$this->answer[$i] = $answer;
$i++;
}
$this->nonemptyanswer = $this->answer;
}
$datasettoremove = false;
$newdatasetvalues = false;
$newdataset = false;
} else {
// Handle reload to get values from the form-elements
// answers, datasetdefs and data_items. In any case the validation
// step will warn the user of any error in settings the values.
// Verification for the specific dataset values as the other parameters
// units, feeedback etc are handled elsewhere.
// Handle request buttons :
// 'analyzequestion' (Identify the wild cards {x..} present in answers).
// 'addbutton' (create new set of datatitems).
// 'updatedatasets' is handled automatically on each reload.
// The analyzequestion is done every time on reload
// to detect any new wild cards so that the current display reflects
// the mandatory (i.e. in answers) datasets.
// To implement : don't do any changes if the question is used in a quiz.
// If new datadef, new properties should erase items.
// most of the data.
$datasettoremove = false;
$newdatasetvalues = false;
$newdataset = false;
$dummyform = new stdClass();
$mandatorydatasets = array();
// Should not test on adding a new answer.
// Should test if there are already olddatasets or if the 'analyzequestion'.
// submit button has been clicked.
if (optional_param_array('datasetdef', false, PARAM_BOOL) || optional_param('analyzequestion', false, PARAM_BOOL)) {
if ($dummyform->answer = optional_param_array('answer', '', PARAM_NOTAGS)) {
// There is always at least one answer...
$fraction = optional_param_array('fraction', '', PARAM_FLOAT);
$tolerance = optional_param_array('tolerance', '', PARAM_FLOAT);
$tolerancetype = optional_param_array('tolerancetype', '', PARAM_FLOAT);
$correctanswerlength = optional_param_array('correctanswerlength', '', PARAM_INT);
$correctanswerformat = optional_param_array('correctanswerformat', '', PARAM_INT);
foreach ($dummyform->answer as $key => $answer) {
if (trim($answer) != '') {
// Just look for non-empty.
$this->answer[$key] = new stdClass();
$this->answer[$key]->answer = $answer;
$this->answer[$key]->fraction = $fraction[$key];
$this->answer[$key]->tolerance = $tolerance[$key];
$this->answer[$key]->tolerancetype = $tolerancetype[$key];
$this->answer[$key]->correctanswerlength = $correctanswerlength[$key];
$this->answer[$key]->correctanswerformat = $correctanswerformat[$key];
$this->nonemptyanswer[] = $this->answer[$key];
$mandatorydatasets += $this->qtypeobj->find_dataset_names($answer);
}
}
}
$this->datasetdefs = array();
// Rebuild datasetdefs from old values.
if ($olddef = optional_param_array('datasetdef', '', PARAM_RAW)) {
$calcmin = optional_param_array('calcmin', '', PARAM_FLOAT);
$calclength = optional_param_array('calclength', '', PARAM_INT);
$calcmax = optional_param_array('calcmax', '', PARAM_FLOAT);
$oldoptions = optional_param_array('defoptions', '', PARAM_RAW);
$newdatasetvalues = false;
$sizeofolddef = count($olddef);
for ($key = 1; $key <= $sizeofolddef; $key++) {
//.........这里部分代码省略.........
示例12: array
$course = $DB->get_record('course', array('id' => $hotpot->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('hotpot', $hotpot->id, $course->id, false, MUST_EXIST);
}
// check login
require_login($course, true, $cm);
if (!has_capability('mod/hotpot:reviewallattempts', $PAGE->context)) {
require_capability('mod/hotpot:reviewmyattempts', $PAGE->context);
}
add_to_log($course->id, 'hotpot', 'report', 'report.php?id=' . $cm->id, $hotpot->id, $cm->id);
// Create an object to represent the current HotPot activity
$hotpot = hotpot::create($hotpot, $cm, $course, $PAGE->context);
// delete attempts, if requested
$action = optional_param('action', '', PARAM_ALPHA);
$confirmed = optional_param('confirmed', 0, PARAM_INT);
if (function_exists('optional_param_array')) {
$selected = optional_param_array('selected', 0, PARAM_INT);
} else {
$selected = optional_param('selected', 0, PARAM_INT);
}
if ($action == 'deleteselected') {
require_sesskey();
if ($confirmed) {
$hotpot->delete_attempts($selected, false);
} else {
// show a confirm button ?
}
}
$PAGE->set_url('/mod/hotpot/report.php', array('id' => $course->id, 'mode' => $mode));
$PAGE->set_title($hotpot->name);
$PAGE->set_heading($course->shortname);
$PAGE->navbar->add(get_string('report', 'quiz'));
示例13: filter
/**
* Filter file listing to display specific types
*
* @param array $value
* @return bool
*/
public function filter(&$value)
{
$accepted_types = optional_param_array('accepted_types', '', PARAM_RAW);
if (isset($value['children'])) {
if (!empty($value['children'])) {
$value['children'] = array_filter($value['children'], array($this, 'filter'));
}
return true;
// always return directories
} else {
if ($accepted_types == '*' or empty($accepted_types) or is_array($accepted_types) and in_array('*', $accepted_types)) {
return true;
} else {
foreach ($accepted_types as $ext) {
if (preg_match('#' . $ext . '$#i', $value['title'])) {
return true;
}
}
}
}
return false;
}
示例14: test_optional_param_array
public function test_optional_param_array()
{
global $CFG;
$_POST['username'] = array('a' => 'post_user');
$_GET['username'] = array('a' => 'get_user');
$this->assertSame($_POST['username'], optional_param_array('username', array('a' => 'default_user'), PARAM_RAW));
unset($_POST['username']);
$this->assertSame($_GET['username'], optional_param_array('username', array('a' => 'default_user'), PARAM_RAW));
unset($_GET['username']);
$this->assertSame(array('a' => 'default_user'), optional_param_array('username', array('a' => 'default_user'), PARAM_RAW));
// Make sure exception is triggered when some params are missing, hide error notices here - new in 2.2.
$_POST['username'] = array('a' => 'post_user');
try {
optional_param_array('username', array('a' => 'default_user'), null);
$this->fail('coding_exception expected');
} catch (moodle_exception $ex) {
$this->assertInstanceOf('coding_exception', $ex);
}
try {
@optional_param_array('username', array('a' => 'default_user'));
$this->fail('coding_exception expected');
} catch (moodle_exception $ex) {
$this->assertInstanceOf('coding_exception', $ex);
}
try {
@optional_param_array('username');
$this->fail('coding_exception expected');
} catch (moodle_exception $ex) {
$this->assertInstanceOf('coding_exception', $ex);
}
try {
optional_param_array('', array('a' => 'default_user'), PARAM_RAW);
$this->fail('coding_exception expected');
} catch (moodle_exception $ex) {
$this->assertInstanceOf('coding_exception', $ex);
}
// Do not allow nested arrays.
try {
$_POST['username'] = array('a' => array('b' => 'post_user'));
optional_param_array('username', array('a' => 'default_user'), PARAM_RAW);
$this->fail('coding_exception expected');
} catch (coding_exception $ex) {
$this->assertTrue(true);
}
// Do not allow non-arrays.
$_POST['username'] = 'post_user';
$this->assertSame(array('a' => 'default_user'), optional_param_array('username', array('a' => 'default_user'), PARAM_RAW));
$this->assertDebuggingCalled();
// Make sure array keys are sanitised.
$_POST['username'] = array('abc123_;-/*-+ ' => 'arrggh', 'a1_-' => 'post_user');
$this->assertSame(array('a1_-' => 'post_user'), optional_param_array('username', array(), PARAM_RAW));
$this->assertDebuggingCalled();
}
示例15: ChatForm
$id = $aux[0];
}
}
$mform = new ChatForm($linkForm, $valoresDefault);
$usuarios = $chatDao->findUser();
if (!$id || $id && $grupo) {
if ($data = $mform->get_data()) {
$grupoChat = new stdClass();
$grupoChat->nome = $data->nome;
$grupoChat->data_registro = time();
if (!$id) {
$id = $DB->insert_record('chatwebgd_grupo', $grupoChat);
$chatDao->inserirUsuarioGrupo($id, $USER->id);
}
if ($id) {
$usuarios = optional_param_array('usuarios_grupo', array(), PARAM_TEXT);
if (count($usuarios)) {
foreach ($usuarios as $usuario) {
if ($chatDao->verificaUsuarioInativo($id, $usuario)) {
$chatDao->ativarUsuario($id, $usuario);
} else {
$chatDao->inserirUsuarioGrupo($id, $usuario);
}
}
}
echo '<meta http-equiv="refresh" content="0; url=' . $CFG->wwwroot . '">';
}
} else {
$mform->display();
}
} else {