-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
129 changed files
with
3,385 additions
and
9,536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.