Skip to content

Commit

Permalink
[MDL-72112] - #4 Review some code standard
Browse files Browse the repository at this point in the history
  • Loading branch information
CrymSonir authored and sarjona committed Sep 13, 2021
1 parent 6982568 commit 99a57ce
Show file tree
Hide file tree
Showing 25 changed files with 491 additions and 263 deletions.
197 changes: 105 additions & 92 deletions ..._presets/lib/admin_presets_base.class.php → admin/tool/admin_presets/classes/base.php
100755 → 100644

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions ...resets/lib/admin_presets_delete.class.php → admin/tool/admin_presets/classes/delete.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin presets tool main controller
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
Expand All @@ -24,16 +24,29 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace admin_tool_presets;

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

require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
global $CFG;

require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');

class admin_presets_delete extends admin_presets_base {
/**
* Admin tool presets plugin this class extend base class and handle delete function.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete extends base {

/**
* Shows a confirm box
*/
public function show() {
public function show(): void {

global $DB, $CFG, $OUTPUT;

Expand All @@ -42,15 +55,15 @@ public function show() {

$deletetext = get_string("deletepreset", "tool_admin_presets", $presetdata->name);
$confirmurl = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=' .
$this->action . '&mode=execute&id=' . $this->id . '&sesskey=' . sesskey();
$this->action . '&mode=execute&id=' . $this->id . '&sesskey=' . sesskey();
$cancelurl = $CFG->wwwroot . '/admin/tool/admin_presets/index.php';

// If the preset was applied add a warning text.
if ($previouslyapplied = $DB->get_records('tool_admin_presets_app',
array('adminpresetid' => $this->id))) {
array('adminpresetid' => $this->id))) {

$deletetext .= '<br/><br/><strong>' .
get_string("deletepreviouslyapplied", "tool_admin_presets") . '</strong>';
get_string("deletepreviouslyapplied", "tool_admin_presets") . '</strong>';
}

$this->outputs = $OUTPUT->confirm($deletetext, $confirmurl, $cancelurl);
Expand All @@ -59,7 +72,7 @@ public function show() {
/**
* Delete the DB preset
*/
public function execute() {
public function execute(): void {

global $DB, $CFG;

Expand All @@ -81,27 +94,27 @@ public function execute() {

// Deleting the preset applications.
if ($previouslyapplied = $DB->get_records('tool_admin_presets_app',
array('adminpresetid' => $this->id), 'id')) {
array('adminpresetid' => $this->id), 'id')) {

foreach ($previouslyapplied as $application) {

// Deleting items.
if (!$DB->delete_records('tool_admin_presets_app_it',
array('adminpresetapplyid' => $application->id))) {
array('adminpresetapplyid' => $application->id))) {

print_error('errordeleting', 'tool_admin_presets');
}

// Deleting attributes.
if (!$DB->delete_records('tool_admin_presets_app_it_a',
array('adminpresetapplyid' => $application->id))) {
array('adminpresetapplyid' => $application->id))) {

print_error('errordeleting', 'tool_admin_presets');
}
}

if (!$DB->delete_records('tool_admin_presets_app',
array('adminpresetid' => $this->id))) {
array('adminpresetid' => $this->id))) {

print_error('errordeleting', 'tool_admin_presets');
}
Expand All @@ -113,4 +126,4 @@ public function execute() {
redirect($CFG->wwwroot . '/admin/tool/admin_presets/index.php');
}

}
}
25 changes: 18 additions & 7 deletions admin/tool/admin_presets/classes/event/preset_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin presets tool main controller
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
Expand All @@ -26,24 +26,35 @@

namespace tool_admin_presets\event;

use core\event\base;

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

class preset_deleted extends \core\event\base {
/**
* Admin tool presets event class deleted.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preset_deleted extends base {

public static function get_name() {
public static function get_name(): string {
return get_string('eventpresetdeleted', 'tool_admin_presets');
}

public function get_description() {
public function get_description(): string {
return "User {$this->userid} has deleted the preset with id {$this->objectid}.";
}

public function get_legacy_logdata() {
public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'delete', '',
$this->objectid, $this->contextinstanceid);
$this->objectid, $this->contextinstanceid);
}

protected function init() {
protected function init(): void {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
Expand Down
33 changes: 27 additions & 6 deletions admin/tool/admin_presets/classes/event/preset_downloaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,47 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_admin_presets\event;

use core\event\base;

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

class preset_downloaded extends \core\event\base {
/**
* Admin tool presets event class downloaded.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preset_downloaded extends base {

public static function get_name() {
public static function get_name(): string {
return get_string('eventpresetdownloaded', 'tool_admin_presets');
}

public function get_description() {
public function get_description(): string {
return "User {$this->userid} has downloaded the preset with id {$this->objectid}.";
}

public function get_url() {
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
array('action' => 'export', 'mode' => 'download_xml', 'id' => $this->objectid, 'sesskey' => sesskey()));
array('action' => 'export', 'mode' => 'download_xml', 'id' => $this->objectid, 'sesskey' => sesskey()));
}

protected function init() {
protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
Expand Down
29 changes: 20 additions & 9 deletions admin/tool/admin_presets/classes/event/preset_exported.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin presets tool main controller
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
Expand All @@ -26,29 +26,40 @@

namespace tool_admin_presets\event;

use core\event\base;

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

class preset_exported extends \core\event\base {
/**
* Admin tool presets event class exported.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preset_exported extends base {

public static function get_name() {
public static function get_name(): string {
return get_string('eventpresetexported', 'tool_admin_presets');
}

public function get_description() {
public function get_description(): string {
return "User {$this->userid} has exported the preset with id {$this->objectid}.";
}

public function get_url() {
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}

public function get_legacy_logdata() {
public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'export', '',
$this->objectid, $this->contextinstanceid);
$this->objectid, $this->contextinstanceid);
}

protected function init() {
protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
Expand Down
29 changes: 20 additions & 9 deletions admin/tool/admin_presets/classes/event/preset_imported.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin presets tool main controller
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
Expand All @@ -26,29 +26,40 @@

namespace tool_admin_presets\event;

use core\event\base;

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

class preset_imported extends \core\event\base {
/**
* Admin tool presets event class imported.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preset_imported extends base {

public static function get_name() {
public static function get_name(): string {
return get_string('eventpresetimported', 'tool_admin_presets');
}

public function get_description() {
public function get_description(): string {
return "User {$this->userid} has imported the preset with id {$this->objectid}.";
}

public function get_url() {
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}

public function get_legacy_logdata() {
public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'import', '',
$this->objectid, $this->contextinstanceid);
$this->objectid, $this->contextinstanceid);
}

protected function init() {
protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
Expand Down
29 changes: 20 additions & 9 deletions admin/tool/admin_presets/classes/event/preset_loaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Admin presets tool main controller
* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
Expand All @@ -26,29 +26,40 @@

namespace tool_admin_presets\event;

use core\event\base;

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

class preset_loaded extends \core\event\base {
/**
* Admin tool presets event class loaded.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko
* @orignalauthor David Monllaó <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class preset_loaded extends base {

public static function get_name() {
public static function get_name(): string {
return get_string('eventpresetloaded', 'tool_admin_presets');
}

public function get_description() {
public function get_description(): string {
return "User {$this->userid} has loaded the preset with id {$this->objectid}.";
}

public function get_url() {
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}

public function get_legacy_logdata() {
public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'load', '',
$this->objectid, $this->contextinstanceid);
$this->objectid, $this->contextinstanceid);
}

protected function init() {
protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
Expand Down
Loading

0 comments on commit 99a57ce

Please sign in to comment.