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/report #136

Merged
merged 25 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42f51ce
Add capquiz_question_rating table and capquiz_user_rating table
andstor Jul 4, 2019
bd7f035
Add upgrade-scripts for the capquiz_user_rating table and capquiz_que…
andstor Jul 4, 2019
ffdbb3c
Add capquiz_user_rating class for representing a capquiz_user_rating …
andstor Jul 4, 2019
6b5d0d2
Add capquiz_question_rating class for representing a capquiz_question…
andstor Jul 4, 2019
e099259
Implement the capquiz_question_rating class
andstor Jul 4, 2019
c9e94f4
Implement the capquiz_user_rating class
andstor Jul 4, 2019
aa1eebc
Add current "new" and old question and user ratings fields to the ca…
andstor Jul 18, 2019
1fa132b
Update capquiz_question_rating and capquiz_user_rating tables
andstor Jul 18, 2019
64f80ee
Update db upgrade file
andstor Jul 18, 2019
141d311
Update the implementation of the capquiz_question_rating and the capq…
andstor Jul 18, 2019
cba33b7
Update the implementation of the capquiz_user_rating and the capquiz_…
andstor Jul 18, 2019
6fa2444
Create CAPQuiz exception class
andstor Jul 18, 2019
2d7eb69
Add view for CAPQuiz reports
andstor Jul 18, 2019
3b33bc2
Add framework for CAPQuiz report sub-pluigins
andstor Jul 18, 2019
531e8ad
Add capabilities: view_report, delete_attempts and manage
andstor Jul 18, 2019
7e4d810
Allow subplugins to be uninstalled
andstor Jul 18, 2019
77b1768
Add attemptsreport files to be extended by report sub-plugins
andstor Jul 18, 2019
012358c
Add "Attempts" capquizreport sub-plugin
andstor Jul 18, 2019
652d3e0
Update backup and restore to conform with the new report sub-plugin r…
andstor Jul 18, 2019
df86634
Update the Privacy API to conform with the new report sub-plugin rela…
andstor Jul 18, 2019
ce71f37
Add new language strings
andstor Jul 18, 2019
f095051
Correct field names in upgrade script
andstor Jul 18, 2019
6d87bc8
Show attempts without ratings in capquizreport_attempts sub-plugin
andstor Jul 18, 2019
574808e
Comply with Moodle coding styles
andstor Jul 18, 2019
1c1d8d9
Fix minor coding style errors
andstor Jul 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions backup/moodle2/backup_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ protected function define_structure() {
$question = new backup_nested_element('question', ['id'], [
'question_id', 'question_list_id', 'rating'
]);
$questionratings = new backup_nested_element('questionratings');
$questionrating = new backup_nested_element('question_rating', ['id'], [
'capquiz_question_id', 'rating', 'manual', 'timecreated'
]);
$questionselections = new backup_nested_element('questionselections');
$questionselection = new backup_nested_element('questionselection', ['id'], [
'capquiz_id', 'strategy', 'configuration'
Expand All @@ -46,32 +50,46 @@ protected function define_structure() {
$user = new backup_nested_element('user', ['id'], [
'user_id', 'capquiz_id', 'rating', 'highest_level'
]);
$userratings = new backup_nested_element('userratings');
$userrating = new backup_nested_element('user_rating', ['id'], [
'capquiz_user_id', 'rating', 'manual', 'timecreated'
]);
$attempts = new backup_nested_element('attempts');
$attempt = new backup_nested_element('attempt', ['id'], [
'slot', 'user_id', 'question_id', 'reviewed', 'answered', 'time_answered', 'time_reviewed', 'feedback'
'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'
]);

// Build the tree.
$capquiz->add_child($users);
$users->add_child($user);
$user->add_child($attempts);
$attempts->add_child($attempt);
$capquiz->add_child($questionlist);
$questionlist->add_child($questions);
$questions->add_child($question);
$question->add_child($questionratings);
$questionratings->add_child($questionrating);

$capquiz->add_child($questionselections);
$questionselections->add_child($questionselection);

$capquiz->add_child($ratingsystems);
$ratingsystems->add_child($ratingsystem);
$capquiz->add_child($questionlist);
$questionlist->add_child($questions);
$questions->add_child($question);

$capquiz->add_child($users);
$users->add_child($user);
$user->add_child($userratings);
$userratings->add_child($userrating);
$user->add_child($attempts);
$attempts->add_child($attempt);

// Define sources.
$capquiz->set_source_table('capquiz', ['id' => backup::VAR_ACTIVITYID]);
$questionlist->set_source_table('capquiz_question_list', ['capquiz_id' => backup::VAR_PARENTID]);
$question->set_source_table('capquiz_question', ['question_list_id' => backup::VAR_PARENTID]);
$questionrating->set_source_table('capquiz_question_rating', ['capquiz_question_id' => backup::VAR_PARENTID]);
$questionselection->set_source_table('capquiz_question_selection', ['capquiz_id' => backup::VAR_PARENTID]);
$ratingsystem->set_source_table('capquiz_rating_system', ['capquiz_id' => backup::VAR_PARENTID]);
if ($this->get_setting_value('userinfo')) {
$user->set_source_table('capquiz_user', ['capquiz_id' => backup::VAR_PARENTID]);
$userrating->set_source_table('capquiz_user_rating', ['capquiz_user_id' => backup::VAR_PARENTID]);
$attempt->set_source_table('capquiz_attempt', ['user_id' => backup::VAR_PARENTID]);
}

Expand Down
26 changes: 26 additions & 0 deletions backup/moodle2/restore_capquiz_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ protected function define_structure() {
$this->add_question_usages($questionlist, $paths);
$paths[] = $questionlist;
$paths[] = new restore_path_element('capquiz_question', '/activity/capquiz/questionlist/questions/question');
$paths[] = new restore_path_element(
'capquiz_question_rating', '/activity/capquiz/questionlist/questions/question/questionratings/question_rating');
$paths[] = new restore_path_element('capquiz_question_selection', '/activity/capquiz/questionselections/questionselection');
$paths[] = new restore_path_element('capquiz_rating_system', '/activity/capquiz/ratingsystems/ratingsystem');
if ($this->get_setting_value('userinfo')) {
$paths[] = new restore_path_element('capquiz_user', '/activity/capquiz/users/user');
$paths[] = new restore_path_element('capquiz_user_rating', '/activity/capquiz/users/user/userratings/user_rating');
$paths[] = new restore_path_element('capquiz_attempt', '/activity/capquiz/users/user/attempts/attempt');
}
return $this->prepare_activity_structure($paths);
Expand Down Expand Up @@ -71,6 +74,15 @@ protected function process_capquiz_question($data) {
$this->set_mapping('capquiz_question', $oldid, $newitemid);
}

protected function process_capquiz_question_rating($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->capquiz_question_id = $this->get_new_parentid('capquiz_question');
$newitemid = $DB->insert_record('capquiz_question_rating', $data);
$this->set_mapping('capquiz_question_rating', $oldid, $newitemid);
}

protected function process_capquiz_question_selection($data) {
global $DB;
$data = (object)$data;
Expand All @@ -97,6 +109,16 @@ protected function process_capquiz_user($data) {
$data->capquiz_id = $this->get_new_parentid('capquiz');
$newitemid = $DB->insert_record('capquiz_user', $data);
$this->set_mapping('capquiz_user', $oldid, $newitemid);

}

protected function process_capquiz_user_rating($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->capquiz_user_id = $this->get_new_parentid('capquiz_user');
$newitemid = $DB->insert_record('capquiz_user_rating', $data);
$this->set_mapping('capquiz_user_rating', $oldid, $newitemid);
}

protected function process_capquiz_attempt($data) {
Expand All @@ -105,6 +127,10 @@ protected function process_capquiz_attempt($data) {
$oldid = $data->id;
$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->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);
$newitemid = $DB->insert_record('capquiz_attempt', $data);
$this->set_mapping('capquiz_attempt', $oldid, $newitemid);
}
Expand Down
4 changes: 4 additions & 0 deletions classes/capquiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function id() : int {
return $this->record->id;
}

public function name() : string {
return $this->record->name;
}

public function is_published() : bool {
return $this->record->published;
}
Expand Down
5 changes: 3 additions & 2 deletions classes/capquiz_action_performer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function set_question_rating(capquiz $capquiz) {
}
$rating = optional_param('rating', null, PARAM_FLOAT);
if ($rating !== null) {
$question->set_rating($rating);
$question->set_rating($rating, true);
}
capquiz_urls::redirect_to_url(capquiz_urls::view_question_list_url());
}
Expand Down Expand Up @@ -154,7 +154,8 @@ private static function create_capquiz_question(int $questionid, capquiz_questio
$ratedquestion->question_list_id = $list->id();
$ratedquestion->question_id = $questionid;
$ratedquestion->rating = $rating;
$DB->insert_record('capquiz_question', $ratedquestion);
$capquizquestionid = $DB->insert_record('capquiz_question', $ratedquestion, true);
capquiz_question_rating::insert_question_rating_entry($capquizquestionid, $rating);
}

private static function remove_capquiz_question(int $questionid, int $qlistid) {
Expand Down
21 changes: 19 additions & 2 deletions classes/capquiz_question.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class capquiz_question {
/** @var \stdClass $record */
private $record;

/** @var capquiz_question_rating $rating */
private $rating;

public function __construct(\stdClass $record) {
global $DB;
$this->record = $record;
Expand All @@ -42,6 +45,12 @@ public function __construct(\stdClass $record) {
$this->record->name = get_string('missing_question', 'capquiz');
$this->record->text = $this->record->name;
}
$rating = capquiz_question_rating::latest_question_rating_by_question($record->id);
if (is_null($rating)) {
$this->rating = capquiz_question_rating::insert_question_rating_entry($this->id(), $this->rating());
} else {
$this->rating = $rating;
}
}

public static function load(int $questionid) {
Expand Down Expand Up @@ -73,10 +82,18 @@ public function rating() : float {
return $this->record->rating;
}

public function set_rating(float $rating) : bool {
public function get_capquiz_question_rating() : capquiz_question_rating {
return $this->rating;
}

public function set_rating($rating, bool $manual = false) {
global $DB;
$this->record->rating = $rating;
return $DB->update_record('capquiz_question', $this->record);
$DB->update_record('capquiz_question', $this->record);

$questionrating = capquiz_question_rating::create_question_rating($this, $rating, $manual);
$this->rating = $questionrating;

}

public function name() : string {
Expand Down
25 changes: 25 additions & 0 deletions classes/capquiz_question_attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public function is_correctly_answered() : bool {
return $moodleattempt->get_state()->is_correct();
}

public function get_state() : bool {
$moodleattempt = $this->quba->get_question_attempt($this->question_slot());
return $moodleattempt->get_state();
}

public function is_reviewed() : bool {
return $this->record->reviewed;
}
Expand Down Expand Up @@ -215,6 +220,26 @@ public function update_student_comment(string $feedback) {
$DB->update_record('capquiz_attempt', $this->record);
}

public function set_question_rating(capquiz_question_rating $rating, $previous = false) {
global $DB;
if (!$previous) {
$this->record->question_rating_id = $rating->id();
} else {
$this->record->previous_question_rating_id = $rating->id();
}
$DB->update_record('capquiz_attempt', $this->record);
}

public function set_user_rating(capquiz_user_rating $rating, $previous = false) {
global $DB;
if (!$previous) {
$this->record->user_rating_id = $rating->id();
} else {
$this->record->previous_user_rating_id = $rating->id();
}
$DB->update_record('capquiz_attempt', $this->record);
}

/**
* @param int $questionid
* @return array
Expand Down
7 changes: 7 additions & 0 deletions classes/capquiz_question_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public function attempt_answered(capquiz_user $user, capquiz_question_attempt $a
}
$ratingsystem = $this->ratingsystemloader->rating_system();
$attempt->mark_as_answered();
$attempt->set_user_rating($user->get_capquiz_user_rating(), true);
$question = $this->capquiz->question_list()->question($attempt->question_id());
if ($attempt->is_correctly_answered()) {
$ratingsystem->update_user_rating($user, $question, 1);
$this->set_new_highest_star_if_attained($user);
} else {
$ratingsystem->update_user_rating($user, $question, 0);
}
$attempt->set_user_rating($user->get_capquiz_user_rating());
$previousattempt = capquiz_question_attempt::previous_attempt($this->capquiz, $user);
if ($previousattempt) {
$this->update_question_rating($previousattempt, $attempt);
Expand Down Expand Up @@ -127,6 +129,9 @@ private function update_question_rating(capquiz_question_attempt $previous, capq
$previouscorrect = $previous->is_correctly_answered();
$currentquestion = $this->capquiz->question_list()->question($current->question_id());
$previousquestion = $this->capquiz->question_list()->question($previous->question_id());

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

if (!$currentquestion || !$previousquestion) {
return;
}
Expand All @@ -135,6 +140,8 @@ private function update_question_rating(capquiz_question_attempt $previous, capq
} else if (!$previouscorrect && $currentcorrect) {
$ratingsystem->question_victory_ratings($previousquestion, $currentquestion);
}

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

}
6 changes: 4 additions & 2 deletions classes/capquiz_question_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public function merge(capquiz_question_list $that) {
$newquestion->question_list_id = $this->id();
$newquestion->question_id = $question->question_id();
$newquestion->rating = $question->rating();
$DB->insert_record('capquiz_question', $newquestion);
$capquizquestionid = $DB->insert_record('capquiz_question', $newquestion, true);
capquiz_question_rating::insert_question_rating_entry($capquizquestionid, $newquestion->rating);
}
}
}
Expand Down Expand Up @@ -230,7 +231,8 @@ private function copy_questions_to_list(int $qlistid) {
$record = $question->entry();
$record->id = null;
$record->question_list_id = $qlistid;
$DB->insert_record('capquiz_question', $record);
$capquizquestionid = $DB->insert_record('capquiz_question', $record, true);
capquiz_question_rating::insert_question_rating_entry($capquizquestionid, $record->rating);
}
}

Expand Down
Loading