Skip to content

Commit

Permalink
Merge branch 'master' into feature/improve_design_of_front_page
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe authored May 23, 2024
2 parents 77902a7 + 83ef413 commit 614b4c9
Show file tree
Hide file tree
Showing 34 changed files with 400 additions and 179 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ jobs:
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
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
2 changes: 1 addition & 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
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 <[email protected]>
* @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: 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
1 change: 1 addition & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
$string['edit_choice'] = 'Edit choice';
$string['rating_endtime'] = 'Rating ends at';
$string['rating_begintime'] = 'Rating begins at';
$string['choice_navigation'] = 'Choices';
$string['newchoicetitle'] = 'New choice {$a}';
$string['deletechoice'] = 'Delete choice';
$string['publishdate'] = 'Estimated publication date';
Expand Down
58 changes: 57 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
// define('NEWMODULE_ULTIMATE_ANSWER', 42);

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

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

// //////////////////////////////////////////////////////////////////////////////
// Moodle core API //
Expand Down Expand Up @@ -381,6 +382,23 @@ function ratingallocate_extend_navigation(navigation_node $navref, stdclass $cou
* {@link navigation_node}
*/
function ratingallocate_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $ratingallocatenode = null) {
$hassecondary = $settingsnav->get_page()->has_secondary_navigation();
if (!$context = context_module::instance($settingsnav->get_page()->cm->id, IGNORE_MISSING)) {
throw new \moodle_exception('badcontext');
}
if (has_capability('mod/ratingallocate:modify_choices', $context)) {
$choicenode = navigation_node::create(get_string('choice_navigation', RATINGALLOCATE_MOD_NAME),
new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_CHOICES]),
navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_choices');
$ratingallocatenode->add_node($choicenode);
}

if (has_capability('mod/ratingallocate:start_distribution', $context)) {
$reportsnode = navigation_node::create(get_string('reports_group', RATINGALLOCATE_MOD_NAME),
new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE]),
navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_reports');
$ratingallocatenode->add_node($reportsnode);
}

}

Expand Down Expand Up @@ -734,3 +752,41 @@ function ratingallocate_reset_course_form_definition($mform) {
function ratingallocate_reset_course_form_defaults($course) {
return ['reset_ratings_and_allocations' => 1];
}

/**
* Add a get_coursemodule_info function in case any ratingallocate type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function ratingallocate_get_coursemodule_info($coursemodule) {
global $DB;

$dbparams = array('id' => $coursemodule->instance);
if (! $ratingallocate = $DB->get_record('ratingallocate', $dbparams)) {
return false;
}

$result = new cached_cm_info();
$result->name = $ratingallocate->name;

if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('ratingallocate', $ratingallocate, $coursemodule->id, false);
}

// Populate some other values that can be used in calendar or on dashboard.
if ($ratingallocate->accesstimestart) {
$result->customdata['accesstimestart'] = $ratingallocate->accesstimestart;
}
if ($ratingallocate->accesstimestop) {
$result->customdata['accesstimestop'] = $ratingallocate->accesstimestop;
}

return $result;
}
Loading

0 comments on commit 614b4c9

Please sign in to comment.