Skip to content

Commit

Permalink
EL-1194/dates
Browse files Browse the repository at this point in the history
  • Loading branch information
stellargela authored and aczerzuh committed Mar 2, 2023
1 parent 2a35b36 commit c3bc755
Show file tree
Hide file tree
Showing 53 changed files with 1,986 additions and 256 deletions.
43 changes: 22 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,45 @@ on: [push, pull_request]
jobs:
test:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
include:
- php: '8.0'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
- php: '7.3'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'

services:
postgres:
image: postgres
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432

options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"

ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
include:
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: plugin

Expand All @@ -53,6 +52,8 @@ jobs:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead.
coverage: none

- name: Deploy moodle-plugin-ci
run: |
Expand Down
14 changes: 8 additions & 6 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ The questionnaire module allows you to construct questionnaires (surveys) from a
variety of question type. It was originally based on phpESP, and Open Source
survey tool.

--------------------------------------------------------------------------------
Developers Note:

There is no main branch. Questionnaire is maintained in MOODLE_XX_STABLE
branches. Use the latest STABLE branch for development or installation.
The current stable branch is MOODLE_400_STABLE, and supports Moodle 4.0 and up.
Use the MOODLE_311_STABLE branch for Moodle 3.9 through 3.11.

--------------------------------------------------------------------------------
To Install:

Expand All @@ -16,9 +24,3 @@ To Upgrade:

--------------------------------------------------------------------------------
Please read the CHANGES.md file for more info about successive changes

--------------------------------------------------------------------------------
Developers Note:

Do not use the main branch. Questionnaire is maintained in MOODLE_XX_STABLE
branches. Use the latest STABLE branch for development or installation.
4 changes: 3 additions & 1 deletion backup/moodle2/restore_questionnaire_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public static function define_decode_contents() {

$contents[] = new restore_decode_content('questionnaire', array('intro'), 'questionnaire');
$contents[] = new restore_decode_content('questionnaire_survey',
array('info', 'thank_head', 'thank_body', 'thanks_page'), 'questionnaire_survey');
array('info', 'thank_head', 'thank_body', 'thanks_page', 'feedbacknotes'), 'questionnaire_survey');
$contents[] = new restore_decode_content('questionnaire_question', array('content'), 'questionnaire_question');
$contents[] = new restore_decode_content('questionnaire_fb_sections', array('sectionheading'), 'questionnaire_fb_sections');
$contents[] = new restore_decode_content('questionnaire_feedback', array('feedbacktext'), 'questionnaire_feedback');

return $contents;
}
Expand Down
3 changes: 2 additions & 1 deletion backup/moodle2/restore_questionnaire_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use mod_questionnaire\feedback\section;

/**
* Define all the restore steps that will be used by the restore_questionnaire_activity_task.
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function process_questionnaire_fb_sections($data) {

// If this questionnaire has separate sections feedbacks.
if (isset($data->scorecalculation)) {
$scorecalculation = unserialize($data->scorecalculation);
$scorecalculation = section::decode_scorecalculation($data->scorecalculation);
$newscorecalculation = array();
foreach ($scorecalculation as $qid => $val) {
$newqid = $this->get_mappingid('questionnaire_question', $qid);
Expand Down
85 changes: 85 additions & 0 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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/>.
declare(strict_types=1);

namespace mod_questionnaire\completion;

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

require_once($CFG->dirroot . '/mod/questionnaire/lib.php');

use coding_exception;
use core_completion\activity_custom_completion;
use moodle_exception;

/**
* Activity custom completion subclass for the data activity.
*
* Class for defining mod_oucontent's custom completion rules and fetching the completion statuses
* of the custom completion rules for a given data instance and a user.
*
* @package mod_questionnaire
* @copyright 2022 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_completion extends activity_custom_completion {
/**
* Fetches the completion state for a given completion rule.
*
* @param string $rule
* @return int
*/
public function get_state(string $rule): int {
$this->validate_rule($rule);
$userid = $this->userid;
$cm = $this->cm;
$status = questionnaire_get_completion_state($cm, $userid, $rule);
return $status ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
}

/**
* Fetch the list of custom completion rules that this module defines.
*
* @return array
*/
public static function get_defined_custom_rules(): array {
return [
'completionsubmit'
];
}

/**
* Returns an associative array of the descriptions of custom completion rules.
*
* @return array
*/
public function get_custom_rule_descriptions(): array {
return [
'completionsubmit' => get_string('completionsubmit', 'questionnaire')
];
}

/**
* Returns an array of all completion rules, in the order they should be displayed to users.
*
* @return array
*/
public function get_sort_order(): array {
return [
'completionsubmit',
];
}
}
71 changes: 71 additions & 0 deletions classes/dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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/>.

/**
* Contains the class for fetching the important dates in mod_questionnaire for a given module instance and a user.
*
* @package mod_questionnaire
* @copyright 2022 University of Vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

declare(strict_types=1);

namespace mod_questionnaire;

use core\activity_dates;

/**
* Class for fetching the important dates in mod_questionnaire for a given module instance and a user.
*
* @copyright 2022 University of Vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates extends activity_dates {

/**
* Returns a list of important dates in mod_questionnaire
*
* @return array
*/
protected function get_dates(): array {
global $DB;

$timeopen = $this->cm->customdata->opendate ?? null;
$timeclose = $this->cm->customdata->closedate ?? null;

$now = time();
$dates = [];

if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
$dates[] = [
'label' => get_string($openlabelid, 'core_course'),
'timestamp' => (int) $timeopen,
];
}

if ($timeclose) {
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
$dates[] = [
'label' => get_string($closelabelid, 'core_course'),
'timestamp' => (int) $timeclose,
];
}

return $dates;
}
}
30 changes: 30 additions & 0 deletions classes/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ public function validation($data, $files) {
}
}

// If this is a slider question.
if ($data['type_id'] == QUESSLIDER) {
if (isset($data['minrange']) && isset($data['maxrange']) && isset($data['startingvalue']) &&
isset($data['stepvalue'])) {
if ($data['minrange'] >= $data['maxrange']) {
$errors['maxrange'] = get_string('invalidrange', 'questionnaire');
}

if (($data['startingvalue'] > $data['maxrange']) || ($data['startingvalue'] < $data['minrange'])) {
$errors['startingvalue'] = get_string('invalidstartingvalue', 'questionnaire');
}

if ($data['startingvalue'] > 100 || $data['startingvalue'] < -100) {
$errors['startingvalue'] = get_string('invalidstartingvalue', 'questionnaire');
}

if (($data['stepvalue'] > $data['maxrange']) || $data['stepvalue'] < 1) {
$errors['stepvalue'] = get_string('invalidincrement', 'questionnaire');
}

if ($data['minrange'] < -100) {
$errors['minrange'] = get_string('invalidminmaxrange', 'questionnaire');
}

if ($data['maxrange'] > 100) {
$errors['maxrange'] = get_string('invalidminmaxrange', 'questionnaire');
}
}
}

return $errors;
}

Expand Down
Loading

0 comments on commit c3bc755

Please sign in to comment.