mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Namespace changes, outagedb changed to used static methods instead on singleton, utils renamed to outagelib (better name when using the 'use' directive). Issue #1
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage;
|
||||
namespace auth_outage\forms\outage;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
@@ -30,7 +30,7 @@ require_once($CFG->libdir . '/formslib.php');
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outagedeleteform extends \moodleform {
|
||||
class delete extends \moodleform {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see moodleform::definition()
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage;
|
||||
namespace auth_outage\forms\outage;
|
||||
|
||||
if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
||||
@@ -30,7 +30,7 @@ require_once($CFG->libdir . '/formslib.php');
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outageform extends \moodleform {
|
||||
class edit extends \moodleform {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see moodleform::definition()
|
||||
@@ -23,7 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage;
|
||||
namespace auth_outage\models;
|
||||
|
||||
use auth_outage\outagelib;
|
||||
|
||||
class outage
|
||||
{
|
||||
@@ -82,7 +84,7 @@ class outage
|
||||
}
|
||||
|
||||
if (is_object($data) || is_array($data)) {
|
||||
outageutils::data2object($data, $this);
|
||||
outagelib::data2object($data, $this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,43 +25,12 @@
|
||||
|
||||
namespace auth_outage;
|
||||
|
||||
use auth_outage\models\outage;
|
||||
|
||||
final class outagedb
|
||||
{
|
||||
/**
|
||||
* @var outagedb Singleton reference created on first use.
|
||||
*/
|
||||
private static $singleton = null;
|
||||
|
||||
/**
|
||||
* Returns the singleton instance.
|
||||
*
|
||||
* @return outagedb The singleton object.
|
||||
*/
|
||||
public static function get() {
|
||||
if (is_null(self::$singleton)) {
|
||||
self::$singleton = new outagedb();
|
||||
}
|
||||
return self::$singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private clone method to prevent cloning singleton.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __clone() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Private unserialize method to prevent unserializing singleton.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __wakeup() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor (singleton), use outagedb::get() instead.
|
||||
* Private constructor, use static methods instead.
|
||||
*/
|
||||
private function __construct() {
|
||||
}
|
||||
@@ -69,7 +38,7 @@ final class outagedb
|
||||
/**
|
||||
* Gets all outage entries.
|
||||
*/
|
||||
public function getall() {
|
||||
public static function getall() {
|
||||
global $DB;
|
||||
|
||||
$outages = [];
|
||||
@@ -83,7 +52,11 @@ final class outagedb
|
||||
return $outages;
|
||||
}
|
||||
|
||||
public function getbyid($id) {
|
||||
/**
|
||||
* @param $id int Outage id to get.
|
||||
* @return outage|null Returns the outage or null if not found.
|
||||
*/
|
||||
public static function getbyid($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) {
|
||||
@@ -107,7 +80,7 @@ final class outagedb
|
||||
* @param outage $outage Outage to save.
|
||||
* @return int Outage ID.
|
||||
*/
|
||||
public function save(outage $outage) {
|
||||
public static function save(outage $outage) {
|
||||
global $DB, $USER;
|
||||
|
||||
// Do not change the original object.
|
||||
@@ -139,7 +112,7 @@ final class outagedb
|
||||
* @param $id outage Outage ID to delete
|
||||
* @throws InvalidArgumentException If ID is not valid.
|
||||
*/
|
||||
public function delete($id) {
|
||||
public static function delete($id) {
|
||||
global $DB;
|
||||
|
||||
if (!is_int($id)) {
|
||||
|
||||
@@ -28,7 +28,7 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
* @copyright Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outageutils
|
||||
class outagelib
|
||||
{
|
||||
/**
|
||||
* Initializes admin pages for outage.
|
||||
@@ -43,7 +43,7 @@ class outageutils
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from an object or array into another object.
|
||||
* Loads data from an object or array into another object. It ensures no new fields are created in the $obj.
|
||||
*
|
||||
* @param $data mixed An object or array.
|
||||
* @param $obj object Destination object to write the properties.
|
||||
@@ -77,7 +77,13 @@ class outageutils
|
||||
}
|
||||
}
|
||||
|
||||
public static function parseformdata($data) {
|
||||
/**
|
||||
* Parses data from the form ensuring it is valid for an outage object.
|
||||
*
|
||||
* @param $data stdClass The input data.
|
||||
* @return stdClass The parsed data.
|
||||
*/
|
||||
public static function parseformdata(\stdClass $data) {
|
||||
if ($data->description['format'] != '1') {
|
||||
throw new \InvalidArgumentException('Not implemented for format ' . $data->description['format']);
|
||||
}
|
||||
Reference in New Issue
Block a user