aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ajax.php5
-rw-r--r--classes/output/mobile.php50
-rw-r--r--classes/privacy/provider.php2
-rw-r--r--db/mobile.php40
-rw-r--r--mobile/algebra.html25
-rw-r--r--mobile/algebra.js51
-rw-r--r--mobile/styles_app.css34
-rw-r--r--mobile_src/addon.js59
-rw-r--r--mobile_src/directive.js42
-rw-r--r--mobile_src/handlers.js90
-rw-r--r--mobile_src/main.js26
-rw-r--r--mobile_src/template.html8
-rw-r--r--tests/behat/add.feature2
-rw-r--r--tests/behat/backup_and_restore.feature2
-rw-r--r--tests/behat/edit.feature2
-rw-r--r--tests/behat/export.feature2
-rw-r--r--tests/behat/import.feature2
-rw-r--r--tests/behat/preview.feature2
18 files changed, 205 insertions, 239 deletions
diff --git a/ajax.php b/ajax.php
index 9231012..544603c 100644
--- a/ajax.php
+++ b/ajax.php
@@ -29,12 +29,17 @@ $p = new qtype_algebra_parser;
$vars = required_param('vars', PARAM_RAW);
$expr = required_param('expr', PARAM_RAW);
+
+// This should be accessed by only valid logged in user.
+require_login(null, false);
+
/*
if (!confirm_sesskey()) {
header('HTTP/1.1 403 Forbidden');
die();
}
*/
+
try {
$vars = explode(',', $vars);
if (empty($expr)) {
diff --git a/classes/output/mobile.php b/classes/output/mobile.php
new file mode 100644
index 0000000..17f7415
--- /dev/null
+++ b/classes/output/mobile.php
@@ -0,0 +1,50 @@
+<?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/>.
+
+/**
+ * Mobile output class for question type algebra.
+ *
+ * @package qtype_algebra
+ * @copyright 2019 Jean-Michel Vedrine
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace qtype_algebra\output;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Mobile output class for question type algebra.
+ * @copyright 2018 Joseph Rézeau
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class mobile {
+ /**
+ * Returns the algebra question view for the mobile app.
+ *
+ * @return void
+ */
+ public static function algebra_view() {
+ global $CFG;
+ return [
+ 'templates' => [[
+ 'id' => 'main',
+ 'html' => file_get_contents($CFG->dirroot . '/question/type/algebra/mobile/algebra.html')
+ ]],
+ 'javascript' => file_get_contents($CFG->dirroot . '/question/type/algebra/mobile/algebra.js')
+ ];
+ }
+} \ No newline at end of file
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
index 65b0a17..9fbda10 100644
--- a/classes/privacy/provider.php
+++ b/classes/privacy/provider.php
@@ -18,7 +18,7 @@
* Privacy main class.
*
* @package qtype_algebra
- * @copyright 2018 Jean-Michel vedrine
+ * @copyright 2018 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/db/mobile.php b/db/mobile.php
index 68b91f6..35ba397 100644
--- a/db/mobile.php
+++ b/db/mobile.php
@@ -1,5 +1,5 @@
<?php
-// This file is part of the Certificate module for Moodle - http://moodle.org/
+// 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
@@ -15,14 +15,40 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * qtype_algebra capability definition
+ * Mobile plugin.
*
- * @package qtype_algebra
- * @copyright 2018 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package qtype_algebra
+ * @copyright 2019 Jean-Michel Vedrine
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
defined('MOODLE_INTERNAL') || die();
+// To enable moodle mobile test site to upload my css files.
+header('Access-Control-Allow-Origin: *');
$addons = array(
- "qtype_algebra" => array()
-);
+ "qtype_algebra" => array(
+ "handlers" => array( // Different places where the add-on will display content.
+ 'algebra' => array( // Handler unique name (can be anything).
+ 'displaydata' => array(
+ 'title' => 'Regular Expression Short Answer',
+ 'icon' => '/question/type/algebra/pix/icon.gif',
+ 'class' => '', // What does this do?
+ ),
+ 'delegate' => 'CoreQuestionDelegate', // Delegate (where to display the link to the add-on).
+ 'method' => 'algebra_view',
+ 'offlinefunctions' => array(
+ 'mobile_get_algebra' => array(),
+ ), // Function needs caching for offline.
+
+ 'styles' => array(
+ 'url' => '/question/type/algebra/mobile/styles_app.css',
+ 'version' => '1.00'
+ ),
+ 'lang' => array(
+ array('pluginname', 'qtype_algebra')
+ )
+ )
+ ),
+ )
+); \ No newline at end of file
diff --git a/mobile/algebra.html b/mobile/algebra.html
new file mode 100644
index 0000000..4f08aad
--- /dev/null
+++ b/mobile/algebra.html
@@ -0,0 +1,25 @@
+<section class="qtype-algebra" ion-list *ngIf="question.text || question.text === ''">
+ <ion-item text-wrap>
+ <core-format-text [component]="component"
+ [componentId]="componentId" [text]="question.text">
+ </core-format-text>
+ </ion-item>
+ <ion-item>
+ <ion-label
+ stacked
+ color="gray"
+ padding-left>
+ {{ 'core.question.answer' | translate }}:
+ </ion-label>
+ <ion-input
+ padding-left
+ type="text"
+ [attr.name]="question.input.name"
+ [value]="question.input.value"
+ autocorrect="off"
+ [disabled]="question.input.readOnly"
+ [ngClass]="[question.input.correctClass]"
+ >
+ </ion-input>
+ </ion-item>
+</section>
diff --git a/mobile/algebra.js b/mobile/algebra.js
new file mode 100644
index 0000000..fa3e6d1
--- /dev/null
+++ b/mobile/algebra.js
@@ -0,0 +1,51 @@
+var that = this;
+var result = {
+
+ componentInit: function() {
+
+ if (!this.question) {
+ console.warn('Aborting because of no question received.');
+ return that.CoreQuestionHelperProvider.showComponentError(that.onAbort);
+ }
+ const div = document.createElement('div');
+ div.innerHTML = this.question.html;
+ // Get question questiontext.
+ const questiontext = div.querySelector('.qtext');
+ // Get question input.
+ const input = div.querySelector('input[type="text"][name*=answer]');
+
+ if (div.querySelector('.readonly') !== null) {
+ this.question.readonly = true;
+ }
+ if (div.querySelector('.feedback') !== null) {
+ this.question.feedback = div.querySelector('.feedback');
+ this.question.feedbackHTML = true;
+ }
+
+ this.question.text = questiontext.innerHTML;
+ this.question.input = input;
+
+ if (typeof this.question.text == 'undefined') {
+ this.logger.warn('Aborting because of an error parsing question.', this.question.name);
+ return this.CoreQuestionHelperProvider.showComponentError(this.onAbort);
+ }
+
+ // Check if question is marked as correct.
+ if (input.classList.contains('incorrect')) {
+ this.question.input.correctClass = 'qtype-algebra question-incorrect';
+ } else if (input.classList.contains('correct')) {
+ this.question.input.correctClass = 'qtype-algebra question-correct';
+ } else if (input.classList.contains('partiallycorrect')) {
+ this.question.input.correctClass = 'qtype-algebra question-partiallycorrect';
+ }
+
+ // @codingStandardsIgnoreStart
+ // Wait for the DOM to be rendered.
+ setTimeout(() => {
+
+ });
+ // @codingStandardsIgnoreEnd
+ return true;
+ }
+};
+result; \ No newline at end of file
diff --git a/mobile/styles_app.css b/mobile/styles_app.css
new file mode 100644
index 0000000..c60d318
--- /dev/null
+++ b/mobile/styles_app.css
@@ -0,0 +1,34 @@
+.collapsibleregioncaption {
+ display: none;
+}
+.qtype-algebra .text-input,
+.qtype-algebra .text-input-md {
+ border: 1px solid #ccc;
+ padding: 4px 6px;
+ border-radius: 4px;
+ margin: 0px 0px;
+ width: calc(100% - 20px);
+ font-size: 1.4rem;
+}
+.qtype-algebra .item-input {
+ padding-left: 6px;
+ margin-top: -14px;
+}
+.qtype-algebra .question-correct:after,
+.qtype-algebra .question-incorrect:after,
+.qtype-algebra .question-partiallycorrect:after {
+ font-family: FontAwesome;
+ padding-left: 3px;
+}
+.qtype-algebra .question-correct:after {
+ content: "\f00c";
+ color: #5e8100;
+}
+.qtype-algebra .question-incorrect:after {
+ content: "\f00d";
+ color: #cb3d4d;
+}
+.qtype-algebra .question-partiallycorrect:after {
+ content: "\f046";
+ color: #f98012;
+}
diff --git a/mobile_src/addon.js b/mobile_src/addon.js
deleted file mode 100644
index 6177522..0000000
--- a/mobile_src/addon.js
+++ /dev/null
@@ -1,59 +0,0 @@
-// 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/>.
-
-/**
- * @package qtype_algebra
- * @copyright 2017 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-angular.module('mm.addons.qtype_algebra', ['mm.core'])
-.config(["$mmQuestionDelegateProvider", function($mmQuestionDelegateProvider) {
- $mmQuestionDelegateProvider.registerHandler('mmaQtypeAlgebra', 'qtype_algebra', '$mmaQtypeAlgebraHandler');
-}]);
-
-angular.module('mm.addons.qtype_algebra')
-.directive('mmaQtypeAlgebra', ["$log", "$mmQuestionHelper", function($log, $mmQuestionHelper) {
- $log = $log.getInstance('mmaQtypeAlgebra');
- return {
- restrict: 'A',
- priority: 100,
- templateUrl: 'addons/qtype/algebra/template.html',
- link: function(scope) {
- $mmQuestionHelper.inputTextDirective(scope, $log);
- }
- };
-}]);
-
-angular.module('mm.addons.qtype_algebra')
-.factory('$mmaQtypeAlgebraHandler', ["$mmUtil", function($mmUtil) {
- var self = {};
- self.isCompleteResponse = function(question, answers) {
- return answers['answer'] || answers['answer'] === 0;
- };
- self.isEnabled = function() {
- return true;
- };
- self.isGradableResponse = function(question, answers) {
- return self.isCompleteResponse(question, answers);
- };
- self.isSameResponse = function(question, prevAnswers, newAnswers) {
- return $mmUtil.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'answer');
- };
- self.getDirectiveName = function(question) {
- return 'mma-qtype-multichoice-set';
- };
- return self;
-}]);
diff --git a/mobile_src/directive.js b/mobile_src/directive.js
deleted file mode 100644
index ef9bddf..0000000
--- a/mobile_src/directive.js
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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/>.
-
-/**
- * @package qtype_algebra
- * @copyright 2017 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-angular.module('mm.addons.qtype_algebra')
-
-/**
- * Directive to render a short answer question.
- *
- * @module mm.addons.qtype_algebra
- * @ngdoc directive
- * @name mmaQtypeAlgebra
- */
-.directive('mmaQtypeAlgebra', function($log, $mmQuestionHelper) {
- $log = $log.getInstance('mmaQtypeAlgebra');
-
- return {
- restrict: 'A',
- priority: 100,
- templateUrl: 'addons/qtype/algebra/template.html',
- link: function(scope) {
- $mmQuestionHelper.inputTextDirective(scope, $log);
- }
- };
-});
diff --git a/mobile_src/handlers.js b/mobile_src/handlers.js
deleted file mode 100644
index d50f76f..0000000
--- a/mobile_src/handlers.js
+++ /dev/null
@@ -1,90 +0,0 @@
-// 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/>.
-
-/**
- * @package qtype_algebra
- * @copyright 2017 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-angular.module('mm.addons.qtype_algebra')
-
-/**
- * Short answer question handlers.
- *
- * @module mm.addons.qtype_algebra
- * @ngdoc service
- * @name $mmaQtypeAlgebraHandler
- */
-.factory('$mmaQtypeAlgebraHandler', function($mmUtil) {
-
- var self = {};
-
- /**
- * Check if a response is complete.
- *
- * @param {Object} question Question.
- * @param {Object} answers Question answers (without prefix).
- * @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
- */
- self.isCompleteResponse = function(question, answers) {
- return answers['answer'] || answers['answer'] === 0;
- };
-
- /**
- * Whether or not the module is enabled for the site.
- *
- * @return {Boolean}
- */
- self.isEnabled = function() {
- return true;
- };
-
- /**
- * Check if a student has provided enough of an answer for the question to be graded automatically,
- * or whether it must be considered aborted.
- *
- * @param {Object} question Question.
- * @param {Object} answers Question answers (without prefix).
- * @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
- */
- self.isGradableResponse = function(question, answers) {
- return self.isCompleteResponse(question, answers);
- };
-
- /**
- * Check if two responses are the same.
- *
- * @param {Object} question Question.
- * @param {Object} prevAnswers Previous answers.
- * @param {Object} newAnswers New answers.
- * @return {Boolean} True if same, false otherwise.
- */
- self.isSameResponse = function(question, prevAnswers, newAnswers) {
- return $mmUtil.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'answer');
- };
-
- /**
- * Get the directive.
- *
- * @param {Object} question The question.
- * @return {String} Directive's name.
- */
- self.getDirectiveName = function(question) {
- return 'mma-qtype-algebra';
- };
-
- return self;
-});
diff --git a/mobile_src/main.js b/mobile_src/main.js
deleted file mode 100644
index 962ae64..0000000
--- a/mobile_src/main.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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/>.
-
-/**
- * @package qtype_algebra
- * @copyright 2017 Jean-Michel Vedrine
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-angular.module('mm.addons.qtype_algebra', ['mm.core'])
-
-.config(function($mmQuestionDelegateProvider) {
- $mmQuestionDelegateProvider.registerHandler('mmaQtypeAlgebra', 'qtype_algebra', '$mmaQtypeAlgebraHandler');
-});
diff --git a/mobile_src/template.html b/mobile_src/template.html
deleted file mode 100644
index 01d9544..0000000
--- a/mobile_src/template.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<section class="list" ng-if="question.text || question.text === ''">
- <div class="item item-text-wrap">
- <p><mm-format-text watch="true" component="{{component}}" component-id="{{componentId}}">{{ question.text }}</mm-format-text></p>
- </div>
- <ion-input class="item item-input" ng-class='{"mm-question-answer-correct": input.isCorrect === 1, "mm-question-answer-incorrect": input.isCorrect === 0}'>
- <input type="text" placeholder="{{ 'mm.question.answer' | translate }}" name="{{input.name}}" value="{{input.value}}" autocorrect="off" ng-disabled="input.readOnly" >
- </ion-input>
-</section>
diff --git a/tests/behat/add.feature b/tests/behat/add.feature
index f72399e..606e05f 100644
--- a/tests/behat/add.feature
+++ b/tests/behat/add.feature
@@ -16,7 +16,7 @@ Feature: Test creating an Algebra question
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage
- And I navigate to "Question bank" node in "Course administration"
+ And I navigate to "Question bank" in current page administration
Scenario: Create an Algebra question
When I add a "Algebra" question filling the form with:
diff --git a/tests/behat/backup_and_restore.feature b/tests/behat/backup_and_restore.feature
index 2122cdf..57c2423 100644
--- a/tests/behat/backup_and_restore.feature
+++ b/tests/behat/backup_and_restore.feature
@@ -28,7 +28,7 @@ Feature: Test duplicating a quiz containing an Algebra question
| Confirmation | Filename | test_backup.mbz |
And I restore "test_backup.mbz" backup into a new course using this options:
| Schema | Course name | Course 2 |
- And I navigate to "Question bank" node in "Course administration"
+ And I navigate to "Question bank" in current page administration
And I click on "Edit" "link" in the "Algebra question" "table_row"
Then the following fields match these values:
| Question name | Algebra question |
diff --git a/tests/behat/edit.feature b/tests/behat/edit.feature
index 9c4ed64..fda1e3d 100644
--- a/tests/behat/edit.feature
+++ b/tests/behat/edit.feature
@@ -22,7 +22,7 @@ Feature: Test editing an Algebra question
| Test questions | algebra | algebra-001 for editing | simplemath |
And I log in as "teacher1"
And I am on "Course 1" course homepage
- And I navigate to "Question bank" node in "Course administration"
+ And I navigate to "Question bank" in current page administration
@javascript @_switch_window
Scenario: Edit an Algebra question
diff --git a/tests/behat/export.feature b/tests/behat/export.feature
index 73f6bac..1c7435b 100644
--- a/tests/behat/export.feature
+++ b/tests/behat/export.feature
@@ -24,7 +24,7 @@ Feature: Test exporting Short answer questions
And I am on "Course 1" course homepage
Scenario: Export an Algebra question
- When I navigate to "Export" node in "Course administration > Question bank"
+ When I navigate to "Question bank > Export" in current page administration
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1100" and "1200" bytes
diff --git a/tests/behat/import.feature b/tests/behat/import.feature
index 8e43aff..6c120c1 100644
--- a/tests/behat/import.feature
+++ b/tests/behat/import.feature
@@ -19,7 +19,7 @@ Feature: Test importing Algebra questions
@javascript @_file_upload
Scenario: import Algebra question.
- When I navigate to "Import" node in "Course administration > Question bank"
+ When I navigate to "Question bank > Import" in current page administration
And I set the field "id_format_xml" to "1"
And I upload "question/type/algebra/tests/fixtures/qtype_sample_algebra.xml" file to "Import" filemanager
And I press "id_submitbutton"
diff --git a/tests/behat/preview.feature b/tests/behat/preview.feature
index fec1b29..b287e99 100644
--- a/tests/behat/preview.feature
+++ b/tests/behat/preview.feature
@@ -22,7 +22,7 @@ Feature: Preview an Algebra question
| Test questions | algebra | algebra-001 | simplemath |
Given I log in as "teacher1"
And I am on "Course 1" course homepage
- And I navigate to "Question bank" node in "Course administration"
+ And I navigate to "Question bank" in current page administration
@javascript @_switch_window
Scenario: Preview an Algebra question with correct answer