Skip to content

Commit

Permalink
#222 #234 DRAFT - Refactoring to simplify codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastsg committed Oct 22, 2024
1 parent 2b45097 commit 30e7712
Show file tree
Hide file tree
Showing 129 changed files with 3,385 additions and 9,536 deletions.
89 changes: 78 additions & 11 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,96 @@
* Performs actions on the capquiz
*
* @package mod_capquiz
* @author Sebastian Gundersen <[email protected]>
* @author Aleksander Skrede <[email protected]>
* @copyright 2018 NTNU
* @copyright 2024 Norwegian University of Science and Technology (NTNU)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_capquiz;
use mod_capquiz\api;
use mod_capquiz\capquiz;
use mod_capquiz\capquiz_question;
use mod_capquiz\capquiz_question_list;

require_once ("../../config.php");

global $CFG, $DB, $PAGE;

require_once("../../config.php");
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/mod/capquiz/lib.php');
require_once($CFG->dirroot . '/mod/capquiz/classes/capquiz_action_performer.php');

$cmid = capquiz_urls::require_course_module_id_param();
$cmid = required_param('id', PARAM_INT);
$cm = get_coursemodule_from_id('capquiz', $cmid, 0, false, MUST_EXIST);
require_login($cm->course, false, $cm);

$context = \context_module::instance($cmid);
$context = context_module::instance($cmid);
require_capability('mod/capquiz:instructor', $context);

$action = required_param('action', PARAM_TEXT);

$capquiz = new capquiz($cmid);
capquiz_urls::set_page_url($capquiz, capquiz_urls::$urlasync);
capquiz_action_performer::perform($action, $capquiz);
$PAGE->set_context($context);
$PAGE->set_cm($cm);
$PAGE->set_url(new moodle_url('/mod/capquiz/action.php'));

$capquiz = new capquiz($cm->instance);

switch ($action) {
case 'remove-question':
$questionid = required_param('questionid', PARAM_INT);
$qlist = capquiz_question_list::get_record(['capquiz_id' => $capquiz->get('id')]);
if ($qlist) {
$DB->delete_records('capquiz_question', ['id' => $questionid, 'question_list_id' => $qlist->get('id')]);
}
exit;

case 'publish-question-list':
$qlist = capquiz_question_list::get_record(['capquiz_id' => $capquiz->get('id')]);
if (capquiz_question::count_records(['question_list_id' => $qlist->get('id')])) {
$capquiz->set('published', 1);
$capquiz->save();
}
break;

case 'set-question-list':
$qlistid = required_param('question-list-id', PARAM_INT);
api::copy_question_list($qlistid, $capquiz->get('id'));
break;

case 'create-question-list-template':
$qlist = capquiz_question_list::get_record(['capquiz_id' => $capquiz->get('id')]);
api::copy_question_list($qlist->get('id'), null);
break;

case 'merge_qlist':
$sourceqlistid = required_param('qlistid', PARAM_INT);
$qlist = capquiz_question_list::get_record(['capquiz_id' => $capquiz->get('id')]);
foreach (capquiz_question::get_records(['question_list_id' => $sourceqlistid]) as $sourcequestion) {
$existingquestion = capquiz_question::get_record([
'question_list_id' => $qlist->get('id'),
'question_id' => $sourcequestion->get('question_id'),
]);
if (!$existingquestion) {
$question = new capquiz_question();
$question->set('question_list_id', $qlist->get('id'));
$question->set('question_id', $sourcequestion->get('question_id'));
$question->save();
api::set_question_rating($question->get('id'), $sourcequestion->get('rating'), false);
}
}
redirect(new moodle_url('/mod/capquiz/view.php', ['id' => $PAGE->cm->id, 'page' => 'questions']));
break;

case 'delete_qlist':
$srcqlistid = required_param('qlistid', PARAM_INT);
$DB->delete_records('capquiz_question', ['question_list_id' => $srcqlistid]);
$DB->delete_records('capquiz_question_list', ['id' => $srcqlistid]);
break;

case 'regrade-all':
capquiz_update_grades($capquiz->to_record());
break;

default:
break;
}

capquiz_urls::redirect_to_dashboard();
redirect(new moodle_url('/mod/capquiz/view.php', ['id' => $cmid]));
1 change: 0 additions & 1 deletion adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function search($query): array {
}
}


/**
* Class that handles the display and configuration of the list of capquiz plugins.
*
Expand Down
2 changes: 2 additions & 0 deletions adminmanageplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

require_once("../../config.php");

global $CFG, $PAGE;

require_login();

require_once($CFG->dirroot . '/mod/capquiz/adminlib.php');
Expand Down
9 changes: 0 additions & 9 deletions amd/build/attempt.min.js

This file was deleted.

1 change: 0 additions & 1 deletion amd/build/attempt.min.js.map

This file was deleted.

8 changes: 1 addition & 7 deletions amd/build/edit_questions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 30e7712

Please sign in to comment.