MDL-74923 quiz: tidy qubaids classes
Including removing an almost duplicate task
This commit is contained in:
@@ -23,11 +23,21 @@ require_once($CFG->dirroot . '/question/engine/datalib.php');
|
||||
/**
|
||||
* A {@see qubaid_condition} for finding all the question usages belonging to a particular quiz.
|
||||
*
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package mod_quiz
|
||||
* @category question
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qubaids_for_quiz extends \qubaid_join {
|
||||
public function __construct($quizid, $includepreviews = true, $onlyfinished = false) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $quizid The quiz to search.
|
||||
* @param bool $includepreviews Whether to include preview attempts
|
||||
* @param bool $onlyfinished Whether to only include finished attempts or not
|
||||
*/
|
||||
public function __construct(int $quizid, bool $includepreviews = true, bool $onlyfinished = false) {
|
||||
$where = 'quiza.quiz = :quizaquiz';
|
||||
$params = array('quizaquiz' => $quizid);
|
||||
|
||||
|
||||
@@ -16,41 +16,28 @@
|
||||
|
||||
namespace mod_quiz\question;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/datalib.php');
|
||||
|
||||
/**
|
||||
* A {@see qubaid_condition} for finding all the question usages belonging to a particular user and quiz combination.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package mod_quiz
|
||||
* @category question
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated This class was never needed because qubaids_for_users_attempts already existed and is more flexible.
|
||||
*/
|
||||
class qubaids_for_quiz_user extends \qubaid_join {
|
||||
class qubaids_for_quiz_user extends qubaids_for_users_attempts {
|
||||
/**
|
||||
* Constructor for this qubaid.
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $quizid The quiz to search.
|
||||
* @param int $userid The user to filter on
|
||||
* @param bool $includepreviews Whether to include preview attempts
|
||||
* @param bool $onlyfinished Whether to only include finished attempts or not
|
||||
* @param int $quizid The quiz to search.
|
||||
* @param int $userid The user to filter on
|
||||
* @param bool $includepreviews Whether to include preview attempts
|
||||
* @param bool $onlyfinished Whether to only include finished attempts or not
|
||||
*/
|
||||
public function __construct($quizid, $userid, $includepreviews = true, $onlyfinished = false) {
|
||||
$where = 'quiza.quiz = :quizaquiz AND quiza.userid = :quizauserid';
|
||||
$params = [
|
||||
'quizaquiz' => $quizid,
|
||||
'quizauserid' => $userid,
|
||||
];
|
||||
|
||||
if (!$includepreviews) {
|
||||
$where .= ' AND preview = 0';
|
||||
}
|
||||
|
||||
if ($onlyfinished) {
|
||||
$where .= ' AND state = :statefinished';
|
||||
$params['statefinished'] = quiz_attempt::FINISHED;
|
||||
}
|
||||
|
||||
parent::__construct('{quiz_attempts} quiza', 'quiza.uniqueid', $where, $params);
|
||||
public function __construct(int $quizid, int $userid,
|
||||
bool $includepreviews = true, bool $onlyfinished = false) {
|
||||
debugging('qubaids_for_quiz_user is deprecated. Please use qubaids_for_users_attempts instead.');
|
||||
parent::__construct($quizid, $userid,
|
||||
$onlyfinished ? 'finished' : 'all', $includepreviews);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,24 +14,18 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* A {@link qubaid_condition} representing all the attempts by one user at a given quiz.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @category question
|
||||
* @copyright 2015 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_quiz\question;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/datalib.php');
|
||||
require_once($CFG->dirroot.'/mod/quiz/attemptlib.php');
|
||||
|
||||
/**
|
||||
* A {@link qubaid_condition} representing all the attempts by one user at a given quiz.
|
||||
* A {@see qubaid_condition} representing all the attempts by one user at a given quiz.
|
||||
*
|
||||
* @package mod_quiz
|
||||
* @category question
|
||||
* @copyright 2015 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -48,7 +42,7 @@ class qubaids_for_users_attempts extends \qubaid_join {
|
||||
*/
|
||||
public function __construct($quizid, $userid, $status = 'finished', $includepreviews = false) {
|
||||
$where = 'quiza.quiz = :quizaquiz AND quiza.userid = :userid';
|
||||
$params = array('quizaquiz' => $quizid, 'userid' => $userid);
|
||||
$params = ['quizaquiz' => $quizid, 'userid' => $userid];
|
||||
|
||||
if (!$includepreviews) {
|
||||
$where .= ' AND preview = 0';
|
||||
|
||||
@@ -1044,7 +1044,7 @@ class structure {
|
||||
$previousmaxmark = $slot->maxmark;
|
||||
$slot->maxmark = $maxmark;
|
||||
$DB->update_record('quiz_slots', $slot);
|
||||
\question_engine::set_max_mark_in_attempts(new \qubaids_for_quiz($slot->quizid),
|
||||
\question_engine::set_max_mark_in_attempts(new qubaids_for_quiz($slot->quizid),
|
||||
$slot->slot, $maxmark);
|
||||
$trans->allow_commit();
|
||||
|
||||
|
||||
+3
-1
@@ -31,6 +31,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
use mod_quiz\question\bank\custom_view;
|
||||
use mod_quiz\question\display_options;
|
||||
use mod_quiz\question\qubaids_for_quiz;
|
||||
use mod_quiz\question\qubaids_for_users_attempts;
|
||||
use core_question\statistics\questions\all_calculated_for_qubaid_condition;
|
||||
|
||||
require_once($CFG->dirroot . '/calendar/lib.php');
|
||||
@@ -416,7 +417,8 @@ function quiz_delete_all_attempts($quiz) {
|
||||
function quiz_delete_user_attempts($quiz, $user) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
question_engine::delete_questions_usage_by_activities(new qubaids_for_quiz_user($quiz->get_quizid(), $user->id));
|
||||
question_engine::delete_questions_usage_by_activities(new qubaids_for_users_attempts(
|
||||
$quiz->get_quizid(), $user->id, 'all'));
|
||||
$params = [
|
||||
'quiz' => $quiz->get_quizid(),
|
||||
'userid' => $user->id,
|
||||
|
||||
@@ -8,7 +8,8 @@ This files describes API changes in the quiz code.
|
||||
doable by adding use statements, and a search/replace.
|
||||
- mod_quiz_display_options => mod_quiz\question\display_options
|
||||
- qubaids_for_quiz => mod_quiz\question\qubaids_for_quiz
|
||||
- qubaids_for_quiz_user => mod_quiz\question\qubaids_for_quiz_user
|
||||
- qubaids_for_quiz_user => mod_quiz\question\qubaids_for_quiz_user - which is deprecated, because
|
||||
it is almost the same as mod_quiz\question\qubaids_for_users_attempts.
|
||||
|
||||
|
||||
=== 4.1 ===
|
||||
|
||||
Reference in New Issue
Block a user