From 738c2af2d5685ff01c78170985763eee0baee5a8 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Tue, 14 May 2019 12:26:15 +0200 Subject: [PATCH] Init --- classes/condition.php | 105 ++++++++++++++++++++++++++++- classes/frontend.php | 37 +++++++++- lang/en/availability_ipaddress.php | 6 +- version.php | 13 +++- yui/src/form/meta/form.json | 10 +++ 5 files changed, 162 insertions(+), 9 deletions(-) diff --git a/classes/condition.php b/classes/condition.php index 9311a93..05c640a 100644 --- a/classes/condition.php +++ b/classes/condition.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * + * Condition class * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @@ -23,4 +23,105 @@ * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven * @author Luuk Verhoeven **/ - \ No newline at end of file + +namespace availability_ipaddress; + +use core_availability\info; + +defined('MOODLE_INTERNAL') || die; + +/** + * Class condition + * + * @package availability_ipaddress + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven + */ +class condition extends \core_availability\condition { + + /** + * @var string + */ + protected $ip_addresses = ''; + + /** + * Determines whether a particular item is currently available + * according to this availability condition. + * + * If implementations require a course or modinfo, they should use + * the get methods in $info. + * + * The $not option is potentially confusing. This option always indicates + * the 'real' value of NOT. For example, a condition inside a 'NOT AND' + * group will get this called with $not = true, but if you put another + * 'NOT OR' group inside the first group, then a condition inside that will + * be called with $not = false. We need to use the real values, rather than + * the more natural use of the current value at this point inside the tree, + * so that the information displayed to users makes sense. + * + * @param bool $not Set true if we are inverting the condition + * @param info $info Item we're checking + * @param bool $grabthelot Performance hint: if true, caches information + * required for all course-modules, to make the front page and similar + * pages work more quickly (works only for current user) + * @param int $userid User ID to check availability for + * + * @return bool True if available + */ + public function is_available($not, info $info, $grabthelot, $userid) { + // Check if the setting is enabled. + + // Check if ip-address matches + + + return false; + } + + /** + * Obtains a string describing this restriction (whether or not + * it actually applies). Used to obtain information that is displayed to + * students if the activity is not available to them, and for staff to see + * what conditions are. + * + * The $full parameter can be used to distinguish between 'staff' cases + * (when displaying all information about the activity) and 'student' cases + * (when displaying only conditions they don't meet). + * + * If implementations require a course or modinfo, they should use + * the get methods in $info. + * + * The special string can be returned, where + * 123 is any number. It will be replaced with the correctly-formatted + * name for that activity. + * + * @param bool $full Set true if this is the 'full information' view + * @param bool $not Set true if we are inverting the condition + * @param info $info Item we're checking + * + * @return string Information string (for admin) about all restrictions on + * this item + * @throws \coding_exception + */ + public function get_description($full, $not, info $info) { + return get_string('require_condition', 'availability_ipaddress'); + } + + /** + * Obtains a representation of the options of this condition as a string, + * for debugging. + * + * @return string Text representation of parameters + */ + protected function get_debug_string() { + // TODO: Implement get_debug_string() method. + } + + /** + * Saves tree data back to a structure object. + * + * @return \stdClass Structure object (ready to be made into JSON format) + */ + public function save() { + // TODO: Implement save() method. + } +} \ No newline at end of file diff --git a/classes/frontend.php b/classes/frontend.php index 9311a93..9536962 100644 --- a/classes/frontend.php +++ b/classes/frontend.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * + * Front-end class * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @@ -23,4 +23,37 @@ * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven * @author Luuk Verhoeven **/ - \ No newline at end of file + +namespace availability_ipaddress; +defined('MOODLE_INTERNAL') || die; + +/** + * Class frontend + * + * @package availability_ipaddress + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven + */ +class frontend extends \core_availability\frontend { + + /** + * @return array + */ + protected function get_javascript_strings() { + return ['requires_app', 'requires_notapp', 'label_access']; + } + + /** + * Decides whether this plugin should be available in a given course. The + * plugin can do this depending on course or system settings. + * + * @param \stdClass $course Course object + * @param \cm_info $cm Course-module currently being edited (null if none) + * @param \section_info $section Section currently being edited (null if none) + * + * @return bool True if there are completion criteria + */ + protected function allow_add($course, \cm_info $cm = null, \section_info $section = null) { + return true; + } +} \ No newline at end of file diff --git a/lang/en/availability_ipaddress.php b/lang/en/availability_ipaddress.php index 9311a93..733e07c 100644 --- a/lang/en/availability_ipaddress.php +++ b/lang/en/availability_ipaddress.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * + * EN language file. * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @@ -23,4 +23,6 @@ * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven * @author Luuk Verhoeven **/ - \ No newline at end of file +$string['pluginname'] = 'IP address'; +$string['title'] = 'IP address'; +$string['description'] = 'Restrict access by ip-address'; \ No newline at end of file diff --git a/version.php b/version.php index de98ef0..1c0d362 100644 --- a/version.php +++ b/version.php @@ -15,12 +15,19 @@ // along with Moodle. If not, see . /** - * + * Version information * * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * - * @package moodle-availability_ipaddress + * @package availability_ipaddress * @copyright 2019-05-14 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven * @author Luuk Verhoeven **/ - \ No newline at end of file + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'availability_ipaddress'; +$plugin->version = 2019051400; +$plugin->release = 'v3.5.0'; +$plugin->requires = 2018120300; +$plugin->maturity = MATURITY_BETA; \ No newline at end of file diff --git a/yui/src/form/meta/form.json b/yui/src/form/meta/form.json index e69de29..b9b1508 100644 --- a/yui/src/form/meta/form.json +++ b/yui/src/form/meta/form.json @@ -0,0 +1,10 @@ +{ + "moodle-availability_ipaddress-form": { + "requires": [ + "base", + "node", + "event", + "moodle-core_availability-form" + ] + } +} \ No newline at end of file