Skip to content

Commit

Permalink
Merge pull request #465 from jrchamp/test/phpcs-ruleset-additions
Browse files Browse the repository at this point in the history
moodle-cs and PSR-1/12 ruleset additions
  • Loading branch information
jrchamp authored Mar 2, 2023
2 parents 3c29fca + 6667c9b commit 4400334
Show file tree
Hide file tree
Showing 44 changed files with 257 additions and 141 deletions.
5 changes: 2 additions & 3 deletions backup/moodle2/backup_zoom_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Provides the steps to perform one complete backup of the zoom instance
*/
class backup_zoom_activity_task extends backup_activity_task {

/**
* No specific settings for this activity
*/
Expand All @@ -57,11 +56,11 @@ public static function encode_content_links($content) {
$base = preg_quote($CFG->wwwroot, '/');

// Link to the list of zooms.
$search = '/('.$base.'\/mod\/zoom\/index.php\?id\=)([0-9]+)/';
$search = '/(' . $base . '\/mod\/zoom\/index.php\?id\=)([0-9]+)/';
$content = preg_replace($search, '$@ZOOMINDEX*$2@$', $content);

// Link to zoom view by moduleid.
$search = '/('.$base.'\/mod\/zoom\/view.php\?id\=)([0-9]+)/';
$search = '/(' . $base . '\/mod\/zoom\/view.php\?id\=)([0-9]+)/';
$content = preg_replace($search, '$@ZOOMVIEWBYID*$2@$', $content);

return $content;
Expand Down
1 change: 0 additions & 1 deletion backup/moodle2/backup_zoom_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* Define the complete zoom structure for backup, with file and id annotations.
*/
class backup_zoom_activity_structure_step extends backup_activity_structure_step {

/**
* Defines the backup structure of the module.
*
Expand Down
2 changes: 0 additions & 2 deletions backup/moodle2/restore_zoom_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* Provides all the settings and steps to perform complete restore of the activity.
*/
class restore_zoom_activity_task extends restore_activity_task {

/**
* Define (add) particular settings this activity can have
*/
Expand Down Expand Up @@ -72,7 +71,6 @@ public static function define_decode_rules() {
$rules[] = new restore_decode_rule('ZOOMINDEX', '/mod/zoom/index.php?id=$1', 'course_module');

return $rules;

}

/**
Expand Down
4 changes: 1 addition & 3 deletions backup/moodle2/restore_zoom_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@

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

require_once($CFG->dirroot.'/mod/zoom/locallib.php');
require_once($CFG->dirroot . '/mod/zoom/locallib.php');

/**
* Structure step to restore one zoom activity
*/
class restore_zoom_activity_structure_step extends restore_activity_structure_step {

/**
* Defines structure of path elements to be processed during the restore
*
* @return array of restore_path_element
*/
protected function define_structure() {

$paths = [];
$paths[] = new restore_path_element('zoom', '/activity/zoom');
$paths[] = new restore_path_element('zoom_tracking_field', '/activity/zoom/trackingfields/trackingfield');
Expand Down
1 change: 0 additions & 1 deletion classes/analytics/indicator/activity_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* Activity base class.
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {

/**
* Grading not implemented.
*
Expand Down
3 changes: 1 addition & 2 deletions classes/analytics/indicator/cognitive_depth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
* Cognitive depth indicator - zoom.
*/
class cognitive_depth extends activity_base {

/**
* Returns the name.
*
* @return object
*/
public static function get_name() : \lang_string {
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_zoom');
}

Expand Down
3 changes: 1 addition & 2 deletions classes/analytics/indicator/social_breadth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
* Social breadth indicator.
*/
class social_breadth extends activity_base {

/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return object
*/
public static function get_name() : \lang_string {
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_zoom');
}

Expand Down
1 change: 0 additions & 1 deletion classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* override methods get_url() and get_legacy_log_data(), too.
*/
class course_module_viewed extends \core\event\course_module_viewed {

/**
* Initialize the event
*/
Expand Down
1 change: 0 additions & 1 deletion classes/event/join_meeting_button_clicked.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* Records when a join meeting button is clicked.
*/
class join_meeting_button_clicked extends \core\event\base {

/**
* Initializes the event.
*/
Expand Down
4 changes: 3 additions & 1 deletion classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* Zoom external functions
*/
class mod_zoom_external extends external_api {

/**
* Returns description of method parameters
*
Expand Down Expand Up @@ -92,6 +91,7 @@ public static function get_state($zoomid) {
$result['start_time'] = $zoom->start_time;
$result['duration'] = $zoom->duration;
}

$result['haspassword'] = (isset($zoom->password) && $zoom->password !== '');
$result['joinbeforehost'] = $zoom->option_jbh;
$result['startvideohost'] = $zoom->option_host_video;
Expand All @@ -111,6 +111,7 @@ public static function get_state($zoomid) {
} else {
$status = get_string('recurringmeetinglong', 'mod_zoom');
}

$result['status'] = $status;

$result['warnings'] = $warnings;
Expand Down Expand Up @@ -194,6 +195,7 @@ public static function grade_item_update($zoomid) {
$warningmsg = clean_param($meetinginfo['error'], PARAM_TEXT);
throw new invalid_response_exception($warningmsg);
}

$result['warnings'] = $warnings;
return $result;
}
Expand Down
14 changes: 12 additions & 2 deletions classes/invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
* Invitation class.
*/
class invitation {

/**
* Invitation settings prefix.
* @var string
*/
const PREFIX = 'invitation_';
public const PREFIX = 'invitation_';

/** @var string|null $invitation The unaltered zoom invitation text. */
private $invitation;
Expand Down Expand Up @@ -63,24 +62,29 @@ public function get_display_string(int $coursemoduleid, int $userid = null) {
if (empty($this->invitation)) {
return null;
}

// If regex patterns are disabled, return the raw zoom meeting invitation.
if (!get_config('zoom', 'invitationregexenabled')) {
return $this->invitation;
}

$displaystring = $this->invitation;
try {
// If setting enabled, strip the invite message.
if (get_config('zoom', 'invitationremoveinvite')) {
$displaystring = $this->remove_element($displaystring, 'invite');
}

// If setting enabled, strip the iCal link.
if (get_config('zoom', 'invitationremoveicallink')) {
$displaystring = $this->remove_element($displaystring, 'icallink');
}

// Check user capabilities, and remove parts of the invitation they don't have permission to view.
if (!has_capability('mod/zoom:viewjoinurl', \context_module::instance($coursemoduleid), $userid)) {
$displaystring = $this->remove_element($displaystring, 'joinurl');
}

if (!has_capability('mod/zoom:viewdialin', \context_module::instance($coursemoduleid), $userid)) {
$displaystring = $this->remove_element($displaystring, 'onetapmobile');
$displaystring = $this->remove_element($displaystring, 'dialin');
Expand All @@ -95,6 +99,7 @@ public function get_display_string(int $coursemoduleid, int $userid = null) {
debugging($e->getMessage(), DEBUG_DEVELOPER);
return $this->invitation;
}

$displaystring = trim($this->clean_paragraphs($displaystring));
return $displaystring;
}
Expand Down Expand Up @@ -160,17 +165,20 @@ private function add_paragraph_break_above_element(string $invitation, string $e
if (empty($configregex[$element])) {
return $invitation;
}

$result = preg_match($configregex[$element], $invitation, $matches, PREG_OFFSET_CAPTURE);
// If error occurred in preg_match, show debugging message to help site administrator.
if ($result === false) {
debugging(get_string('invitationmodificationfailed', 'mod_zoom',
['element' => $element, 'pattern' => $configregex[$element]]),
DEBUG_DEVELOPER);
}

// No match found, so return invitation string unaltered.
if (empty($matches)) {
return $invitation;
}

// Get the position of the element in the full invitation string.
$pos = $matches[0][1];
// Inject a paragraph break above element. Use $this->clean_paragraphs() to fix uneven breaks between paragraphs.
Expand Down Expand Up @@ -201,13 +209,15 @@ private function get_config_invitation_regex(): array {
if ($this->configregex !== null) {
return $this->configregex;
}

$config = get_config('zoom');
$this->configregex = [];
// Get the regex defined in the plugin settings for each element.
foreach (self::get_default_invitation_regex() as $element => $pattern) {
$settingname = self::PREFIX . $element;
$this->configregex[$element] = $config->$settingname;
}

return $this->configregex;
}

Expand Down
1 change: 0 additions & 1 deletion classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Mobile output class for zoom
*/
class mobile {

/**
* Returns the zoom course view for the mobile app,
* including meeting details and launch button (if applicable).
Expand Down
5 changes: 4 additions & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class provider implements

// This plugin currently implements the original plugin_provider interface.
\core_privacy\local\request\plugin\provider {

/**
* Returns meta data about this system.
*
Expand Down Expand Up @@ -274,18 +273,21 @@ public static function delete_data_for_all_users_in_context(\context $context) {
foreach ($meetingdetails as $meetingdetail) {
$DB->delete_records('zoom_meeting_participants', ['detailsid' => $meetingdetail->id]);
}

$DB->delete_records('zoom_meeting_details', ['zoomid' => $cm->instance]);

$meetingrecordings = $DB->get_records('zoom_meeting_recordings', ['zoomid' => $cm->instance]);
foreach ($meetingrecordings as $recording) {
$DB->delete_records('zoom_meeting_recordings_view', ['recordingsid' => $recording->id]);
}

$DB->delete_records('zoom_meeting_recordings', ['zoomid' => $cm->instance]);

$breakoutrooms = $DB->get_records('zoom_meeting_breakout_rooms', ['zoomid' => $cm->instance]);
foreach ($breakoutrooms as $room) {
$DB->delete_records('zoom_breakout_participants', ['breakoutroomid' => $room->id]);
}

$DB->delete_records('zoom_meeting_breakout_rooms', ['zoomid' => $cm->instance]);
}
}
Expand All @@ -308,6 +310,7 @@ public static function delete_data_for_user(\core_privacy\local\request\approved
if (!($context instanceof \context_module)) {
continue;
}

if ($cm = get_coursemodule_from_id('zoom', $context->instanceid)) {
$meetingdetails = $DB->get_records('zoom_meeting_details', ['zoomid' => $cm->instance]);
foreach ($meetingdetails as $meetingdetail) {
Expand Down
1 change: 0 additions & 1 deletion classes/search/activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* Search area for mod_zoom activities.
*/
class activity extends \core_search\base_activity {

/**
* Returns true if this area uses file indexing.
*
Expand Down
2 changes: 1 addition & 1 deletion classes/task/get_meeting_recordings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* Scheduled task to get the meeting recordings.
*/
class get_meeting_recordings extends \core\task\scheduled_task {

/**
* Returns name of task.
*
Expand Down Expand Up @@ -91,6 +90,7 @@ public function execute() {
mtrace('Recording id: ' . $zoomrecordinginfo->recordingid . ' exist(s)...skipping');
continue;
}

$rec = new \stdClass();
$rec->zoomid = $zoom->id;
$rec->meetinguuid = trim($zoomrecordinginfo->meetinguuid);
Expand Down
Loading

0 comments on commit 4400334

Please sign in to comment.