Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/questions report #138

Merged
merged 10 commits into from
Jul 26, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added
- Framework for CAPQuiz **report** sub-plugins
- New **Attempts** report sub-plugin where one can view/generate reports on CAPQuiz attempts made within the activity.
- New **Questions** report sub-plugin where one can view/generate reports on the development of CAPQuiz question ratings over time.
- Ability to manage the question bank in the context of the CAPQuiz activity, via new link in the navigation menu.
- Check out the commented question in the comments pane (teacher view) by providing link to question preview.

Expand Down
3 changes: 2 additions & 1 deletion backup/moodle2/backup_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ protected function define_structure() {
$attempts = new backup_nested_element('attempts');
$attempt = new backup_nested_element('attempt', ['id'], [
'slot', 'user_id', 'question_id', 'reviewed', 'answered', 'time_answered', 'time_reviewed',
'question_rating_id', 'previous_question_rating_id', 'user_rating_id', 'previous_user_rating_id', 'feedback'
'question_rating_id', 'question_prev_rating_id', 'prev_question_rating_id',
'prev_question_prev_rating_id', 'user_rating_id', 'user_prev_rating_id', 'feedback'
]);

// Build the tree.
Expand Down
6 changes: 4 additions & 2 deletions backup/moodle2/restore_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ protected function process_capquiz_attempt($data) {
$data->user_id = $this->get_new_parentid('capquiz_user');
$data->question_id = $this->get_mappingid('capquiz_question', $data->question_id);
$data->question_rating_id = $this->get_mappingid('capquiz_question_rating', $data->question_rating_id);
$data->previous_question_rating_id = $this->get_mappingid('capquiz_question_rating', $data->previous_question_rating_id);
$data->question_prev_rating_id = $this->get_mappingid('capquiz_question_rating', $data->question_prev_rating_id);
$data->prev_question_rating_id = $this->get_mappingid('capquiz_question_rating', $data->prev_question_rating_id);
$data->prev_question_prev_rating_id = $this->get_mappingid('capquiz_question_rating', $data->prev_question_prev_rating_id);
$data->user_rating_id = $this->get_mappingid('capquiz_user_rating', $data->user_rating_id);
$data->previous_user_rating_id = $this->get_mappingid('capquiz_user_rating', $data->previous_user_rating_id);
$data->user_prev_rating_id = $this->get_mappingid('capquiz_user_rating', $data->user_prev_rating_id);
$newitemid = $DB->insert_record('capquiz_attempt', $data);
$this->set_mapping('capquiz_attempt', $oldid, $newitemid);
}
Expand Down
14 changes: 12 additions & 2 deletions classes/capquiz_question_attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,17 @@ public function set_question_rating(capquiz_question_rating $rating, $previous =
if (!$previous) {
$this->record->question_rating_id = $rating->id();
} else {
$this->record->previous_question_rating_id = $rating->id();
$this->record->question_prev_rating_id = $rating->id();
}
$DB->update_record('capquiz_attempt', $this->record);
}

public function set_previous_question_rating(capquiz_question_rating $rating, $previous = false) {
global $DB;
if (!$previous) {
$this->record->prev_question_rating_id = $rating->id();
} else {
$this->record->prev_question_prev_rating_id = $rating->id();
}
$DB->update_record('capquiz_attempt', $this->record);
}
Expand All @@ -235,7 +245,7 @@ public function set_user_rating(capquiz_user_rating $rating, $previous = false)
if (!$previous) {
$this->record->user_rating_id = $rating->id();
} else {
$this->record->previous_user_rating_id = $rating->id();
$this->record->user_prev_rating_id = $rating->id();
}
$DB->update_record('capquiz_attempt', $this->record);
}
Expand Down
6 changes: 6 additions & 0 deletions classes/capquiz_question_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function attempt_for_current_user() {

public function delete_invalid_attempt(capquiz_user $user) {
$attempt = $this->attempt_for_user($user);

if (!$attempt->is_question_valid()) {
$attempt->delete();
}
Expand Down Expand Up @@ -130,6 +131,7 @@ private function update_question_rating(capquiz_question_attempt $previous, capq
$currentquestion = $this->capquiz->question_list()->question($current->question_id());
$previousquestion = $this->capquiz->question_list()->question($previous->question_id());

$current->set_previous_question_rating($previousquestion->get_capquiz_question_rating(), true);
$current->set_question_rating($currentquestion->get_capquiz_question_rating(), true);

if (!$currentquestion || !$previousquestion) {
Expand All @@ -139,8 +141,12 @@ private function update_question_rating(capquiz_question_attempt $previous, capq
$ratingsystem->question_victory_ratings($currentquestion, $previousquestion);
} else if (!$previouscorrect && $currentcorrect) {
$ratingsystem->question_victory_ratings($previousquestion, $currentquestion);
} else {
$previousquestion->set_rating($previousquestion->rating());
$currentquestion->set_rating($currentquestion->rating());
}

$current->set_previous_question_rating($previousquestion->get_capquiz_question_rating());
$current->set_question_rating($currentquestion->get_capquiz_question_rating());
}

Expand Down
3 changes: 3 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public static function get_metadata(collection $items): collection {
// The 'capquiz_question' table is used to map the usage of a question used in a CAPQuiz activity.
// It does not contain user data.

// The 'capquiz_question_rating' contains each change of rating for a question.
// It does not contain user data.

// The 'capquiz_question_list' table is used to store the set of question lists used by a CapQuiz activity.
// It does not contain user data.

Expand Down
12 changes: 8 additions & 4 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,23 @@
<FIELD NAME="time_answered" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="time_reviewed" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="question_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the capquiz_question_rating for the question used in this attempt"/>
<FIELD NAME="previous_question_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the previous capquiz_question_rating for the question used in this attempt"/>
<FIELD NAME="question_prev_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the previous capquiz_question_rating for the question used in this attempt"/>
<FIELD NAME="prev_question_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the capquiz_question_rating for the previous question used in this attempt"/>
<FIELD NAME="prev_question_prev_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the previous capquiz_question_rating for the previous question used in this attempt"/>
<FIELD NAME="user_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the capquiz_user_rating for the user used in this attempt"/>
<FIELD NAME="previous_user_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the previous capquiz_user_rating for the user used in this attempt"/>
<FIELD NAME="user_prev_rating_id" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false" COMMENT="The id of the previous capquiz_user_rating for the user used in this attempt"/>
<FIELD NAME="feedback" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="user_id" TYPE="foreign" FIELDS="user_id" REFTABLE="user" REFFIELDS="id"/>
<KEY NAME="question_id" TYPE="foreign" FIELDS="question_id" REFTABLE="capquiz_question" REFFIELDS="id"/>
<KEY NAME="question_rating_id" TYPE="foreign" FIELDS="question_rating_id" REFTABLE="capquiz_question_rating" REFFIELDS="id"/>
<KEY NAME="previous_question_rating_id" TYPE="foreign" FIELDS="previous_question_rating_id" REFTABLE="capquiz_question_rating" REFFIELDS="id"/>
<KEY NAME="question_prev_rating_id" TYPE="foreign" FIELDS="question_prev_rating_id" REFTABLE="capquiz_question_rating" REFFIELDS="id"/>
<KEY NAME="prev_question_rating_id" TYPE="foreign" FIELDS="prev_question_rating_id" REFTABLE="capquiz_question_rating" REFFIELDS="id"/>
<KEY NAME="prev_question_prev_rating_id" TYPE="foreign" FIELDS="prev_question_prev_rating_id" REFTABLE="capquiz_question_rating" REFFIELDS="id"/>
<KEY NAME="user_rating_id" TYPE="foreign" FIELDS="user_rating_id" REFTABLE="capquiz_user_rating" REFFIELDS="id"/>
<KEY NAME="previous_user_rating_id" TYPE="foreign" FIELDS="previous_question_rating_id" REFTABLE="capquiz_user_rating" REFFIELDS="id"/>
<KEY NAME="user_previous_rating_id" TYPE="foreign" FIELDS="prev_question_rating_id" REFTABLE="capquiz_user_rating" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="capquiz_question_rating" COMMENT="Stores a rating for a CAPQuiz question.">
Expand Down
39 changes: 31 additions & 8 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function xmldb_capquiz_upgrade($oldversion) {
}
upgrade_mod_savepoint(true, 2019062553, 'capquiz');
}
if ($oldversion < 2019071800) {
if ($oldversion < 2019072500) {
// Define table capquiz_user_rating to be created.
$utable = new xmldb_table('capquiz_user_rating');

Expand Down Expand Up @@ -130,36 +130,59 @@ function xmldb_capquiz_upgrade($oldversion) {
}

$atable = new xmldb_table('capquiz_attempt');

$aqrfield = new xmldb_field(
'question_rating_id', XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aqrkey = new xmldb_key(
'question_rating_id', XMLDB_KEY_FOREIGN, array('question_rating_id'), 'capquiz_question_rating', array('id'));
$aqprevrfield = new xmldb_field(
'question_prev_rating_id',
XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aqprevrkey = new xmldb_key(
'question_prev_rating_id',
XMLDB_KEY_FOREIGN, array('question_prev_rating_id'), 'capquiz_question_rating', array('id'));

$aprevqrfield = new xmldb_field(
'previous_question_rating_id',
'prev_question_rating_id',
XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aprevqrkey = new xmldb_key(
'previous_question_rating_id',
XMLDB_KEY_FOREIGN, array('previous_question_rating_id'), 'capquiz_question_rating', array('id'));
'prev_question_rating_id',
XMLDB_KEY_FOREIGN, array('prev_question_rating_id'), 'capquiz_question_rating', array('id'));

$aprevqprevrfield = new xmldb_field(
'prev_question_prev_rating_id',
XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aprevqprevrkey = new xmldb_key(
'prev_question_prev_rating_id',
XMLDB_KEY_FOREIGN, array('prev_question_prev_rating_id'), 'capquiz_question_rating', array('id'));

if (!$dbman->field_exists($atable, $aqrfield)) {
$dbman->add_field($atable, $aqrfield);
$dbman->add_key($atable, $aqrkey);
}
if (!$dbman->field_exists($atable, $aqprevrfield)) {
$dbman->add_field($atable, $aqprevrfield);
$dbman->add_key($atable, $aqprevrkey);
}
if (!$dbman->field_exists($atable, $aprevqrfield)) {
$dbman->add_field($atable, $aprevqrfield);
$dbman->add_key($atable, $aprevqrkey);
}
if (!$dbman->field_exists($atable, $aprevqprevrfield)) {
$dbman->add_field($atable, $aprevqprevrfield);
$dbman->add_key($atable, $aprevqprevrkey);
}

$aurfield = new xmldb_field(
'user_rating_id', XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aurkey = new xmldb_key(
'user_rating_id', XMLDB_KEY_FOREIGN, array('user_rating_id'), 'capquiz_user_rating', array('id'));
$aprevurfield = new xmldb_field(
'previous_user_rating_id',
'user_prev_rating_id',
XMLDB_TYPE_INTEGER, 11, null, null, null, null);
$aprevurkey = new xmldb_key(
'previous_user_rating_id',
XMLDB_KEY_FOREIGN, array('previous_user_rating_id'), 'capquiz_user_rating', array('id'));
'user_prev_rating_id',
XMLDB_KEY_FOREIGN, array('user_prev_rating_id'), 'capquiz_user_rating', array('id'));

if (!$dbman->field_exists($atable, $aurfield)) {
$dbman->add_field($atable, $aurfield);
Expand All @@ -170,7 +193,7 @@ function xmldb_capquiz_upgrade($oldversion) {
$dbman->add_key($atable, $aprevurkey);
}

upgrade_mod_savepoint(true, 2019071800, 'capquiz');
upgrade_mod_savepoint(true, 2019072500, 'capquiz');
}
return true;
}
8 changes: 8 additions & 0 deletions lang/en/capquiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,11 @@

$string['true'] = 'True';
$string['false'] = 'False';
$string['questionid'] = 'Question id';
$string['moodlequestionid'] = 'Moodle question id';
$string['capquizquestionid'] = 'CAPQuiz question id';
$string['userid'] = 'User id';
$string['timeanswered'] = 'Time answered';
$string['timereviewed'] = 'Time reviewed';
$string['strftimedatetimeseconds'] = '%d %B %Y, %I:%M:%S %p';
$string['reportshowonlyanswered'] = 'Show only answered attempts';
3 changes: 0 additions & 3 deletions report/attempts/attempts_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function validation($data, $files) {

if (!($data['urating']
|| $data['uprevrating']
|| $data['qrating']
|| $data['qprevrating']
|| $data['ansstate']
|| $data['qtext']
Expand All @@ -66,8 +65,6 @@ protected function other_preference_fields(MoodleQuickForm $mform) {
get_string('urating', 'capquizreport_attempts')),
$mform->createElement('advcheckbox', 'uprevrating', '',
get_string('uprevrating', 'capquizreport_attempts')),
$mform->createElement('advcheckbox', 'qrating', '',
get_string('qrating', 'capquizreport_attempts')),
$mform->createElement('advcheckbox', 'qprevrating', '',
get_string('qprevrating', 'capquizreport_attempts')),
$mform->createElement('advcheckbox', 'qtext', '',
Expand Down
12 changes: 1 addition & 11 deletions report/attempts/attempts_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class capquizreport_attempts_options extends capquiz_attempts_report_options {
/** @var bool whether to show the question answer state (correct or wrong) columns. */
public $showansstate = true;

/** @var bool whether to show the question rating columns. */
public $showqrating = true;

/** @var bool whether to show the previous question rating columns. */
public $showqprevrating = true;

Expand All @@ -72,7 +69,6 @@ public function get_initial_form_data() {
$toform->ansstate = $this->showansstate;
$toform->urating = $this->showurating;
$toform->uprevrating = $this->showuprevrating;
$toform->qrating = $this->showqrating;
$toform->qprevrating = $this->showqprevrating;
$toform->qtext = $this->showqtext;
$toform->resp = $this->showresponses;
Expand All @@ -87,7 +83,6 @@ public function setup_from_form_data($fromform) {
$this->showansstate = $fromform->ansstate;
$this->showurating = $fromform->urating;
$this->showuprevrating = $fromform->uprevrating;
$this->showqrating = $fromform->qrating;
$this->showqprevrating = $fromform->qprevrating;
$this->showqtext = $fromform->qtext;
$this->showresponses = $fromform->resp;
Expand All @@ -100,7 +95,6 @@ public function setup_from_params() {
$this->showansstate = optional_param('ansstate', $this->showansstate, PARAM_BOOL);
$this->showurating = optional_param('urating', $this->showurating, PARAM_BOOL);
$this->showuprevrating = optional_param('uprevrating', $this->showuprevrating, PARAM_BOOL);
$this->showqrating = optional_param('qrating', $this->showqrating, PARAM_BOOL);
$this->showqprevrating = optional_param('qprevrating', $this->showqprevrating, PARAM_BOOL);
$this->showqtext = optional_param('qtext', $this->showqtext, PARAM_BOOL);
$this->showresponses = optional_param('resp', $this->showresponses, PARAM_BOOL);
Expand All @@ -113,7 +107,6 @@ public function setup_from_user_preferences() {
$this->showansstate = get_user_preferences('capquizreport_attempts_ansstate', $this->showansstate);
$this->showurating = get_user_preferences('capquizreport_attempts_urating', $this->showurating);
$this->showuprevrating = get_user_preferences('capquizreport_attempts_uprevrating', $this->showuprevrating);
$this->showqrating = get_user_preferences('capquizreport_attempts_qrating', $this->showqrating);
$this->showqprevrating = get_user_preferences('capquizreport_attempts_qprevrating', $this->showqprevrating);
$this->showqtext = get_user_preferences('capquizreport_attempts_qtext', $this->showqtext);
$this->showresponses = get_user_preferences('capquizreport_attempts_resp', $this->showresponses);
Expand All @@ -126,7 +119,6 @@ public function update_user_preferences() {
set_user_preference('capquizreport_attempts_ansstate', $this->showansstate);
set_user_preference('capquizreport_attempts_urating', $this->showurating);
set_user_preference('capquizreport_attempts_uprevrating', $this->showuprevrating);
set_user_preference('capquizreport_attempts_qrating', $this->showqrating);
set_user_preference('capquizreport_attempts_qprevrating', $this->showqprevrating);
set_user_preference('capquizreport_attempts_qtext', $this->showqtext);
set_user_preference('capquizreport_attempts_resp', $this->showresponses);
Expand All @@ -139,15 +131,14 @@ public function resolve_dependencies() {
if (!$this->showansstate
&& !$this->showurating
&& !$this->showuprevrating
&& !$this->showqrating
&& !$this->showqprevrating
&& !$this->showqtext
&& !$this->showresponses
&& !$this->showright) {
// We have to show at least something.
$this->showansstate = true;
$this->showurating = true;
$this->showqrating = true;
$this->showqprevrating = true;
}

// We only want to show the checkbox to delete attempts
Expand All @@ -161,7 +152,6 @@ protected function get_url_params() {
$params['ansstate'] = $this->showansstate;
$params['urating'] = $this->showurating;
$params['uprevrating'] = $this->showuprevrating;
$params['qrating'] = $this->showqrating;
$params['qprevrating'] = $this->showqprevrating;
$params['qtext'] = $this->showqtext;
$params['resp'] = $this->showresponses;
Expand Down
Loading