Skip to content

Commit

Permalink
Qbank_questiontoactivity: Initial plugin release
Browse files Browse the repository at this point in the history
This commit implements the first initial release of
the qbank question to activity plugin.
  • Loading branch information
3ark91 authored and safatshahin committed Jan 31, 2023
1 parent f1fa4ec commit a9af26e
Show file tree
Hide file tree
Showing 15 changed files with 880 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
phpunit.xml
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Question to activity - A Moodle Question Bank Plugin

## Description
Question to activity (qtoactivity) is a plugin for the Moodle LMS that extends the functionality of the question bank question management page.
This plugin adds the option for users to select individual or multiple questions and add them right to an activity of their choosing, without having to access that individual activities management page.

---

## Installation instructions
_Follow these steps to install Question to activity:_
1. Download the plugin to the ___{moodle directory}/question/bank/___ directory as a new folder called ___qtoactivity___. This can be done in either of the following ways:
- With Git from within the _/question/bank_ directory, running the following command:
```
git clone https://github.com/safatshahin/moodle-qbank_qtoactivity
```
- Or by downloading the code manually from https://github.com/safatshahin/moodle-qbank_qtoactivity and extracting it to the _question/bank/qtoactivity_ directory.
2. Access the Admin Dashboard from your Moodle site to automatically trigger the install, or use the cli.
---
## Usage
To use the plugin, simply navigate to the question bank question management page and do either of the following:
### Individual questions
- You can choose to add a single question to an activity by selecting the __Add to module__ option from the actions column. Follow the on-screen instructions to select the activity to add the question to.
### Multiple questions
- You can choose to add multiple questions to an activity by first selecting the check boxes of the questions you wish to add, and then choosing the __Add to module__ option from the bulk actions drop down beneath the list of questions. Follow the on-screen instructions to select the activity to add the questions to.
---
<br />
# Credits and thanks
## Project information
This project was initially started as part of a student project collaboration with Catalyst IT Australia and University of New England.
The main goal of this project was to help students prepare for the industry by having a mentor from the host company, coming up with a project idea
and finally create an mvp of the idea using industry approach and methodologies. This project was a huge success where all the students were able to
learn and develop an mvp of the qbank plugin and showcase their work to the university.
Project manager:
- A K M Safat Shahin - safatshahin@yahoo.com
Team members from University of new England:
- Mark Hay - mhay23@myune.edu.au
- Henry Campbell - hcampb25@myune.edu.au
- Luke Purnell - lpurnell@myune.edu.au
- Harrison Liddell - hliddell@myune.edu.au
## Project enhancement
The initial product was done in a short timeframe and proved that the idea is possible and students gained a real experience of the industry.
To make this project usable and available to the community, a lot of work needed to be done on top of the great work from the students.
The current phase took advantage of the initial development, polished the code and changed it to allow a better future and follow the proper
moodle way of doing plugins.
---
107 changes: 107 additions & 0 deletions addtoactivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Add to activity page.
*
* @package qbank_qtoactivity
* @copyright 2023 Safat Shahin <safatshahin@yahoo.com>
* @author Luke Purnel, Henry Campbell, Mark Hay, Harrison Liddell
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

global $CFG, $OUTPUT, $PAGE, $COURSE;

require_once(__DIR__ . '/../../../config.php');
require_once($CFG->dirroot . '/question/editlib.php');

$addtomoduleselected = optional_param('addtomoduleselected', false, PARAM_BOOL);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
$confirm = optional_param('confirm', '', PARAM_ALPHANUM);
$addtomodule = optional_param('addtomodule', null, PARAM_INT);
$addtomodulesquestions = optional_param('addtomodulesquestions', null, PARAM_RAW);

if ($returnurl) {
$returnurl = new moodle_url($returnurl);
}

// Check if plugin is enabled or not.
\core_question\local\bank\helper::require_plugin_enabled('qbank_qtoactivity');

if ($cmid) {
list($module, $cm) = get_module_from_cmid($cmid);
require_login($cm->course, false, $cm);
$thiscontext = context_module::instance($cmid);
$modules = \qbank_qtoactivity\helper::get_module($cmid);
} else if ($courseid) {
require_login($courseid, false);
$thiscontext = context_course::instance($courseid);
$modules = \qbank_qtoactivity\helper::get_modules_for_course($courseid);
} else {
throw new moodle_exception('missingcourseorcmid', 'question');
}

$contexts = new core_question\local\bank\question_edit_contexts($thiscontext);
$url = new moodle_url('/question/bank/qtoactivity/addtoactivity.php');
$title = get_string('addtomodule', 'qbank_qtoactivity');

// Context and page setup.
$PAGE->set_url($url);
$PAGE->set_title($title);
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_pagelayout('standard');
$PAGE->activityheader->disable();
$PAGE->set_secondary_active_tab("questionbank");



if ($addtomodulesquestions && $confirm && confirm_sesskey()) {
if ($confirm == md5($addtomodulesquestions)) {
\qbank_qtoactivity\helper::add_to_module($addtomodulesquestions, $addtomodule);
}
redirect($returnurl);
}

// Show the header.
echo $OUTPUT->header();



if ($addtomoduleselected) {
$rawquestions = $_REQUEST;
list($questionids, $questionlist) = \qbank_qtoactivity\helper::process_question_ids($rawquestions);
// No questions were selected.
if (!$questionids) {
redirect($returnurl);
}
// Create the urls.
$addtomoduleparams = [
'addtomodulesquestions' => $questionlist,
'confirm' => md5($questionlist),
'sesskey' => sesskey(),
'returnurl' => $returnurl,
'cmid' => $cmid,
'courseid' => $courseid,
];
$addtomoduleurl = new \moodle_url($url, $addtomoduleparams);
echo $PAGE->get_renderer('qbank_qtoactivity')
->render_add_to_module_form($addtomoduleurl, $returnurl, $modules);
}

// Show the footer.
echo $OUTPUT->footer();
66 changes: 66 additions & 0 deletions classes/add_action_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace qbank_qtoactivity;

use core_question\local\bank\menu_action_column_base;

/**
* Adds a single action titled 'Add to Quiz' to the actions menu.
*
* @package qbank_qtoactivity
* @copyright 2023 Safat Shahin <safatshahin@yahoo.com>
* @author Luke Purnel, Henry Campbell, Mark Hay, Harrison Liddell
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class add_action_column extends menu_action_column_base {

/**
* Array of the return parameters.
* @var array $returnparams
*/
protected $returnparams;

public function init(): void {
parent::init();
if (!empty($this->qbank->cm->id)) {
$this->returnparams['cmid'] = $this->qbank->cm->id;
}
if (!empty($this->qbank->course->id)) {
$this->returnparams['courseid'] = $this->qbank->course->id;
}
if (!empty($this->qbank->returnurl)) {
$this->returnparams['returnurl'] = $this->qbank->returnurl;
}
}

public function get_name(): string {
return 'addtomoduleaction';
}

protected function get_url_icon_and_label(\stdClass $question): array {
$params = [
'addtomoduleselected' => $question->id,
'q' . $question->id => 1,
'sesskey' => sesskey()
];
$addtomoduleparams = array_merge($params, $this->returnparams);
$url = new \moodle_url('/question/bank/qtoactivity/addtoactivity.php', $addtomoduleparams);

return [$url, 't/add', get_string('addtomodule', 'qbank_qtoactivity')];
}

}
46 changes: 46 additions & 0 deletions classes/bulk_add_action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace qbank_qtoactivity;

/**
* Class for 'Add to activity' bulk action.
*
* @package qbank_qtoactivity
* @copyright 2023 Safat Shahin <safatshahin@yahoo.com>
* @author Luke Purnel, Henry Campbell, Mark Hay, Harrison Liddell
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class bulk_add_action extends \core_question\local\bank\bulk_action_base {

public function get_bulk_action_title(): string {
return get_string('addtomodule', 'qbank_qtoactivity');
}

public function get_bulk_action_url(): \moodle_url {
return new \moodle_url('/question/bank/qtoactivity/addtoactivity.php');
}

public function get_bulk_action_capabilities(): ?array {
return [
'moodle/question:editall',
];
}

public function get_key(): string {
return 'addtomoduleselected';
}
}
Loading

0 comments on commit a9af26e

Please sign in to comment.