Skip to content

Commit

Permalink
privacy api implemented, cache query
Browse files Browse the repository at this point in the history
  • Loading branch information
CustomAP committed May 7, 2019
1 parent a05abd8 commit 17a4088
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 71 deletions.
68 changes: 33 additions & 35 deletions block_export_quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,30 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__.'/../../config.php');
require_once('export_quiz_form.php');
defined('MOODLE_INTERNAL') || die();

require_once('block_export_quiz_form.php');

class block_export_quiz extends block_base{

/**
/**
* Initialise the block.
*/
public function init() {
$this->title = get_string('pluginname', 'block_export_quiz');
}

/**
* Should be only visible in a particular course and in the quiz modules
* Should be only visible in a particular course and in the quiz modules
*/
public function applicable_formats() {
return array ('course-view' => true, 'mod-quiz' => true);
}
return array ('course-view' => true, 'mod-quiz' => true);
}


public function get_content_type() {
return BLOCK_TYPE_TEXT;
}
public function get_content_type() {
return BLOCK_TYPE_TEXT;
}

/**
* Return the content of this block.
Expand All @@ -64,33 +65,30 @@ public function get_content() {
$courseid = $this->page->course->id;

$quiztags = array();

/**
* Adding quiz names and corresponding urls created in $quiztags array
* Adding quiz names and corresponding urls created in $quiztags array
*/
if ($quizes = $DB->get_records('quiz', array('course' => $courseid))) {
foreach ($quizes as $quiz) {

/**
* Check if the Quiz is visible to the user only then display it :
* Teacher can choose to hide the quiz from the students in that case it should not be visible to students
*/
$modinfo = get_fast_modinfo($this->page->course);
$cm = $modinfo->get_cm($DB->get_record('course_modules', array('module' => 16, 'instance' => $quiz->id))->id);
if(!$cm->uservisible)
continue;

$pageurl = new moodle_url('/blocks/export_quiz/export.php',
array('courseid' => $COURSE->id,
'id' => $quiz->id,
'sesskey' => $_SESSION['USER']->sesskey));

$quiztags[(string)$pageurl] = $quiz->name;
}
}

$quizes = get_fast_modinfo($this->page->course)->instances['quiz'];
foreach ($quizes as $quiz) {

/**
* Check if the Quiz is visible to the user only then display it :
* Teacher can choose to hide the quiz from the students in that case it should not be visible to students
*/
if(!$quiz->uservisible)
continue;

$pageurl = new moodle_url('/blocks/export_quiz/export.php',
array('courseid' => $COURSE->id,
'id' => $quiz->id,
'sesskey' => $_SESSION['USER']->sesskey));

$quiztags[(string)$pageurl] = $quiz->name;
}

// Export form
$export_quiz_form = new export_quiz_form((string)$this->page->url, array('quiz' => $quiztags));
$export_quiz_form = new block_export_quiz_form((string)$this->page->url, array('quiz' => $quiztags));

$export_quiz_form->set_data('');

Expand All @@ -107,6 +105,6 @@ public function get_content() {
}
}

return $this->content;
return $this->content;
}
}
}
38 changes: 19 additions & 19 deletions export_quiz_form.php → block_export_quiz_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@
* Form to export questions from the quiz.
*
* @copyright 2019 onwards Ashish Pawar (github : CustomAP)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

class export_quiz_form extends moodleform {
class block_export_quiz_form extends moodleform {

function definition(){
$mform = $this->_form;
function definition(){
$mform = $this->_form;

$quizes = $this->_customdata['quiz'];
$format = get_import_export_formats('export');
$quizes = $this->_customdata['quiz'];
$format = get_import_export_formats('export');

$formats = array();
$formats = array();

foreach ($format as $shortname => $fileformatname){
$formats[$shortname] = $fileformatname;
}
foreach ($format as $shortname => $fileformatname) {
$formats[$shortname] = $fileformatname;
}

// Quiz select
$mform->addElement('select', 'quiz', get_string('quiz', 'block_export_quiz'),
$quizes);
// Quiz select.
$mform->addElement('select', 'quiz', get_string('quiz', 'block_export_quiz'),
$quizes);

// Format select
$mform->addElement('select', 'format', get_string('format', 'block_export_quiz'),
$formats);
// Format select.
$mform->addElement('select', 'format', get_string('format', 'block_export_quiz'),
$formats);

// Submit buttons.
// Submit buttons.
$this->add_action_buttons(false, get_string('export', 'block_export_quiz'));
}
}
}
}
47 changes: 47 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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/>.

/**
* Privacy Subsystem implementation for block_export_quiz.
*
* @package block_export_quiz
* @copyright 2019 onwards Ashish Pawar (github : CustomAP)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace block_export_quiz\privacy;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy Subsystem implementation for block_export_quiz.
*
* @package block_export_quiz
* @copyright 2019 onwards Ashish Pawar (github : CustomAP)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
11 changes: 6 additions & 5 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

defined('MOODLE_INTERNAL') || die();

$capabilities = array(

'block/export_quiz:myaddinstance' => array(
Expand All @@ -32,20 +32,21 @@
'archetypes' => array(
'user' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/my:manageblocks'
),



'block/export_quiz:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),

'clonepermissionsfrom' => 'moodle/site:manageblocks'
)
);
16 changes: 7 additions & 9 deletions export.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,36 @@
print_error('missingcourseorcmid', 'question');
}

require_sesskey();
require_sesskey();

// Load the necessary data.
$contexts = new question_edit_contexts($thiscontext);
$questiondata = array();
if ($questions = $DB->get_records('quiz_slots', array('quizid' => $quizid))) {
foreach ($questions as $question) {
array_push($questiondata, question_bank::load_question_data($question->questionid));
}
}
}

/**
* Check if the Quiz is visible to the user only then display it :
* Check if the Quiz is visible to the user only then display it :
* Teacher can choose to hide the quiz from the students in that case it should not be visible to students
*/
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($DB->get_record('course_modules', array('module' => 16, 'instance' => $quizid))->id);
if(!$cm->uservisible)
print_error('noaccess', 'block_export_quiz');


// Initialise $PAGE.
$nexturl = new moodle_url('/question/type/stack/questiontestrun.php', $urlparams);
$PAGE->set_url('/blocks/export_quiz/export.php', $urlparams);
$PAGE->set_heading(get_string('pluginname','block_export_quiz'));
$PAGE->set_pagelayout('admin');

// Check if the question format is readable, if yes import it : This way support is added for any third-party question format installed
// Check if the question format is readable, if yes import it : This way support is added for any third-party question format installed.
if (!is_readable($CFG->dirroot . "/question/format/{$format}/format.php")) {
print_error('unknowformat', '', '', $format);
} else{
} else {
require_once($CFG->dirroot . "/question/format/{$format}/format.php");
}

Expand All @@ -82,16 +81,15 @@
$qformat->setContexttofile(false);
$qformat->setQuestions($questiondata);

// Get quiz name to assign it to file name used for exporting
// Get quiz name to assign it to file name used for exporting.
$filename = get_string('quiz', 'block_export_quiz').
$qformat->export_file_extension();

if ($quiz = $DB->get_record('quiz', array('id' => $quizid))) {
$filename = $quiz->name;
}


// Pre-processing the export
// Pre-processing the export.
if (!$qformat->exportpreprocess()) {
send_file_not_found();
}
Expand Down
5 changes: 2 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2019032000; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2019050500; // The current plugin version (Date: YYYYMMDDXX)
$plugin->maturity = MATURITY_STABLE; // Maturity level.
$plugin->requires = 2011070100.03; // Requires this Moodle version
$plugin->component = 'block_export_quiz'; // Full name of the plugin (used for diagnostics)
$plugin->release = '1.0.0 (Build: 2019032000)'; // The current module release in human-readable form (x.y).

$plugin->release = '1.0.2 (Build: 2019050500)'; // The current module release in human-readable form (x.y).

0 comments on commit 17a4088

Please sign in to comment.