Skip to content

Commit

Permalink
fix coding style violations
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed May 24, 2024
1 parent f6d78b2 commit 8f484ac
Show file tree
Hide file tree
Showing 54 changed files with 941 additions and 254 deletions.
19 changes: 18 additions & 1 deletion backup/moodle2/backup_restore_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package moodlecore
* Backup restore helper.
*
* @package mod_ratingallocate
* @subpackage backup-moodle2
* @copyright 2014 C. Usener
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* @param $class
* @return array
* @throws ReflectionException
*/
function get_fields_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
Expand All @@ -33,12 +40,22 @@ function get_fields_for_tableclass($class) {
return array_values($constants);
}

/**
* @param $class
* @return mixed
* @throws ReflectionException
*/
function get_tablename_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
return $constants['TABLE'];
}

/**
* @param $class
* @return array
* @throws ReflectionException
*/
function get_id_for_tableclass($class) {
$class = new ReflectionClass($class);
$constants = $class->getConstants();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
*
* @package moodlecore
* @package mod_ratingallocate
* @subpackage backup-moodle2
* @copyright 2014 C. Usener
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down
5 changes: 5 additions & 0 deletions backup/moodle2/restore_ratingallocate_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
require_once($CFG->dirroot . '/mod/ratingallocate/backup/moodle2/restore_ratingallocate_activity_stepslib.php');

/**
* @class restore_ratingallocate_activity_task
* @copyright 214 C. Usener
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_ratingallocate_activity_task extends restore_activity_task {

/**
Expand Down
20 changes: 16 additions & 4 deletions classes/algorithm_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class algorithm_status {
const FAILURE = -1; // Algorithm did not finish correctly.
const NOTSTARTED = 0; // Default status for new instances.
const RUNNING = 1; // Algorithm is currently running.
const FINISHED = 2; // Algorithm finished correctly.
/**
* Algorithm did not finish correctly.
*/
const FAILURE = -1;
/**
* Default status for new instances.
*/
const NOTSTARTED = 0;
/**
* Algorithm is currently running.
*/
const RUNNING = 1;
/**
* Algorithm finished correctly.
*/
const FINISHED = 2;
}
7 changes: 5 additions & 2 deletions classes/allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
require_once($CFG->libdir . '/tablelib.php');
require_once($CFG->dirroot . '/user/lib.php');

/**
* @class allocations_table
*/
class allocations_table extends \table_sql {

/**
Expand Down Expand Up @@ -203,7 +206,7 @@ private function get_user_link($user) {
$name = fullname($user);

if ($COURSE->id == SITEID) {
$profileurl = new \moodle_url('/user/profile.php',['id' => $user->id]);
$profileurl = new \moodle_url('/user/profile.php', ['id' => $user->id]);
} else {
$profileurl = new \moodle_url('/user/view.php',
['id' => $user->id, 'course' => $COURSE->id]);
Expand All @@ -229,7 +232,7 @@ public function init_sql() {

$where = "c.ratingallocateid = :ratingallocateid";

$params =[];
$params = [];
$params['ratingallocateid'] = $this->ratingallocate->ratingallocate->id;

$this->set_sql($fields, $from, $where, $params);
Expand Down
26 changes: 21 additions & 5 deletions classes/choice_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@

require_once($CFG->libdir . '/csvlib.class.php');


/**
* @class choice_importer
*/
class choice_importer {
/**
* Required fields.
*/
const REQUIRED_FIELDS = ["title", "explanation", "maxsize", "active", "groups"];

// The import process worked as expected.
/**
* The import process worked as expected.
*/
const IMPORT_STATUS_OK = 'csvupload_ok';
// Something went wrong during setup; import cannot continue.
/**
* Something went wrong during setup; import cannot continue.
*/
const IMPORT_STATUS_SETUP_ERROR = 'csvupload_setuperror';
// Partial success with data errors.
/** Partial success with data errors.*/
const IMPORT_STATUS_DATA_ERROR = 'csvupload_dataerror';

// Default maximum number of warnings to show notifications for on import problems.
/** Default maximum number of warnings to show notifications for on import problems. */
const MAX_WARNING_COUNT = 5;

/**
Expand Down Expand Up @@ -66,11 +75,18 @@ public static function print_fields($fields=self::REQUIRED_FIELDS) {
return '[' . join(', ', $fields) . ']';
}

/**
* @param $ratingallocateid
* @param $ratingallocate
*/
public function __construct($ratingallocateid, $ratingallocate) {
$this->ratingallocate = $ratingallocate;
$this->ratingallocateid = $ratingallocateid;
}

/**
* Destruct.
*/
public function __destruct() {
$this->free_reader();
}
Expand Down
6 changes: 3 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public static function get_metadata(collection $items): collection {
$items->add_database_table('ratingallocate_ratings', [
'choiceid' => 'privacy:metadata:ratingallocate_ratings:choiceid',
'userid' => 'privacy:metadata:ratingallocate_ratings:userid',
'rating' => 'privacy:metadata:ratingallocate_ratings:rating'
'rating' => 'privacy:metadata:ratingallocate_ratings:rating',
],
'privacy:metadata:ratingallocate_ratings');

$items->add_database_table('ratingallocate_allocations', [
'userid' => 'privacy:metadata:ratingallocate_allocations:userid',
'ratingallocateid' => 'privacy:metadata:ratingallocate_allocations:ratingallocateid',
'choiceid' => 'privacy:metadata:ratingallocate_allocations:choiceid'
'choiceid' => 'privacy:metadata:ratingallocate_allocations:choiceid',
], 'privacy:metadata:ratingallocate_allocations');

$items->add_user_preference('flextable_mod_ratingallocate_table_filter',
Expand Down Expand Up @@ -290,7 +290,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
WHERE ratingallocateid = :instanceid) AND userid = :userid",
[
'instanceid' => $instanceid,
'userid' => $userid
'userid' => $userid,
]
);
}
Expand Down
7 changes: 5 additions & 2 deletions classes/ratingallocate_observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use coding_exception;
use dml_exception;

/**
* @class ratingallocate_observer
*/
class ratingallocate_observer {

/**
Expand All @@ -36,7 +39,7 @@ class ratingallocate_observer {
* @throws coding_exception
* @throws dml_exception
*/
public static function ch_gengroups_delete (\core\event\group_deleted $event) {
public static function ch_gengroups_delete(\core\event\group_deleted $event) {
global $DB;

$eventdata = $event->get_record_snapshot('groups', $event->objectid);
Expand All @@ -61,7 +64,7 @@ public static function ch_gengroups_delete (\core\event\group_deleted $event) {
* @throws coding_exception
* @throws dml_exception
*/
public static function ra_groupings_delete (\core\event\grouping_deleted $event) {
public static function ra_groupings_delete(\core\event\grouping_deleted $event) {
global $DB;

$eventdata = $event->get_record_snapshot('groupings', $event->objectid);
Expand Down
56 changes: 44 additions & 12 deletions classes/ratings_and_allocations_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Ratings and allocations table.
*
* @package mod_ratingallocate
* @copyright 2016 Janek Lasocki-Biczysko <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -27,18 +29,33 @@
global $CFG;
require_once($CFG->libdir . '/tablelib.php');

/**
* @class ratings_and_allocations_table
*/
class ratings_and_allocations_table extends \table_sql {

/**
* Choice column.
*/
const CHOICE_COL = 'choice_';
/**
* Alloc suffix.
*/
const EXPORT_CHOICE_ALLOC_SUFFIX = 'alloc';
/**
* Text suffix.
*/
const EXPORT_CHOICE_TEXT_SUFFIX = 'text';

private $choicenames =[];
private $choicemax =[];
private $choicesum =[];

/** @var array $choicenames */
private $choicenames = [];
/** @var array $choicemax */
private $choicemax = [];
/** @var array $choicesum */
private $choicesum = [];
/** @var $titles */
private $titles;

/** @var true $shownames */
private $shownames;

/**
Expand Down Expand Up @@ -71,6 +88,16 @@ class ratings_and_allocations_table extends \table_sql {
*/
private $renderer;

/**
* @param \mod_ratingallocate_renderer $renderer
* @param $titles
* @param $ratingallocate
* @param $action
* @param $uniqueid
* @param $downloadable
* @throws \coding_exception
* @throws \dml_exception
*/
public function __construct(\mod_ratingallocate_renderer $renderer, $titles, $ratingallocate,
$action = ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE, $uniqueid = 'mod_ratingallocate_table', $downloadable = true) {
parent::__construct($uniqueid);
Expand Down Expand Up @@ -243,7 +270,7 @@ public function build_table_by_sql($ratings, $allocations, $writeable = false) {
$users = $this->rawdata;

// Group all ratings per user to match table structure.
$ratingsbyuser =[];
$ratingsbyuser = [];
foreach ($ratings as $rating) {
if (empty($ratingsbyuser[$rating->userid])) {
$ratingsbyuser[$rating->userid] = [];
Expand Down Expand Up @@ -332,7 +359,7 @@ private function add_user_ratings_row($user, $userratings, $userallocations) {
foreach ($userratings as $choiceid => $userrating) {
$row[self::CHOICE_COL . $choiceid] = [
'rating' => $userrating,
'hasallocation' => false // May be overridden later.
'hasallocation' => false, // May be overridden later.
];
}

Expand All @@ -349,7 +376,7 @@ private function add_user_ratings_row($user, $userratings, $userallocations) {
// User has not rated this choice, but it was assigned to him/her.
$row[$rowkey] = [
'rating' => null,
'hasallocation' => true
'hasallocation' => true,
];
} else {
// User has rated this choice.
Expand Down Expand Up @@ -532,7 +559,7 @@ private function setup_filter($hidenorating = null, $showallocnecessary = null,
$filter = [
'hidenorating' => $this->hidenorating,
'showallocnecessary' => $this->showallocnecessary,
'groupselect' => $this->groupselect
'groupselect' => $this->groupselect,
];
}
if (!is_null($hidenorating)) {
Expand All @@ -558,7 +585,7 @@ public function get_filter() {
$filter = [
'hidenorating' => $this->hidenorating,
'showallocnecessary' => $this->showallocnecessary,
'groupselect' => $this->groupselect
'groupselect' => $this->groupselect,
];
return $filter;
}
Expand Down Expand Up @@ -617,12 +644,17 @@ function($u) {
[
'ratingallocateid' => $this->ratingallocate->ratingallocate->id,
'ratingallocateid2' => $this->ratingallocate->ratingallocate->id,
'groupselect' => $this->groupselect
'groupselect' => $this->groupselect,
]
)
);
}

/**
* @param $choiceids
* @return array
* @throws \dml_exception
*/
private function filter_choiceids($choiceids) {
global $DB;
if (!$choiceids) {
Expand Down Expand Up @@ -655,7 +687,7 @@ function($c) {
$DB->get_records_sql($sql,
[
'ratingallocateid' => $this->ratingallocate->ratingallocate->id,
'groupselect' => $this->groupselect
'groupselect' => $this->groupselect,
]
)
);
Expand Down
5 changes: 5 additions & 0 deletions classes/task/send_distribution_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Send distibution notification.
*
* @package mod_ratingallocate
* @copyright 2014 M Schulze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand All @@ -28,6 +30,9 @@

use ratingallocate\db as this_db;

/**
* @class send_distibution_notification
*/
class send_distribution_notification extends \core\task\adhoc_task {
// Gets executed by the task runner. Will lookup the ratingallocation object and
// command it to notify users.
Expand Down
Loading

0 comments on commit 8f484ac

Please sign in to comment.