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.
Merge branch 'MDL-61423-master' of git://github.com/mihailges/moodle
- Loading branch information
Showing
25 changed files
with
1,189 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Contains helper class for digital consent. | ||
* | ||
* @package core_auth | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_auth; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Helper class for digital consent. | ||
* | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class digital_consent { | ||
|
||
/** | ||
* Returns true if age and location verification is enabled in the site. | ||
* | ||
* @return bool | ||
*/ | ||
public static function is_age_digital_consent_verification_enabled() { | ||
global $CFG; | ||
|
||
return !empty($CFG->agedigitalconsentverification); | ||
} | ||
|
||
/** | ||
* Checks if a user is a digital minor. | ||
* | ||
* @param int $age | ||
* @param string $country The country code (ISO 3166-2) | ||
* @return bool | ||
*/ | ||
public static function is_minor($age, $country) { | ||
global $CFG; | ||
|
||
$ageconsentmap = $CFG->agedigitalconsentmap; | ||
$agedigitalconsentmap = self::parse_age_digital_consent_map($ageconsentmap); | ||
|
||
return array_key_exists($country, $agedigitalconsentmap) ? | ||
$age < $agedigitalconsentmap[$country] : $age < $agedigitalconsentmap['*']; | ||
} | ||
|
||
/** | ||
* Parse the agedigitalconsentmap setting into an array. | ||
* | ||
* @param string $ageconsentmap The value of the agedigitalconsentmap setting | ||
* @return array $ageconsentmapparsed | ||
*/ | ||
public static function parse_age_digital_consent_map($ageconsentmap) { | ||
|
||
$ageconsentmapparsed = array(); | ||
$countries = get_string_manager()->get_list_of_countries(); | ||
$isdefaultvaluepresent = false; | ||
$lines = preg_split('/\r|\n/', $ageconsentmap, -1, PREG_SPLIT_NO_EMPTY); | ||
foreach ($lines as $line) { | ||
$arr = explode(",", $line); | ||
// Handle if there is more or less than one comma separator. | ||
if (count($arr) != 2) { | ||
throw new \moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line); | ||
} | ||
$country = trim($arr[0]); | ||
$age = trim($arr[1]); | ||
// Check if default. | ||
if ($country == "*") { | ||
$isdefaultvaluepresent = true; | ||
} | ||
// Handle if the presented value for country is not valid. | ||
if ($country !== "*" && !array_key_exists($country, $countries)) { | ||
throw new \moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country); | ||
} | ||
// Handle if the presented value for age is not valid. | ||
if (!is_numeric($age)) { | ||
throw new \moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age); | ||
} | ||
$ageconsentmapparsed[$country] = $age; | ||
} | ||
// Handle if a default value does not exist. | ||
if (!$isdefaultvaluepresent) { | ||
throw new \moodle_exception('agedigitalconsentmapinvaliddefault'); | ||
} | ||
|
||
return $ageconsentmapparsed; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Age and location verification mform. | ||
* | ||
* @package core_auth | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_auth\form; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir.'/formslib.php'); | ||
|
||
use moodleform; | ||
|
||
/** | ||
* Age and location verification mform class. | ||
* | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class verify_age_location_form extends moodleform { | ||
/** | ||
* Defines the form fields. | ||
*/ | ||
public function definition() { | ||
global $CFG; | ||
|
||
$mform = $this->_form; | ||
|
||
$mform->addElement('text', 'age', get_string('whatisyourage'), array('optional' => false)); | ||
$mform->setType('age', PARAM_RAW); | ||
$mform->addRule('age', null, 'required', null, 'client'); | ||
$mform->addRule('age', null, 'numeric', null, 'client'); | ||
|
||
$countries = get_string_manager()->get_list_of_countries(); | ||
$defaultcountry[''] = get_string('selectacountry'); | ||
$countries = array_merge($defaultcountry, $countries); | ||
$mform->addElement('select', 'country', get_string('wheredoyoulive'), $countries); | ||
$mform->addRule('country', null, 'required', null, 'client'); | ||
$mform->setDefault('country', $CFG->country); | ||
|
||
$this->add_action_buttons(true, get_string('proceed')); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Digital minor renderable. | ||
* | ||
* @package core_auth | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_auth\output; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use renderable; | ||
use renderer_base; | ||
use templatable; | ||
|
||
/** | ||
* Digital minor renderable class. | ||
* | ||
* @copyright 2018 Mihail Geshoski <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class digital_minor_page implements renderable, templatable { | ||
|
||
/** | ||
* Export the page data for the mustache template. | ||
* | ||
* @param renderer_base $output renderer to be used to render the page elements. | ||
* @return stdClass | ||
*/ | ||
public function export_for_template(renderer_base $output) { | ||
global $SITE, $CFG; | ||
|
||
$sitename = format_string($SITE->fullname); | ||
$supportname = $CFG->supportname; | ||
$supportemail = $CFG->supportemail; | ||
|
||
$context = [ | ||
'sitename' => $sitename, | ||
'supportname' => $supportname, | ||
'supportemail' => $supportemail, | ||
'homelink' => new \moodle_url('/') | ||
]; | ||
|
||
return $context; | ||
} | ||
} |
Oops, something went wrong.