Skip to content

Commit

Permalink
Merge pull request #43 from sbourget/ACTIVITY_COMPLETION_GDPR
Browse files Browse the repository at this point in the history
Activity completion support, improved scoring and logging with GDPR support
  • Loading branch information
xow authored Jun 25, 2018
2 parents aa904ca + 58b2317 commit 6476202
Show file tree
Hide file tree
Showing 31 changed files with 1,811 additions and 43 deletions.
19 changes: 14 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
language: php

sudo: true
sudo: false

addons:
firefox: "47.0.1"
postgresql: "9.3"
apt:
packages:
- oracle-java8-installer
- oracle-java8-set-default

cache:
directories:
- $HOME/.composer/cache
- $HOME/.npm

php:
- 7.0
Expand All @@ -24,7 +33,7 @@ before_install:
- nvm use 8.9
- cd ../..
- composer selfupdate
- composer create-project -n --no-dev moodlerooms/moodle-plugin-ci ci ^1
- composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2
- export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH"

install:
Expand All @@ -35,10 +44,10 @@ script:
- moodle-plugin-ci phpcpd
- moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
- moodle-plugin-ci csslint
- moodle-plugin-ci shifter
- moodle-plugin-ci jshint
- moodle-plugin-ci validate
- moodle-plugin-ci savepoints
- moodle-plugin-ci mustache
- moodle-plugin-ci grunt
- moodle-plugin-ci phpunit
- moodle-plugin-ci behat

2 changes: 1 addition & 1 deletion amd/build/quizgame.min.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions amd/src/quizgame.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
* @copyright 2016 John Okely <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($) {
define(['jquery','core/yui', 'core/notification', 'core/ajax'], function($, Y, notification, ajax) {
var questions;
var quizgame;
var stage;
var score = 0;
var particles = [];
Expand Down Expand Up @@ -171,6 +172,11 @@ define(['jquery'], function($) {
}

function endGame() {
ajax.call([{
methodname: 'mod_quizgame_update_score',
args: {quizgameid: quizgame, score: Math.trunc(score)},
fail: notification.exception
}]);
menuEvents();
}

Expand All @@ -196,6 +202,13 @@ define(['jquery'], function($) {
touchDown = false;
mouseDown = false;

// Queue & trigger the game_started event.
ajax.call([{
methodname: 'mod_quizgame_start_game',
args: {quizgameid: quizgame},
fail: notification.exception
}]);

player = new Player("pix/ship.png", 0, 0);
player.x = displayRect.width / 2;
player.y = displayRect.height / 2;
Expand Down Expand Up @@ -858,8 +871,9 @@ define(['jquery'], function($) {
return array;
}

function doInitialize(q) {
function doInitialize(q, qid) {
questions = q;
quizgame = qid;
if (document.addEventListener) {
document.addEventListener('fullscreenchange', fschange, false);
document.addEventListener('MSFullscreenChange', fschange, false);
Expand Down
5 changes: 2 additions & 3 deletions backup/moodle2/backup_quizgame_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ protected function define_structure() {
// Define each element separated.
$quizgame = new backup_nested_element('quizgame', array('id'), array(
'course', 'name', 'intro', 'introformat', 'timecreated',
'timemodified', 'questioncategory', 'grade'));
'timemodified', 'questioncategory', 'grade', 'completionscore'));

$scores = new backup_nested_element('scores');

$score = new backup_nested_element('score', array('id'), array(
'quizgameid', 'userid', 'score'));
'quizgameid', 'userid', 'score', 'timecreated'));
// Build the tree.

$quizgame->add_child($scores);
Expand All @@ -65,7 +65,6 @@ protected function define_structure() {
// Define id annotations.
$score->annotate_ids('user', 'userid');


// Define file annotations.
$quizgame->annotate_files('mod_quizgame', 'intro', null); // This file area hasn't itemid.

Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/restore_quizgame_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static public function define_decode_rules() {
return $rules;

}

/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
Expand Down
22 changes: 11 additions & 11 deletions backup/moodle2/restore_quizgame_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ protected function process_quizgame($data) {
$newcontext = $DB->get_field('question_categories', 'contextid', array('id' => $newcat));
// Assemble the field data.
if (!empty($newcat)) {
$data->questioncategory = implode(',', array($newcat, $newcontext));
$data->questioncategory = implode(',', array($newcat, $newcontext));
} else {
if (!$this->task->is_samesite() || $data->course != $oldcourse) {
// We cannot map to the question category.
// They were not included in the backup since they were at a higher context.
// This can happen when we are backing up the activity alone and trying to restore it elsewhere.
$this->log('question category ' . $category[0] . ' was associated with the quizgame ' .
$data->id . ' but cannot actually be used as it is not available in this backup. ' .
'The category needs to be re-selected.', backup::LOG_INFO);

// Remove the old data.
$data->questioncategory = "";
if (!$this->task->is_samesite() || $data->course != $oldcourse) {
// We cannot map to the question category.
// They were not included in the backup since they were at a higher context.
// This can happen when we are backing up the activity alone and trying to restore it elsewhere.
$this->log('question category ' . $category[0] . ' was associated with the quizgame ' .
$data->id . ' but cannot actually be used as it is not available in this backup. ' .
'The category needs to be re-selected.', backup::LOG_INFO);

// Remove the old data.
$data->questioncategory = "";
}
}

Expand Down
78 changes: 78 additions & 0 deletions classes/event/game_score_added.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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/>.

/**
* The mod_quizgame game_score_added event.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_quizgame\event;
defined('MOODLE_INTERNAL') || die();

/**
* The mod_quizgame game_score_added class.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class game_score_added extends \core\event\base {

/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'quizgame_scores';
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}

/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgamescoreadded', 'mod_quizgame');
}

/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/view.php', array('id' => $this->contextinstanceid));
}

/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' scored ".$this->other['score'] .
" in the quizventure with course module id '$this->contextinstanceid'.";
}


public static function get_objectid_mapping() {
return array('db' => 'quizgame_scores', 'restore' => 'quizgame_scores');
}
}
78 changes: 78 additions & 0 deletions classes/event/game_scores_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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/>.

/**
* The mod_quizgame game_scores_viewed event.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_quizgame\event;
defined('MOODLE_INTERNAL') || die();

/**
* The mod_quizgame game_scores_viewed event class.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class game_scores_viewed extends \core\event\base {

/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'quizgame';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}

/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgamescoresviewed', 'mod_quizgame');
}

/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/scores.php', array('id' => $this->objectid));
}

/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed all of the player scores for the quizventure with"
. " course module id '$this->contextinstanceid'.";
}


public static function get_objectid_mapping() {
return array('db' => 'quizgame', 'restore' => 'quizgame');
}
}
77 changes: 77 additions & 0 deletions classes/event/game_started.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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/>.

/**
* The mod_quizgame game_started event.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_quizgame\event;
defined('MOODLE_INTERNAL') || die();

/**
* The mod_quizgame game_started event class.
*
* @package mod_quizgame
* @copyright 2018 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class game_started extends \core\event\base {

/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'quizgame';
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}

/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgamestarted', 'mod_quizgame');
}

/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/view.php', array('id' => $this->contextinstanceid));
}

/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' started the quizventure with course module id '$this->contextinstanceid'.";
}


public static function get_objectid_mapping() {
return array('db' => 'quizgame', 'restore' => 'quizgame');
}
}
Loading

0 comments on commit 6476202

Please sign in to comment.