本文整理汇总了PHP中question_categorylist函数的典型用法代码示例。如果您正苦于以下问题:PHP question_categorylist函数的具体用法?PHP question_categorylist怎么用?PHP question_categorylist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了question_categorylist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: game_millionaire_html_getquestions
/**
* This page export the game millionaire to html
*
* @author bdaloukas
* @version $Id: exporthtml_millionaire.php,v 1.14 2012/07/25 11:16:03 bdaloukas Exp $
* @package game
**/
function game_millionaire_html_getquestions($game, $context, &$maxanswers, &$countofquestions, &$retfeedback, $destdir, &$files)
{
global $CFG, $DB, $USER;
$maxanswers = 0;
$countofquestions = 0;
$files = array();
if ($game->sourcemodule != 'quiz' and $game->sourcemodule != 'question') {
print_error(get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string('modulename', 'quiz')) . ' ' . get_string('modulename', $game->sourcemodule));
}
if ($game->sourcemodule == 'quiz') {
if ($game->quizid == 0) {
print_error(get_string('must_select_quiz', 'game'));
}
$select = "qtype='multichoice' AND quiz='{$game->quizid}' " . " AND qqi.question=q.id";
$table = "{question} q,{quiz_question_instances} qqi";
} else {
if ($game->questioncategoryid == 0) {
print_error(get_string('must_select_questioncategory', 'game'));
}
//include subcategories
$select = 'category=' . $game->questioncategoryid;
if ($game->subcategories) {
$cats = question_categorylist($game->questioncategoryid);
if (strpos($cats, ',') > 0) {
$select = 'category in (' . $cats . ')';
}
}
$select .= " AND qtype='multichoice'";
$table = "{question} q";
}
$select .= " AND q.hidden=0";
$sql = "SELECT q.id as id, q.questiontext FROM {$table} WHERE {$select}";
$recs = $DB->get_records_sql($sql);
$ret = '';
$retfeedback = '';
foreach ($recs as $rec) {
$recs2 = $DB->get_records('question_answers', array('question' => $rec->id), 'fraction DESC', 'id,answer,feedback');
//Must parse the questiontext and get the name of files.
$line = $rec->questiontext;
$line = game_export_split_files($game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files);
$linefeedback = '';
foreach ($recs2 as $rec2) {
$line .= '#' . str_replace(array('"', '#'), array("'", ' '), game_export_split_files($game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files));
$linefeedback .= '#' . str_replace(array('"', '#'), array("'", ' '), $rec2->feedback);
}
if ($ret != '') {
$ret .= ",\r";
}
$ret .= '"' . base64_encode($line) . '"';
if ($retfeedback != '') {
$retfeedback .= ",\r";
}
$retfeedback .= '"' . base64_encode($linefeedback) . '"';
if (count($recs2) > $maxanswers) {
$maxanswers = count($recs2);
}
$countofquestions++;
}
return $ret;
}
示例2: get_questions_category
/**
* Function to read all questions for category into big array
*
* @param int $category category number
* @param bool $noparent if true only questions with NO parent will be selected
* @param bool $recurse include subdirectories
* @param bool $export set true if this is called by questionbank export
*/
function get_questions_category($category, $noparent = false, $recurse = true, $export = true)
{
global $DB;
// Build sql bit for $noparent
$npsql = '';
if ($noparent) {
$npsql = " and parent='0' ";
}
// Get list of categories
if ($recurse) {
$categorylist = question_categorylist($category->id);
} else {
$categorylist = array($category->id);
}
// Get the list of questions for the category
list($usql, $params) = $DB->get_in_or_equal($categorylist);
$questions = $DB->get_records_select('question', "category {$usql} {$npsql}", $params, 'qtype, name');
// Iterate through questions, getting stuff we need
$qresults = array();
foreach ($questions as $key => $question) {
$question->export_process = $export;
$qtype = question_bank::get_qtype($question->qtype, false);
if ($export && $qtype->name() == 'missingtype') {
// Unrecognised question type. Skip this question when exporting.
continue;
}
$qtype->get_question_options($question);
$qresults[] = $question;
}
return $qresults;
}
示例3: init
/**
* Initialize the object so it will be ready to return where() and params()
*/
private function init()
{
global $DB;
if (!($this->category = $this->get_current_category($this->cat))) {
return;
}
if ($this->recurse) {
$categoryids = question_categorylist($this->category->id);
} else {
$categoryids = array($this->category->id);
}
list($catidtest, $this->params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'cat');
$this->where = 'q.category ' . $catidtest;
}
示例4: create_session_and_responses
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
{
global $QTYPE_EXCLUDE_FROM_RANDOM;
// Choose a random question from the category:
// We need to make sure that no question is used more than once in the
// quiz. Therfore the following need to be excluded:
// 1. All questions that are explicitly assigned to the quiz
// 2. All random questions
// 3. All questions that are already chosen by an other random question
// 4. Deleted questions
if (!isset($cmoptions->questionsinuse)) {
$cmoptions->questionsinuse = $attempt->layout;
}
if (!isset($this->catrandoms[$question->category][$question->questiontext])) {
// Need to fetch random questions from category $question->category"
// (Note: $this refers to the questiontype, not the question.)
global $CFG;
if ($question->questiontext == "1") {
// recurse into subcategories
$categorylist = question_categorylist($question->category);
} else {
$categorylist = $question->category;
}
if ($catrandoms = get_records_select('question', "category IN ({$categorylist})\n AND parent = '0'\n AND hidden = '0'\n AND id NOT IN ({$cmoptions->questionsinuse})\n AND qtype NOT IN ({$QTYPE_EXCLUDE_FROM_RANDOM})", '', 'id')) {
$this->catrandoms[$question->category][$question->questiontext] = draw_rand_array($catrandoms, count($catrandoms));
// from bug 1889
} else {
$this->catrandoms[$question->category][$question->questiontext] = array();
}
}
while ($wrappedquestion = array_pop($this->catrandoms[$question->category][$question->questiontext])) {
if (!ereg("(^|,){$wrappedquestion->id}(,|\$)", $cmoptions->questionsinuse)) {
/// $randomquestion is not in use and will therefore be used
/// as the randomquestion here...
$wrappedquestion = get_record('question', 'id', $wrappedquestion->id);
global $QTYPES;
$QTYPES[$wrappedquestion->qtype]->get_question_options($wrappedquestion);
$QTYPES[$wrappedquestion->qtype]->create_session_and_responses($wrappedquestion, $state, $cmoptions, $attempt);
$wrappedquestion->name_prefix = $question->name_prefix;
$wrappedquestion->maxgrade = $question->maxgrade;
$cmoptions->questionsinuse .= ",{$wrappedquestion->id}";
$state->options->question =& $wrappedquestion;
return true;
}
}
$question->questiontext = '<span class="notifyproblem">' . get_string('toomanyrandom', 'quiz') . '</span>';
$question->qtype = 'description';
$state->responses = array('' => '');
return true;
}
示例5: game_millionaire_html_getquestions
/**
* This page export the game millionaire to html
*
* @author bdaloukas
* @version $Id: exporthtml_millionaire.php,v 1.9 2010/07/26 00:43:58 bdaloukas Exp $
* @package game
**/
function game_millionaire_html_getquestions($game, &$max)
{
global $CFG, $DB, $USER;
$max = 0;
if ($game->sourcemodule != 'quiz' and $game->sourcemodule != 'question') {
print_error(get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string('modulename', 'quiz')) . ' ' . get_string('modulename', $attempt->sourcemodule));
}
if ($game->sourcemodule == 'quiz') {
if ($game->quizid == 0) {
print_error(get_string('must_select_quiz', 'game'));
}
$select = "qtype='multichoice' AND quiz='{$game->quizid}' " . " AND qqi.question=q.id";
$table = "{question} q,{quiz_question_instances} qqi";
} else {
if ($game->questioncategoryid == 0) {
print_error(get_string('must_select_questioncategory', 'game'));
}
//include subcategories
$select = 'category=' . $game->questioncategoryid;
if ($game->subcategories) {
$cats = question_categorylist($game->questioncategoryid);
if (strpos($cats, ',') > 0) {
$select = 'category in (' . $cats . ')';
}
}
$select .= " AND qtype='multichoice'";
$table = "{question} q";
}
$select .= " AND q.hidden=0";
$sql = "SELECT q.id as id, q.questiontext FROM {$table} WHERE {$select}";
$recs = $DB->get_records_sql($sql);
$ret = '';
foreach ($recs as $rec) {
$recs2 = $DB->get_records('question_answers', array('question' => $rec->id), 'fraction DESC', 'id,answer');
$line = $rec->questiontext;
foreach ($recs2 as $rec2) {
$line .= '#' . str_replace(array('"', '#'), array("'", ' '), $rec2->answer);
}
if ($ret != '') {
$ret .= ",\r";
}
$ret .= '"' . base64_encode($line) . '"';
if (count($recs2) > $max) {
$max = count($recs2);
}
}
return $ret;
}
示例6: game_showanswers_question
function game_showanswers_question($game)
{
global $DB;
if ($game->gamekind != 'bookquiz') {
$select = ' category=' . $game->questioncategoryid;
if ($game->subcategories) {
$cats = question_categorylist($game->questioncategoryid);
if (strpos($cats, ',') > 0) {
$select = ' category in (' . $cats . ')';
}
}
} else {
$context = get_context_instance(50, $COURSE->id);
$select = " contextid in ({$context->id})";
$select2 = '';
if ($recs = $DB->get_records_select('question_categories', $select, null, 'id,id')) {
foreach ($recs as $rec) {
$select2 .= ',' . $rec->id;
}
}
$select = ' AND category IN (' . substr($select2, 1) . ')';
}
$select .= ' AND hidden = 0 ';
$select .= game_showanswers_appendselect($game);
$showcategories = $game->gamekind == 'bookquiz';
$order = $showcategories ? 'category,questiontext' : 'questiontext';
game_showanswers_question_select($game, '{question} q', $select, '*', $order, $showcategories, $game->course);
}
示例7: get_all_question_types_used
/**
* Return all the question types used in this quiz.
*
* @param boolean $includepotential if the quiz include random questions, setting this flag to true will make the function to
* return all the possible question types in the random questions category
* @return array a sorted array including the different question types
* @since Moodle 3.1
*/
public function get_all_question_types_used($includepotential = false)
{
$questiontypes = array();
// To control if we need to look in categories for questions.
$qcategories = array();
// We must be careful with random questions, if we find a random question we must assume that the quiz may content
// any of the questions in the referenced category (or subcategories).
foreach ($this->get_questions() as $questiondata) {
if ($questiondata->qtype == 'random' and $includepotential) {
$includesubcategories = (bool) $questiondata->questiontext;
if (!isset($qcategories[$questiondata->category])) {
$qcategories[$questiondata->category] = false;
}
if ($includesubcategories) {
$qcategories[$questiondata->category] = true;
}
} else {
if (!in_array($questiondata->qtype, $questiontypes)) {
$questiontypes[] = $questiondata->qtype;
}
}
}
if (!empty($qcategories)) {
// We have to look for all the question types in these categories.
$categoriestolook = array();
foreach ($qcategories as $cat => $includesubcats) {
if ($includesubcats) {
$categoriestolook = array_merge($categoriestolook, question_categorylist($cat));
} else {
$categoriestolook[] = $cat;
}
}
$questiontypesincategories = question_bank::get_all_question_types_in_categories($categoriestolook);
$questiontypes = array_merge($questiontypes, $questiontypesincategories);
}
$questiontypes = array_unique($questiontypes);
sort($questiontypes);
return $questiontypes;
}
示例8: game_questions_shortanswer_question
function game_questions_shortanswer_question($game)
{
if ($game->questioncategoryid == 0) {
print_error(get_string('must_select_questioncategory', 'game'));
}
//include subcategories
$select = 'q.category=' . $game->questioncategoryid;
if ($game->subcategories) {
$cats = question_categorylist($game->questioncategoryid);
if (strpos($cats, ',') > 0) {
$select = 'q.category in (' . $cats . ')';
}
}
$select .= " AND qtype='shortanswer' " . " AND qa.question=q.id" . " AND q.hidden=0";
$table = "{question} q,{question_answers} qa";
$fields = "qa.id as qaid, q.id, q.questiontext as questiontext, " . "qa.answer as answertext, q.id as questionid";
return game_questions_shortanswer_question_fraction($table, $fields, $select);
}
示例9: question_categorylist
/**
* @return array of question category ids of the category and all subcategories.
*/
function question_categorylist($categoryid)
{
global $DB;
$subcategories = $DB->get_records('question_categories', array('parent' => $categoryid), 'sortorder ASC', 'id, 1');
$categorylist = array($categoryid);
foreach ($subcategories as $subcategory) {
$categorylist = array_merge($categorylist, question_categorylist($subcategory->id));
}
return $categorylist;
}
示例10: get_usable_questions_from_category
/**
* Get all the usable questions from a particular question category.
*
* @param integer $categoryid the id of a question category.
* @param boolean whether to include questions from subcategories.
* @param string $questionsinuse comma-separated list of question ids to exclude from consideration.
* @return array of question records.
*/
function get_usable_questions_from_category($categoryid, $subcategories, $questionsinuse) {
global $DB;
$this->init_qtype_lists();
if ($subcategories) {
$categorylist = question_categorylist($categoryid);
} else {
$categorylist = $categoryid;
}
if (!$catrandoms = $DB->get_records_select('question',
"category IN ($categorylist)
AND parent = 0
AND hidden = 0
AND id NOT IN ($questionsinuse)
AND qtype NOT IN ($this->excludedqtypes)", null, '', 'id')) {
$catrandoms = array();
}
return $catrandoms;
}
示例11: offlinequiz_add_random_questions
/**
* Randomly add a number of multichoice questions to an offlinequiz group.
*
* @param unknown_type $offlinequiz
* @param unknown_type $addonpage
* @param unknown_type $categoryid
* @param unknown_type $number
* @param unknown_type $includesubcategories
*/
function offlinequiz_add_random_questions($offlinequiz, $offlinegroup, $categoryid, $number, $recurse)
{
global $DB;
$category = $DB->get_record('question_categories', array('id' => $categoryid));
if (!$category) {
print_error('invalidcategoryid', 'error');
}
$catcontext = context::instance_by_id($category->contextid);
require_capability('moodle/question:useall', $catcontext);
if ($recurse) {
$categoryids = question_categorylist($category->id);
} else {
$categoryids = array($category->id);
}
list($qcsql, $qcparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'qc');
// Find all questions in the selected categories that are not in the offline group yet.
$sql = "SELECT id\n FROM {question} q\n WHERE q.category {$qcsql}\n AND q.parent = 0\n AND q.hidden = 0\n AND q.qtype IN ('multichoice', 'multichoiceset')\n AND NOT EXISTS (SELECT 1 \n FROM {offlinequiz_group_questions} ogq\n WHERE ogq.questionid = q.id\n AND ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid)";
$qcparams['offlinequizid'] = $offlinequiz->id;
$qcparams['offlinegroupid'] = $offlinegroup->id;
$questionids = $DB->get_fieldset_sql($sql, $qcparams);
srand(microtime() * 1000000);
shuffle($questionids);
$chosenids = array();
while (($questionid = array_shift($questionids)) && $number > 0) {
$chosenids[] = $questionid;
$number -= 1;
}
$maxmarks = array();
if ($chosenids) {
// Get the old maxmarks in case questions are already in other offlinequiz groups.
list($qsql, $params) = $DB->get_in_or_equal($chosenids, SQL_PARAMS_NAMED);
$sql = "SELECT id, questionid, maxmark\n FROM {offlinequiz_group_questions}\n WHERE offlinequizid = :offlinequizid\n AND questionid {$qsql}";
$params['offlinequizid'] = $offlinequiz->id;
if ($slots = $DB->get_records_sql($sql, $params)) {
foreach ($slots as $slot) {
if (!array_key_exists($slot->questionid, $maxmarks)) {
$maxmarks[$slot->questionid] = $slot->maxmark;
}
}
}
}
offlinequiz_add_questionlist_to_group($chosenids, $offlinequiz, $offlinegroup, null, $maxmarks);
}
示例12: question_categorylist
/**
* Returns a comma separated list of ids of the category and all subcategories
*/
function question_categorylist($categoryid)
{
global $DB;
// returns a comma separated list of ids of the category and all subcategories
$categorylist = $categoryid;
if ($subcategories = $DB->get_records('question_categories', array('parent' => $categoryid), 'sortorder ASC', 'id, 1')) {
foreach ($subcategories as $subcategory) {
$categorylist .= ',' . question_categorylist($subcategory->id);
}
}
return $categorylist;
}
示例13: question_list
/**
* Prints the table of questions in a category with interactions
*
* @param object $course The course object
* @param int $categoryid The id of the question category to be displayed
* @param int $cm The course module record if we are in the context of a particular module, 0 otherwise
* @param int $recurse This is 1 if subcategories should be included, 0 otherwise
* @param int $page The number of the page to be displayed
* @param int $perpage Number of questions to show per page
* @param boolean $showhidden True if also hidden questions should be displayed
* @param boolean $showquestiontext whether the text of each question should be shown in the list
*/
function question_list($contexts, $pageurl, $categoryandcontext, $cm = null, $recurse = 1, $page = 0, $perpage = 100, $showhidden = false, $sortorder = 'typename', $sortorderdecoded = 'qtype, name ASC', $showquestiontext = false, $addcontexts = array())
{
global $USER, $CFG, $THEME, $COURSE;
$lastchangedid = optional_param('lastchanged', 0, PARAM_INT);
list($categoryid, $contextid) = explode(',', $categoryandcontext);
$qtypemenu = question_type_menu();
$strcategory = get_string("category", "quiz");
$strquestion = get_string("question", "quiz");
$straddquestions = get_string("addquestions", "quiz");
$strimportquestions = get_string("importquestions", "quiz");
$strexportquestions = get_string("exportquestions", "quiz");
$strnoquestions = get_string("noquestions", "quiz");
$strselect = get_string("select", "quiz");
$strselectall = get_string("selectall", "quiz");
$strselectnone = get_string("selectnone", "quiz");
$strcreatenewquestion = get_string("createnewquestion", "quiz");
$strquestionname = get_string("questionname", "quiz");
$strdelete = get_string("delete");
$stredit = get_string("edit");
$strmove = get_string('moveqtoanothercontext', 'question');
$strview = get_string("view");
$straction = get_string("action");
$strrestore = get_string('restore');
$strtype = get_string("type", "quiz");
$strcreatemultiple = get_string("createmultiple", "quiz");
$strpreview = get_string("preview", "quiz");
if (!$categoryid) {
echo "<p style=\"text-align:center;\"><b>";
print_string("selectcategoryabove", "quiz");
echo "</b></p>";
return;
}
if (!($category = get_record('question_categories', 'id', $categoryid, 'contextid', $contextid))) {
notify('Category not found!');
return;
}
$catcontext = get_context_instance_by_id($contextid);
$canadd = has_capability('moodle/question:add', $catcontext);
//check for capabilities on all questions in category, will also apply to sub cats.
$caneditall = has_capability('moodle/question:editall', $catcontext);
$canuseall = has_capability('moodle/question:useall', $catcontext);
$canmoveall = has_capability('moodle/question:moveall', $catcontext);
if ($cm and $cm->modname == 'quiz') {
$quizid = $cm->instance;
} else {
$quizid = 0;
}
$returnurl = $pageurl->out();
$questionurl = new moodle_url("{$CFG->wwwroot}/question/question.php", array('returnurl' => $returnurl));
if ($cm !== null) {
$questionurl->param('cmid', $cm->id);
} else {
$questionurl->param('courseid', $COURSE->id);
}
$questionmoveurl = new moodle_url("{$CFG->wwwroot}/question/contextmoveq.php", array('returnurl' => $returnurl));
if ($cm !== null) {
$questionmoveurl->param('cmid', $cm->id);
} else {
$questionmoveurl->param('courseid', $COURSE->id);
}
echo '<div class="boxaligncenter">';
$formatoptions = new stdClass();
$formatoptions->noclean = true;
echo format_text($category->info, FORMAT_MOODLE, $formatoptions, $COURSE->id);
echo '<table><tr>';
if ($canadd) {
echo '<td valign="top" align="right">';
popup_form($questionurl->out(false, array('category' => $category->id)) . '&qtype=', $qtypemenu, "addquestion", "", "choose", "", "", false, "self", "<strong>{$strcreatenewquestion}</strong>");
echo '</td><td valign="top" align="right">';
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
echo '</td>';
} else {
echo '<td>';
print_string('nopermissionadd', 'question');
echo '</td>';
}
echo '</tr></table>';
echo '</div>';
$categorylist = $recurse ? question_categorylist($category->id) : $category->id;
// hide-feature
$showhidden = $showhidden ? '' : " AND hidden = '0'";
if (!($totalnumber = count_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}"))) {
echo "<p style=\"text-align:center;\">";
print_string("noquestions", "quiz");
echo "</p>";
return;
}
if (!($questions = get_records_select('question', "category IN ({$categorylist}) AND parent = '0' {$showhidden}", $sortorderdecoded, '*', $page * $perpage, $perpage))) {
//.........这里部分代码省略.........
示例14: get_available_saquestions_from_category
/**
* Get all the usable shortanswer questions from a particular question category.
*
* @param integer $categoryid the id of a question category.
* @param bool $subcategories whether to include questions from subcategories.
* @return array of question records.
*/
public function get_available_saquestions_from_category($categoryid, $subcategories)
{
if (isset($this->availablesaquestionsbycategory[$categoryid][$subcategories])) {
return $this->availablesaquestionsbycategory[$categoryid][$subcategories];
}
if ($subcategories) {
$categoryids = question_categorylist($categoryid);
} else {
$categoryids = array($categoryid);
}
$questionids = question_bank::get_finder()->get_questions_from_categories($categoryids, "qtype = 'shortanswer'");
$this->availablesaquestionsbycategory[$categoryid][$subcategories] = $questionids;
return $questionids;
}
示例15: get_categories
private function get_categories()
{
$cmid = optional_param('cmid', 0, PARAM_INT);
$categoryparam = optional_param('category', '', PARAM_TEXT);
$courseid = optional_param('courseid', 0, PARAM_INT);
if ($cmid) {
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
if ($pagevars['cat']) {
$categoryparam = $pagevars['cat'];
}
}
if ($categoryparam) {
$catandcontext = explode(',', $categoryparam);
$cats = question_categorylist($catandcontext[0]);
return $cats;
} else {
if ($cmid) {
list($module, $cm) = get_module_from_cmid($cmid);
$courseid = $cm->course;
require_login($courseid, false, $cm);
$thiscontext = context_module::instance($cmid);
} else {
$module = null;
$cm = null;
if ($courseid) {
$thiscontext = context_course::instance($courseid);
} else {
$thiscontext = null;
}
}
}
$cats = get_categories_for_contexts($thiscontext->id);
return array_keys($cats);
}