本文整理汇总了PHP中html_is_blank函数的典型用法代码示例。如果您正苦于以下问题:PHP html_is_blank函数的具体用法?PHP html_is_blank怎么用?PHP html_is_blank使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了html_is_blank函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:28,代码来源:edit_shortanswer_form.php
示例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;
}
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:57,代码来源:questiontype.php
示例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;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:52,代码来源:questiontype.php
示例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');
}
开发者ID:elnata,项目名称:moodle,代码行数:13,代码来源:renderer.php
示例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();
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:60,代码来源:lib.php
示例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;
}
}
开发者ID:veritech,项目名称:pare-project,代码行数:73,代码来源:questiontype.php
示例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');
}
}
开发者ID:nottmoo,项目名称:moodle,代码行数:38,代码来源:edit_numerical_form.php
示例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;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:34,代码来源:edit_numerical_form.php
示例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;
}
开发者ID:nigeli,项目名称:moodle,代码行数:30,代码来源:behaviourbase.php
示例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();
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:31,代码来源:view.php
示例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();
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:57,代码来源:lib.php
示例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;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:47,代码来源:edit_numerical_form.php
示例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;
}
开发者ID:ndunand,项目名称:moodle-qtype_ddimageortext,代码行数:18,代码来源:questionbase.php
示例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;
}
开发者ID:rezeau,项目名称:moodle-qtype_regexp,代码行数:70,代码来源:edit_regexp_form.php
示例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);
}
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:9,代码来源:functions.php
示例16: print_maintenance_message
/**
* Prints a maintenance message from $CFG->maintenance_message or default if empty.
*/
function print_maintenance_message()
{
global $CFG, $SITE, $PAGE, $OUTPUT;
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
header('Status: 503 Moodle under maintenance');
header('Retry-After: 300');
$PAGE->set_pagetype('maintenance-message');
$PAGE->set_pagelayout('maintenance');
$PAGE->set_title(strip_tags($SITE->fullname));
$PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('sitemaintenance', 'admin'));
if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
echo $OUTPUT->box_start('maintenance_message generalbox boxwidthwide boxaligncenter');
echo $CFG->maintenance_message;
echo $OUTPUT->box_end();
}
echo $OUTPUT->footer();
die;
}
开发者ID:gabrielrosset,项目名称:moodle,代码行数:23,代码来源:weblib.php
示例17: enable_cli_maintenance_mode
/**
* Enables CLI maintenance mode by creating new dataroot/climaintenance.html file.
*/
function enable_cli_maintenance_mode()
{
global $CFG;
if (file_exists("{$CFG->dataroot}/climaintenance.html")) {
unlink("{$CFG->dataroot}/climaintenance.html");
}
if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
$data = $CFG->maintenance_message;
$data = bootstrap_renderer::early_error_content($data, null, null, null);
$data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
} else {
if (file_exists("{$CFG->dataroot}/climaintenance.template.html")) {
$data = file_get_contents("{$CFG->dataroot}/climaintenance.template.html");
} else {
$data = get_string('sitemaintenance', 'admin');
$data = bootstrap_renderer::early_error_content($data, null, null, null);
$data = bootstrap_renderer::plain_page(get_string('sitemaintenance', 'admin'), $data);
}
}
file_put_contents("{$CFG->dataroot}/climaintenance.html", $data);
chmod("{$CFG->dataroot}/climaintenance.html", $CFG->filepermissions);
}
开发者ID:Alexbado,项目名称:moodle2,代码行数:25,代码来源:adminlib.php
示例18: save_hints
public function save_hints($formdata, $withparts = false) {
global $DB;
$context = $formdata->context;
$oldhints = $DB->get_records('question_hints',
array('questionid' => $formdata->id), 'id ASC');
$numhints = $this->count_hints_on_form($formdata, $withparts);
for ($i = 0; $i < $numhints; $i += 1) {
if (html_is_blank($formdata->hint[$i]['text'])) {
$formdata->hint[$i]['text'] = '';
}
if ($withparts) {
$clearwrong = !empty($formdata->hintclearwrong[$i]);
$shownumcorrect = !empty($formdata->hintshownumcorrect[$i]);
}
if ($this->is_hint_empty_in_form_data($formdata, $i, $withparts)) {
continue;
}
// Update an existing hint if possible.
$hint = array_shift($oldhints);
if (!$hint) {
$hint = new stdClass();
$hint->questionid = $formdata->id;
$hint->hint = '';
$hint->id = $DB->insert_record('question_hints', $hint);
}
$hint->hint = $this->import_or_save_files($formdata->hint[$i],
$context, 'question', 'hint', $hint->id);
$hint->hintformat = $formdata->hint[$i]['format'];
if ($withparts) {
$hint->clearwrong = $clearwrong;
$hint->shownumcorrect = $shownumcorrect;
}
$hint->options = $this->save_hint_options($formdata, $i, $withparts);
$DB->update_record('question_hints', $hint);
}
// Delete any remaining old hints.
$fs = get_file_storage();
foreach ($oldhints as $oldhint) {
$fs->delete_area_files($context->id, 'question', 'hint', $oldhint->id);
$DB->delete_records('question_hints', array('id' => $oldhint->id));
}
}
开发者ID:rwijaya,项目名称:moodle,代码行数:51,代码来源:questiontypebase.php
示例19: save_question_options
function save_question_options($question)
{
global $DB, $SESSION;
$result = new stdClass();
$context = $question->context;
$oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC');
$answers = array();
//$maxfraction = -1;
// Insert all the new answers
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);
// set grade for Answer 1 to 1 (100%)
if ($key === 0) {
$question->fraction[$key] = 1;
}
$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];
}*/
}
$question->answers = implode(',', $answers);
$parentresult = parent::save_question_options($question);
if ($parentresult !== null) {
// Parent function returns null if all is OK
return $parentresult;
}
// 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));
}
$this->save_hints($question);
// JR dec 2011 unset alternateanswers and alternatecorrectanswers after question has been edited, just in case
$qid = $question->id;
if (isset($SESSION->qtype_regexp_question->alternateanswers[$qid])) {
unset($SESSION->qtype_regexp_question->alternateanswers[$qid]);
}
if (isset($SESSION->qtype_regexp_question->alternatecorrectanswers[$qid])) {
unset($SESSION->qtype_regexp_question->alternatecorrectanswers[$qid]);
}
// Perform sanity checks on fractional grades
/* if ($maxfraction != 1) {
$result->noticeyesno = get_string('fractionsnomax', 'quiz', $maxfraction * 100);
return $result;
}*/
}
开发者ID:rezeau,项目名称:moodle-qtype_regexp,代码行数:64,代码来源:questiontype.php
示例20: role_get_description
/**
* Returns localised role description if available.
* If the name is empty it tries to find the default role name using
* hardcoded list of default role names or other methods in the future.
*
* @param stdClass $role
* @return string localised role name
*/
function role_get_description(stdClass $role) {
if (!html_is_blank($role->description)) {
return format_text($role->description, FORMAT_HTML, array('context'=>context_system::instance()));
}
switch ($role->shortname) {
case 'manager': return get_string('managerdescription', 'role');
case 'coursecreator': return get_string('coursecreatorsdescription');
case 'editingteacher': return get_string('defaultcourseteacherdescription');
case 'teacher': return get_string('noneditingteacherdescription');
case 'student': return get_string('defaultcoursestudentdescription');
case 'guest': return get_string('guestdescription');
case 'user': return get_string('authenticateduserdescription');
case 'frontpage': return get_string('frontpageuserdescription', 'role');
default: return '';
}
}
开发者ID:rwijaya,项目名称:moodle,代码行数:25,代码来源:accesslib.php
注:本文中的html_is_blank函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论