本文整理汇总了PHP中html_is_blank函数的典型用法代码示例。如果您正苦于以下问题:PHP html_is_blank函数的具体用法?PHP html_is_blank怎么用?PHP html_is_blank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了html_is_blank函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validation
public function validation($data, $files)
{
$errors = parent::validation($data, $files);
$answers = $data['answer'];
$answercount = 0;
$maxgrade = false;
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) {
$errors["answer[{$key}]"] = get_string('answermustbegiven', 'qtype_shortanswer');
$answercount++;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_shortanswer', 1);
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
return $errors;
}
示例2: save_question_options
function save_question_options($question)
{
global $DB;
$result = new stdClass();
if (!($oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC'))) {
$oldanswers = array();
}
$answers = array();
$maxfraction = -1;
// Insert all the new answers
foreach ($question->answer as $key => $dataanswer) {
// Check for, and ingore, completely blank answer from the form.
if (trim($dataanswer) == '' && $question->fraction[$key] == 0 && html_is_blank($question->feedback[$key])) {
continue;
}
if ($oldanswer = array_shift($oldanswers)) {
// Existing answer, so reuse it
$answer = $oldanswer;
$answer->answer = trim($dataanswer);
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
$DB->update_record("question_answers", $answer);
} else {
// This is a completely new answer
$answer = new stdClass();
$answer->answer = trim($dataanswer);
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
$answer->id = $DB->insert_record("question_answers", $answer);
}
$answers[] = $answer->id;
if ($question->fraction[$key] > $maxfraction) {
$maxfraction = $question->fraction[$key];
}
}
$question->answers = implode(',', $answers);
$parentresult = parent::save_question_options($question);
if ($parentresult !== null) {
// Parent function returns null if all is OK
return $parentresult;
}
// delete old answer records
if (!empty($oldanswers)) {
foreach ($oldanswers as $oa) {
$DB->delete_records('question_answers', array('id' => $oa->id));
}
}
/// Perform sanity checks on fractional grades
if ($maxfraction != 1) {
$maxfraction = $maxfraction * 100;
$result->noticeyesno = get_string("fractionsnomax", "quiz", $maxfraction);
return $result;
} else {
return true;
}
}
示例3: save_question_options
function save_question_options($question)
{
global $DB;
$result = new stdClass();
$context = $question->context;
$oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC');
// Insert all the new answers
$answers = array();
$maxfraction = -1;
foreach ($question->answer as $key => $answerdata) {
// Check for, and ignore, completely blank answer from the form.
if (trim($answerdata) == '' && $question->fraction[$key] == 0 && html_is_blank($question->feedback[$key]['text'])) {
continue;
}
// Update an existing answer if possible.
$answer = array_shift($oldanswers);
if (!$answer) {
$answer = new stdClass();
$answer->question = $question->id;
$answer->answer = '';
$answer->feedback = '';
$answer->id = $DB->insert_record('question_answers', $answer);
}
$answer->answer = trim($answerdata);
$answer->fraction = $question->fraction[$key];
$answer->feedback = $this->import_or_save_files($question->feedback[$key], $context, 'question', 'answerfeedback', $answer->id);
$answer->feedbackformat = $question->feedback[$key]['format'];
$DB->update_record('question_answers', $answer);
$answers[] = $answer->id;
if ($question->fraction[$key] > $maxfraction) {
$maxfraction = $question->fraction[$key];
}
}
// Delete any left over old answer records.
$fs = get_file_storage();
foreach ($oldanswers as $oldanswer) {
$fs->delete_area_files($context->id, 'question', 'answerfeedback', $oldanswer->id);
$DB->delete_records('question_answers', array('id' => $oldanswer->id));
}
$question->answers = implode(',', $answers);
$parentresult = parent::save_question_options($question);
if ($parentresult !== null) {
// Parent function returns null if all is OK
return $parentresult;
}
// Perform sanity checks on fractional grades
if ($maxfraction != 1) {
$result->noticeyesno = get_string('fractionsnomax', 'quiz', $maxfraction * 100);
return $result;
}
return true;
}
示例4: quiz_intro
/**
* Output the quiz intro.
* @param object $quiz the quiz settings.
* @param object $cm the course_module object.
* @return string HTML to output.
*/
public function quiz_intro($quiz, $cm)
{
if (html_is_blank($quiz->intro)) {
return '';
}
return $this->box(format_module_intro('quiz', $quiz, $cm->id), 'generalbox', 'intro');
}
示例5: read_submitted_permissions
public function read_submitted_permissions()
{
global $DB;
$this->errors = array();
// Role short name. We clean this in a special way. We want to end up
// with only lowercase safe ASCII characters.
$shortname = optional_param('shortname', null, PARAM_RAW);
if (!is_null($shortname)) {
$this->role->shortname = $shortname;
$this->role->shortname = textlib::specialtoascii($this->role->shortname);
$this->role->shortname = textlib::strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
}
}
if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) {
$this->errors['shortname'] = get_string('errorexistsroleshortname', 'role');
}
// Role name.
$name = optional_param('name', null, PARAM_TEXT);
if (!is_null($name)) {
$this->role->name = $name;
// Hack: short names of standard roles are equal to archetypes, empty name means localised via lang packs.
$archetypes = get_role_archetypes();
if (!isset($archetypes[$shortname]) and html_is_blank($this->role->name)) {
$this->errors['name'] = get_string('errorbadrolename', 'role');
}
}
if ($this->role->name !== '' and $DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) {
$this->errors['name'] = get_string('errorexistsrolename', 'role');
}
// Description.
$description = optional_param('description', null, PARAM_RAW);
if (!is_null($description)) {
$this->role->description = $description;
}
// Legacy type.
$archetype = optional_param('archetype', null, PARAM_RAW);
if (isset($archetype)) {
$archetypes = get_role_archetypes();
if (isset($archetypes[$archetype])) {
$this->role->archetype = $archetype;
} else {
$this->role->archetype = '';
}
}
// Assignable context levels.
foreach ($this->allcontextlevels as $cl => $notused) {
$assignable = optional_param('contextlevel' . $cl, null, PARAM_BOOL);
if (!is_null($assignable)) {
if ($assignable) {
$this->contextlevels[$cl] = $cl;
} else {
unset($this->contextlevels[$cl]);
}
}
}
// Now read the permissions for each capability.
parent::read_submitted_permissions();
}
示例6: save_question_options
function save_question_options($question)
{
$result = new stdClass();
if (!($oldanswers = get_records('question_answers', 'question', $question->id, 'id ASC'))) {
$oldanswers = array();
}
$answers = array();
$maxfraction = -1;
// Insert all the new answers
foreach ($question->answer as $key => $dataanswer) {
// Check for, and ingore, completely blank answer from the form.
if (trim($dataanswer) == '' && $question->fraction[$key] == 0 && html_is_blank($question->feedback[$key])) {
continue;
}
if ($oldanswer = array_shift($oldanswers)) {
// Existing answer, so reuse it
$answer = $oldanswer;
$answer->answer = trim($dataanswer);
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!update_record("question_answers", $answer)) {
$result->error = "Could not update quiz answer! (id={$answer->id})";
return $result;
}
} else {
// This is a completely new answer
$answer = new stdClass();
$answer->answer = trim($dataanswer);
$answer->question = $question->id;
$answer->fraction = $question->fraction[$key];
$answer->feedback = $question->feedback[$key];
if (!($answer->id = insert_record("question_answers", $answer))) {
$result->error = "Could not insert quiz answer!";
return $result;
}
}
$answers[] = $answer->id;
if ($question->fraction[$key] > $maxfraction) {
$maxfraction = $question->fraction[$key];
}
}
if ($options = get_record("question_shortanswer", "question", $question->id)) {
$options->answers = implode(",", $answers);
$options->usecase = $question->usecase;
if (!update_record("question_shortanswer", $options)) {
$result->error = "Could not update quiz shortanswer options! (id={$options->id})";
return $result;
}
} else {
unset($options);
$options->question = $question->id;
$options->answers = implode(",", $answers);
$options->usecase = $question->usecase;
if (!insert_record("question_shortanswer", $options)) {
$result->error = "Could not insert quiz shortanswer options!";
return $result;
}
}
// delete old answer records
if (!empty($oldanswers)) {
foreach ($oldanswers as $oa) {
delete_records('question_answers', 'id', $oa->id);
}
}
/// Perform sanity checks on fractional grades
if ($maxfraction != 1) {
$maxfraction = $maxfraction * 100;
$result->noticeyesno = get_string("fractionsnomax", "quiz", $maxfraction);
return $result;
} else {
return true;
}
}
示例7: validate_answers
/**
* Validate the answers.
* @param array $data the submitted data.
* @param array $errors the errors array to add to.
* @return array the updated errors array.
*/
protected function validate_answers($data, $errors) {
// Check the answers.
$answercount = 0;
$maxgrade = false;
$answers = $data['answer'];
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer != '') {
$answercount++;
if (!$this->is_valid_answer($trimmedanswer, $data)) {
$errors['answer[' . $key . ']'] = $this->valid_answer_message();
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
if (!is_numeric($data['tolerance'][$key])) {
$errors['tolerance['.$key.']'] =
get_string('mustbenumeric', 'qtype_calculated');
}
} else if ($data['fraction'][$key] != 0 ||
!html_is_blank($data['feedback'][$key]['text'])) {
$errors['answer[' . $key . ']'] = $this->valid_answer_message();
$answercount++;
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_numerical');
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
}
示例8: validation
function validation($data, $files)
{
global $QTYPES;
$errors = parent::validation($data, $files);
// Check the answers.
$answercount = 0;
$maxgrade = false;
$answers = $data['answer'];
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer != '') {
$answercount++;
if (!(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
$answercount++;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_numerical');
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
$QTYPES['numerical']->validate_numerical_options($data, $errors);
return $errors;
}
示例9: is_same_comment
/**
* Checks whether two manual grading actions are the same. That is, whether
* the comment, and the mark (if given) is the same.
*
* @param question_attempt_step $pendingstep contains the new responses.
* @return bool whether the new response is the same as we already have.
*/
protected function is_same_comment($pendingstep) {
$previouscomment = $this->qa->get_last_behaviour_var('comment');
$newcomment = $pendingstep->get_behaviour_var('comment');
if (is_null($previouscomment) && !html_is_blank($newcomment) ||
$previouscomment != $newcomment) {
return false;
}
// So, now we know the comment is the same, so check the mark, if present.
$previousfraction = $this->qa->get_fraction();
$newmark = $pendingstep->get_behaviour_var('mark');
if (is_null($previousfraction)) {
return is_null($newmark) || $newmark === '';
} else if (is_null($newmark) || $newmark === '') {
return false;
}
$newfraction = $newmark / $pendingstep->get_behaviour_var('maxmark');
return abs($newfraction - $previousfraction) < 0.0000001;
}
示例10: print_error
print_error('queryfailed', 'report_customsql', report_customsql_url('index.php'), $e);
}
} else {
$cvstimestamp = optional_param('timestamp', time(), PARAM_INT);
}
// Start the page.
admin_externalpage_setup('reportcustomsql');
admin_externalpage_print_header();
print_heading(format_string($report->displayname));
echo '<style>';
// (nadavkav)
//include('styles.php');
echo '.reporttitle { font-size:1.1em; } ';
//echo '#admin-report-customsql-edit #id_querysql { direction:ltr; } ';
echo '</style>';
if (!html_is_blank($report->description)) {
echo '<p>' . format_text($report->description, FORMAT_HTML) . '</p>';
}
$count = 0;
if (is_null($cvstimestamp)) {
echo '<p>' . get_string('nodatareturned', 'report_customsql') . '</p>';
} else {
list($csvfilename, $cvstimestamp) = report_customsql_csv_filename($report, $cvstimestamp);
if (!is_readable($csvfilename)) {
echo '<p>' . get_string('notrunyet', 'report_customsql') . '</p>';
} else {
$handle = fopen($csvfilename, 'r');
if ($report->runable != 'manual' && !$report->singlerow) {
print_heading(get_string('reportfor', 'report_customsql', userdate($cvstimestamp, get_string('strftimedate'))), '', 3);
}
$table = new stdClass();
示例11: read_submitted_permissions
public function read_submitted_permissions()
{
global $DB;
$this->errors = array();
// Role name.
$name = optional_param('name', null, PARAM_MULTILANG);
if (!is_null($name)) {
$this->role->name = $name;
if (html_is_blank($this->role->name)) {
$this->errors['name'] = get_string('errorbadrolename', 'role');
}
}
if ($DB->record_exists_select('role', 'name = ? and id <> ?', array($this->role->name, $this->roleid))) {
$this->errors['name'] = get_string('errorexistsrolename', 'role');
}
// Role short name. We clean this in a special way. We want to end up
// with only lowercase safe ASCII characters.
$shortname = optional_param('shortname', null, PARAM_RAW);
if (!is_null($shortname)) {
$this->role->shortname = $shortname;
$this->role->shortname = textlib_get_instance()->specialtoascii($this->role->shortname);
$this->role->shortname = moodle_strtolower(clean_param($this->role->shortname, PARAM_ALPHANUMEXT));
if (empty($this->role->shortname)) {
$this->errors['shortname'] = get_string('errorbadroleshortname', 'role');
}
}
if ($DB->record_exists_select('role', 'shortname = ? and id <> ?', array($this->role->shortname, $this->roleid))) {
$this->errors['shortname'] = get_string('errorexistsroleshortname', 'role');
}
// Description.
$description = optional_param('description', null, PARAM_CLEAN);
if (!is_null($description)) {
$this->role->description = $description;
}
// Legacy type.
$legacytype = optional_param('legacytype', null, PARAM_RAW);
if (!is_null($legacytype)) {
if (array_key_exists($legacytype, $this->legacyroles)) {
$this->role->legacytype = $legacytype;
} else {
$this->role->legacytype = '';
}
}
// Assignable context levels.
foreach ($this->allcontextlevels as $cl => $notused) {
$assignable = optional_param('contextlevel' . $cl, null, PARAM_BOOL);
if (!is_null($assignable)) {
if ($assignable) {
$this->contextlevels[$cl] = $cl;
} else {
unset($this->contextlevels[$cl]);
}
}
}
// Now read the permissions for each capability.
parent::read_submitted_permissions();
}
示例12: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
// Check the answers.
$answercount = 0;
$maxgrade = false;
$answers = $data['answer'];
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer != '') {
$answercount++;
if (!(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
}
if ($data['fraction'][$key] == 1) {
$maxgrade = true;
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key])) {
$errors["answer[{$key}]"] = get_string('answermustbenumberorstar', 'qtype_numerical');
$answercount++;
}
}
}
if ($answercount == 0) {
$errors['answer[0]'] = get_string('notenoughanswers', 'qtype_numerical');
}
if ($maxgrade == false) {
$errors['fraction[0]'] = get_string('fractionsnomax', 'question');
}
// Check units.
$alreadyseenunits = array();
if (isset($data['unit'])) {
foreach ($data['unit'] as $key => $unit) {
$trimmedunit = trim($unit);
if ($trimmedunit != '' && in_array($trimmedunit, $alreadyseenunits)) {
$errors["unit[{$key}]"] = get_string('errorrepeatedunit', 'qtype_numerical');
if (trim($data['multiplier'][$key]) == '') {
$errors["multiplier[{$key}]"] = get_string('errornomultiplier', 'qtype_numerical');
}
} else {
$alreadyseenunits[] = $trimmedunit;
}
}
}
return $errors;
}
示例13: get_question_summary
public function get_question_summary()
{
$summary = '';
if (!html_is_blank($this->questiontext)) {
$question = $this->html_to_text($this->questiontext, $this->questiontextformat);
$summary .= $question . '; ';
}
$places = array();
foreach ($this->places as $place) {
$cs = array();
foreach ($this->choices[$place->group] as $choice) {
$cs[] = $choice->summarise();
}
$places[] = '[[' . $place->summarise() . ']] -> {' . implode(' / ', $cs) . '}';
}
$summary .= implode('; ', $places);
return $summary;
}
示例14: validation
public function validation($data, $files)
{
global $CFG;
require_once $CFG->dirroot . '/question/type/regexp/locallib.php';
$errors = parent::validation($data, $files);
$answers = $data['answer'];
$data['fraction'][0] = 1;
$grades = $data['fraction'];
$answercount = 0;
$illegalmetacharacters = ". ^ \$ * + ? { } \\";
foreach ($answers as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
$parenserror = '';
$metacharserror = '';
// we do not check parenthesis and square brackets in Answer 1 (correct answer)
if ($key > 0) {
$markedline = '';
for ($i = 0; $i < strlen($trimmedanswer); $i++) {
$markedline .= ' ';
}
$parenserror = check_my_parens($trimmedanswer, $markedline);
if ($parenserror) {
$errors["answer[{$key}]"] = get_string("regexperrorparen", "qtype_regexp") . '<br />';
$markedline = $parenserror;
}
// we do not test unescaped metacharacters in Answers expressions for incorrect responses (grade = None)
if ($data['fraction'][$key] > 0) {
$metacharserror = check_unescaped_metachars($trimmedanswer, $markedline);
if ($metacharserror) {
$errormessage = get_string("illegalcharacters", "qtype_regexp", $illegalmetacharacters);
if (empty($errors["answer[{$key}]"])) {
$errors["answer[{$key}]"] = $errormessage;
} else {
$errors["answer[{$key}]"] .= $errormessage;
}
}
}
if ($metacharserror || $parenserror) {
$answerstringchunks = splitstring($trimmedanswer);
$nbchunks = count($answerstringchunks);
$errors["answer[{$key}]"] .= '<pre><div class="displayvalidationerrors">';
if ($metacharserror) {
$illegalcharschunks = splitstring($metacharserror);
for ($i = 0; $i < $nbchunks; $i++) {
$errors["answer[{$key}]"] .= '<br />' . $answerstringchunks[$i] . '<br />' . $illegalcharschunks[$i];
}
} elseif ($parenserror) {
$illegalcharschunks = splitstring($parenserror);
for ($i = 0; $i < $nbchunks; $i++) {
$errors["answer[{$key}]"] .= '<br />' . $answerstringchunks[$i] . '<br />' . $illegalcharschunks[$i];
}
}
$errors["answer[{$key}]"] .= '</div></pre>';
}
}
} else {
if ($data['fraction'][$key] != 0 || !html_is_blank($data['feedback'][$key]['text'])) {
if ($key === 0) {
$errors['answer[0]'] = get_string('answer1mustbegiven', 'qtype_regexp');
} else {
$errors["answer[{$key}]"] = get_string('answermustbegiven', 'qtype_regexp');
}
$answercount++;
}
}
}
return $errors;
}
示例15: wrsqz_html_is_blank
function wrsqz_html_is_blank($str){
if (function_exists("html_is_blank")){
//If moodle in new enough
return html_is_blank($str);
}else{
//If moodle is old
return wrsqz_deprecated_html_is_blank($str);
}
}