本文整理汇总了PHP中fullclone函数的典型用法代码示例。如果您正苦于以下问题:PHP fullclone函数的具体用法?PHP fullclone怎么用?PHP fullclone使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fullclone函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: definition
/**
* Form definition
*/
public function definition()
{
$data = fullclone($this->_customdata);
if (isset($data->id)) {
$data->tc = $data->id;
$data->action = 'colledit';
} else {
$data = new stdClass();
$data->action = 'colladd';
$data->isdefault = false;
}
$mform = $this->_form;
$mform->addElement('hidden', 'tc');
$mform->setType('tc', PARAM_INT);
$mform->addElement('hidden', 'action');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('text', 'name', get_string('name'));
$mform->setType('name', PARAM_NOTAGS);
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
if (empty($data->isdefault)) {
$mform->addRule('name', get_string('required'), 'required', null, 'client');
} else {
$mform->addElement('static', 'collnameexplained', '', get_string('collnameexplained', 'tag', get_string('defautltagcoll', 'tag')));
}
$mform->addElement('advcheckbox', 'searchable', get_string('searchable', 'tag'));
$mform->addHelpButton('searchable', 'searchable', 'tag');
$mform->setDefault('searchable', 1);
if (!empty($data->isdefault)) {
$mform->freeze('searchable');
}
$this->add_action_buttons();
$this->set_data($data);
}
开发者ID:rushi963,项目名称:moodle,代码行数:36,代码来源:collection_form.php
示例2: mediaplugin_filter
function mediaplugin_filter($courseid, $text)
{
global $CFG;
include 'defaultsettings.php';
// You should never modify parameters passed to a method or function, it's BAD practice. Create a copy instead.
// The reason is that you must always be able to refer to the original parameter that was passed.
// For this reason, I changed $text = preg_replace(..,..,$text) into $newtext = preg.... (NICOLAS CONNAULT)
// Thanks to Pablo Etcheverry for pointing this out! MDL-10177
// We're using the UFO technique for flash to attain XHTML Strict 1.0
// See: http://www.bobbyvandersluis.com/ufo/
$newtext = fullclone($text);
if ($CFG->filter_mediaplugin_enable_mp3) {
$search = '/<a.*?href="([^<]+\\.mp3)"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_swf) {
$search = '/<a.*?href="([^<]+\\.swf)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_flv) {
$search = '/<a.*?href="([^<]+\\.flv)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_mov) {
$search = '/<a.*?href="([^<]+\\.mov)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_wmv) {
$search = '/<a.*?href="([^<]+\\.wmv)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_mpg) {
$search = '/<a.*?href="([^<]+\\.mpe?g)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_avi) {
$search = '/<a.*?href="([^<]+\\.avi)(\\?d=([\\d]{1,3}%?)x([\\d]{1,3}%?))?"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_ram) {
$search = '/<a.*?href="([^<]+\\.ram)"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_rpm) {
$search = '/<a.*?href="([^<]+\\.rpm)"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
}
if ($CFG->filter_mediaplugin_enable_rm) {
$search = '/<a.*?href="([^<]+\\.rm)"[^>]*>.*?<\\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
}
if (is_null($newtext)) {
$newtext = $text;
}
return $newtext;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:56,代码来源:filter.php
示例3: filter
function filter($text, array $options = array())
{
if (!($courseid = get_courseid_from_context($this->context))) {
return $text;
}
// Initialise/invalidate our trivial cache if dealing with a different course
if (!isset(self::$cachedcourseid) || self::$cachedcourseid !== (int) $courseid) {
self::$activitylist = null;
}
self::$cachedcourseid = (int) $courseid;
/// It may be cached
if (is_null(self::$activitylist)) {
self::$activitylist = array();
$modinfo = get_fast_modinfo($courseid);
if (!empty($modinfo->cms)) {
self::$activitylist = array();
/// We will store all the activities here
//Sort modinfo by name length
$sortedactivities = fullclone($modinfo->cms);
usort($sortedactivities, 'filter_activitynames_comparemodulenamesbylength');
foreach ($sortedactivities as $cm) {
//Exclude labels, hidden activities and activities for group members only
if ($cm->visible and empty($cm->groupmembersonly) and $cm->has_view()) {
$title = s(trim(strip_tags($cm->name)));
$currentname = trim($cm->name);
$entitisedname = s($currentname);
/// Avoid empty or unlinkable activity names
if (!empty($title)) {
$href_tag_begin = html_writer::start_tag('a', array('class' => 'autolink', 'title' => $title, 'href' => $cm->get_url()));
self::$activitylist[$cm->id] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
if ($currentname != $entitisedname) {
/// If name has some entity (& " < >) add that filter too. MDL-17545
self::$activitylist[$cm->id . '-e'] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
}
}
}
}
}
}
$filterslist = array();
if (self::$activitylist) {
$cmid = $this->context->instanceid;
if ($this->context->contextlevel == CONTEXT_MODULE && isset(self::$activitylist[$cmid])) {
// remove filterobjects for the current module
$filterslist = array_diff_key(self::$activitylist, array($cmid => 1, $cmid . '-e' => 1));
} else {
$filterslist = self::$activitylist;
}
}
if ($filterslist) {
return $text = filter_phrases($text, $filterslist);
} else {
return $text;
}
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:55,代码来源:filter.php
示例4: reader_selector
/**
* Prints/return reader selector
*
* @param report_log_renderable $reportlog log report.
*/
public function reader_selector(report_log_renderable $reportlog) {
$readers = $reportlog->get_readers(true);
if (empty($readers)) {
$readers = array(get_string('nologreaderenabled', 'report_log'));
}
$url = fullclone ($reportlog->url);
$url->remove_params(array('logreader'));
$select = new single_select($url, 'logreader', $readers, $reportlog->selectedlogreader, null);
$select->set_label(get_string('selectlogreader', 'report_log'));
echo $this->output->render($select);
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:16,代码来源:renderer.php
示例5: unset
unset($itemdata->locked);
unset($itemdata->locktime);
$convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef', 'aggregationcoef2');
foreach ($convert as $param) {
if (property_exists($itemdata, $param)) {
$itemdata->{$param} = unformat_float($itemdata->{$param});
}
}
if (isset($itemdata->aggregationcoef2)) {
$itemdata->aggregationcoef2 = $itemdata->aggregationcoef2 / 100.0;
}
// When creating a new category, a number of grade item fields are filled out automatically, and are required.
// If the user leaves these fields empty during creation of a category, we let the default values take effect
// Otherwise, we let the user-entered grade item values take effect
$grade_item = $grade_category->load_grade_item();
$grade_item_copy = fullclone($grade_item);
grade_item::set_properties($grade_item, $itemdata);
if (empty($grade_item->id)) {
$grade_item->id = $grade_item_copy->id;
}
if (empty($grade_item->grademax) && $grade_item->grademax != '0') {
$grade_item->grademax = $grade_item_copy->grademax;
}
if (empty($grade_item->grademin) && $grade_item->grademin != '0') {
$grade_item->grademin = $grade_item_copy->grademin;
}
if (empty($grade_item->gradepass) && $grade_item->gradepass != '0') {
$grade_item->gradepass = $grade_item_copy->gradepass;
}
if (empty($grade_item->aggregationcoef) && $grade_item->aggregationcoef != '0') {
$grade_item->aggregationcoef = $grade_item_copy->aggregationcoef;
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:category.php
示例6: multichoice_comment_on_datasetitems
public function multichoice_comment_on_datasetitems($questionid, $questiontext,
$answers, $data, $number) {
global $DB;
$comment = new stdClass();
$comment->stranswers = array();
$comment->outsidelimit = false;
$comment->answers = array();
// Find a default unit:
if (!empty($questionid) && $unit = $DB->get_record('question_numerical_units',
array('question' => $questionid, 'multiplier' => 1.0))) {
$unit = $unit->unit;
} else {
$unit = '';
}
$answers = fullclone($answers);
$errors = '';
$delimiter = ': ';
foreach ($answers as $key => $answer) {
$answer->answer = $this->substitute_variables($answer->answer, $data);
//evaluate the equations i.e {=5+4)
$qtext = '';
$qtextremaining = $answer->answer;
while (preg_match('~\{=([^[:space:]}]*)}~', $qtextremaining, $regs1)) {
$qtextsplits = explode($regs1[0], $qtextremaining, 2);
$qtext = $qtext.$qtextsplits[0];
$qtextremaining = $qtextsplits[1];
if (empty($regs1[1])) {
$str = '';
} else {
if ($formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) {
$str = $formulaerrors;
} else {
eval('$str = '.$regs1[1].';');
$texteval= qtype_calculated_calculate_answer(
$str, $data, $answer->tolerance,
$answer->tolerancetype, $answer->correctanswerlength,
$answer->correctanswerformat, '');
$str = $texteval->answer;
}
}
$qtext = $qtext.$str;
}
$answer->answer = $qtext.$qtextremaining;;
$comment->stranswers[$key]= $answer->answer;
}
return fullclone($comment);
}
开发者ID:ncsu-delta,项目名称:moodle,代码行数:51,代码来源:questiontype.php
示例7: definition
function definition()
{
$mform =& $this->_form;
$strquestionlabel = $this->qtypeobj->comment_header($this->question);
if ($this->maxnumber != -1) {
$this->noofitems = $this->maxnumber;
} else {
$this->noofitems = 0;
}
//------------------------------------------------------------------------------------------------------------------------------
$mform->addElement('submit', 'updatedatasets', get_string('updatedatasetparam', 'qtype_datasetdependent'));
$mform->registerNoSubmitButton('updatedatasets');
$mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_datasetdependent'));
$idx = 1;
$j = $this->noofitems * count($this->datasetdefs) + 1;
foreach ($this->datasetdefs as $defkey => $datasetdef) {
$mform->addElement('text', "number[{$j}]", get_string('param', 'qtype_datasetdependent', $datasetdef->name));
$mform->setType("number[{$j}]", PARAM_NUMBER);
$this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
$idx++;
$mform->addElement('hidden', "definition[{$j}]");
$mform->addElement('hidden', "itemid[{$j}]");
$mform->addElement('static', "divider[{$j}]", '', '<hr />');
$j++;
}
$mform->addElement('header', 'updateanswershdr', get_string('answerstoleranceparam', 'qtype_datasetdependent'));
$mform->addElement('submit', 'updateanswers', get_string('updatetolerancesparam', 'qtype_datasetdependent'));
$mform->setAdvanced('updateanswers', true);
$mform->registerNoSubmitButton('updateanswers');
$answers = fullclone($this->question->options->answers);
$key1 = 1;
foreach ($answers as $key => $answer) {
if ('' === $answer->answer) {
} else {
if ('*' === $answer->answer) {
$mform->addElement('static', 'answercomment[' . ($this->noofitems + $key1) . ']', $answer->answer);
$mform->addElement('hidden', 'tolerance[' . $key . ']', '');
$mform->setAdvanced('tolerance[' . $key . ']', true);
$mform->addElement('hidden', 'tolerancetype[' . $key . ']', '');
$mform->setAdvanced('tolerancetype[' . $key . ']', true);
$mform->addElement('hidden', 'correctanswerlength[' . $key . ']', '');
$mform->setAdvanced('correctanswerlength[' . $key . ']', true);
$mform->addElement('hidden', 'correctanswerformat[' . $key . ']', '');
$mform->setAdvanced('correctanswerformat[' . $key . ']', true);
} else {
$mform->addElement('static', 'answercomment[' . ($this->noofitems + $key1) . ']', $answer->answer);
$mform->addElement('text', 'tolerance[' . $key . ']', get_string('tolerance', 'qtype_calculated'));
$mform->setAdvanced('tolerance[' . $key . ']', true);
$mform->addElement('select', 'tolerancetype[' . $key . ']', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types());
$mform->setAdvanced('tolerancetype[' . $key . ']', true);
$mform->addElement('select', 'correctanswerlength[' . $key . ']', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
$mform->setAdvanced('correctanswerlength[' . $key . ']', true);
$answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz'));
$mform->addElement('select', 'correctanswerformat[' . $key . ']', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
$mform->setAdvanced('correctanswerformat[' . $key . ']', true);
$mform->addElement('static', 'dividertolerance', '', '<hr />');
$mform->setAdvanced('dividertolerance', true);
}
}
$key1++;
}
$addremoveoptions = array();
$addremoveoptions['1'] = '1';
for ($i = 10; $i <= 100; $i += 10) {
$addremoveoptions["{$i}"] = "{$i}";
}
$mform->addElement('header', 'additemhdr', get_string('add', 'moodle'));
$mform->closeHeaderBefore('additemhdr');
if ($this->qtypeobj->supports_dataset_item_generation()) {
$radiogrp = array();
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('reuseifpossible', 'qtype_datasetdependent'), 0);
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('forceregeneration', 'qtype_datasetdependent'), 1);
$mform->addGroup($radiogrp, 'forceregenerationgrp', get_string('nextitemtoadd', 'qtype_calculated'), "<br/>", false);
}
$mform->addElement('submit', 'getnextbutton', get_string('getnextnow', 'qtype_datasetdependent'));
$mform->addElement('static', "dividera", '', '<hr />');
$addgrp = array();
$addgrp[] =& $mform->createElement('submit', 'addbutton', get_string('add', 'moodle'));
$addgrp[] =& $mform->createElement('select', "selectadd", get_string('additem', 'qtype_datasetdependent'), $addremoveoptions);
$addgrp[] =& $mform->createElement('static', "stat", "Items", get_string('item(s)', 'qtype_datasetdependent'));
$mform->addGroup($addgrp, 'addgrp', '', ' ', false);
$mform->addElement('static', "divideradd", '', '');
// $mform->closeHeaderBefore('divideradd');
if ($this->noofitems > 0) {
$mform->addElement('header', 'additemhdr', get_string('delete', 'moodle'));
$deletegrp = array();
$deletegrp[] =& $mform->createElement('submit', 'deletebutton', get_string('delete', 'moodle'));
$deletegrp[] =& $mform->createElement('select', "selectdelete", get_string('deleteitem', 'qtype_datasetdependent') . "1", $addremoveoptions);
$deletegrp[] =& $mform->createElement('static', "stat", "Items", get_string('lastitem(s)', 'qtype_datasetdependent'));
$mform->addGroup($deletegrp, 'deletegrp', '', ' ', false);
// $mform->addElement('static', "dividerdelete", '', '<hr />');
// $mform->closeHeaderBefore('dividerdelete');
} else {
$mform->addElement('static', 'warning', '', '<span class="error">' . get_string('youmustaddatleastoneitem', 'qtype_datasetdependent') . '</span>');
}
//------------------------------------------------------------------------------------------------------------------------------
$j = $this->noofitems * count($this->datasetdefs);
for ($i = $this->noofitems; $i >= 1; $i--) {
$mform->addElement('header', '', get_string('itemno', 'qtype_datasetdependent', $i));
foreach ($this->datasetdefs as $defkey => $datasetdef) {
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:datasetitems_form.php
示例8: require_logout
/**
* This function just makes sure a user is logged out.
*
* @package core_access
* @category access
*/
function require_logout()
{
global $USER, $DB;
if (!isloggedin()) {
// This should not happen often, no need for hooks or events here.
\core\session\manager::terminate_current();
return;
}
// Execute hooks before action.
$authplugins = array();
$authsequence = get_enabled_auth_plugins();
foreach ($authsequence as $authname) {
$authplugins[$authname] = get_auth_plugin($authname);
$authplugins[$authname]->prelogout_hook();
}
// Store info that gets removed during logout.
$sid = session_id();
$event = \core\event\user_loggedout::create(array('userid' => $USER->id, 'objectid' => $USER->id, 'other' => array('sessionid' => $sid)));
if ($session = $DB->get_record('sessions', array('sid' => $sid))) {
$event->add_record_snapshot('sessions', $session);
}
// Clone of $USER object to be used by auth plugins.
$user = fullclone($USER);
// Delete session record and drop $_SESSION content.
\core\session\manager::terminate_current();
// Trigger event AFTER action.
$event->trigger();
// Hook to execute auth plugins redirection after event trigger.
foreach ($authplugins as $authplugin) {
$authplugin->postlogout_hook($user);
}
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:38,代码来源:moodlelib.php
示例9: create_course
/**
* Will create the moodle course from the template
* course_ext is an array as obtained from ldap -- flattened somewhat
*
* @param array $course_ext
* @param progress_trace $trace
* @return mixed false on error, id for the newly created course otherwise.
*/
function create_course($course_ext, progress_trace $trace)
{
global $CFG, $DB;
require_once "{$CFG->dirroot}/course/lib.php";
// Override defaults with template course
$template = false;
if ($this->get_config('template')) {
if ($template = $DB->get_record('course', array('shortname' => $this->get_config('template')))) {
$template = fullclone(course_get_format($template)->get_course());
unset($template->id);
// So we are clear to reinsert the record
unset($template->fullname);
unset($template->shortname);
unset($template->idnumber);
}
}
if (!$template) {
$courseconfig = get_config('moodlecourse');
$template = new stdClass();
$template->summary = '';
$template->summaryformat = FORMAT_HTML;
$template->format = $courseconfig->format;
$template->newsitems = $courseconfig->newsitems;
$template->showgrades = $courseconfig->showgrades;
$template->showreports = $courseconfig->showreports;
$template->maxbytes = $courseconfig->maxbytes;
$template->groupmode = $courseconfig->groupmode;
$template->groupmodeforce = $courseconfig->groupmodeforce;
$template->visible = $courseconfig->visible;
$template->lang = $courseconfig->lang;
$template->enablecompletion = $courseconfig->enablecompletion;
}
$course = $template;
$course->category = $this->get_config('category');
if (!$DB->record_exists('course_categories', array('id' => $this->get_config('category')))) {
$categories = $DB->get_records('course_categories', array(), 'sortorder', 'id', 0, 1);
$first = reset($categories);
$course->category = $first->id;
}
// Override with required ext data
$course->idnumber = $course_ext[$this->get_config('course_idnumber')][0];
$course->fullname = $course_ext[$this->get_config('course_fullname')][0];
$course->shortname = $course_ext[$this->get_config('course_shortname')][0];
if (empty($course->idnumber) || empty($course->fullname) || empty($course->shortname)) {
// We are in trouble!
$trace->output(get_string('cannotcreatecourse', 'enrol_ldap') . ' ' . var_export($course, true));
return false;
}
$summary = $this->get_config('course_summary');
if (!isset($summary) || empty($course_ext[$summary][0])) {
$course->summary = '';
} else {
$course->summary = $course_ext[$this->get_config('course_summary')][0];
}
// Check if the shortname already exists if it does - skip course creation.
if ($DB->record_exists('course', array('shortname' => $course->shortname))) {
$trace->output(get_string('duplicateshortname', 'enrol_ldap', $course));
return false;
}
$newcourse = create_course($course);
return $newcourse->id;
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:70,代码来源:lib.php
示例10: generate_courses
public function generate_courses()
{
global $DB;
$this->verbose("Generating " . $this->get('number_of_courses') . " courses...");
$base_course = new stdClass();
$next_course_id = $DB->get_field_sql("SELECT MAX(id) FROM {course}") + 1;
$base_course->MAX_FILE_SIZE = '2097152';
$base_course->category = '1';
$base_course->summary = 'Blah Blah';
$base_course->format = 'weeks';
$base_course->numsections = '10';
$base_course->startdate = mktime();
$base_course->id = '0';
$courses_count = 0;
$courses = array();
for ($i = 1; $i <= $this->get('number_of_courses'); $i++) {
$newcourse = fullclone($base_course);
$newcourse->fullname = "Test course {$next_course_id}";
$newcourse->shortname = "Test {$next_course_id}";
$newcourse->idnumber = $next_course_id;
if (!($course = create_course($newcourse))) {
$this->verbose("Error inserting a new course in the database!");
if (!$this->get('ignore_errors')) {
die;
}
} else {
$courses_count++;
$next_course_id++;
$courses[] = $course->id;
$next_course_id = $course->id + 1;
$this->verbose("Inserted {$course->fullname} into DB (idnumber={$course->idnumber}).");
}
}
if (!$this->get('quiet')) {
echo "{$courses_count} test courses correctly inserted into the database.{$this->eolchar}";
}
return $courses;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:38,代码来源:generator.php
示例11: validation
function validation($data, $files)
{
$errors = parent::validation($data, $files);
if (isset($this->questiondisplay->options->questions)) {
$subquestions = fullclone($this->questiondisplay->options->questions);
if (count($subquestions)) {
$sub = 1;
foreach ($subquestions as $subquestion) {
$prefix = 'sub_' . $sub . '_';
$answercount = 0;
$maxgrade = false;
$maxfraction = -1;
foreach ($subquestion->answer as $key => $answer) {
$trimmedanswer = trim($answer);
if ($trimmedanswer !== '') {
$answercount++;
if ($subquestion->qtype == 'numerical' && !(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
$errors[$prefix . 'answer[' . $key . ']'] = get_string('answermustbenumberorstar', 'qtype_numerical');
}
if ($subquestion->fraction[$key] == 1) {
$maxgrade = true;
}
if ($subquestion->fraction[$key] > $maxfraction) {
$maxfraction = $subquestion->fraction[$key];
}
}
}
if ($answercount == 0) {
if ($subquestion->qtype == 'multichoice') {
$errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
} else {
$errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'quiz', 1);
}
}
if ($maxgrade == false) {
$errors[$prefix . 'fraction[0]'] = get_string('fractionsnomax', 'question');
}
$sub++;
}
} else {
$errors['questiontext'] = get_string('questionsmissing', 'qtype_multianswer');
}
}
return $errors;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:45,代码来源:edit_multianswer_form.php
示例12: definition
protected function definition()
{
global $PAGE;
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
$mform = $this->_form;
$mform->setDisableShortforms();
$strquestionlabel = $this->qtypeobj->comment_header($this->question);
if ($this->maxnumber != -1) {
$this->noofitems = $this->maxnumber;
} else {
$this->noofitems = 0;
}
$label = get_string("sharedwildcards", "qtype_calculated");
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared($this->question, $this->datasetdefs);
$mform->addElement('static', 'listcategory', $label, $html2);
// ...----------------------------------------------------------------------.
$mform->addElement('submit', 'updatedatasets', get_string('updatedatasetparam', 'qtype_calculated'));
$mform->registerNoSubmitButton('updatedatasets');
$mform->addElement('header', 'additemhdr', get_string('itemtoadd', 'qtype_calculated'));
$idx = 1;
$data = array();
$j = $this->noofitems * count($this->datasetdefs) + 1;
foreach ($this->datasetdefs as $defkey => $datasetdef) {
if ($datasetdef->category |= 0) {
$name = get_string('sharedwildcard', 'qtype_calculated', $datasetdef->name);
} else {
$name = get_string('wildcard', 'qtype_calculated', $datasetdef->name);
}
$mform->addElement('text', "number[{$j}]", $name);
$mform->setType("number[{$j}]", PARAM_RAW);
// This parameter will be validated in validation().
$this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
$idx++;
$mform->addElement('hidden', "definition[{$j}]");
$mform->setType("definition[{$j}]", PARAM_RAW);
$mform->addElement('hidden', "itemid[{$j}]");
$mform->setType("itemid[{$j}]", PARAM_RAW);
$mform->addElement('static', "divider[{$j}]", '', '<hr />');
$mform->setType("divider[{$j}]", PARAM_RAW);
$j++;
}
$mform->addElement('header', 'updateanswershdr', get_string('answerstoleranceparam', 'qtype_calculated'));
$mform->addElement('submit', 'updateanswers', get_string('updatetolerancesparam', 'qtype_calculated'));
$mform->setAdvanced('updateanswers', true);
$mform->registerNoSubmitButton('updateanswers');
$answers = fullclone($this->question->options->answers);
$key1 = 1;
foreach ($answers as $key => $answer) {
$ans = shorten_text($answer->answer, 17, true);
if ($ans === '*') {
$mform->addElement('static', 'answercomment[' . ($this->noofitems + $key1) . ']', $ans);
$mform->addElement('hidden', 'tolerance[' . $key . ']', '');
$mform->setType('tolerance[' . $key . ']', PARAM_RAW);
$mform->setAdvanced('tolerance[' . $key . ']', true);
$mform->addElement('hidden', 'tolerancetype[' . $key . ']', '');
$mform->setType('tolerancetype[' . $key . ']', PARAM_RAW);
$mform->setAdvanced('tolerancetype[' . $key . ']', true);
$mform->addElement('hidden', 'correctanswerlength[' . $key . ']', '');
$mform->setType('correctanswerlength[' . $key . ']', PARAM_RAW);
$mform->setAdvanced('correctanswerlength[' . $key . ']', true);
$mform->addElement('hidden', 'correctanswerformat[' . $key . ']', '');
$mform->setType('correctanswerformat[' . $key . ']', PARAM_RAW);
$mform->setAdvanced('correctanswerformat[' . $key . ']', true);
} else {
if ($ans !== '') {
$mform->addElement('static', 'answercomment[' . ($this->noofitems + $key1) . ']', $ans);
$mform->addElement('text', 'tolerance[' . $key . ']', get_string('tolerance', 'qtype_calculated'));
$mform->setType('tolerance[' . $key . ']', PARAM_RAW);
$mform->setAdvanced('tolerance[' . $key . ']', true);
$mform->addElement('select', 'tolerancetype[' . $key . ']', get_string('tolerancetype', 'qtype_numerical'), $this->qtypeobj->tolerance_types());
$mform->setAdvanced('tolerancetype[' . $key . ']', true);
$mform->addElement('select', 'correctanswerlength[' . $key . ']', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
$mform->setAdvanced('correctanswerlength[' . $key . ']', true);
$answerlengthformats = array('1' => get_string('decimalformat', 'qtype_numerical'), '2' => get_string('significantfiguresformat', 'qtype_calculated'));
$mform->addElement('select', 'correctanswerformat[' . $key . ']', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
$mform->setAdvanced('correctanswerformat[' . $key . ']', true);
$mform->addElement('static', 'dividertolerance', '', '<hr />');
$mform->setAdvanced('dividertolerance', true);
}
}
$key1++;
}
$addremoveoptions = array();
$addremoveoptions['1'] = '1';
for ($i = 10; $i <= 100; $i += 10) {
$addremoveoptions["{$i}"] = "{$i}";
}
$showoptions = array();
$showoptions['1'] = '1';
$showoptions['2'] = '2';
$showoptions['5'] = '5';
for ($i = 10; $i <= 100; $i += 10) {
$showoptions["{$i}"] = "{$i}";
}
$mform->addElement('header', 'addhdr', get_string('add', 'moodle'));
$mform->closeHeaderBefore('addhdr');
if ($this->qtypeobj->supports_dataset_item_generation()) {
$radiogrp = array();
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('reuseifpossible', 'qtype_calculated'), 0);
$radiogrp[] =& $mform->createElement('radio', 'nextpageparam[forceregeneration]', null, get_string('forceregenerationshared', 'qtype_calculated'), 1);
//.........这里部分代码省略.........
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:101,代码来源:datasetitems_form.php
示例13: comment_on_datasetitems
function comment_on_datasetitems($questionid, $answers, $data, $number)
{
global $DB;
$comment = new stdClass();
$comment->stranswers = array();
$comment->outsidelimit = false;
$comment->answers = array();
/// Find a default unit:
if (!empty($questionid) && ($unit = $DB->get_record('question_numerical_units', array('question' => $questionid, 'multiplier' => 1.0)))) {
$unit = $unit->unit;
} else {
$unit = '';
}
$answers = fullclone($answers);
$strmin = get_string('min', 'quiz');
$strmax = get_string('max', 'quiz');
$errors = '';
$delimiter = ': ';
$virtualqtype = $this->get_virtual_qtype();
foreach ($answers as $key => $answer) {
$formula = $this->substitute_variables($answer->answer, $data);
$formattedanswer = qtype_calculated_calculate_answer($answer->answer, $data, $answer->tolerance, $answer->tolerancetype, $answer->correctanswerlength, $answer->correctanswerformat, $unit);
if ($formula === '*') {
$answer->min = ' ';
$formattedanswer->answer = $answer->answer;
} else {
eval('$answer->answer = ' . $formula . ';');
$virtualqtype->get_tolerance_interval($answer);
}
if ($answer->min === '') {
// This should mean that something is wrong
$comment->stranswers[$key] = " {$formattedanswer->answer}" . '<br/><br/>';
} else {
if ($formula === '*') {
$comment->stranswers[$key] = $formula . ' = ' . get_string('anyvalue', 'qtype_calculated') . '<br/><br/><br/>';
} else {
$comment->stranswers[$key] = $formula . ' = ' . $formattedanswer->answer . '<br/>';
$comment->stranswers[$key] .= $strmin . $delimiter . $answer->min . '---';
$comment->stranswers[$key] .= $strmax . $delimiter . $answer->max;
$comment->stranswers[$key] .= '<br/>';
$correcttrue->correct = $formattedanswer->answer;
$correcttrue->true = $answer->answer;
if ($formattedanswer->answer < $answer->min || $formattedanswer->answer > $answer->max) {
$comment->outsidelimit = true;
$comment->answers[$key] = $key;
$comment->stranswers[$key] .= get_string('trueansweroutsidelimits', 'qtype_calculated', $correcttrue);
//<span class="error">ERROR True answer '..' outside limits</span>';
} else {
$comment->stranswers[$key] .= get_string('trueanswerinsidelimits', 'qtype_calculated', $correcttrue);
//' True answer :'.$calculated->trueanswer.' inside limits';
}
$comment->stranswers[$key] .= '';
}
}
}
return fullclone($comment);
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:57,代码来源:questiontype.php
示例14: definition
protected function definition() {
$labelsharedwildcard = get_string("sharedwildcard", "qtype_calculated");
$mform =& $this->_form;
$strquestionlabel = $this->qtypeobj->comment_header($this->question);
if ($this->maxnumber != -1 ) {
$this->noofitems = $this->maxnumber;
} else {
$this->noofitems = 0;
}
$label = get_string("sharedwildcards", "qtype_calculated");
$html2 = $this->qtypeobj->print_dataset_definitions_category_shared(
$this->question, $this->datasetdefs);
$mform->addElement('static', 'listcategory', $label, $html2);
//----------------------------------------------------------------------
$mform->addElement('submit', 'updatedatasets',
get_string('updatedatasetparam', 'qtype_calculated'));
$mform->registerNoSubmitButton('updatedatasets');
$mform->addElement('header', 'additemhdr',
get_string('itemtoadd', 'qtype_calculated'));
$idx = 1;
$data = array();
$j = (($this->noofitems) * count($this->datasetdefs))+1;
foreach ($this->datasetdefs as $defkey => $datasetdef) {
if ($datasetdef->category |= 0 ) {
$name = get_string('sharedwildcard', 'qtype_calculated', $datasetdef->name);
} else {
$name = get_string('wildcard', 'qtype_calculated', $datasetdef->name);
}
$mform->addElement('text', "number[$j]", $name);
$mform->setType("number[$j]", PARAM_NUMBER);
$this->qtypeobj->custom_generator_tools_part($mform, $idx, $j);
$idx++;
$mform->addElement('hidden', "definition[$j]");
$mform->setType("definition[$j]", PARAM_RAW);
$mform->addElement('hidden', "itemid[$j]");
$mform->setType("itemid[$j]", PARAM_RAW);
$mform->addElement('static', "divider[$j]", '', '<hr />');
$mform->setType("divider[$j]", PARAM_RAW);
$j++;
}
$mform->addElement('header', 'updateanswershdr',
get_string('answerstoleranceparam', 'qtype_calculated'));
$mform->addElement('submit', 'updateanswers',
get_string('updatetolerancesparam', 'qtype_calculated'));
$mform->setAdvanced('updateanswers', true);
$mform->registerNoSubmitButton('updateanswers');
$answers = fullclone($this->question->options->answers);
$key1 =1;
foreach ($answers as $key => $answer) {
if ('' === $answer->answer) {
// Do nothing.
} else if ('*' === $answer->answer) {
$mform->addElement('static',
'answercomment[' . ($this->noofitems+$key1) . ']', $answer->answer);
$mform->addElement('hidden', 'tolerance['.$key.']', '');
$mform->setType('tolerance['.$key.']', PARAM_RAW);
$mform->setAdvanced('tolerance['.$key.']', true);
$mform->addElement('hidden', 'tolerancetype['.$key.']', '');
$mform->setType('tolerancetype['.$key.']', PARAM_RAW);
$mform->setAdvanced('tolerancetype['.$key.']', true);
$mform->addElement('hidden', 'correctanswerlength['.$key.']', '');
$mform->setType('correctanswerlength['.$key.']', PARAM_RAW);
$mform->setAdvanced('correctanswerlength['.$key.']', true);
$mform->addElement('hidden', 'correctanswerformat['.$key.']', '');
$mform->setType('correctanswerformat['.$key.']', PARAM_RAW);
$mform->setAdvanced('correctanswerformat['.$key.']', true);
} else {
$mform->addElement('static', 'answercomment[' . ($this->noofitems+$key1) . ']',
$answer->answer);
$mform->addElement('text', 'tolerance['.$key.']',
get_string('tolerance', 'qtype_calculated'));
$mform->setAdvanced('tolerance['.$key.']', true);
$mform->addElement('select', 'tolerancetype['.$key.']',
get_string('tolerancetype', 'qtype_numerical'),
$this->qtypeobj->tolerance_types());
$mform->setAdvanced('tolerancetype['.$key.']', true);
$mform->addElement('select', 'correctanswerlength['.$key.']',
get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
$mform->setAdvanced('correctanswerlength['.$key.']', true);
$answerlengthformats = array(
'1' => get_string('decimalformat', 'qtype_numerical'),
'2' => get_string('significantfiguresformat', 'qtype_calculated')
);
$mform->addElement('select', 'correctanswerformat['.$key.']',
get_string('correctanswershowsformat', 'qtype_calculated'),
$answerlengthformats);
$mform->setAdvanced('correctanswerformat['.$key.']', true);
$mform->addElement('static', 'dividertolerance', '', '<hr />');
$mform->setAdvanced('dividertolerance', true);
}
$key1++;
}
$addremoveoptions = array();
//.........这里部分代码省略.........
开发者ID:nigeldaley,项目名称:moodle,代码行数:101,代码来源:datasetitems_form.php
|
请发表评论