first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+139
View File
@@ -0,0 +1,139 @@
<?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/>.
/**
* Mock condition.
*
* @package core_availability
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace availability_mock;
defined('MOODLE_INTERNAL') || die();
/**
* Mock condition.
*
* @package core_availability
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class condition extends \core_availability\condition {
/** @var bool True if available */
protected $available;
/** @var string Message if not available */
protected $message;
/** @var bool True if available for all (normal state) */
protected $forall;
/** @var bool True if available for all (NOT state) */
protected $forallnot;
/** @var string Dependency table (empty if none) */
protected $dependtable;
/** @var id Dependency id (0 if none) */
protected $dependid;
/** @var array Array of user ids for filter results, empty if no filter support */
protected $filter;
/**
* Constructs a mock condition with given structure.
*
* @param \stdClass $structure Structure object
*/
public function __construct($structure) {
$this->available = isset($structure->a) ? $structure->a : false;
$this->message = isset($structure->m) ? $structure->m : '';
$this->forall = isset($structure->all) ? $structure->all : false;
$this->forallnot = isset($structure->allnot) ? $structure->allnot : false;
$this->dependtable = isset($structure->table) ? $structure->table : '';
$this->dependid = isset($structure->id) ? $structure->id : 0;
$this->filter = isset($structure->filter) ? $structure->filter : array();
}
public function save() {
return (object)array('a' => $this->available, 'm' => $this->message,
'all' => $this->forall, 'allnot' => $this->forallnot,
'table' => $this->dependtable, 'id' => $this->dependid,
'filter' => $this->filter);
}
public function is_available($not, \core_availability\info $info, $grabthelot, $userid) {
return $not ? !$this->available : $this->available;
}
public function is_available_for_all($not = false) {
return $not ? $this->forallnot : $this->forall;
}
public function get_description($full, $not, \core_availability\info $info) {
$fulltext = $full ? '[FULL]' : '';
$nottext = $not ? '!' : '';
return $nottext . $fulltext . $this->message;
}
public function get_standalone_description(
$full, $not, \core_availability\info $info) {
// Override so that we can spot that this function is used.
return 'SA: ' . $this->get_description($full, $not, $info);
}
public function update_dependency_id($table, $oldid, $newid) {
if ($table === $this->dependtable && (int)$oldid === (int)$this->dependid) {
$this->dependid = $newid;
return true;
} else {
return false;
}
}
protected function get_debug_string() {
return ($this->available ? 'y' : 'n') . ',' . $this->message;
}
public function is_applied_to_user_lists() {
return $this->filter;
}
public function filter_user_list(array $users, $not, \core_availability\info $info,
\core_availability\capability_checker $checker) {
$result = array();
foreach ($users as $id => $user) {
$match = in_array($id, $this->filter);
if ($not) {
$match = !$match;
}
if ($match) {
$result[$id] = $user;
}
}
return $result;
}
public function get_user_list_sql($not, \core_availability\info $info, $onlyactive) {
global $DB;
// The data for this condition is not really stored in the database,
// so we return SQL that contains the hard-coded user list.
list ($enrolsql, $enrolparams) =
get_enrolled_sql($info->get_context(), '', 0, $onlyactive);
$condition = $not ? 'NOT' : '';
list ($matchsql, $matchparams) = $DB->get_in_or_equal($this->filter, SQL_PARAMS_NAMED);
$sql = "SELECT userids.id
FROM ($enrolsql) userids
WHERE $condition (userids.id $matchsql)";
return array($sql, array_merge($enrolparams, $matchparams));
}
}
+78
View File
@@ -0,0 +1,78 @@
<?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/>.
/**
* For use in unit tests that require an info object which isn't really used.
*
* @package core_availability
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_availability;
defined('MOODLE_INTERNAL') || die();
/**
* For use in unit tests that require an info object which isn't really used.
*
* @package core_availability
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mock_info extends info {
/** @var int User id for modinfo */
protected $userid;
/**
* Constructs with item details.
*
* @param \stdClass $course Optional course param (otherwise uses $SITE)
* @param int $userid Userid for modinfo (if used)
*/
public function __construct($course = null, $userid = 0) {
global $SITE;
if (!$course) {
$course = $SITE;
}
parent::__construct($course, true, null);
$this->userid = $userid;
}
protected function get_thing_name() {
return 'Mock';
}
public function get_context() {
return \context_course::instance($this->get_course()->id);
}
protected function get_view_hidden_capability() {
return 'moodle/course:ignoreavailabilityrestrictions';
}
protected function set_in_database($availability) {
}
public function get_modinfo() {
// Allow modinfo usage outside is_available etc., so we can use this
// to directly call into condition is_available.
if (!$this->userid) {
throw new \coding_exception('Need to set mock_info userid');
}
return get_fast_modinfo($this->course, $this->userid);
}
}
+115
View File
@@ -0,0 +1,115 @@
<?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/>.
/**
* For use in unit tests that require an info module which isn't really used.
*
* @package core_availability
* @copyright 2019 Ferran Recio
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_availability;
defined('MOODLE_INTERNAL') || die();
/**
* For use in unit tests that require an info module which isn't really used.
*
* @package core_availability
* @copyright 2019 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mock_info_module extends info_module {
/** @var int User id for modinfo */
protected $userid;
/** @var \cm_info Activity. */
protected $cm;
/**
* Constructs with item details.
*
* @param int $userid Userid for modinfo (if used)
* @param \cm_info $cm Course-module object
*/
public function __construct($userid = 0, \cm_info $cm = null) {
parent::__construct($cm);
$this->userid = $userid;
$this->cm = $cm;
}
/**
* Just returns a mock name.
*
* @return string Name of item
*/
protected function get_thing_name() {
return 'Mock Module';
}
/**
* Returns the current context.
*
* @return \context Context for this item
*/
public function get_context() {
return \context_course::instance($this->get_course()->id);
}
/**
* Returns the cappability used to ignore access restrictions.
*
* @return string Name of capability used to view hidden items of this type
*/
protected function get_view_hidden_capability() {
return 'moodle/course:ignoreavailabilityrestrictions';
}
/**
* Mocks don't need to save anything into DB.
*
* @param string $availability New JSON value
*/
protected function set_in_database($availability) {
}
/**
* Obtains the modinfo associated with this availability information.
*
* Note: This field is available ONLY for use by conditions when calculating
* availability or information.
*
* @return \course_modinfo Modinfo
* @throws \coding_exception If called at incorrect times
*/
public function get_modinfo() {
// Allow modinfo usage outside is_available etc., so we can use this
// to directly call into condition is_available.
if (!$this->userid) {
throw new \coding_exception('Need to set mock_info userid');
}
return get_fast_modinfo($this->course, $this->userid);
}
/**
* Override course-module info.
* @param \cm_info $cm
*/
public function set_cm(\cm_info $cm) {
$this->cm = $cm;
}
}
+116
View File
@@ -0,0 +1,116 @@
<?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/>.
/**
* For use in unit tests that require an info section which isn't really used.
*
* @package core_availability
* @copyright 2019 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_availability;
defined('MOODLE_INTERNAL') || die();
/**
* For use in unit tests that require an info section which isn't really used.
*
* @package core_availability
* @copyright 2019 Ferran Recio
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mock_info_section extends info_section {
/** @var int User id for modinfo */
protected $userid;
/** @var \section_info Section. */
protected $section;
/**
* Constructs with item details.
*
* @param int $userid Userid for modinfo (if used)
* @param \section_info $section Section object
*/
public function __construct($userid = 0, \section_info $section = null) {
parent::__construct($section);
$this->userid = $userid;
$this->section = $section;
}
/**
* Just returns a mock name.
*
* @return string Name of item
*/
protected function get_thing_name() {
return 'Mock Section';
}
/**
* Returns the current context.
*
* @return \context Context for this item
*/
public function get_context() {
return \context_course::instance($this->get_course()->id);
}
/**
* Returns the cappability used to ignore access restrictions.
*
* @return string Name of capability used to view hidden items of this type
*/
protected function get_view_hidden_capability() {
return 'moodle/course:ignoreavailabilityrestrictions';
}
/**
* Mocks don't need to save anything into DB.
*
* @param string $availability New JSON value
*/
protected function set_in_database($availability) {
}
/**
* Obtains the modinfo associated with this availability information.
*
* Note: This field is available ONLY for use by conditions when calculating
* availability or information.
*
* @return \course_modinfo Modinfo
* @throws \coding_exception If called at incorrect times
*/
public function get_modinfo() {
// Allow modinfo usage outside is_available etc., so we can use this
// to directly call into condition is_available.
if (!$this->userid) {
throw new \coding_exception('Need to set mock_info userid');
}
return get_fast_modinfo($this->course, $this->userid);
}
/**
* Override section info.
*
* @param \section_info $section
*/
public function set_section(\section_info $section) {
$this->section = $section;
}
}