Skip to content

Commit

Permalink
Merge branch 'master' into feature/improve_ratingallocate_navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Laur0r authored May 7, 2024
2 parents e66be02 + 188c17f commit e9c9a28
Show file tree
Hide file tree
Showing 30 changed files with 502 additions and 158 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:

strategy:
matrix:
php: ['8.1']
moodle-branch: ['MOODLE_402_STABLE']
php: ['8.2']
moodle-branch: ['MOODLE_403_STABLE']
database: ['pgsql']

steps:
Expand Down Expand Up @@ -108,9 +108,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE']
php: ['8.0', '8.1', '8.2']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE']
database: ['mariadb', 'pgsql']
exclude:
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
Expand Down
24 changes: 12 additions & 12 deletions backup/moodle2/backup_ratingallocate_activity_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

require_once(dirname(__FILE__) . '/backup_restore_helper.php');

use ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

/**
* Define the complete ratingallocate structure for backup, with [file and] id annotations
Expand All @@ -35,38 +35,38 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$class = 'ratingallocate\db\ratingallocate';
$class = 'mod_ratingallocate\db\ratingallocate';
$ratingallocate = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_choices';
$class = 'mod_ratingallocate\db\ratingallocate_choices';
$ratingallocatechoices = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocatechoice = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_ratings';
$class = 'mod_ratingallocate\db\ratingallocate_ratings';
$ratingallocateratings = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocaterating = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$class = 'ratingallocate\db\ratingallocate_allocations';
$class = 'mod_ratingallocate\db\ratingallocate_allocations';
$ratingallocateallocations = new backup_nested_element(get_tablename_for_tableClass($class) . 's');
$ratingallocateallocation = new backup_nested_element(get_tablename_for_tableClass($class), get_id_for_tableClass($class),
get_fields_for_tableClass($class));

$groupchoiceclass = 'ratingallocate\db\ratingallocate_group_choices';
$groupchoiceclass = 'mod_ratingallocate\db\ratingallocate_group_choices';
$groupchoices = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass) . 's');
$groupchoice = new backup_nested_element(get_tablename_for_tableClass($groupchoiceclass),
get_id_for_tableClass($groupchoiceclass),
get_fields_for_tableClass($groupchoiceclass));

$choicegroupclass = 'ratingallocate\db\ratingallocate_ch_gengroups';
$choicegroupclass = 'mod_ratingallocate\db\ratingallocate_ch_gengroups';
$ratingallocatechoicegroups = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass) . 's');
$ratingallocatechoicegroup = new backup_nested_element(get_tablename_for_tableClass($choicegroupclass),
get_id_for_tableClass($choicegroupclass),
get_fields_for_tableClass($choicegroupclass));

$groupingclass = 'ratingallocate\db\ratingallocate_groupings';
$groupingclass = 'mod_ratingallocate\db\ratingallocate_groupings';
$ratingallocategroupings = new backup_nested_element(get_tablename_for_tableClass($groupingclass) . 's');
$ratingallocategrouping = new backup_nested_element(get_tablename_for_tableClass($groupingclass),
get_id_for_tableClass($groupingclass),
Expand All @@ -92,9 +92,9 @@ protected function define_structure() {
$ratingallocatechoicegroups->add_child($ratingallocatechoicegroup);

// Define sources.
$ratingallocate->set_source_table(get_tablename_for_tableClass('ratingallocate\db\ratingallocate'),
$ratingallocate->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'),
array(this_db\ratingallocate::ID => backup::VAR_ACTIVITYID), this_db\ratingallocate_choices::ID . ' ASC');
$ratingallocatechoice->set_source_table(get_tablename_for_tableClass('ratingallocate\db\ratingallocate_choices'),
$ratingallocatechoice->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'),
array(this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID),
this_db\ratingallocate_choices::ID . ' ASC');
$groupchoice->set_source_table(get_tablename_for_tableClass($groupchoiceclass), ['choiceid' => backup::VAR_PARENTID]);
Expand All @@ -105,11 +105,11 @@ protected function define_structure() {

if ($userinfo) {
$ratingallocaterating->set_source_table(get_tablename_for_tableClass(
'ratingallocate\db\ratingallocate_ratings'),
'mod_ratingallocate\db\ratingallocate_ratings'),
array(this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID),
this_db\ratingallocate_ratings::ID . ' ASC');
$ratingallocateallocation->set_source_table(
get_tablename_for_tableClass('ratingallocate\db\ratingallocate_allocations'),
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'),
array(
this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID,
this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

/**
*
Expand Down
16 changes: 15 additions & 1 deletion classes/choice_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_ratingallocate;
use ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

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

Expand Down Expand Up @@ -162,6 +162,8 @@ public function import($content, $live=true) {
$reader->init();
while ($record = $reader->next()) {
$importstatus->rowcount++;
// Unless we hear otherwise.
$ischoiceimportable = true;
$recordmap = new \stdClass();

// Map cell contents to field names.
Expand All @@ -173,6 +175,13 @@ public function import($content, $live=true) {
continue;
}

if ($fieldname === 'title' && mb_strlen($cell, 'UTF-8') > 255) {
$importstatus->status = self::IMPORT_STATUS_DATA_ERROR;
$importstatus->errors[] = get_string('csvupload_too_long_title',
RATINGALLOCATE_MOD_NAME, $cell);
$ischoiceimportable = false;
}

if ($fieldname == 'groups') {
$groups = array();

Expand All @@ -199,6 +208,11 @@ public function import($content, $live=true) {
}
}

if (!$ischoiceimportable) {
// Parsed data of this choice has critical errors, so we will not add the choice.
continue;
}

// Create and insert a choice record.
// Note: this will add duplicates if run multiple times.
$choice = new \ratingallocate_choice($recordmap);
Expand Down
70 changes: 70 additions & 0 deletions classes/dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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_ratingallocate for a given module instance and a user.
*
* @package mod_ratingallocate
* @copyright 2022 University of Vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

declare(strict_types=1);

namespace mod_ratingallocate;

use core\activity_dates;

/**
* Class for fetching the important dates in mod_ratingallocate for a given module instance and a user.
*
* @copyright 2022 Jakob Mischke <jakob.mischke@univie.ac.at>
* @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_ratingallocate
*
* @return array
*/
protected function get_dates(): array {
global $DB;

$timeopen = $this->cm->customdata['accesstimestart'] ?? null;
$timeclose = $this->cm->customdata['accesstimestop'] ?? 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;
}
}
2 changes: 2 additions & 0 deletions classes/ratings_and_allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ function($o) {
},
$this->groupsofallchoices)))) {
$sql .= "," . $gmgroupid . ") ) ";
} else {
$sql .= "))";
}
} else if ($this->groupselect != 0) {
$sql .= "AND u.id in ( SELECT gm.userid FROM {groups_members} gm WHERE gm.groupid= :groupselect ) ";
Expand Down
2 changes: 1 addition & 1 deletion classes/task/cron_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace mod_ratingallocate\task;

use ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

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

Expand Down
5 changes: 4 additions & 1 deletion classes/task/distribute_unallocated_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class distribute_unallocated_task extends adhoc_task {
* @throws moodle_exception
*/
public function execute(): void {
global $DB;
global $CFG, $DB;
// Make sure to include the global definitions of constants defined in locallib.
require_once($CFG->dirroot . '/mod/ratingallocate/locallib.php');

$data = $this->get_custom_data();
if (empty($data->distributionalgorithm) ||
!in_array($data->distributionalgorithm, [ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY, ACTION_DISTRIBUTE_UNALLOCATED_FILL])) {
Expand Down
2 changes: 1 addition & 1 deletion classes/task/send_distribution_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

require_once(dirname(__FILE__) . '/../../db/db_structure.php');

use ratingallocate\db as this_db;
use mod_ratingallocate\db as this_db;

class send_distribution_notification extends \core\task\adhoc_task {
// Gets executed by the task runner. Will lookup the ratingallocation object and
Expand Down
2 changes: 1 addition & 1 deletion db/db_structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace ratingallocate\db;
namespace mod_ratingallocate\db;

defined('MOODLE_INTERNAL') || die();
class ratingallocate {
Expand Down
2 changes: 2 additions & 0 deletions form_modify_choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function definition() {
$mform->setType($elementname, PARAM_TEXT);
$mform->addHelpButton($elementname, 'choice_title', RATINGALLOCATE_MOD_NAME);
$mform->addRule($elementname, get_string('err_required', 'form'), 'required', null, 'server');
$mform->addRule($elementname, get_string('title_too_long_error', RATINGALLOCATE_MOD_NAME),
'maxlength', '255');

$elementname = 'explanation';
$editoroptions = array(
Expand Down
6 changes: 6 additions & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
$string['deleteconfirm'] = 'Do you really want to delete the choice "{$a}"?';
$string['choice_deleted_notification'] = 'Choice "{$a}" was deleted.';
$string['choice_deleted_notification_error'] = 'Choice requested for deletion could not be found.';
$string['title_too_long_error'] = 'The title of the choice has too many characters, only 255 are allowed.';
$string['modify_choices_group'] = 'Choices';
$string['modify_choices'] = 'Edit Choices';
$string['modify_choices_explanation'] = 'Shows the list of all choices. Here, the choices can be hidden, altered and deleted.';
Expand Down Expand Up @@ -259,6 +260,7 @@
$string['csvupload_test_success'] = 'CSV import test successful. {$a->importcount} choices can be imported.';
$string['csvupload_test_upload'] = 'Test upload';
$string['csvupload_test_upload_help'] = 'When checked: test the uploaded CSV file for data problems, but do not commit to the database.';
$string['csvupload_too_long_title'] = 'Too long title (> 255 characters): {$a}';
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Form to edit the instance(administrator)">
$string['choice_active'] = 'Choice is active';
Expand Down Expand Up @@ -460,3 +462,7 @@
and ratable choices by groups that had the ability to access them.
* Only groups used in the *use groups* option can be selected.
* If *no group* is selected, users that are in none of the groups used by a choice are shown.';

// Language Strings for resetting.
$string['remove_ratings_and_allocations'] = 'Delete all ratings and allocations';
$string['ratings_and_allocations_deleted'] = 'Ratings and allocations deleted';
Loading

0 comments on commit e9c9a28

Please sign in to comment.