forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDL-72112] - #4 Review some code standard
- Loading branch information
Showing
25 changed files
with
491 additions
and
263 deletions.
There are no files selected for viewing
197 changes: 105 additions & 92 deletions
197
..._presets/lib/admin_presets_base.class.php → admin/tool/admin_presets/classes/base.php
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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; | ||
|
||
|
@@ -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); | ||
|
@@ -59,7 +72,7 @@ public function show() { | |
/** | ||
* Delete the DB preset | ||
*/ | ||
public function execute() { | ||
public function execute(): void { | ||
|
||
global $DB, $CFG; | ||
|
||
|
@@ -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'); | ||
} | ||
|
@@ -113,4 +126,4 @@ public function execute() { | |
redirect($CFG->wwwroot . '/admin/tool/admin_presets/index.php'); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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'; | ||
|
Oops, something went wrong.