Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 60 additions & 31 deletions backup/moodle2/backup_ratingallocate_activity_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_ratingallocate_activity_structure_step extends backup_activity_structure_step {

/**
* Define the complete ratingallocate structure for backup.
* @return backup_nested_element
Expand All @@ -51,41 +50,59 @@ protected function define_structure() {

// Define each element separated.
$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));
$ratingallocate = new backup_nested_element(
get_tablename_for_tableClass($class),
get_id_for_tableClass($class),
get_fields_for_tableClass($class)
);

$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));
$ratingallocatechoice = new backup_nested_element(
get_tablename_for_tableClass($class),
get_id_for_tableClass($class),
get_fields_for_tableClass($class)
);

$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));
$ratingallocaterating = new backup_nested_element(
get_tablename_for_tableClass($class),
get_id_for_tableClass($class),
get_fields_for_tableClass($class)
);

$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));
$ratingallocateallocation = new backup_nested_element(
get_tablename_for_tableClass($class),
get_id_for_tableClass($class),
get_fields_for_tableClass($class)
);

$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),
$groupchoice = new backup_nested_element(
get_tablename_for_tableClass($groupchoiceclass),
get_id_for_tableClass($groupchoiceclass),
get_fields_for_tableClass($groupchoiceclass));
get_fields_for_tableClass($groupchoiceclass)
);

$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));
$ratingallocatechoicegroup = new backup_nested_element(
get_tablename_for_tableClass($choicegroupclass),
get_id_for_tableClass($choicegroupclass),
get_fields_for_tableClass($choicegroupclass)
);

$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),
get_fields_for_tableClass($groupingclass));
$ratingallocategrouping = new backup_nested_element(
get_tablename_for_tableClass($groupingclass),
get_id_for_tableClass($groupingclass),
get_fields_for_tableClass($groupingclass)
);

// Build the tree.
$ratingallocate->add_child($ratingallocatechoices);
Expand All @@ -107,29 +124,41 @@ protected function define_structure() {
$ratingallocatechoicegroups->add_child($ratingallocatechoicegroup);

// Define sources.
$ratingallocate->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'),
[this_db\ratingallocate::ID => backup::VAR_ACTIVITYID], this_db\ratingallocate_choices::ID . ' ASC');
$ratingallocatechoice->set_source_table(get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'),
[this_db\ratingallocate_choices::RATINGALLOCATEID => backup::VAR_PARENTID],
this_db\ratingallocate_choices::ID . ' ASC');
$ratingallocate->set_source_table(
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate'),
[this_db\ratingallocate::ID => backup::VAR_ACTIVITYID],
this_db\ratingallocate_choices::ID . ' ASC'
);
$ratingallocatechoice->set_source_table(
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_choices'),
[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]);
$ratingallocatechoicegroup->set_source_table(
get_tablename_for_tableClass($choicegroupclass), ['choiceid' => backup::VAR_PARENTID]);
get_tablename_for_tableClass($choicegroupclass),
['choiceid' => backup::VAR_PARENTID]
);
$ratingallocategrouping->set_source_table(
get_tablename_for_tableClass($groupingclass), ['ratingallocateid' => backup::VAR_PARENTID]);
get_tablename_for_tableClass($groupingclass),
['ratingallocateid' => backup::VAR_PARENTID]
);

if ($userinfo) {
$ratingallocaterating->set_source_table(get_tablename_for_tableClass(
'mod_ratingallocate\db\ratingallocate_ratings'),
[this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID],
this_db\ratingallocate_ratings::ID . ' ASC');
$ratingallocaterating->set_source_table(
get_tablename_for_tableClass(
'mod_ratingallocate\db\ratingallocate_ratings'
),
[this_db\ratingallocate_ratings::CHOICEID => backup::VAR_PARENTID],
this_db\ratingallocate_ratings::ID . ' ASC'
);
$ratingallocateallocation->set_source_table(
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'),
[
get_tablename_for_tableClass('mod_ratingallocate\db\ratingallocate_allocations'),
[
this_db\ratingallocate_allocations::RATINGALLOCATEID => backup::VAR_ACTIVITYID,
this_db\ratingallocate_allocations::CHOICEID => backup::VAR_PARENTID,
],
this_db\ratingallocate_allocations::ID . ' ASC'
this_db\ratingallocate_allocations::ID . ' ASC'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_ratingallocate_activity_task extends backup_activity_task {

/**
* Define (add) particular settings this activity can have
*/
Expand Down
33 changes: 21 additions & 12 deletions backup/moodle2/restore_ratingallocate_activity_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_ratingallocate_activity_structure_step extends restore_activity_structure_step {

/**
* Define the complete ratingallocate structure for restore.
* @return mixed
Expand All @@ -39,18 +38,28 @@ protected function define_structure() {
$choicespath =
$ratingallocatepath . '/' . this_db\ratingallocate_choices::TABLE . 's/' . this_db\ratingallocate_choices::TABLE;
$paths[] = new restore_path_element(this_db\ratingallocate_choices::TABLE, $choicespath);
$paths[] = new restore_path_element(this_db\ratingallocate_group_choices::TABLE,
$choicespath .'/' . this_db\ratingallocate_group_choices::TABLE .'s/' . this_db\ratingallocate_group_choices::TABLE);
$paths[] = new restore_path_element(this_db\ratingallocate_ch_gengroups::TABLE,
$choicespath .'/'. this_db\ratingallocate_ch_gengroups::TABLE . 's/' . this_db\ratingallocate_ch_gengroups::TABLE);
$paths[] = new restore_path_element(this_db\ratingallocate_groupings::TABLE,
$ratingallocatepath . '/' . this_db\ratingallocate_groupings::TABLE . 's/' . this_db\ratingallocate_groupings::TABLE);
$paths[] = new restore_path_element(
this_db\ratingallocate_group_choices::TABLE,
$choicespath . '/' . this_db\ratingallocate_group_choices::TABLE . 's/' . this_db\ratingallocate_group_choices::TABLE
);
$paths[] = new restore_path_element(
this_db\ratingallocate_ch_gengroups::TABLE,
$choicespath . '/' . this_db\ratingallocate_ch_gengroups::TABLE . 's/' . this_db\ratingallocate_ch_gengroups::TABLE
);
$paths[] = new restore_path_element(
this_db\ratingallocate_groupings::TABLE,
$ratingallocatepath . '/' . this_db\ratingallocate_groupings::TABLE . 's/' . this_db\ratingallocate_groupings::TABLE
);
if ($userinfo) {
$paths[] = new restore_path_element(this_db\ratingallocate_ratings::TABLE,
$choicespath . '/' . this_db\ratingallocate_ratings::TABLE . 's/' . this_db\ratingallocate_ratings::TABLE);
$paths[] = new restore_path_element(this_db\ratingallocate_allocations::TABLE,
$choicespath . '/' . this_db\ratingallocate_allocations::TABLE . 's/' .
this_db\ratingallocate_allocations::TABLE);
$paths[] = new restore_path_element(
this_db\ratingallocate_ratings::TABLE,
$choicespath . '/' . this_db\ratingallocate_ratings::TABLE . 's/' . this_db\ratingallocate_ratings::TABLE
);
$paths[] = new restore_path_element(
this_db\ratingallocate_allocations::TABLE,
$choicespath . '/' . this_db\ratingallocate_allocations::TABLE . 's/' .
this_db\ratingallocate_allocations::TABLE
);
}

// Return the paths wrapped into standard activity structure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_ratingallocate_activity_task extends restore_activity_task {

/**
* Define (add) particular settings this activity can have
*/
Expand Down
21 changes: 12 additions & 9 deletions classes/allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @package mod_ratingallocate
*/
class allocations_table extends \table_sql {

/**
* @var ratingallocate
*/
Expand Down Expand Up @@ -95,8 +94,10 @@ public function setup_table() {
$headers[] = get_string('firstname');
$columns[] = 'lastname';
$headers[] = get_string('lastname');
if (in_array('email', $additionalfields) &&
has_capability('moodle/course:useremail', $this->ratingallocate->get_context())) {
if (
in_array('email', $additionalfields) &&
has_capability('moodle/course:useremail', $this->ratingallocate->get_context())
) {
$columns[] = 'email';
$headers[] = get_string('email');
}
Expand Down Expand Up @@ -128,7 +129,7 @@ public function build_table_by_sql() {
$data = $this->rawdata;

// Retrieve all users, who rated within the course.
$userwithratingids = array_map(function($x) {
$userwithratingids = array_map(function ($x) {
return $x->userid;
},
$this->ratingallocate->get_users_with_ratings());
Expand Down Expand Up @@ -175,8 +176,9 @@ public function build_table_by_sql() {
if (count($userwithrating) > 0 && ($this->currpage + 1) * $this->pagesize >= $this->totalrows) {
$noallocation = new \stdClass();
$noallocation->choicetitle = get_string(
'allocations_table_noallocation',
RATINGALLOCATE_MOD_NAME);
'allocations_table_noallocation',
RATINGALLOCATE_MOD_NAME
);

foreach ($userwithrating as $userid => $user) {
if (object_property_exists($noallocation, 'users')) {
Expand Down Expand Up @@ -210,8 +212,10 @@ private function get_user_link($user) {
if ($COURSE->id == SITEID) {
$profileurl = new \moodle_url('/user/profile.php', ['id' => $user->id]);
} else {
$profileurl = new \moodle_url('/user/view.php',
['id' => $user->id, 'course' => $COURSE->id]);
$profileurl = new \moodle_url(
'/user/view.php',
['id' => $user->id, 'course' => $COURSE->id]
);
}
return \html_writer::link($profileurl, $name);
}
Expand Down Expand Up @@ -241,5 +245,4 @@ public function init_sql() {

$this->query_db(20);
}

}
1 change: 0 additions & 1 deletion classes/choice/ratingallocate_choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ public function __set($name, $value) {
public function __construct($record) {
$this->dbrecord = $record;
}

}
38 changes: 23 additions & 15 deletions classes/choice_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class choice_importer {
* @param array $fields
* @return void
*/
public static function print_fields($fields=self::REQUIRED_FIELDS) {
public static function print_fields($fields = self::REQUIRED_FIELDS) {
return '[' . join(', ', $fields) . ']';
}

Expand Down Expand Up @@ -137,12 +137,12 @@ public function free_reader() {
* - rowcount: The number of being row processed. (Once finished, should add up to readcount.)
* - importcount: The number of rows successfully processed.
*/
public function import($content, $live=true) {
public function import($content, $live = true) {
global $DB;

$reader = $this->get_reader();

$importstatus = new \stdClass;
$importstatus = new \stdClass();
$importstatus->status = self::IMPORT_STATUS_OK; // Unless we hear otherwise.
$importstatus->live = $live; // Only commit live transactions.
$importstatus->errors = [];
Expand All @@ -169,8 +169,11 @@ public function import($content, $live=true) {
$missingfields = array_diff(self::REQUIRED_FIELDS, $fieldnames);
if ($missingfields) {
$importstatus->status = self::IMPORT_STATUS_SETUP_ERROR;
$importstatus->errors[] = get_string('csvupload_missing_fields', 'ratingallocate',
self::print_fields($missingfields));
$importstatus->errors[] = get_string(
'csvupload_missing_fields',
'ratingallocate',
self::print_fields($missingfields)
);
return $importstatus;
}

Expand All @@ -181,7 +184,6 @@ public function import($content, $live=true) {
// Start DB transaction.
$transaction = $this->ratingallocate->db->start_delegated_transaction();
try {

$reader->init();
while ($record = $reader->next()) {
$importstatus->rowcount++;
Expand All @@ -200,8 +202,11 @@ public function import($content, $live=true) {

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);
$importstatus->errors[] = get_string(
'csvupload_too_long_title',
RATINGALLOCATE_MOD_NAME,
$cell
);
$ischoiceimportable = false;
}

Expand Down Expand Up @@ -275,13 +280,11 @@ public function import($content, $live=true) {
$transaction->allow_commit();
}
$transaction->dispose();

} catch (\Exception $e) {
if (isset($transaction)) {
$transaction->rollback($e);
}
}

}
}

Expand All @@ -296,11 +299,15 @@ public function import($content, $live=true) {
}
} else {
if ($live) {
$importstatus->status_message = get_string('csvupload_live_problems', 'ratingallocate',
$importstatus->status_message = get_string(
'csvupload_live_problems',
'ratingallocate',
count($importstatus->errors)
);
} else {
$importstatus->status_message = get_string('csvupload_test_problems', 'ratingallocate',
$importstatus->status_message = get_string(
'csvupload_test_problems',
'ratingallocate',
count($importstatus->errors)
);
}
Expand All @@ -321,9 +328,10 @@ public function import($content, $live=true) {
* @param int $max Maximum number of individual notifications to send.
* @return void
*/
public function issue_notifications($errors,
$notificationtype=\core\output\notification::NOTIFY_WARNING,
$max=self::MAX_WARNING_COUNT
public function issue_notifications(
$errors,
$notificationtype = \core\output\notification::NOTIFY_WARNING,
$max = self::MAX_WARNING_COUNT
) {
$errorcount = count($errors);

Expand Down
2 changes: 0 additions & 2 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @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.
*
Expand Down Expand Up @@ -104,4 +103,3 @@ public function get_sort_order(): array {
];
}
}

Loading