本文整理汇总了PHP中make_unique_id_code函数的典型用法代码示例。如果您正苦于以下问题:PHP make_unique_id_code函数的具体用法?PHP make_unique_id_code怎么用?PHP make_unique_id_code使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_unique_id_code函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_test_question_data
/**
* @return object the data to construct a question like
* {@link qtype_gapselect_test_helper::make_a_gapselect_question()}.
*/
protected function get_test_question_data()
{
global $USER;
$gapselect = new stdClass();
$gapselect->id = 0;
$gapselect->category = 0;
$gapselect->contextid = 0;
$gapselect->parent = 0;
$gapselect->questiontextformat = FORMAT_HTML;
$gapselect->generalfeedbackformat = FORMAT_HTML;
$gapselect->defaultmark = 1;
$gapselect->penalty = 0.3333333;
$gapselect->length = 1;
$gapselect->stamp = make_unique_id_code();
$gapselect->version = make_unique_id_code();
$gapselect->hidden = 0;
$gapselect->timecreated = time();
$gapselect->timemodified = time();
$gapselect->createdby = $USER->id;
$gapselect->modifiedby = $USER->id;
$gapselect->name = 'Selection from drop down list question';
$gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
$gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
$gapselect->qtype = 'gapselect';
$gapselect->options = new stdClass();
$gapselect->options->shuffleanswers = true;
test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
$gapselect->options->answers = array((object) array('answer' => 'quick', 'feedback' => '1'), (object) array('answer' => 'fox', 'feedback' => '2'), (object) array('answer' => 'lazy', 'feedback' => '3'), (object) array('answer' => 'assiduous', 'feedback' => '3'), (object) array('answer' => 'dog', 'feedback' => '2'), (object) array('answer' => 'slow', 'feedback' => '1'));
return $gapselect;
}
示例2: get_unknown_questiondata
protected function get_unknown_questiondata()
{
$questiondata = new stdClass();
$questiondata->id = 0;
$questiondata->category = 0;
$questiondata->contextid = 0;
$questiondata->parent = 0;
$questiondata->name = 'Test';
$questiondata->questiontext = 'This is the question text.';
$questiondata->questiontextformat = FORMAT_HTML;
$questiondata->generalfeedback = 'This is the general feedback.';
$questiondata->generalfeedbackformat = FORMAT_HTML;
$questiondata->defaultmark = 1;
$questiondata->penalty = 0.3333333;
$questiondata->qtype = 'strange_unknown';
$questiondata->length = 1;
$questiondata->stamp = make_unique_id_code();
$questiondata->version = make_unique_id_code();
$questiondata->hidden = 0;
$questiondata->timecreated = 0;
$questiondata->timemodified = 0;
$questiondata->createdby = 0;
$questiondata->modifiedby = 0;
return $questiondata;
}
示例3: get_linkerdesc_question_data_info
/**
* Get the question data, as it would be loaded by get_question_options.
* @return object
*/
public static function get_linkerdesc_question_data_info()
{
global $USER;
$qdata = new stdClass();
$qdata->id = 0;
$qdata->contextid = 0;
$qdata->category = 0;
$qdata->parent = 0;
$qdata->stamp = make_unique_id_code();
$qdata->version = make_unique_id_code();
$qdata->timecreated = time();
$qdata->timemodified = time();
$qdata->createdby = $USER->id;
$qdata->modifiedby = $USER->id;
$qdata->qtype = 'linkerdesc';
$qdata->name = 'Description';
$qdata->questiontext = 'Here is some information about the questions you are about to attempt.';
$qdata->questiontextformat = FORMAT_HTML;
$qdata->generalfeedback = 'And here is some more text shown only on the review page.';
$qdata->generalfeedbackformat = FORMAT_HTML;
$qdata->defaultmark = 0;
$qdata->length = 0;
$qdata->penalty = 0;
$qdata->hidden = 0;
$qdata->hints = array();
$qdata->options = new stdClass();
$qdata->options->answers = array();
return $qdata;
}
示例4: get_test_question_data
/**
* @return object the data to construct a question like
* {@link qtype_ddwtos_test_helper::make_ddwtos_question_fox()}.
*/
protected function get_test_question_data()
{
global $USER;
$dd = new stdClass();
$dd->id = 0;
$dd->category = 0;
$dd->contextid = 0;
$dd->parent = 0;
$dd->questiontextformat = FORMAT_HTML;
$dd->generalfeedbackformat = FORMAT_HTML;
$dd->defaultmark = 1;
$dd->penalty = 0.3333333;
$dd->length = 1;
$dd->stamp = make_unique_id_code();
$dd->version = make_unique_id_code();
$dd->hidden = 0;
$dd->timecreated = time();
$dd->timemodified = time();
$dd->createdby = $USER->id;
$dd->modifiedby = $USER->id;
$dd->name = 'Drag-and-drop words into sentences question';
$dd->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
$dd->generalfeedback = 'This sentence uses each letter of the alphabet.';
$dd->qtype = 'ddwtos';
$dd->options = new stdClass();
$dd->options->shuffleanswers = true;
test_question_maker::set_standard_combined_feedback_fields($dd->options);
$dd->options->answers = array((object) array('answer' => 'quick', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'), (object) array('answer' => 'fox', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'), (object) array('answer' => 'lazy', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'), (object) array('answer' => 'assiduous', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'), (object) array('answer' => 'dog', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'), (object) array('answer' => 'slow', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'));
return $dd;
}
示例5: get_test_question_data
protected function get_test_question_data()
{
global $USER;
$q = new stdClass();
$q->id = 0;
$q->name = 'Gapfill Question';
$q->category = 0;
$q->contextid = 0;
$q->parent = 0;
$q->questiontext = 'The [cat] sat on the [mat]';
$q->questiontextformat = FORMAT_HTML;
$q->generalfeedback = 'General feedback.';
$q->generalfeedbackformat = FORMAT_HTML;
$q->defaultmark = 1;
$q->penalty = 0.3333333;
$q->length = 1;
$q->stamp = make_unique_id_code();
$q->version = make_unique_id_code();
$q->hidden = 0;
$q->timecreated = time();
$q->timemodified = time();
$q->createdby = $USER->id;
$q->modifiedby = $USER->id;
$q->options = new stdClass();
test_question_maker::set_standard_combined_feedback_fields($q->options);
$q->options->displayanswers = 0;
$q->options->delimitchars = "[]";
return $q;
}
示例6: get_test_question_data
protected function get_test_question_data()
{
global $USER;
$q = new stdClass();
$q->id = 0;
$q->name = 'Drag and drop matching question';
$q->category = 0;
$q->contextid = 0;
$q->parent = 0;
$q->questiontext = 'Classify the animals.';
$q->questiontextformat = FORMAT_HTML;
$q->generalfeedback = 'General feedback.';
$q->generalfeedbackformat = FORMAT_HTML;
$q->defaultmark = 1;
$q->penalty = 0.3333333;
$q->length = 1;
$q->stamp = make_unique_id_code();
$q->version = make_unique_id_code();
$q->hidden = 0;
$q->timecreated = time();
$q->timemodified = time();
$q->createdby = $USER->id;
$q->modifiedby = $USER->id;
$q->options = new stdClass();
$q->options->shuffleanswers = false;
test_question_maker::set_standard_combined_feedback_fields($q->options);
$q->options->subquestions = array(14 => (object) array('id' => 14, 'questiontext' => 'frog', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'amphibian', 'answertextformat' => FORMAT_HTML), 15 => (object) array('id' => 15, 'questiontext' => 'cat', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'mammal', 'answertextformat' => FORMAT_HTML), 16 => (object) array('id' => 16, 'questiontext' => 'newt', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'amphibian', 'answertextformat' => FORMAT_HTML), 17 => (object) array('id' => 17, 'questiontext' => '', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'insect', 'answertextformat' => FORMAT_HTML));
return $q;
}
示例7: create_question_category
/**
* Create a new question category.
* @param array|stdClass $record
* @return stdClass question_categories record.
*/
public function create_question_category($record = null)
{
global $DB;
$this->categorycount++;
$defaults = array('name' => 'Test question category ' . $this->categorycount, 'contextid' => context_system::instance()->id, 'info' => '', 'infoformat' => FORMAT_HTML, 'stamp' => make_unique_id_code(), 'parent' => 0, 'sortorder' => 999);
$record = $this->datagenerator->combine_defaults_and_record($defaults, $record);
$record['id'] = $DB->insert_record('question_categories', $record);
return (object) $record;
}
示例8: get_test_question_data
protected function get_test_question_data() {
global $USER;
$q = new stdClass();
$q->id = 0;
$q->name = 'Simple multianswer';
$q->category = 0;
$q->contextid = 0;
$q->parent = 0;
$q->questiontext =
'Complete this opening line of verse: "The {#1} and the {#2} went to sea".';
$q->questiontextformat = FORMAT_HTML;
$q->generalfeedback = 'Generalfeedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' .
'"The owl and the pussycat went to see';
$q->generalfeedbackformat = FORMAT_HTML;
$q->defaultmark = 2;
$q->penalty = 0.3333333;
$q->length = 1;
$q->stamp = make_unique_id_code();
$q->version = make_unique_id_code();
$q->hidden = 0;
$q->timecreated = time();
$q->timemodified = time();
$q->createdby = $USER->id;
$q->modifiedby = $USER->id;
$sadata = new stdClass();
$sadata->id = 1;
$sadata->qtype = 'shortanswer';
$sadata->defaultmark = 1;
$sadata->options->usecase = true;
$sadata->options->answers[1] = (object) array('answer' => 'Bow-wow', 'fraction' => 0);
$sadata->options->answers[2] = (object) array('answer' => 'Wiggly worm', 'fraction' => 0);
$sadata->options->answers[3] = (object) array('answer' => 'Pussy-cat', 'fraction' => 1);
$mcdata = new stdClass();
$mcdata->id = 1;
$mcdata->qtype = 'multichoice';
$mcdata->defaultmark = 1;
$mcdata->options->single = true;
$mcdata->options->answers[1] = (object) array('answer' => 'Dog', 'fraction' => 0);
$mcdata->options->answers[2] = (object) array('answer' => 'Owl', 'fraction' => 1);
$mcdata->options->answers[3] = (object) array('answer' => '*', 'fraction' => 0);
$q->options->questions = array(
1 => $sadata,
2 => $mcdata,
);
return $q;
}
示例9: make_test_question
public function make_test_question() {
global $USER;
$q = new stdClass();
$q->id = 0;
$q->contextid = 0;
$q->category = 0;
$q->parent = 0;
$q->questiontextformat = FORMAT_HTML;
$q->generalfeedbackformat = FORMAT_HTML;
$q->defaultmark = 1;
$q->penalty = 0.3333333;
$q->length = 1;
$q->stamp = make_unique_id_code();
$q->version = make_unique_id_code();
$q->hidden = 0;
$q->timecreated = time();
$q->timemodified = time();
$q->createdby = $USER->id;
$q->modifiedby = $USER->id;
return $q;
}
示例10: get_default_question_category
/**
* Gets the default category in a course
*
* It returns the first category with no parent category. If no categories
* exist yet then one is created.
* @return object The default category
* @param integer $courseid The id of the course whose default category is wanted
*/
function get_default_question_category($courseid)
{
// If it already exists, just return it.
if ($category = get_records_select("question_categories", "course = '{$courseid}' AND parent = '0'", 'id', '*', '', 1)) {
return reset($category);
}
// Otherwise, we need to make one
$category = new stdClass();
$category->name = get_string("default", "quiz");
$category->info = get_string("defaultinfo", "quiz");
$category->course = $courseid;
$category->parent = 0;
$category->sortorder = 999;
// By default, all categories get this number, and are sorted alphabetically.
$category->publish = 0;
$category->stamp = make_unique_id_code();
if (!($category->id = insert_record("question_categories", $category))) {
notify("Error creating a default category!");
return false;
}
return $category;
}
示例11: question_make_default_categories
/**
* Gets the default category in the most specific context.
* If no categories exist yet then default ones are created in all contexts.
*
* @param array $contexts The context objects for this context and all parent contexts.
* @return object The default category - the category in the course context
*/
function question_make_default_categories($contexts)
{
$toreturn = null;
// If it already exists, just return it.
foreach ($contexts as $key => $context) {
if (!($categoryrs = get_recordset_select("question_categories", "contextid = '{$context->id}'", 'sortorder, name', '*', '', 1))) {
error('error getting category record');
} else {
if (!($category = rs_fetch_record($categoryrs))) {
// Otherwise, we need to make one
$category = new stdClass();
$contextname = print_context_name($context, false, true);
$category->name = addslashes(get_string('defaultfor', 'question', $contextname));
$category->info = addslashes(get_string('defaultinfofor', 'question', $contextname));
$category->contextid = $context->id;
$category->parent = 0;
$category->sortorder = 999;
// By default, all categories get this number, and are sorted alphabetically.
$category->stamp = make_unique_id_code();
if (!($category->id = insert_record('question_categories', $category))) {
error('Error creating a default category for context ' . print_context_name($context));
}
}
}
if ($context->contextlevel == CONTEXT_COURSE) {
$toreturn = clone $category;
}
}
return $toreturn;
}
示例12: addRandomQuizQuestions
function addRandomQuizQuestions($cmid, $cat_id)
{
global $QTYPES;
$result = true;
$recurse = 1;
list($quiz, $cm) = get_module_from_cmid($cmid);
if ($rs = get_records('question_categories', 'parent', $cat_id, 'sortorder')) {
$course = get_record('course', 'id', $quiz->course);
foreach ($rs as $cat) {
$categoryid = $cat->id;
$randomcount = 1;
// load category
if (!($category = get_record('question_categories', 'id', $categoryid))) {
error('Category ID is incorrect');
}
$catcontext = get_context_instance_by_id($category->contextid);
require_capability('moodle/question:useall', $catcontext);
$category->name = addslashes($category->name);
// Find existing random questions in this category that are not used by any quiz.
if ($existingquestions = get_records_sql("SELECT * FROM " . $CFG->prefix . "question q\n WHERE qtype = '" . RANDOM . "'\n AND category = {$category->id}\n AND " . sql_compare_text('questiontext') . " = '{$recurse}'\n AND NOT EXISTS (SELECT * FROM " . $CFG->prefix . "quiz_question_instances WHERE question = q.id)\n ORDER BY id")) {
// Take as many of these as needed.
while ($existingquestion = array_shift($existingquestions) and $randomcount > 0) {
if (!quiz_add_quiz_question($existingquestion->id, $quiz)) {
$result = false;
}
$randomcount--;
}
}
// If more are needed, create them.
if ($randomcount > 0) {
//echo "NOT EXISTING:".$cat->id."<br/>";
$form->questiontext = $recurse;
// we use the questiontext field to store the info
// on whether to include questions in subcategories
$form->questiontextformat = 0;
$form->image = '';
$form->defaultgrade = 1;
$form->hidden = 1;
for ($i = 0; $i < $randomcount; $i++) {
$form->category = "{$category->id},{$category->contextid}";
$form->stamp = make_unique_id_code();
// Set the unique code (not to be changed)
$question = new stdClass();
$question->qtype = RANDOM;
$question = $QTYPES[RANDOM]->save_question($question, $form, $course);
if (!isset($question->id)) {
error('Could not insert new random question!');
$result = false;
}
//quiz_add_quiz_question($question->id, $quiz);
if (!quiz_add_quiz_question($question->id, $quiz)) {
$result = false;
}
}
}
$significantchangemade = true;
}
}
return $result;
/*
$result = true;
$recurse = 1;
list($quiz, $cm) = get_module_from_cmid($cmid);
if ($rs = get_recordset('question_categories','parent',$cat_id)) {
$course = get_record('course','id',$quiz->course);
foreach ($rs as $category) {
echo $category->name."<br/>";
/// Add random questions to the quiz
// - Source from: /mod/quiz/edit.php
$randomcount = 1;
// load category
//$catcontext = get_context_instance_by_id($category->contextid);
//require_capability('moodle/question:useall', $catcontext);
$category->name = $category->name;
// Find existing random questions in this category that are
// not used by any quiz.
if ($existingquestions = get_records_sql(
"SELECT q.id,q.qtype FROM {question} q
WHERE qtype = '" . RANDOM . "'
AND category = ?
AND " . $DB->sql_compare_text('questiontext') . " = ?
AND NOT EXISTS (SELECT * FROM {quiz_question_instances} WHERE question = q.id)
ORDER BY id", array($category->id, $recurse))) {
// Take as many of these as needed.
while (($existingquestion = array_shift($existingquestions)) && $randomcount > 0) {
//quiz_add_quiz_question($existingquestion->id, $quiz);
if(!quiz_add_quiz_question($existingquestion->id, $quiz)){
$result = false;
}
$randomcount--;
}
}
// If more are needed, create them.
if ($randomcount > 0) {
$form->questiontext = $recurse; // we use the questiontext field
// to store the info on whether to include
// questions in subcategories
$form->questiontextformat = 0;
$form->image = '';
$form->defaultgrade = 1;
//.........这里部分代码省略.........
示例13: question_make_default_categories
/**
* Gets the default category in the most specific context.
* If no categories exist yet then default ones are created in all contexts.
*
* @param array $contexts The context objects for this context and all parent contexts.
* @return object The default category - the category in the course context
*/
function question_make_default_categories($contexts)
{
global $DB;
static $preferredlevels = array(CONTEXT_COURSE => 4, CONTEXT_MODULE => 3, CONTEXT_COURSECAT => 2, CONTEXT_SYSTEM => 1);
$toreturn = null;
$preferredness = 0;
// If it already exists, just return it.
foreach ($contexts as $key => $context) {
if (!($exists = $DB->record_exists("question_categories", array('contextid' => $context->id)))) {
// Otherwise, we need to make one
$category = new stdClass();
$contextname = $context->get_context_name(false, true);
$category->name = get_string('defaultfor', 'question', $contextname);
$category->info = get_string('defaultinfofor', 'question', $contextname);
$category->contextid = $context->id;
$category->parent = 0;
// By default, all categories get this number, and are sorted alphabetically.
$category->sortorder = 999;
$category->stamp = make_unique_id_code();
$category->id = $DB->insert_record('question_categories', $category);
} else {
$category = question_get_default_category($context->id);
}
$thispreferredness = $preferredlevels[$context->contextlevel];
if (has_any_capability(array('moodle/question:usemine', 'moodle/question:useall'), $context)) {
$thispreferredness += 10;
}
if ($thispreferredness > $preferredness) {
$toreturn = $category;
$preferredness = $thispreferredness;
}
}
if (!is_null($toreturn)) {
$toreturn = clone $toreturn;
}
return $toreturn;
}
示例14: initialise_question_data
public static function initialise_question_data($qdata)
{
global $USER;
$qdata->id = 0;
$qdata->category = 0;
$qdata->contextid = 0;
$qdata->parent = 0;
$qdata->questiontextformat = FORMAT_HTML;
$qdata->generalfeedbackformat = FORMAT_HTML;
$qdata->defaultmark = 1;
$qdata->penalty = 0.3333333;
$qdata->length = 1;
$qdata->stamp = make_unique_id_code();
$qdata->version = make_unique_id_code();
$qdata->hidden = 0;
$qdata->timecreated = time();
$qdata->timemodified = time();
$qdata->createdby = $USER->id;
$qdata->modifiedby = $USER->id;
$qdata->hints = array();
}
示例15: xmldb_main_upgrade
//.........这里部分代码省略.........
}
$stattask->nextruntime = $nextruntime;
$stattask->minute = $minute;
$stattask->hour = $hour;
$stattask->customised = 1;
$DB->update_record('task_scheduled', $stattask);
}
// These settings are no longer used.
unset_config('statsruntimestarthour');
unset_config('statsruntimestartminute');
unset_config('statslastexecution');
upgrade_main_savepoint(true, 2016081700.02);
}
if ($oldversion < 2016082200.0) {
// An upgrade step to remove any duplicate stamps, within the same context, in the question_categories table, and to
// add a unique index to (contextid, stamp) to avoid future stamp duplication. See MDL-54864.
// Extend the execution time limit of the script to 2 hours.
upgrade_set_timeout(7200);
// This SQL fetches the id of those records which have duplicate stamps within the same context.
// This doesn't return the original record within the context, from which the duplicate stamps were likely created.
$fromclause = "FROM (\n SELECT min(id) AS minid, contextid, stamp\n FROM {question_categories}\n GROUP BY contextid, stamp\n ) minid\n JOIN {question_categories} qc\n ON qc.contextid = minid.contextid AND qc.stamp = minid.stamp AND qc.id > minid.minid";
// Get the total record count - used for the progress bar.
$countduplicatessql = "SELECT count(qc.id) {$fromclause}";
$total = $DB->count_records_sql($countduplicatessql);
// Get the records themselves.
$getduplicatessql = "SELECT qc.id {$fromclause} ORDER BY minid";
$rs = $DB->get_recordset_sql($getduplicatessql);
// For each duplicate, update the stamp to a new random value.
$i = 0;
$pbar = new progress_bar('updatequestioncategorystamp', 500, true);
foreach ($rs as $record) {
// Generate a new, unique stamp and update the record.
do {
$newstamp = make_unique_id_code();
} while (isset($usedstamps[$newstamp]));
$usedstamps[$newstamp] = 1;
$DB->set_field('question_categories', 'stamp', $newstamp, array('id' => $record->id));
// Update progress.
$i++;
$pbar->update($i, $total, "Updating duplicate question category stamp - {$i}/{$total}.");
}
unset($usedstamps);
// The uniqueness of each (contextid, stamp) pair is now guaranteed, so add the unique index to stop future duplicates.
$table = new xmldb_table('question_categories');
$index = new xmldb_index('contextidstamp', XMLDB_INDEX_UNIQUE, array('contextid', 'stamp'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Savepoint reached.
upgrade_main_savepoint(true, 2016082200.0);
}
if ($oldversion < 2016091900.0) {
// Removing the themes from core.
$themes = array('base', 'canvas');
foreach ($themes as $key => $theme) {
if (check_dir_exists($CFG->dirroot . '/theme/' . $theme, false)) {
// Ignore the themes that have been re-downloaded.
unset($themes[$key]);
}
}
if (!empty($themes)) {
// Hacky emulation of plugin uninstallation.
foreach ($themes as $theme) {
unset_all_config_for_plugin('theme_' . $theme);
}
}