本文整理汇总了PHP中quiz_has_attempts函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_has_attempts函数的具体用法?PHP quiz_has_attempts怎么用?PHP quiz_has_attempts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_has_attempts函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_stuff
function test_stuff()
{
global $CFG, $DB;
$dbman = $this->testdb->get_manager();
$this->assertFalse($dbman->table_exists('quiz_attempts'));
$this->assertFalse($dbman->table_exists('quiz'));
$this->create_test_table('quiz_attempts', 'mod/quiz');
$this->assertTrue($dbman->table_exists('quiz_attempts'));
$this->assertFalse($dbman->table_exists('quiz'));
$this->load_test_data('quiz_attempts', array('quiz', 'uniqueid', 'attempt', 'preview', 'layout'), array(array(1, 1, 1, 0, '1,2,3,0'), array(1, 2, 2, 1, '2,3,1,0')));
$this->switch_to_test_db();
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
$this->assertTrue(quiz_has_attempts(1));
$this->revert_to_real_db();
$this->drop_test_table('quiz_attempts');
$this->assertFalse($dbman->table_exists('quiz_attempts'));
}
示例2: set_user_preference
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
if ($quiz_qbanktool > -1) {
$thispageurl->param('qbanktool', $quiz_qbanktool);
set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
} else {
$quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
}
if ($quiz_reordertool > -1) {
$thispageurl->param('reordertool', $quiz_reordertool);
set_user_preference('quiz_reordertab', $quiz_reordertool);
} else {
$quiz_reordertool = get_user_preferences('quiz_reordertab', 0);
}
$canaddrandom = $contexts->have_cap('moodle/question:useall');
$canaddquestion = (bool) $contexts->having_add_and_use();
$quizhasattempts = quiz_has_attempts($quiz->id);
$PAGE->set_url($thispageurl);
// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $quiz->course));
if (!$course) {
print_error('invalidcourseid', 'error');
}
$questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz);
$questionbank->set_quiz_has_attempts($quizhasattempts);
// Log this visit.
add_to_log($cm->course, 'quiz', 'editquestions', "view.php?id={$cm->id}", "{$quiz->id}", $cm->id);
// You need mod/quiz:manage in addition to question capabilities to access this page.
require_capability('mod/quiz:manage', $contexts->lowest());
if (empty($quiz->grades)) {
$quiz->grades = quiz_get_all_question_grades($quiz);
}
示例3: get_edit_page_warnings
/**
* Get any warnings to show at the top of the edit page.
* @return string[] array of strings.
*/
public function get_edit_page_warnings()
{
$warnings = array();
if (quiz_has_attempts($this->quizobj->get_quizid())) {
$reviewlink = quiz_attempt_summary_link_to_reports($this->quizobj->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context());
$warnings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink);
}
if ($this->is_shuffled()) {
$updateurl = new \moodle_url('/course/mod.php', array('return' => 'true', 'update' => $this->quizobj->get_cmid(), 'sesskey' => sesskey()));
$updatelink = '<a href="' . $updateurl->out() . '">' . get_string('updatethis', '', get_string('modulename', 'quiz')) . '</a>';
$warnings[] = get_string('shufflequestionsselected', 'quiz', $updatelink);
}
return $warnings;
}
示例4: quiz_update_sumgrades
/**
* Update the sumgrades field of the quiz. This needs to be called whenever
* the grading structure of the quiz is changed. For example if a question is
* added or removed, or a question weight is changed.
*
* You should call {@link quiz_delete_previews()} before you call this function.
*
* @param object $quiz a quiz.
*/
function quiz_update_sumgrades($quiz) {
global $DB;
$sql = 'UPDATE {quiz}
SET sumgrades = COALESCE((
SELECT SUM(grade)
FROM {quiz_question_instances}
WHERE quiz = {quiz}.id
), 0)
WHERE id = ?';
$DB->execute($sql, array($quiz->id));
$quiz->sumgrades = $DB->get_field('quiz', 'sumgrades', array('id' => $quiz->id));
if ($quiz->sumgrades < 0.000005 && quiz_has_attempts($quiz->id)) {
// If the quiz has been attempted, and the sumgrades has been
// set to 0, then we must also set the maximum possible grade to 0, or
// we will get a divide by zero error.
quiz_set_grade(0, $quiz);
}
}
示例5: get_edit_page_warnings
/**
* Get any warnings to show at the top of the edit page.
* @return string[] array of strings.
*/
public function get_edit_page_warnings()
{
$warnings = array();
if (quiz_has_attempts($this->quizobj->get_quizid())) {
$reviewlink = quiz_attempt_summary_link_to_reports($this->quizobj->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context());
$warnings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink);
}
return $warnings;
}
示例6: page_split_join_button
/**
* Display an icon to split or join two pages of the quiz.
*
* @param \stdClass $quiz the quiz settings from the database.
* @param \stdClass $question data from the question and quiz_slots tables.
* @param bool $insertpagebreak if true, show an insert page break icon.
* else show a join pages icon.
* @return string HTML to output.
*/
public function page_split_join_button($quiz, $question, $insertpagebreak)
{
$url = new \moodle_url('repaginate.php', array('cmid' => $quiz->cmid, 'quizid' => $quiz->id, 'slot' => $question->slot, 'repag' => $insertpagebreak ? 2 : 1, 'sesskey' => sesskey()));
if ($insertpagebreak) {
$title = get_string('addpagebreak', 'quiz');
$image = $this->pix_icon('e/insert_page_break', $title);
$action = 'addpagebreak';
} else {
$title = get_string('removepagebreak', 'quiz');
$image = $this->pix_icon('e/remove_page_break', $title);
$action = 'removepagebreak';
}
// Disable the link if quiz has attempts.
$disabled = null;
if (quiz_has_attempts($quiz->id)) {
$disabled = "disabled";
}
return html_writer::span($this->action_link($url, $image, null, array('title' => $title, 'class' => 'page_split_join cm-edit-action', 'disabled' => $disabled, 'data-action' => $action)), 'page_split_join_wrapper');
}
示例7: required_param
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Rest endpoint for ajax editing for paging operations on the quiz structure.
*
* @package mod_quiz
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once __DIR__ . '/../../config.php';
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
$cmid = required_param('cmid', PARAM_INT);
$quizid = required_param('quizid', PARAM_INT);
$slotnumber = required_param('slot', PARAM_INT);
$repagtype = required_param('repag', PARAM_INT);
require_sesskey();
$quizobj = quiz::create($quizid);
require_login($quizobj->get_course(), false, $quizobj->get_cm());
require_capability('mod/quiz:manage', $quizobj->get_context());
if (quiz_has_attempts($quizid)) {
$reportlink = quiz_attempt_summary_link_to_reports($quizobj->get_quiz(), $quizobj->get_cm(), $quizobj->get_context());
throw new \moodle_exception('cannoteditafterattempts', 'quiz', new moodle_url('/mod/quiz/edit.php', array('cmid' => $cmid)), $reportlink);
}
$slotnumber++;
$repage = new \mod_quiz\repaginate($quizid);
$repage->repaginate_slots($slotnumber, $repagtype);
$structure = $quizobj->get_structure();
$slots = $structure->refresh_page_numbers_and_update_db($structure->get_quiz());
redirect(new moodle_url('edit.php', array('cmid' => $quizobj->get_cmid())));
示例8: define
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Ajax script to update the contents of the question bank dialogue.
*
* @package mod_quiz
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once __DIR__ . '/../../config.php';
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
require_once $CFG->dirroot . '/question/editlib.php';
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
require_capability('mod/quiz:manage', $contexts->lowest());
// Create quiz question bank view.
$questionbank = new mod_quiz\question\bank\custom_view($contexts, $thispageurl, $course, $cm, $quiz);
$questionbank->set_quiz_has_attempts(quiz_has_attempts($quiz->id));
// Output.
$output = $PAGE->get_renderer('mod_quiz', 'edit');
$contents = $output->question_bank_contents($questionbank, $pagevars);
echo json_encode(array('status' => 'OK', 'contents' => $contents));