���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/external.tar
���ѧ٧ѧ�
cohort_summary_exporter.php 0000644 00000005421 15151236530 0012263 0 ustar 00 <?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/>. /** * Class for exporting a cohort summary from an stdClass. * * @package core_cohort * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_cohort\external; defined('MOODLE_INTERNAL') || die(); use renderer_base; /** * Class for exporting a cohort summary from an stdClass. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cohort_summary_exporter extends \core\external\exporter { protected static function define_related() { // Cohorts can exist on a category context. return array('context' => '\\context'); } public static function define_properties() { return array( 'id' => array( 'type' => PARAM_INT, ), 'name' => array( 'type' => PARAM_TEXT, ), 'idnumber' => array( 'type' => PARAM_RAW, // ID numbers are plain text. 'default' => '', 'null' => NULL_ALLOWED ), 'description' => array( 'type' => PARAM_TEXT, 'default' => '', 'null' => NULL_ALLOWED ), 'descriptionformat' => array( 'type' => PARAM_INT, 'default' => FORMAT_HTML, 'null' => NULL_ALLOWED ), 'visible' => array( 'type' => PARAM_BOOL, ), 'theme' => array( 'type' => PARAM_THEME, 'null' => NULL_ALLOWED ) ); } public static function define_other_properties() { return array( 'contextname' => array( // The method context::get_context_name() already formats the string, and may return HTML. 'type' => PARAM_RAW ), ); } protected function get_other_values(renderer_base $output) { return array( 'contextname' => $this->related['context']->get_context_name() ); } } create_gradecategories.php 0000644 00000027040 15151251213 0011727 0 ustar 00 <?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/>. namespace core_grades\external; use external_api; use external_function_parameters; use external_value; use external_single_structure; use external_multiple_structure; use external_warnings; defined('MOODLE_INTERNAL') || die; require_once("$CFG->libdir/externallib.php"); require_once("$CFG->libdir/gradelib.php"); require_once("$CFG->dirroot/grade/edit/tree/lib.php"); /** * Create gradecategories webservice. * * @package core_grades * @copyright 2021 Peter Burnett <peterburnett@catalyst-au.net> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 3.11 */ class create_gradecategories extends external_api { /** * Returns description of method parameters * * @return external_function_parameters * @since Moodle 3.11 */ public static function execute_parameters(): external_function_parameters { return new external_function_parameters( [ 'courseid' => new external_value(PARAM_INT, 'id of course', VALUE_REQUIRED), 'categories' => new external_multiple_structure( new external_single_structure([ 'fullname' => new external_value(PARAM_TEXT, 'fullname of category', VALUE_REQUIRED), 'options' => new external_single_structure([ 'aggregation' => new external_value(PARAM_INT, 'aggregation method', VALUE_OPTIONAL), 'aggregateonlygraded' => new external_value(PARAM_BOOL, 'exclude empty grades', VALUE_OPTIONAL), 'aggregateoutcomes' => new external_value(PARAM_BOOL, 'aggregate outcomes', VALUE_OPTIONAL), 'droplow' => new external_value(PARAM_INT, 'drop low grades', VALUE_OPTIONAL), 'itemname' => new external_value(PARAM_TEXT, 'the category total name', VALUE_OPTIONAL), 'iteminfo' => new external_value(PARAM_TEXT, 'the category iteminfo', VALUE_OPTIONAL), 'idnumber' => new external_value(PARAM_TEXT, 'the category idnumber', VALUE_OPTIONAL), 'gradetype' => new external_value(PARAM_INT, 'the grade type', VALUE_OPTIONAL), 'grademax' => new external_value(PARAM_INT, 'the grade max', VALUE_OPTIONAL), 'grademin' => new external_value(PARAM_INT, 'the grade min', VALUE_OPTIONAL), 'gradepass' => new external_value(PARAM_INT, 'the grade to pass', VALUE_OPTIONAL), 'display' => new external_value(PARAM_INT, 'the display type', VALUE_OPTIONAL), 'decimals' => new external_value(PARAM_INT, 'the decimal count', VALUE_OPTIONAL), 'hiddenuntil' => new external_value(PARAM_INT, 'grades hidden until', VALUE_OPTIONAL), 'locktime' => new external_value(PARAM_INT, 'lock grades after', VALUE_OPTIONAL), 'weightoverride' => new external_value(PARAM_BOOL, 'weight adjusted', VALUE_OPTIONAL), 'aggregationcoef2' => new external_value(PARAM_RAW, 'weight coefficient', VALUE_OPTIONAL), 'parentcategoryid' => new external_value(PARAM_INT, 'The parent category id', VALUE_OPTIONAL), 'parentcategoryidnumber' => new external_value(PARAM_TEXT, 'the parent category idnumber', VALUE_OPTIONAL), ], 'optional category data', VALUE_DEFAULT, []), ], 'Category to create', VALUE_REQUIRED) , 'Categories to create', VALUE_REQUIRED) ] ); } /** * Creates gradecategories inside of the specified course. * * @param int $courseid the courseid to create the gradecategory in. * @param array $categories the categories to create. * @return array array of created categoryids and warnings. * @since Moodle 3.11 */ public static function execute(int $courseid, array $categories): array { $params = self::validate_parameters(self::execute_parameters(), ['courseid' => $courseid, 'categories' => $categories]); // Now params are validated, update the references. $courseid = $params['courseid']; $categories = $params['categories']; // Check that the context and permissions are OK. $context = \context_course::instance($courseid); self::validate_context($context); require_capability('moodle/grade:manage', $context); return self::create_gradecategories_from_data($courseid, $categories); } /** * Returns description of method result value * * @return external_single_structure * @since Moodle 3.11 */ public static function execute_returns(): external_single_structure { return new external_single_structure([ 'categoryids' => new external_multiple_structure( new external_value(PARAM_INT, 'created cateogry ID') ), 'warnings' => new external_warnings(), ]); } /** * Takes an array of categories and creates the inside the category tree for the supplied courseid. * * @param int $courseid the courseid to create the categories inside of. * @param array $categories the categories to create. * @return array array of results and warnings. */ public static function create_gradecategories_from_data(int $courseid, array $categories): array { global $CFG, $DB; $defaultparentcat = \grade_category::fetch_course_category($courseid); // Setup default data so WS call needs to contain only data to set. // This is not done in the Parameters, so that the array of options can be optional. $defaultdata = [ 'aggregation' => grade_get_setting($courseid, 'aggregation', $CFG->grade_aggregation, true), 'aggregateonlygraded' => 1, 'aggregateoutcomes' => 0, 'droplow' => 0, 'grade_item_itemname' => '', 'grade_item_iteminfo' => '', 'grade_item_idnumber' => '', 'grade_item_gradetype' => GRADE_TYPE_VALUE, 'grade_item_grademax' => 100, 'grade_item_grademin' => 1, 'grade_item_gradepass' => 1, 'grade_item_display' => GRADE_DISPLAY_TYPE_DEFAULT, // Hack. This must be -2 to use the default setting. 'grade_item_decimals' => -2, 'grade_item_hiddenuntil' => 0, 'grade_item_locktime' => 0, 'grade_item_weightoverride' => 0, 'grade_item_aggregationcoef2' => 0, 'parentcategory' => $defaultparentcat->id ]; // Most of the data items need boilerplate prepended. These are the exceptions. $ignorekeys = [ 'aggregation', 'aggregateonlygraded', 'aggregateoutcomes', 'droplow', 'parentcategoryid', 'parentcategoryidnumber' ]; $createdcats = []; foreach ($categories as $category) { // Setup default data so WS call needs to contain only data to set. // This is not done in the Parameters, so that the array of options can be optional. $data = $defaultdata; $data['fullname'] = $category['fullname']; foreach ($category['options'] as $key => $value) { if (!in_array($key, $ignorekeys)) { $fullkey = 'grade_item_' . $key; $data[$fullkey] = $value; } else { $data[$key] = $value; } } // Handle parent category special case. // This figures the parent category id from the provided id OR idnumber. if (array_key_exists('parentcategoryid', $category['options']) && $parentcat = $DB->get_record('grade_categories', ['id' => $category['options']['parentcategoryid'], 'courseid' => $courseid])) { $data['parentcategory'] = $parentcat->id; } else if (array_key_exists('parentcategoryidnumber', $category['options']) && $parentcatgradeitem = $DB->get_record('grade_items', [ 'itemtype' => 'category', 'courseid' => $courseid, 'idnumber' => $category['options']['parentcategoryidnumber'] ], '*', IGNORE_MULTIPLE)) { if ($parentcat = $DB->get_record('grade_categories', ['courseid' => $courseid, 'id' => $parentcatgradeitem->iteminstance])) { $data['parentcategory'] = $parentcat->id; } } // Create new gradecategory item. $gradecategory = new \grade_category(['courseid' => $courseid], false); $gradecategory->apply_default_settings(); $gradecategory->apply_forced_settings(); // Data Validation. if (array_key_exists('grade_item_gradetype', $data) and $data['grade_item_gradetype'] == GRADE_TYPE_SCALE) { if (empty($data['grade_item_scaleid'])) { $warnings[] = ['item' => 'scaleid', 'warningcode' => 'invalidscale', 'message' => get_string('missingscale', 'grades')]; } } if (array_key_exists('grade_item_grademin', $data) and array_key_exists('grade_item_grademax', $data)) { if (($data['grade_item_grademax'] != 0 OR $data['grade_item_grademin'] != 0) AND ($data['grade_item_grademax'] == $data['grade_item_grademin'] OR $data['grade_item_grademax'] < $data['grade_item_grademin'])) { $warnings[] = ['item' => 'grademax', 'warningcode' => 'invalidgrade', 'message' => get_string('incorrectminmax', 'grades')]; } } if (!empty($warnings)) { return ['categoryids' => [], 'warnings' => $warnings]; } // Now call the update function with data. Transactioned so the gradebook isn't broken on bad data. // This is done per-category so that children can correctly discover the parent categories. try { $transaction = $DB->start_delegated_transaction(); \grade_edit_tree::update_gradecategory($gradecategory, (object) $data); $transaction->allow_commit(); $createdcats[] = $gradecategory->id; } catch (\Exception $e) { // If the submitted data was broken for any reason. $warnings['database'] = $e->getMessage(); $transaction->rollback($e); return ['warnings' => $warnings]; } } return['categoryids' => $createdcats, 'warnings' => []]; } } get_enrolled_users_for_search_widget.php 0000644 00000013533 15151251213 0014700 0 ustar 00 <?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/>. namespace core_grades\external; use external_api; use external_function_parameters; use external_value; use external_single_structure; use external_multiple_structure; use moodle_url; use core_user; defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot.'/grade/lib.php'); /** * Get the enrolled users within and map some fields to the returned array of user objects. * * @package core_grades * @copyright 2022 Mihail Geshoski <mihail@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since Moodle 4.1 */ class get_enrolled_users_for_search_widget extends external_api { /** * Returns description of method parameters. * * @return external_function_parameters */ public static function execute_parameters(): external_function_parameters { return new external_function_parameters ( [ 'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED), 'actionbaseurl' => new external_value(PARAM_URL, 'The base URL for the user option', VALUE_REQUIRED), 'groupid' => new external_value(PARAM_INT, 'Group Id', VALUE_DEFAULT, 0) ] ); } /** * Given a course ID find the enrolled users within and map some fields to the returned array of user objects. * * @param int $courseid * @param string $actionbaseurl The base URL for the user option. * @param int|null $groupid * @return array Users and warnings to pass back to the calling widget. * @throws coding_exception * @throws invalid_parameter_exception * @throws moodle_exception * @throws restricted_context_exception */ public static function execute(int $courseid, string $actionbaseurl, ?int $groupid = 0): array { global $DB, $PAGE; $params = self::validate_parameters( self::execute_parameters(), [ 'courseid' => $courseid, 'actionbaseurl' => $actionbaseurl, 'groupid' => $groupid ] ); $warnings = []; $coursecontext = \context_course::instance($params['courseid']); parent::validate_context($coursecontext); require_capability('moodle/course:viewparticipants', $coursecontext); $course = $DB->get_record('course', ['id' => $params['courseid']]); // Create a graded_users_iterator because it will properly check the groups etc. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext); $gui = new \graded_users_iterator($course, null, $params['groupid']); $gui->require_active_enrolment($showonlyactiveenrol); $gui->init(); $users = []; while ($userdata = $gui->next_user()) { $guiuser = $userdata->user; $user = new \stdClass(); $user->fullname = fullname($guiuser); $user->id = $guiuser->id; $user->url = (new moodle_url($actionbaseurl, ['id' => $courseid, 'userid' => $guiuser->id]))->out(false); $userpicture = new \user_picture($guiuser); $userpicture->size = 1; $user->profileimage = $userpicture->get_url($PAGE)->out(false); $user->email = $guiuser->email; $user->active = false; // @TODO MDL-76246 $users[] = $user; } $gui->close(); return [ 'users' => $users, 'warnings' => $warnings, ]; } /** * Returns description of method result value. * * @return external_single_structure */ public static function execute_returns(): external_single_structure { return new external_single_structure([ 'users' => new external_multiple_structure(self::user_description()), 'warnings' => new \external_warnings(), ]); } /** * Create user return value description. * * @return \external_description */ public static function user_description(): \external_description { $userfields = [ 'id' => new external_value(core_user::get_property_type('id'), 'ID of the user'), 'profileimage' => new external_value( PARAM_URL, 'The location of the users larger image', VALUE_OPTIONAL ), 'url' => new external_value( PARAM_URL, 'The link to the user report', VALUE_OPTIONAL ), 'fullname' => new external_value(PARAM_TEXT, 'The full name of the user', VALUE_OPTIONAL), 'email' => new external_value( core_user::get_property_type('email'), 'An email address - allow email as root@localhost', VALUE_OPTIONAL), 'active' => new external_value(PARAM_BOOL, 'Are we currently on this item?', VALUE_REQUIRED) ]; return new external_single_structure($userfields); } } get_groups_for_search_widget.php 0000644 00000013364 15151251213 0013174 0 ustar 00 <?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/>. namespace core_grades\external; use coding_exception; use context_course; use external_api; use external_description; use external_function_parameters; use external_multiple_structure; use external_single_structure; use external_value; use external_warnings; use invalid_parameter_exception; use moodle_exception; use restricted_context_exception; defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir.'/externallib.php'); /** * External group report API implementation * * @package core_grades * @copyright 2022 Mathew May <mathew.solutions> * @category external * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class get_groups_for_search_widget extends external_api { /** * Returns description of method parameters. * * @return external_function_parameters */ public static function execute_parameters(): external_function_parameters { return new external_function_parameters ( [ 'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED), 'actionbaseurl' => new external_value(PARAM_URL, 'The base URL for the group action', VALUE_REQUIRED) ] ); } /** * Given a course ID find the existing user groups and map some fields to the returned array of group objects. * * @param int $courseid * @param string $actionbaseurl The base URL for the group action. * @return array Groups and warnings to pass back to the calling widget. * @throws coding_exception * @throws invalid_parameter_exception * @throws moodle_exception * @throws restricted_context_exception */ protected static function execute(int $courseid, string $actionbaseurl): array { global $DB, $USER, $COURSE; $params = self::validate_parameters( self::execute_parameters(), [ 'courseid' => $courseid, 'actionbaseurl' => $actionbaseurl ] ); $warnings = []; $context = context_course::instance($params['courseid']); parent::validate_context($context); $mappedgroups = []; $course = $DB->get_record('course', ['id' => $params['courseid']]); // Initialise the grade tracking object. if ($groupmode = $course->groupmode) { $aag = has_capability('moodle/site:accessallgroups', $context); $usergroups = []; $groupuserid = 0; if ($groupmode == VISIBLEGROUPS || $aag) { // Get user's own groups and put to the top. $usergroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid); } else { $groupuserid = $USER->id; } $allowedgroups = groups_get_all_groups($course->id, $groupuserid, $course->defaultgroupingid); $allgroups = array_merge($allowedgroups, $usergroups); // Filter out any duplicate groups. $groupsmenu = array_intersect_key($allgroups, array_unique(array_column($allgroups, 'name'))); if (!$allowedgroups || $groupmode == VISIBLEGROUPS || $aag) { array_unshift($groupsmenu, (object) [ 'id' => 0, 'name' => get_string('allparticipants'), ]); } $mappedgroups = array_map(function($group) use ($COURSE, $actionbaseurl, $context) { $url = new \moodle_url($actionbaseurl, [ 'id' => $COURSE->id, 'group' => $group->id ]); return (object) [ 'id' => $group->id, 'name' => format_string($group->name, true, ['context' => $context]), 'url' => $url->out(false), 'active' => false // @TODO MDL-76246 ]; }, $groupsmenu); } return [ 'groups' => $mappedgroups, 'warnings' => $warnings, ]; } /** * Returns description of what the group search for the widget should return. * * @return external_single_structure */ public static function execute_returns(): external_single_structure { return new external_single_structure([ 'groups' => new external_multiple_structure(self::group_description()), 'warnings' => new external_warnings(), ]); } /** * Create group return value description. * * @return external_description */ public static function group_description(): external_description { $groupfields = [ 'id' => new external_value(PARAM_ALPHANUM, 'An ID for the group', VALUE_REQUIRED), 'url' => new external_value(PARAM_URL, 'The link that applies the group action', VALUE_REQUIRED), 'name' => new external_value(PARAM_TEXT, 'The full name of the group', VALUE_REQUIRED), 'active' => new external_value(PARAM_BOOL, 'Are we currently on this item?', VALUE_REQUIRED) ]; return new external_single_structure($groupfields); } } course_competency_statistics_exporter.php 0000644 00000007606 15151261354 0015221 0 ustar 00 <?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/>. /** * Class for exporting a course competency statistics summary. * * @package tool_lp * @copyright 2016 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use renderer_base; use moodle_url; use core_competency\external\competency_exporter; use core_competency\external\performance_helper; /** * Class for exporting a course competency statistics summary. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class course_competency_statistics_exporter extends \core\external\exporter { public static function define_properties() { return array( 'competencycount' => array( 'type' => PARAM_INT, ), 'proficientcompetencycount' => array( 'type' => PARAM_INT, ), ); } public static function define_other_properties() { return array( 'proficientcompetencypercentage' => array( 'type' => PARAM_FLOAT ), 'proficientcompetencypercentageformatted' => array( 'type' => PARAM_RAW ), 'leastproficient' => array( 'type' => competency_exporter::read_properties_definition(), 'multiple' => true ), 'leastproficientcount' => array( 'type' => PARAM_INT ), 'canbegradedincourse' => array( 'type' => PARAM_BOOL ), 'canmanagecoursecompetencies' => array( 'type' => PARAM_BOOL ), ); } protected static function define_related() { return array('context' => 'context'); } protected function get_other_values(renderer_base $output) { $proficientcompetencypercentage = 0; $proficientcompetencypercentageformatted = ''; if ($this->data->competencycount > 0) { $proficientcompetencypercentage = ((float) $this->data->proficientcompetencycount / (float) $this->data->competencycount) * 100.0; $proficientcompetencypercentageformatted = format_float($proficientcompetencypercentage); } $competencies = array(); $helper = new performance_helper(); foreach ($this->data->leastproficientcompetencies as $competency) { $context = $helper->get_context_from_competency($competency); $exporter = new competency_exporter($competency, array('context' => $context)); $competencies[] = $exporter->export($output); } return array( 'proficientcompetencypercentage' => $proficientcompetencypercentage, 'proficientcompetencypercentageformatted' => $proficientcompetencypercentageformatted, 'leastproficient' => $competencies, 'leastproficientcount' => count($competencies), 'canbegradedincourse' => has_capability('moodle/competency:coursecompetencygradable', $this->related['context']), 'canmanagecoursecompetencies' => has_capability('moodle/competency:coursecompetencymanage', $this->related['context']) ); } } user_evidence_summary_exporter.php 0000644 00000011152 15151261354 0013605 0 ustar 00 <?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/>. /** * Class for exporting user evidence with all competencies. * * @package tool_lp * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use moodle_url; use renderer_base; use core_files\external\stored_file_exporter; use core_competency\external\performance_helper; /** * Class for exporting user evidence with all competencies. * * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_evidence_summary_exporter extends \core\external\persistent_exporter { protected static function define_class() { return \core_competency\user_evidence::class; } protected static function define_other_properties() { return array( 'canmanage' => array( 'type' => PARAM_BOOL ), 'filecount' => array( 'type' => PARAM_INT ), 'files' => array( 'type' => stored_file_exporter::read_properties_definition(), 'multiple' => true ), 'hasurlorfiles' => array( 'type' => PARAM_BOOL ), 'urlshort' => array( 'type' => PARAM_TEXT ), 'competencycount' => array( 'type' => PARAM_INT ), 'usercompetencies' => array( 'type' => user_evidence_competency_summary_exporter::read_properties_definition(), 'optional' => true, 'multiple' => true ), 'userhasplan' => array( 'type' => PARAM_BOOL ), ); } protected function get_other_values(renderer_base $output) { $urlshort = ''; $url = $this->persistent->get('url'); if (!empty($url)) { $murl = new moodle_url($url); $shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false)); $urlshort = shorten_text($shorturl, 30, true); } $files = array(); $storedfiles = $this->persistent->get_files(); if (!empty($storedfiles)) { foreach ($storedfiles as $storedfile) { $fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context'])); $files[] = $fileexporter->export($output); } } $userevidencecompetencies = array(); $usercompetencies = $this->persistent->get_user_competencies(); $helper = new performance_helper(); foreach ($usercompetencies as $usercompetency) { $competency = $usercompetency->get_competency(); $context = $helper->get_context_from_competency($competency); $framework = $helper->get_framework_from_competency($competency); $scale = $helper->get_scale_from_competency($competency); $related = array('competency' => $competency, 'usercompetency' => $usercompetency, 'scale' => $scale, 'context' => $context); $userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related); $userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output); } $values = array( 'canmanage' => $this->persistent->can_manage(), 'filecount' => count($files), 'files' => $files, 'userhasplan' => $this->persistent->user_has_plan(), 'hasurlorfiles' => !empty($files) || !empty($url), 'urlshort' => $urlshort, 'competencycount' => count($userevidencecompetencies), 'usercompetencies' => $userevidencecompetencies ); return $values; } } competency_summary_exporter.php 0000644 00000013460 15151261354 0013137 0 ustar 00 <?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/>. /** * Class for exporting competency data with the set of linked courses. * * @package tool_lp * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use context_course; use renderer_base; use stdClass; use moodle_url; use core_competency\competency_framework; use core_competency\external\competency_exporter; use core_competency\external\competency_framework_exporter; use core_course\external\course_summary_exporter; /** * Class for exporting competency data with additional related data. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class competency_summary_exporter extends \core\external\exporter { protected static function define_related() { // We cache the context so it does not need to be retrieved from the framework every time. return array('context' => '\\context', 'competency' => '\\core_competency\\competency', 'framework' => '\\core_competency\\competency_framework', 'linkedcourses' => '\\stdClass[]', 'relatedcompetencies' => '\\core_competency\\competency[]'); } protected static function define_other_properties() { return array( 'linkedcourses' => array( 'type' => course_summary_exporter::read_properties_definition(), 'multiple' => true ), 'relatedcompetencies' => array( 'type' => competency_exporter::read_properties_definition(), 'multiple' => true ), 'competency' => array( 'type' => competency_exporter::read_properties_definition() ), 'framework' => array( 'type' => competency_framework_exporter::read_properties_definition() ), 'hascourses' => array( 'type' => PARAM_BOOL ), 'hasrelatedcompetencies' => array( 'type' => PARAM_BOOL ), 'scaleid' => array( 'type' => PARAM_INT ), 'scaleconfiguration' => array( 'type' => PARAM_RAW ), 'taxonomyterm' => array( 'type' => PARAM_TEXT ), 'comppath' => array( 'type' => competency_path_exporter::read_properties_definition(), ), 'pluginbaseurl' => [ 'type' => PARAM_URL ] ); } protected function get_other_values(renderer_base $output) { $result = new stdClass(); $context = $this->related['context']; $courses = $this->related['linkedcourses']; $linkedcourses = array(); foreach ($courses as $course) { $context = context_course::instance($course->id); $exporter = new course_summary_exporter($course, array('context' => $context)); $courseexport = $exporter->export($output); array_push($linkedcourses, $courseexport); } $result->linkedcourses = $linkedcourses; $result->hascourses = count($linkedcourses) > 0; $relatedcompetencies = array(); foreach ($this->related['relatedcompetencies'] as $competency) { $exporter = new competency_exporter($competency, array('context' => $context)); $competencyexport = $exporter->export($output); array_push($relatedcompetencies, $competencyexport); } $result->relatedcompetencies = $relatedcompetencies; $result->hasrelatedcompetencies = count($relatedcompetencies) > 0; $competency = $this->related['competency']; $exporter = new competency_exporter($competency, array('context' => $context)); $result->competency = $exporter->export($output); $exporter = new competency_framework_exporter($this->related['framework']); $result->framework = $exporter->export($output); $scaleconfiguration = $this->related['framework']->get('scaleconfiguration'); $scaleid = $this->related['framework']->get('scaleid'); if ($competency->get('scaleid')) { $scaleconfiguration = $competency->get('scaleconfiguration'); $scaleid = $competency->get('scaleid'); } $result->scaleconfiguration = $scaleconfiguration; $result->scaleid = $scaleid; $level = $competency->get_level(); $taxonomy = $this->related['framework']->get_taxonomy($level); $result->taxonomyterm = (string) (competency_framework::get_taxonomies_list()[$taxonomy]); // Competency path. $exporter = new competency_path_exporter([ 'ancestors' => $competency->get_ancestors(), 'framework' => $this->related['framework'], 'context' => $context ]); $result->comppath = $exporter->export($output); $result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true); $result->showlinks = \core_competency\api::show_links(); return (array) $result; } } user_competency_summary_exporter.php 0000644 00000016421 15151261354 0014175 0 ustar 00 <?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/>. /** * Class for exporting user competency data with all the evidence * * @package tool_lp * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use context_user; use renderer_base; use stdClass; use core_comment\external\comment_area_exporter; use core_competency\external\evidence_exporter; use core_competency\external\user_competency_exporter; use core_competency\external\user_competency_plan_exporter; use core_competency\external\user_competency_course_exporter; use core_user\external\user_summary_exporter; use core_competency\user_competency; /** * Class for exporting user competency data with additional related data. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_competency_summary_exporter extends \core\external\exporter { protected static function define_related() { // We cache the context so it does not need to be retrieved from the framework every time. return array('competency' => '\\core_competency\\competency', 'relatedcompetencies' => '\\core_competency\\competency[]', 'user' => '\\stdClass', 'usercompetency' => '\\core_competency\\user_competency?', 'usercompetencyplan' => '\\core_competency\\user_competency_plan?', 'usercompetencycourse' => '\\core_competency\\user_competency_course?', 'evidence' => '\\core_competency\\evidence[]'); } protected static function define_other_properties() { return array( 'showrelatedcompetencies' => array( 'type' => PARAM_BOOL ), 'cangrade' => array( 'type' => PARAM_BOOL ), 'competency' => array( 'type' => competency_summary_exporter::read_properties_definition() ), 'user' => array( 'type' => user_summary_exporter::read_properties_definition(), ), 'usercompetency' => array( 'type' => user_competency_exporter::read_properties_definition(), 'optional' => true ), 'usercompetencyplan' => array( 'type' => user_competency_plan_exporter::read_properties_definition(), 'optional' => true ), 'usercompetencycourse' => array( 'type' => user_competency_course_exporter::read_properties_definition(), 'optional' => true ), 'evidence' => array( 'type' => evidence_exporter::read_properties_definition(), 'multiple' => true ), 'commentarea' => array( 'type' => comment_area_exporter::read_properties_definition(), 'optional' => true ), ); } protected function get_other_values(renderer_base $output) { global $DB; $result = new stdClass(); $result->showrelatedcompetencies = true; $competency = $this->related['competency']; $exporter = new competency_summary_exporter(null, array( 'competency' => $competency, 'context' => $competency->get_context(), 'framework' => $competency->get_framework(), 'linkedcourses' => array(), 'relatedcompetencies' => $this->related['relatedcompetencies'] )); $result->competency = $exporter->export($output); $result->cangrade = user_competency::can_grade_user($this->related['user']->id); if ($this->related['user']) { $exporter = new user_summary_exporter($this->related['user']); $result->user = $exporter->export($output); } $related = array('scale' => $competency->get_scale()); if ($this->related['usercompetency']) { $exporter = new user_competency_exporter($this->related['usercompetency'], $related); $result->usercompetency = $exporter->export($output); } if ($this->related['usercompetencyplan']) { $exporter = new user_competency_plan_exporter($this->related['usercompetencyplan'], $related); $result->usercompetencyplan = $exporter->export($output); } if ($this->related['usercompetencycourse']) { $exporter = new user_competency_course_exporter($this->related['usercompetencycourse'], $related); $result->usercompetencycourse = $exporter->export($output); } $allevidence = array(); $usercache = array(); $scale = $competency->get_scale(); $result->evidence = array(); if (count($this->related['evidence'])) { foreach ($this->related['evidence'] as $evidence) { $actionuserid = $evidence->get('actionuserid'); if (!empty($actionuserid)) { $usercache[$evidence->get('actionuserid')] = true; } } $users = array(); if (!empty($usercache)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($usercache)); $users = $DB->get_records_select('user', 'id ' . $sql, $params); } foreach ($users as $user) { $usercache[$user->id] = $user; } foreach ($this->related['evidence'] as $evidence) { $actionuserid = $evidence->get('actionuserid'); $related = array( 'scale' => $scale, 'usercompetency' => ($this->related['usercompetency'] ? $this->related['usercompetency'] : null), 'usercompetencyplan' => ($this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null), 'context' => $evidence->get_context() ); $related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null; $exporter = new evidence_exporter($evidence, $related); $allevidence[] = $exporter->export($output); } $result->evidence = $allevidence; } $usercompetency = !empty($this->related['usercompetency']) ? $this->related['usercompetency'] : null; if (!empty($usercompetency) && $usercompetency->can_read_comments()) { $commentareaexporter = new comment_area_exporter($usercompetency->get_comment_object()); $result->commentarea = $commentareaexporter->export($output); } return (array) $result; } } path_node_exporter.php 0000644 00000005413 15151261354 0011154 0 ustar 00 <?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/>. /** * Class for exporting path_node data. * * @package tool_lp * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use context_system; /** * Class for exporting path_node data. * * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class path_node_exporter extends \core\external\exporter { /** * Constructor - saves the persistent object, and the related objects. * * @param mixed $data The data. * @param array $related Array of relateds. */ public function __construct($data, $related = array()) { if (!isset($related['context'])) { // Previous code was automatically using the system context which was not always correct. // We let developers know that they must fix their code without breaking anything, // and fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5. debugging('Missing related context in path_node_exporter.', DEBUG_DEVELOPER); $related['context'] = context_system::instance(); } parent::__construct($data, $related); } /** * Return the list of properties. * * @return array */ protected static function define_related() { return [ 'context' => 'context' ]; } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'id' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED ], 'name' => [ 'type' => PARAM_TEXT ], 'first' => [ 'type' => PARAM_BOOL ], 'last' => [ 'type' => PARAM_BOOL ], 'position' => [ 'type' => PARAM_INT ] ]; } } template_statistics_exporter.php 0000644 00000013155 15151261354 0013302 0 ustar 00 <?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/>. /** * Class for exporting a template statistics summary. * * @package tool_lp * @copyright 2016 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use renderer_base; use moodle_url; use core_competency\external\competency_exporter; use core_competency\external\performance_helper; /** * Class for exporting a cohort summary from an stdClass. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class template_statistics_exporter extends \core\external\exporter { public static function define_properties() { return array( 'competencycount' => array( 'type' => PARAM_INT, ), 'unlinkedcompetencycount' => array( 'type' => PARAM_INT, ), 'plancount' => array( 'type' => PARAM_INT, ), 'completedplancount' => array( 'type' => PARAM_INT, ), 'usercompetencyplancount' => array( 'type' => PARAM_INT, ), 'proficientusercompetencyplancount' => array( 'type' => PARAM_INT, ) ); } public static function define_other_properties() { return array( 'linkedcompetencypercentage' => array( 'type' => PARAM_FLOAT ), 'linkedcompetencypercentageformatted' => array( 'type' => PARAM_RAW ), 'linkedcompetencycount' => array( 'type' => PARAM_INT ), 'completedplanpercentage' => array( 'type' => PARAM_FLOAT ), 'completedplanpercentageformatted' => array( 'type' => PARAM_RAW ), 'proficientusercompetencyplanpercentage' => array( 'type' => PARAM_FLOAT ), 'proficientusercompetencyplanpercentageformatted' => array( 'type' => PARAM_RAW ), 'leastproficient' => array( 'type' => competency_exporter::read_properties_definition(), 'multiple' => true ), 'leastproficientcount' => array( 'type' => PARAM_INT ), ); } protected function get_other_values(renderer_base $output) { $linkedcompetencycount = $this->data->competencycount - $this->data->unlinkedcompetencycount; if ($linkedcompetencycount < 0) { // Should never happen. $linkedcompetencycount = 0; } $linkedcompetencypercentage = 0; $linkedcompetencypercentageformatted = ''; if ($this->data->competencycount > 0) { $linkedcompetencypercentage = ((float) $linkedcompetencycount / (float) $this->data->competencycount) * 100.0; $linkedcompetencypercentageformatted = format_float($linkedcompetencypercentage); } $completedplanpercentage = 0; $completedplanpercentageformatted = ''; if ($this->data->plancount > 0) { $completedplanpercentage = ((float) $this->data->completedplancount / (float) $this->data->plancount) * 100.0; $completedplanpercentageformatted = format_float($completedplanpercentage); } $proficientusercompetencyplanpercentage = 0; $proficientusercompetencyplanpercentageformatted = ''; if ($this->data->usercompetencyplancount > 0) { $proficientusercompetencyplanpercentage = ((float) $this->data->proficientusercompetencyplancount / (float) $this->data->usercompetencyplancount) * 100.0; $proficientusercompetencyplanpercentageformatted = format_float($proficientusercompetencyplanpercentage); } $competencies = array(); $helper = new performance_helper(); foreach ($this->data->leastproficientcompetencies as $competency) { $context = $helper->get_context_from_competency($competency); $exporter = new competency_exporter($competency, array('context' => $context)); $competencies[] = $exporter->export($output); } return array( 'linkedcompetencycount' => $linkedcompetencycount, 'linkedcompetencypercentage' => $linkedcompetencypercentage, 'linkedcompetencypercentageformatted' => $linkedcompetencypercentageformatted, 'completedplanpercentage' => $completedplanpercentage, 'completedplanpercentageformatted' => $completedplanpercentageformatted, 'proficientusercompetencyplanpercentage' => $proficientusercompetencyplanpercentage, 'proficientusercompetencyplanpercentageformatted' => $proficientusercompetencyplanpercentageformatted, 'leastproficient' => $competencies, 'leastproficientcount' => count($competencies) ); } } competency_path_exporter.php 0000644 00000010155 15151261354 0012374 0 ustar 00 <?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/>. /** * Class for exporting competency_path data. * * @package tool_lp * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use renderer_base; use moodle_url; /** * Class for exporting competency_path data. * * @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class competency_path_exporter extends \core\external\exporter { /** * Constructor. * * @param array $related - related objects. */ public function __construct($related) { parent::__construct([], $related); } /** * Return the list of properties. * * @return array */ protected static function define_related() { return [ 'ancestors' => 'core_competency\\competency[]', 'framework' => 'core_competency\\competency_framework', 'context' => 'context' ]; } /** * Return the list of additional properties used only for display. * * @return array - Keys with their types. */ protected static function define_other_properties() { return [ 'ancestors' => [ 'type' => path_node_exporter::read_properties_definition(), 'multiple' => true, ], 'framework' => [ 'type' => path_node_exporter::read_properties_definition() ], 'pluginbaseurl' => [ 'type' => PARAM_URL ], 'pagecontextid' => [ 'type' => PARAM_INT ], 'showlinks' => [ 'type' => PARAM_BOOL ] ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $result = new \stdClass(); $ancestors = []; $nodescount = count($this->related['ancestors']); $i = 1; $result->showlinks = \core_competency\api::show_links(); foreach ($this->related['ancestors'] as $competency) { $exporter = new path_node_exporter([ 'id' => $competency->get('id'), 'name' => $competency->get('idnumber'), 'position' => $i, 'first' => $i == 1, 'last' => $i == $nodescount ], [ 'context' => $this->related['context'], ] ); $ancestors[] = $exporter->export($output); $i++; } $result->ancestors = $ancestors; $exporter = new path_node_exporter([ 'id' => $this->related['framework']->get('id'), 'name' => $this->related['framework']->get('shortname'), 'first' => 0, 'last' => 0, 'position' => -1 ], [ 'context' => $this->related['context'] ] ); $result->framework = $exporter->export($output); $result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true); $result->pagecontextid = $this->related['context']->id; return (array) $result; } } user_competency_summary_in_course_exporter.php 0000644 00000011654 15151261354 0016246 0 ustar 00 <?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/>. /** * Class for exporting user competency data with all the evidence in a course * * @package tool_lp * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use core_competency\api; use core_competency\user_competency; use core_competency\external\plan_exporter; use core_course\external\course_module_summary_exporter; use core_course\external\course_summary_exporter; use context_course; use renderer_base; use stdClass; use moodle_url; /** * Class for exporting user competency data with additional related data in a plan. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_competency_summary_in_course_exporter extends \core\external\exporter { protected static function define_related() { // We cache the context so it does not need to be retrieved from the framework every time. return array('competency' => '\\core_competency\\competency', 'relatedcompetencies' => '\\core_competency\\competency[]', 'user' => '\\stdClass', 'course' => '\\stdClass', 'usercompetencycourse' => '\\core_competency\\user_competency_course?', 'evidence' => '\\core_competency\\evidence[]', 'scale' => '\\grade_scale'); } protected static function define_other_properties() { return array( 'usercompetencysummary' => array( 'type' => user_competency_summary_exporter::read_properties_definition() ), 'course' => array( 'type' => course_summary_exporter::read_properties_definition(), ), 'coursemodules' => array( 'type' => course_module_summary_exporter::read_properties_definition(), 'multiple' => true ), 'plans' => array( 'type' => plan_exporter::read_properties_definition(), 'multiple' => true ), 'pluginbaseurl' => [ 'type' => PARAM_URL ], ); } protected function get_other_values(renderer_base $output) { // Arrays are copy on assign. $related = $this->related; $result = new stdClass(); // Remove course from related as it is not wanted by the user_competency_summary_exporter. unset($related['course']); $related['usercompetencyplan'] = null; $related['usercompetency'] = null; $exporter = new user_competency_summary_exporter(null, $related); $result->usercompetencysummary = $exporter->export($output); $result->usercompetencysummary->cangrade = user_competency::can_grade_user_in_course($this->related['user']->id, $this->related['course']->id); $context = context_course::instance($this->related['course']->id); $exporter = new course_summary_exporter($this->related['course'], array('context' => $context)); $result->course = $exporter->export($output); $coursemodules = api::list_course_modules_using_competency($this->related['competency']->get('id'), $this->related['course']->id); $fastmodinfo = get_fast_modinfo($this->related['course']->id); $exportedmodules = array(); foreach ($coursemodules as $cm) { $cminfo = $fastmodinfo->cms[$cm]; $cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo)); $exportedmodules[] = $cmexporter->export($output); } $result->coursemodules = $exportedmodules; // User learning plans. $plans = api::list_plans_with_competency($this->related['user']->id, $this->related['competency']); $exportedplans = array(); foreach ($plans as $plan) { $planexporter = new plan_exporter($plan, array('template' => $plan->get_template())); $exportedplans[] = $planexporter->export($output); } $result->plans = $exportedplans; $result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true); return (array) $result; } } user_competency_summary_in_plan_exporter.php 0000644 00000006124 15151261354 0015674 0 ustar 00 <?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/>. /** * Class for exporting user competency data with all the evidence in a plan * * @package tool_lp * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use context_user; use renderer_base; use stdClass; use core_competency\external\plan_exporter; /** * Class for exporting user competency data with additional related data in a plan. * * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_competency_summary_in_plan_exporter extends \core\external\exporter { protected static function define_related() { // We cache the context so it does not need to be retrieved from the framework every time. return array('competency' => '\\core_competency\\competency', 'relatedcompetencies' => '\\core_competency\\competency[]', 'user' => '\\stdClass', 'plan' => '\\core_competency\\plan', 'usercompetency' => '\\core_competency\\user_competency?', 'usercompetencyplan' => '\\core_competency\\user_competency_plan?', 'evidence' => '\\core_competency\\evidence[]'); } protected static function define_other_properties() { return array( 'usercompetencysummary' => array( 'type' => user_competency_summary_exporter::read_properties_definition() ), 'plan' => array( 'type' => plan_exporter::read_properties_definition(), ) ); } protected function get_other_values(renderer_base $output) { // Arrays are copy on assign. $related = $this->related; // Remove plan from related as it is not wanted by the user_competency_summary_exporter. unset($related['plan']); // We do not need user_competency_course in user_competency_summary_exporter. $related['usercompetencycourse'] = null; $exporter = new user_competency_summary_exporter(null, $related); $result = new stdClass(); $result->usercompetencysummary = $exporter->export($output); $exporter = new plan_exporter($this->related['plan'], array('template' => $this->related['plan']->get_template())); $result->plan = $exporter->export($output); return (array) $result; } } user_evidence_competency_summary_exporter.php 0000644 00000005163 15151261354 0016040 0 ustar 00 <?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/>. /** * Class for exporting user evidence competency data. * * @package tool_lp * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace tool_lp\external; defined('MOODLE_INTERNAL') || die(); use moodle_url; use renderer_base; use core_competency\external\competency_exporter; use core_competency\external\user_competency_exporter; /** * Class for exporting user evidence competency data. * * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_evidence_competency_summary_exporter extends \core\external\exporter { protected static function define_related() { return array('competency' => '\\core_competency\\competency', 'usercompetency' => '\\core_competency\\user_competency', 'scale' => 'grade_scale', 'context' => '\\context' ); } protected static function define_other_properties() { return array( 'competency' => array( 'type' => competency_exporter::read_properties_definition() ), 'usercompetency' => array( 'type' => user_competency_exporter::read_properties_definition(), ) ); } protected function get_other_values(renderer_base $output) { $competencyexporter = new competency_exporter($this->related['competency'], array('context' => $this->related['context'])); $usercompetencyexporter = new user_competency_exporter($this->related['usercompetency'], array('scale' => $this->related['scale'])); $values = array( 'competency' => $competencyexporter->export($output), 'usercompetency' => $usercompetencyexporter->export($output) ); return $values; } } footer_options_exporter.php 0000644 00000011274 15152011771 0012263 0 ustar 00 <?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/>. /** * Class for exporting calendar footer view options data. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; use stdClass; use moodle_url; /** * Class for exporting calendar footer view options data. * * @copyright 2017 Simey Lameze * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class footer_options_exporter extends exporter { /** * @var \calendar_information $calendar The calendar to be rendered. */ protected $calendar; /** * @var int $userid The user id. */ protected $userid; /** * @var string $token The user sha1 token. */ protected $token; /** * @var bool $showfullcalendarlink Whether the full calendar link should be displayed or not. */ protected $showfullcalendarlink; /** * Constructor for month_exporter. * * @param \calendar_information $calendar The calendar being represented * @param int $userid The user id * @param string $token The user sha1 token. * @param array $options Display options for the footer. If an option is not set, a default value will be provided. * It consists of: * - showfullcalendarlink - bool - Whether to show the full calendar link or not. Defaults to false. */ public function __construct(\calendar_information $calendar, $userid, $token, array $options = []) { $this->calendar = $calendar; $this->userid = $userid; $this->token = $token; $this->showfullcalendarlink = $options['showfullcalendarlink'] ?? false; } /** * Get manage subscription link. * * @return string|null The manage subscription hyperlink. */ protected function get_manage_subscriptions_link(): ?string { if (calendar_user_can_add_event($this->calendar->course)) { $managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php'); return $managesubscriptionurl->out(true); } return null; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { global $CFG; $values = new stdClass(); $values->footerlinks = []; if ($this->showfullcalendarlink) { $values->footerlinks[] = (object)[ 'url' => $this->get_calendar_url(), 'linkname' => get_string('fullcalendar', 'calendar'), ]; } if (!empty($CFG->enablecalendarexport) && $managesubscriptionlink = $this->get_manage_subscriptions_link()) { $values->footerlinks[] = (object)[ 'url' => $managesubscriptionlink, 'linkname' => get_string('managesubscriptions', 'calendar'), ]; } return (array) $values; } /** * Return the list of additional properties. * * @return array */ public static function define_other_properties() { return [ 'footerlinks' => [ 'type' => [ 'url' => [ 'type' => PARAM_URL, ], 'linkname' => [ 'type' => PARAM_TEXT, ], ], 'multiple' => true, 'optional' => true, ], ]; } /** * Build the calendar URL. * * @return string The calendar URL. */ public function get_calendar_url() { $url = new moodle_url('/calendar/view.php', [ 'view' => 'month', 'time' => $this->calendar->time, ]); return $url->out(false); } } event_subscription_exporter.php 0000644 00000005075 15152011771 0013141 0 ustar 00 <?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 event class for displaying a calendar event's subscription. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \core\external\exporter; use \core_calendar\local\event\entities\event_interface; /** * Class for displaying a calendar event's subscription. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class event_subscription_exporter extends exporter { /** * Constructor. * * @param event_interface $event */ public function __construct(event_interface $event) { global $CFG; $data = new \stdClass(); $data->displayeventsource = false; if ($event->get_subscription()) { $subscription = calendar_get_subscription($event->get_subscription()->get('id')); if (!empty($subscription) && $CFG->calendar_showicalsource) { $data->displayeventsource = true; if (!empty($subscription->url)) { $data->subscriptionurl = $subscription->url; } $data->subscriptionname = $subscription->name; } } parent::__construct($data); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'displayeventsource' => [ 'type' => PARAM_BOOL ], 'subscriptionname' => [ 'type' => PARAM_RAW, 'optional' => true ], 'subscriptionurl' => [ 'type' => PARAM_URL, 'optional' => true ], ]; } } event_icon_exporter.php 0000644 00000013150 15152011771 0011336 0 ustar 00 <?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 event class for displaying a calendar event's icon. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \core\external\exporter; use \core_calendar\local\event\entities\event_interface; /** * Class for displaying a calendar event's icon. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class event_icon_exporter extends exporter { /** * Constructor. * * @param event_interface $event * @param array $related The related data. */ public function __construct(event_interface $event, $related = []) { global $PAGE; $coursemodule = $event->get_course_module(); $category = $event->get_category(); $categoryid = $category ? $category->get('id') : null; $course = $event->get_course(); $courseid = $course ? $course->get('id') : null; $group = $event->get_group(); $groupid = $group ? $group->get('id') : null; $user = $event->get_user(); $userid = $user ? $user->get('id') : null; $isactivityevent = !empty($coursemodule); $issiteevent = ($course && $courseid == SITEID); $iscategoryevent = ($category && !empty($categoryid)); $iscourseevent = ($course && !empty($courseid) && $courseid != SITEID && empty($groupid)); $isgroupevent = ($group && !empty($groupid)); $isuserevent = ($user && !empty($userid)); $iconurl = ''; $iconclass = ''; if ($isactivityevent) { $key = 'monologo'; $component = $coursemodule->get('modname'); $iconurl = get_fast_modinfo($courseid)->get_cm($coursemodule->get('id'))->get_icon_url(); $iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter'; $iconurl = $iconurl->out(false); if (get_string_manager()->string_exists($event->get_type(), $component)) { $alttext = get_string($event->get_type(), $component); } else { $alttext = get_string('activityevent', 'calendar'); } } else if ($event->get_component()) { // Guess the icon and the title for the component event. By default display calendar icon and the // plugin name as the alttext. if ($PAGE->theme->resolve_image_location($event->get_type(), $event->get_component())) { $key = $event->get_type(); $component = $event->get_component(); } else { $key = 'i/otherevent'; $component = 'core'; } if (get_string_manager()->string_exists($event->get_type(), $event->get_component())) { $alttext = get_string($event->get_type(), $event->get_component()); } else { $alttext = get_string('pluginname', $event->get_component()); } } else if ($issiteevent) { $key = 'i/siteevent'; $component = 'core'; $alttext = get_string('typesite', 'calendar'); } else if ($iscategoryevent) { $key = 'i/categoryevent'; $component = 'core'; $alttext = get_string('typecategory', 'calendar'); } else if ($iscourseevent) { $key = 'i/courseevent'; $component = 'core'; $alttext = get_string('typecourse', 'calendar'); } else if ($isgroupevent) { $key = 'i/groupevent'; $component = 'core'; $alttext = get_string('typegroup', 'calendar'); } else if ($isuserevent) { $key = 'i/userevent'; $component = 'core'; $alttext = get_string('typeuser', 'calendar'); } else { // Default to site event icon? $key = 'i/siteevent'; $component = 'core'; $alttext = get_string('typesite', 'calendar'); } $data = new \stdClass(); $data->key = $key; $data->component = $component; $data->alttext = $alttext; $data->iconurl = $iconurl; $data->iconclass = $iconclass; parent::__construct($data, $related); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'key' => ['type' => PARAM_TEXT], 'component' => ['type' => PARAM_TEXT], 'alttext' => ['type' => PARAM_TEXT], 'iconurl' => ['type' => PARAM_TEXT], 'iconclass' => ['type' => PARAM_TEXT], ]; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'context' => 'context', ]; } } week_exporter.php 0000644 00000013610 15152011771 0010141 0 ustar 00 <?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 event class for displaying the week view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; /** * Class for displaying the week view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class week_exporter extends exporter { /** * @var array $days An array of day_exporter objects. */ protected $days = []; /** * @var int $prepadding The number of pre-padding days at the start of the week. */ protected $prepadding = 0; /** * @var int $postpadding The number of post-padding days at the start of the week. */ protected $postpadding = 0; /** * @var \calendar_information $calendar The calendar being displayed. */ protected $calendar; /** * Constructor. * * @param \calendar_information $calendar The calendar information for the period being displayed * @param mixed $days An array of day_exporter objects. * @param int $prepadding The number of pre-padding days at the start of the week. * @param int $postpadding The number of post-padding days at the start of the week. * @param array $related Related objects. */ public function __construct(\calendar_information $calendar, $days, $prepadding, $postpadding, $related) { $this->days = $days; $this->prepadding = $prepadding; $this->postpadding = $postpadding; $this->calendar = $calendar; parent::__construct([], $related); } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'prepadding' => [ 'type' => PARAM_INT, 'multiple' => true, ], 'postpadding' => [ 'type' => PARAM_INT, 'multiple' => true, ], 'days' => [ 'type' => week_day_exporter::read_properties_definition(), 'multiple' => true, ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { global $CFG; $return = [ 'prepadding' => [], 'postpadding' => [], 'days' => [], ]; for ($i = 0; $i < $this->prepadding; $i++) { $return['prepadding'][] = $i; } for ($i = 0; $i < $this->postpadding; $i++) { $return['postpadding'][] = $i; } $return['days'] = []; $today = $this->related['type']->timestamp_to_date_array(time()); $weekend = CALENDAR_DEFAULT_WEEKEND; if (isset($CFG->calendar_weekend)) { $weekend = intval($CFG->calendar_weekend); } $numberofdaysinweek = $this->related['type']->get_num_weekdays(); foreach ($this->days as $daydata) { $events = []; foreach ($this->related['events'] as $event) { $times = $event->get_times(); $starttime = $times->get_start_time()->getTimestamp(); $startdate = $this->related['type']->timestamp_to_date_array($starttime); $endtime = $times->get_end_time()->getTimestamp(); $enddate = $this->related['type']->timestamp_to_date_array($endtime); if ((($startdate['year'] * 366) + $startdate['yday']) > ($daydata['year'] * 366) + $daydata['yday']) { // Starts after today. continue; } if ((($enddate['year'] * 366) + $enddate['yday']) < ($daydata['year'] * 366) + $daydata['yday']) { // Ends before today. continue; } $events[] = $event; } $istoday = true; $istoday = $istoday && $today['year'] == $daydata['year']; $istoday = $istoday && $today['yday'] == $daydata['yday']; $daydata['istoday'] = $istoday; $daydata['isweekend'] = !!($weekend & (1 << ($daydata['wday'] % $numberofdaysinweek))); $day = new week_day_exporter($this->calendar, $daydata, [ 'events' => $events, 'cache' => $this->related['cache'], 'type' => $this->related['type'], ]); $return['days'][] = $day->export($output); } return $return; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } } event_exporter.php 0000644 00000006650 15152011771 0010335 0 ustar 00 <?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 event class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . "/calendar/lib.php"); use \core_calendar\local\event\entities\action_event_interface; use \core_calendar\local\event\container; use \core_course\external\course_summary_exporter; use \renderer_base; /** * Class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class event_exporter extends event_exporter_base { /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { $values = parent::define_other_properties(); $values['url'] = ['type' => PARAM_URL]; return $values; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $values = parent::get_other_values($output); global $CFG; require_once($CFG->dirroot.'/course/lib.php'); $event = $this->event; $context = $this->related['context']; if ($moduleproxy = $event->get_course_module()) { $modulename = $moduleproxy->get('modname'); $moduleid = $moduleproxy->get('id'); $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]); // Build edit event url for action events. $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey()); $editurl = new \moodle_url('/course/mod.php', $params); $values['editurl'] = $editurl->out(false); } else if ($event->get_type() == 'category') { $url = $event->get_category()->get_proxied_instance()->get_view_link(); } else if ($event->get_type() == 'course') { $url = \course_get_url($this->related['course'] ?: SITEID); } else { $url = \course_get_url($this->related['course'] ?: SITEID); } $values['url'] = $url->out(false); // Override default formatted time to make sure the date portion of the time is always rendered. $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event); $values['formattedtime'] = calendar_format_event_time($legacyevent, time(), null, false); return $values; } } day_name_exporter.php 0000644 00000004537 15152011771 0010773 0 ustar 00 <?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 event class for displaying the day name. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; /** * Class for displaying the day view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class day_name_exporter extends exporter { /** * @var int $dayno The day number. */ protected $dayno; /** * @var string $shortname The formatted short name of the day. */ protected $shortname; /** * @var string $fullname The formatted full name of the day. */ protected $fullname; /** * Constructor. * * @param int $dayno The day number. * @param array $names The list of names. */ public function __construct($dayno, $names) { $data = $names + ['dayno' => $dayno]; parent::__construct($data, []); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'dayno' => [ 'type' => PARAM_INT, ], 'shortname' => [ // Note: The calendar type class has already formatted the names. 'type' => PARAM_RAW, ], 'fullname' => [ // Note: The calendar type class has already formatted the names. 'type' => PARAM_RAW, ], ]; } } events_related_objects_cache.php 0000644 00000021602 15152011771 0013116 0 ustar 00 <?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 event class for providing the related objects when exporting a list of calendar events. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use context; use \core_calendar\local\event\entities\event_interface; use stdClass; /** * Class to providing the related objects when exporting a list of calendar events. * * This class is only meant for use with exporters. It attempts to bulk load * the related objects for a list of events and cache them to avoid having * to query the database when exporting each individual event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class events_related_objects_cache { /** * @var array $events The events for which we need related objects. */ protected $events; /** * @var array $courses The related courses. */ protected $courses = null; /** * @var array $groups The related groups. */ protected $groups = null; /** * @var array $coursemodules The related course modules. */ protected $coursemodules = []; /** * @var array $moduleinstances The related module instances. */ protected $moduleinstances = null; /** * Constructor. * * @param array $events Array of event_interface events * @param array $courses Array of courses to populate the cache with */ public function __construct(array $events, array $courses = null) { $this->events = $events; if (!is_null($courses)) { $this->courses = []; foreach ($courses as $course) { $this->courses[$course->id] = $course; } } } /** * Get the related course object for a given event. * * @param event_interface $event The event object. * @return stdClass|null */ public function get_course(event_interface $event) { if (is_null($this->courses)) { $this->load_courses(); } if ($course = $event->get_course()) { $courseid = $course->get('id'); return isset($this->courses[$courseid]) ? $this->courses[$courseid] : null; } else { return null; } } /** * Get the related context for a given event. * * @param event_interface $event The event object. * @return context|null */ public function get_context(event_interface $event) { global $USER; $categoryid = $event->get_category() ? $event->get_category()->get('id') : null; $courseid = $event->get_course() ? $event->get_course()->get('id') : null; $groupid = $event->get_group() ? $event->get_group()->get('id') : null; $userid = $event->get_user() ? $event->get_user()->get('id') : null; $moduleid = $event->get_course_module() ? $event->get_course_module()->get('id') : null; if (!empty($categoryid)) { return \context_coursecat::instance($categoryid); } else if (!empty($courseid)) { return \context_course::instance($event->get_course()->get('id')); } else if (!empty($groupid)) { $group = $this->get_group($event); return \context_course::instance($group->courseid); } else if (!empty($userid) && $userid == $USER->id) { return \context_user::instance($userid); } else if (!empty($userid) && $userid != $USER->id && $moduleid && $moduleid > 0) { $cm = $this->get_course_module($event); return \context_course::instance($cm->course); } else { return \context_user::instance($userid); } } /** * Get the related group object for a given event. * * @param event_interface $event The event object. * @return stdClass|null */ public function get_group(event_interface $event) { if (is_null($this->groups)) { $this->load_groups(); } if ($group = $event->get_group()) { $groupid = $group->get('id'); return isset($this->groups[$groupid]) ? $this->groups[$groupid] : null; } else { return null; } } /** * Get the related course module for a given event. * * @param event_interface $event The event object. * @return stdClass|null */ public function get_course_module(event_interface $event) { if (!$event->get_course_module()) { return null; } $id = $event->get_course_module()->get('id'); $name = $event->get_course_module()->get('modname'); $key = $name . '_' . $id; if (!isset($this->coursemodules[$key])) { $this->coursemodules[$key] = get_coursemodule_from_instance($name, $id, 0, false, MUST_EXIST); } return $this->coursemodules[$key]; } /** * Get the related module instance for a given event. * * @param event_interface $event The event object. * @return stdClass|null */ public function get_module_instance(event_interface $event) { if (!$event->get_course_module()) { return null; } if (is_null($this->moduleinstances)) { $this->load_module_instances(); } $id = $event->get_course_module()->get('instance'); $name = $event->get_course_module()->get('modname'); if (isset($this->moduleinstances[$name])) { if (isset($this->moduleinstances[$name][$id])) { return $this->moduleinstances[$name][$id]; } } return null; } /** * Load the list of all of the distinct courses required for the * list of provided events and save the result in memory. */ protected function load_courses() { global $DB; $courseids = []; foreach ($this->events as $event) { if ($course = $event->get_course()) { $id = $course->get('id'); $courseids[$id] = true; } } if (empty($courseids)) { $this->courses = []; return; } list($idsql, $params) = $DB->get_in_or_equal(array_keys($courseids)); $sql = "SELECT * FROM {course} WHERE id {$idsql}"; $this->courses = $DB->get_records_sql($sql, $params); } /** * Load the list of all of the distinct groups required for the * list of provided events and save the result in memory. */ protected function load_groups() { global $DB; $groupids = []; foreach ($this->events as $event) { if ($group = $event->get_group()) { $id = $group->get('id'); $groupids[$id] = true; } } if (empty($groupids)) { $this->groups = []; return; } list($idsql, $params) = $DB->get_in_or_equal(array_keys($groupids)); $sql = "SELECT * FROM {groups} WHERE id {$idsql}"; $this->groups = $DB->get_records_sql($sql, $params); } /** * Load the list of all of the distinct module instances required for the * list of provided events and save the result in memory. */ protected function load_module_instances() { global $DB; $this->moduleinstances = []; $modulestoload = []; foreach ($this->events as $event) { if ($module = $event->get_course_module()) { $id = $module->get('instance'); $name = $module->get('modname'); $ids = isset($modulestoload[$name]) ? $modulestoload[$name] : []; $ids[$id] = true; $modulestoload[$name] = $ids; } } if (empty($modulestoload)) { return; } foreach ($modulestoload as $modulename => $ids) { list($idsql, $params) = $DB->get_in_or_equal(array_keys($ids)); $sql = "SELECT * FROM {" . $modulename . "} WHERE id {$idsql}"; $this->moduleinstances[$modulename] = $DB->get_records_sql($sql, $params); } } } date_exporter.php 0000644 00000004743 15152011771 0010132 0 ustar 00 <?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/>. /** * Class for normalising the date data. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; use moodle_url; /** * Class for normalising the date data. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class date_exporter extends exporter { /** * Constructor for date_exporter. * * @param array $data * @param array $related The related information */ public function __construct($data, $related = []) { $data['timestamp'] = $data[0]; unset($data[0]); parent::__construct($data, $related); } protected static function define_properties() { return [ 'seconds' => [ 'type' => PARAM_INT, ], 'minutes' => [ 'type' => PARAM_INT, ], 'hours' => [ 'type' => PARAM_INT, ], 'mday' => [ 'type' => PARAM_INT, ], 'wday' => [ 'type' => PARAM_INT, ], 'mon' => [ 'type' => PARAM_INT, ], 'year' => [ 'type' => PARAM_INT, ], 'yday' => [ 'type' => PARAM_INT, ], 'weekday' => [ 'type' => PARAM_RAW, ], 'month' => [ 'type' => PARAM_RAW, ], 'timestamp' => [ 'type' => PARAM_INT, ], ]; } } event_exporter_base.php 0000644 00000035470 15152011771 0011331 0 ustar 00 <?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 event class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . "/calendar/lib.php"); require_once($CFG->libdir . "/filelib.php"); use \core\external\exporter; use \core_calendar\local\event\container; use \core_calendar\local\event\entities\event_interface; use \core_calendar\local\event\entities\action_event_interface; use \core_course\external\course_summary_exporter; use \core\external\coursecat_summary_exporter; use \renderer_base; use moodle_url; /** * Class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class event_exporter_base extends exporter { /** * @var event_interface $event */ protected $event; /** * Constructor. * * @param event_interface $event * @param array $related The related data. */ public function __construct(event_interface $event, $related = []) { $this->event = $event; $starttimestamp = $event->get_times()->get_start_time()->getTimestamp(); $endtimestamp = $event->get_times()->get_end_time()->getTimestamp(); $groupid = $event->get_group() ? $event->get_group()->get('id') : null; $userid = $event->get_user() ? $event->get_user()->get('id') : null; $categoryid = $event->get_category() ? $event->get_category()->get('id') : null; $data = new \stdClass(); $data->id = $event->get_id(); $data->name = $event->get_name(); $data->description = file_rewrite_pluginfile_urls( $event->get_description()->get_value(), 'pluginfile.php', $related['context']->id, 'calendar', 'event_description', $event->get_id() ); $data->descriptionformat = $event->get_description()->get_format(); $data->location = external_format_text($event->get_location(), FORMAT_PLAIN, $related['context']->id)[0]; $data->groupid = $groupid; $data->userid = $userid; $data->categoryid = $categoryid; $data->eventtype = $event->get_type(); $data->timestart = $starttimestamp; $data->timeduration = $endtimestamp - $starttimestamp; $data->timesort = $event->get_times()->get_sort_time()->getTimestamp(); $data->timeusermidnight = $event->get_times()->get_usermidnight_time()->getTimestamp(); $data->visible = $event->is_visible() ? 1 : 0; $data->timemodified = $event->get_times()->get_modified_time()->getTimestamp(); $data->component = $event->get_component(); $data->overdue = $data->timesort < time(); if ($repeats = $event->get_repeats()) { $data->repeatid = $repeats->get_id(); $data->eventcount = $repeats->get_num() + 1; } if ($cm = $event->get_course_module()) { $data->modulename = $cm->get('modname'); $data->instance = $cm->get('id'); $data->activityname = $cm->get('name'); $component = 'mod_' . $data->modulename; if (!component_callback_exists($component, 'core_calendar_get_event_action_string')) { $modulename = get_string('modulename', $data->modulename); $data->activitystr = get_string('requiresaction', 'calendar', $modulename); } else { $data->activitystr = component_callback( $component, 'core_calendar_get_event_action_string', [$event->get_type()] ); } } parent::__construct($data, $related); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'id' => ['type' => PARAM_INT], 'name' => ['type' => PARAM_TEXT], 'description' => [ 'type' => PARAM_RAW, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'descriptionformat' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'location' => [ 'type' => PARAM_RAW, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'categoryid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'groupid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'userid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'repeatid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'eventcount' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'component' => [ 'type' => PARAM_COMPONENT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'modulename' => [ 'type' => PARAM_TEXT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'activityname' => [ 'type' => PARAM_TEXT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'activitystr' => [ 'type' => PARAM_TEXT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'instance' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'eventtype' => ['type' => PARAM_TEXT], 'timestart' => ['type' => PARAM_INT], 'timeduration' => ['type' => PARAM_INT], 'timesort' => ['type' => PARAM_INT], 'timeusermidnight' => ['type' => PARAM_INT], 'visible' => ['type' => PARAM_INT], 'timemodified' => ['type' => PARAM_INT], 'overdue' => [ 'type' => PARAM_BOOL, 'optional' => true, 'default' => false, 'null' => NULL_ALLOWED ], ]; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'icon' => [ 'type' => event_icon_exporter::read_properties_definition(), ], 'category' => [ 'type' => coursecat_summary_exporter::read_properties_definition(), 'optional' => true, ], 'course' => [ 'type' => course_summary_exporter::read_properties_definition(), 'optional' => true, ], 'subscription' => [ 'type' => event_subscription_exporter::read_properties_definition(), 'optional' => true, ], 'canedit' => [ 'type' => PARAM_BOOL ], 'candelete' => [ 'type' => PARAM_BOOL ], 'deleteurl' => [ 'type' => PARAM_URL ], 'editurl' => [ 'type' => PARAM_URL ], 'viewurl' => [ 'type' => PARAM_URL ], 'formattedtime' => [ 'type' => PARAM_RAW, ], 'formattedlocation' => [ 'type' => PARAM_RAW, ], 'isactionevent' => [ 'type' => PARAM_BOOL ], 'iscourseevent' => [ 'type' => PARAM_BOOL ], 'iscategoryevent' => [ 'type' => PARAM_BOOL ], 'groupname' => [ 'type' => PARAM_RAW, 'optional' => true, 'default' => null, 'null' => NULL_ALLOWED ], 'normalisedeventtype' => [ 'type' => PARAM_TEXT ], 'normalisedeventtypetext' => [ 'type' => PARAM_TEXT ], 'action' => [ 'type' => event_action_exporter::read_properties_definition(), 'optional' => true, ], 'purpose' => [ 'type' => PARAM_TEXT ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $values = []; $event = $this->event; $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event); $context = $this->related['context']; $course = $this->related['course']; $values['isactionevent'] = false; $values['iscourseevent'] = false; $values['iscategoryevent'] = false; $values['normalisedeventtype'] = $event->get_type(); if ($moduleproxy = $event->get_course_module()) { // We need a separate property to flag if an event is action event. // That's required because canedit return true but action action events cannot be edited on the calendar UI. // But they are considered editable because you can drag and drop the event on the month view. $values['isactionevent'] = true; // Activity events are normalised to "look" like course events. $values['normalisedeventtype'] = 'course'; } else if ($event->get_type() == 'course') { $values['iscourseevent'] = true; } else if ($event->get_type() == 'category') { $values['iscategoryevent'] = true; } $timesort = $event->get_times()->get_sort_time()->getTimestamp(); $iconexporter = new event_icon_exporter($event, ['context' => $context]); $identifier = 'type' . $values['normalisedeventtype']; $stringexists = get_string_manager()->string_exists($identifier, 'calendar'); if (!$stringexists) { // Property normalisedeventtype is used to build the name of the CSS class for the events. $values['normalisedeventtype'] = 'other'; } $values['normalisedeventtypetext'] = $stringexists ? get_string($identifier, 'calendar') : ''; $purpose = 'none'; if ($moduleproxy) { $purpose = plugin_supports('mod', $moduleproxy->get('modname'), FEATURE_MOD_PURPOSE, 'none'); } $values['purpose'] = $purpose; $values['icon'] = $iconexporter->export($output); $subscriptionexporter = new event_subscription_exporter($event); $values['subscription'] = $subscriptionexporter->export($output); $proxy = $this->event->get_category(); if ($proxy && $proxy->get('id')) { $category = $proxy->get_proxied_instance(); $categorysummaryexporter = new coursecat_summary_exporter($category, ['context' => $context]); $values['category'] = $categorysummaryexporter->export($output); } if ($course && $course->id != SITEID) { $coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]); $values['course'] = $coursesummaryexporter->export($output); } $courseid = (!$course) ? SITEID : $course->id; $values['canedit'] = calendar_edit_event_allowed($legacyevent, true); $values['candelete'] = calendar_delete_event_allowed($legacyevent); $deleteurl = new moodle_url('/calendar/delete.php', ['id' => $event->get_id(), 'course' => $courseid]); $values['deleteurl'] = $deleteurl->out(false); $editurl = new moodle_url('/calendar/event.php', ['action' => 'edit', 'id' => $event->get_id(), 'course' => $courseid]); $values['editurl'] = $editurl->out(false); $viewurl = new moodle_url('/calendar/view.php', ['view' => 'day', 'course' => $courseid, 'time' => $timesort]); $viewurl->set_anchor('event_' . $event->get_id()); $values['viewurl'] = $viewurl->out(false); $values['formattedtime'] = calendar_format_event_time($legacyevent, time(), null, false, $timesort); $values['formattedlocation'] = calendar_format_event_location($legacyevent); if ($group = $event->get_group()) { $values['groupname'] = format_string($group->get('name'), true, ['context' => \context_course::instance($event->get_course()->get('id'))]); } if ($event instanceof action_event_interface) { // Export event action if applicable. $actionrelated = [ 'context' => $this->related['context'], 'event' => $event ]; $actionexporter = new event_action_exporter($event->get_action(), $actionrelated); $values['action'] = $actionexporter->export($output); } return $values; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'context' => 'context', 'course' => 'stdClass?', ]; } } month_exporter.php 0000644 00000037027 15152011771 0010343 0 ustar 00 <?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 event class for displaying the month view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; use moodle_url; /** * Class for displaying the month view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class month_exporter extends exporter { /** @var int Number of calendar instances displayed. */ protected static $calendarinstances = 0; /** @var int This calendar instance's ID. */ protected $calendarinstanceid = 0; /** * @var \calendar_information $calendar The calendar to be rendered. */ protected $calendar; /** * @var int $firstdayofweek The first day of the week. */ protected $firstdayofweek; /** * @var moodle_url $url The URL for the events page. */ protected $url; /** * @var bool $includenavigation Whether navigation should be included on the output. */ protected $includenavigation = true; /** * @var bool $initialeventsloaded Whether the events have been loaded for this month. */ protected $initialeventsloaded = true; /** * @var bool $showcoursefilter Whether to render the course filter selector as well. */ protected $showcoursefilter = false; /** * Constructor for month_exporter. * * @param \calendar_information $calendar The calendar being represented * @param \core_calendar\type_base $type The calendar type (e.g. Gregorian) * @param array $related The related information */ public function __construct(\calendar_information $calendar, \core_calendar\type_base $type, $related) { // Increment the calendar instances count on initialisation. self::$calendarinstances++; // Assign this instance an ID based on the latest calendar instances count. $this->calendarinstanceid = self::$calendarinstances; $this->calendar = $calendar; $this->firstdayofweek = $type->get_starting_weekday(); $this->url = new moodle_url('/calendar/view.php', [ 'view' => 'month', 'time' => $calendar->time, ]); if ($this->calendar->course && SITEID !== $this->calendar->course->id) { $this->url->param('course', $this->calendar->course->id); } else if ($this->calendar->categoryid) { $this->url->param('category', $this->calendar->categoryid); } $related['type'] = $type; $data = [ 'url' => $this->url->out(false), ]; parent::__construct($data, $related); } protected static function define_properties() { return [ 'url' => [ 'type' => PARAM_URL, ], ]; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'courseid' => [ 'type' => PARAM_INT, ], 'categoryid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => 0, ], 'filter_selector' => [ 'type' => PARAM_RAW, 'optional' => true, ], 'weeks' => [ 'type' => week_exporter::read_properties_definition(), 'multiple' => true, ], 'daynames' => [ 'type' => day_name_exporter::read_properties_definition(), 'multiple' => true, ], 'view' => [ 'type' => PARAM_ALPHA, ], 'date' => [ 'type' => date_exporter::read_properties_definition(), ], 'periodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'includenavigation' => [ 'type' => PARAM_BOOL, 'default' => true, ], // Tracks whether the first set of events have been loaded and provided // to the exporter. 'initialeventsloaded' => [ 'type' => PARAM_BOOL, 'default' => true, ], 'previousperiod' => [ 'type' => date_exporter::read_properties_definition(), ], 'previousperiodlink' => [ 'type' => PARAM_URL, ], 'previousperiodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'nextperiod' => [ 'type' => date_exporter::read_properties_definition(), ], 'nextperiodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'nextperiodlink' => [ 'type' => PARAM_URL, ], 'larrow' => [ // The left arrow defined by the theme. 'type' => PARAM_RAW, ], 'rarrow' => [ // The right arrow defined by the theme. 'type' => PARAM_RAW, ], 'defaulteventcontext' => [ 'type' => PARAM_INT, 'default' => 0, ], 'calendarinstanceid' => [ 'type' => PARAM_INT, 'default' => 0, ], 'viewingmonth' => [ 'type' => PARAM_BOOL, 'default' => true, ], 'showviewselector' => [ 'type' => PARAM_BOOL, 'default' => true, ], 'viewinginblock' => [ 'type' => PARAM_BOOL, 'default' => false, ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $previousperiod = $this->get_previous_month_data(); $nextperiod = $this->get_next_month_data(); $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $nextperiodlink = new moodle_url($this->url); $nextperiodlink->param('time', $nextperiod[0]); $previousperiodlink = new moodle_url($this->url); $previousperiodlink->param('time', $previousperiod[0]); $viewmode = $this->calendar->get_viewmode() ?? 'month'; $return = [ 'courseid' => $this->calendar->courseid, 'weeks' => $this->get_weeks($output), 'daynames' => $this->get_day_names($output), 'view' => $viewmode, 'date' => (new date_exporter($date))->export($output), 'periodname' => userdate($this->calendar->time, get_string('strftimemonthyear')), 'previousperiod' => (new date_exporter($previousperiod))->export($output), 'previousperiodname' => userdate($previousperiod[0], get_string('strftimemonth')), 'previousperiodlink' => $previousperiodlink->out(false), 'nextperiod' => (new date_exporter($nextperiod))->export($output), 'nextperiodname' => userdate($nextperiod[0], get_string('strftimemonth')), 'nextperiodlink' => $nextperiodlink->out(false), 'larrow' => $output->larrow(), 'rarrow' => $output->rarrow(), 'includenavigation' => $this->includenavigation, 'initialeventsloaded' => $this->initialeventsloaded, 'calendarinstanceid' => $this->calendarinstanceid, 'showviewselector' => $viewmode === 'month', 'viewinginblock' => $viewmode === 'monthblock', ]; if ($this->showcoursefilter) { $return['filter_selector'] = $this->get_course_filter_selector($output); } if ($context = $this->get_default_add_context()) { $return['defaulteventcontext'] = $context->id; } if ($this->calendar->categoryid) { $return['categoryid'] = $this->calendar->categoryid; } return $return; } /** * Get the course filter selector. * * @param renderer_base $output * @return string The html code for the course filter selector. */ protected function get_course_filter_selector(renderer_base $output) { $content = ''; $content .= $output->course_filter_selector($this->url, '', $this->calendar->course->id, $this->calendarinstanceid); return $content; } /** * Get the list of day names for display, re-ordered from the first day * of the week. * * @param renderer_base $output * @return day_name_exporter[] */ protected function get_day_names(renderer_base $output) { $weekdays = $this->related['type']->get_weekdays(); $daysinweek = count($weekdays); $daynames = []; for ($i = 0; $i < $daysinweek; $i++) { // Bump the currentdayno and ensure it loops. $dayno = ($i + $this->firstdayofweek + $daysinweek) % $daysinweek; $dayname = new day_name_exporter($dayno, $weekdays[$dayno]); $daynames[] = $dayname->export($output); } return $daynames; } /** * Get the list of week days, ordered into weeks and padded according * to the value of the first day of the week. * * @param renderer_base $output * @return array The list of weeks. */ protected function get_weeks(renderer_base $output) { $weeks = []; $alldays = $this->get_days(); $daysinweek = count($this->related['type']->get_weekdays()); // Calculate which day number is the first, and last day of the week. $firstdayofweek = $this->firstdayofweek; // The first week is special as it may have padding at the beginning. $day = reset($alldays); $firstdayno = $day['wday']; $prepadding = ($firstdayno + $daysinweek - $firstdayofweek) % $daysinweek; $daysinfirstweek = $daysinweek - $prepadding; $days = array_slice($alldays, 0, $daysinfirstweek); $week = new week_exporter($this->calendar, $days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related); $weeks[] = $week->export($output); // Now chunk up the remaining day. and turn them into weeks. $daychunks = array_chunk(array_slice($alldays, $daysinfirstweek), $daysinweek); foreach ($daychunks as $days) { $week = new week_exporter($this->calendar, $days, 0, ($daysinweek - count($days)), $this->related); $weeks[] = $week->export($output); } return $weeks; } /** * Get the list of days with the matching date array. * * @return array */ protected function get_days() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthdays = $this->related['type']->get_num_days_in_month($date['year'], $date['mon']); $days = []; for ($dayno = 1; $dayno <= $monthdays; $dayno++) { // Get the gregorian representation of the day. $timestamp = $this->related['type']->convert_to_timestamp($date['year'], $date['mon'], $dayno); $days[] = $this->related['type']->timestamp_to_date_array($timestamp); } return $days; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } /** * Get the current month timestamp. * * @return int The month timestamp. */ protected function get_month_data() { $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $monthtime = $this->related['type']->convert_to_gregorian($date['year'], $date['month'], 1); return make_timestamp($monthtime['year'], $monthtime['month']); } /** * Get the previous month timestamp. * * @return int The previous month timestamp. */ protected function get_previous_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_prev_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); } /** * Get the next month timestamp. * * @return int The next month timestamp. */ protected function get_next_month_data() { $type = $this->related['type']; $date = $type->timestamp_to_date_array($this->calendar->time); list($date['mon'], $date['year']) = $type->get_next_month($date['year'], $date['mon']); $time = $type->convert_to_timestamp($date['year'], $date['mon'], 1); return $type->timestamp_to_date_array($time); } /** * Set whether the navigation should be shown. * * @param bool $include * @return $this */ public function set_includenavigation($include) { $this->includenavigation = $include; return $this; } /** * Set whether the initial events have already been loaded and * provided to the exporter. * * @param bool $loaded * @return $this */ public function set_initialeventsloaded(bool $loaded) { $this->initialeventsloaded = $loaded; return $this; } /** * Set whether the course filter selector should be shown. * * @param bool $show * @return $this */ public function set_showcoursefilter(bool $show) { $this->showcoursefilter = $show; return $this; } /** * Get the default context for use when adding a new event. * * @return null|\context */ protected function get_default_add_context() { if (calendar_user_can_add_event($this->calendar->course)) { return \context_course::instance($this->calendar->course->id); } return null; } } week_day_exporter.php 0000644 00000011733 15152011771 0011002 0 ustar 00 <?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 event class for displaying the day on month view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use renderer_base; use moodle_url; /** * Class for displaying the day on month view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class week_day_exporter extends day_exporter { /** * Constructor. * * @param \calendar_information $calendar The calendar information for the period being displayed * @param mixed $data Either an stdClass or an array of values. * @param array $related Related objects. */ public function __construct(\calendar_information $calendar, $data, $related) { parent::__construct($calendar, $data, $related); // Fix the url for today to be based on the today timestamp // rather than the calendar_information time set in the parent // constructor. $this->url->param('time', $this->data[0]); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { $return = parent::define_properties(); $return = array_merge($return, [ // These are additional params. 'istoday' => [ 'type' => PARAM_BOOL, 'default' => false, ], 'isweekend' => [ 'type' => PARAM_BOOL, 'default' => false, ], ]); return $return; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { $return = parent::define_other_properties(); $return = array_merge($return, [ 'popovertitle' => [ 'type' => PARAM_RAW, 'default' => '', ], 'daytitle' => [ 'type' => PARAM_RAW, ] ]); return $return; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $return = parent::get_other_values($output); if ($popovertitle = $this->get_popover_title()) { $return['popovertitle'] = $popovertitle; } $return['daytitle'] = $this->get_day_title(); return $return; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } /** * Get the title for this popover. * * @return string */ protected function get_popover_title() { $title = null; $userdate = userdate($this->data[0], get_string('strftimedayshort')); if (count($this->related['events'])) { $title = get_string('eventsfor', 'calendar', $userdate); } else if ($this->data['istoday']) { $title = $userdate; } if ($this->data['istoday']) { $title = get_string('todayplustitle', 'calendar', $userdate); } return $title; } /** * Get the title for this day. * * @return string */ protected function get_day_title(): string { $userdate = userdate($this->data[0], get_string('strftimedayshort')); $numevents = count($this->related['events']); if ($numevents == 1) { $title = get_string('dayeventsone', 'calendar', $userdate); } else if ($numevents) { $title = get_string('dayeventsmany', 'calendar', ['num' => $numevents, 'day' => $userdate]); } else { $title = get_string('dayeventsnone', 'calendar', $userdate); } return $title; } } subscription/delete.php 0000644 00000006507 15152011771 0011253 0 ustar 00 <?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/>. /** * Calendar external API for deleting the subscription. * * @package core_calendar * @category external * @copyright 2021 Huong Nguyen <huongnv13@gmail.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external\subscription; defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/calendar/lib.php'); use external_api; use external_function_parameters; use external_single_structure; use external_value; use external_warnings; /** * Calendar external API for deleting the subscription. * * @package core_calendar * @category external * @copyright 2021 Huong Nguyen <huongnv13@gmail.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class delete extends external_api { /** * Describes the parameters for deleting the subscription. * * @return external_function_parameters * @since Moodle 4.0 */ public static function execute_parameters(): external_function_parameters { return new external_function_parameters([ 'subscriptionid' => new external_value(PARAM_INT, 'The id of the subscription', VALUE_REQUIRED) ]); } /** * External function to delete the calendar subscription. * * @param int $subscriptionid Subscription id. * @return array */ public static function execute(int $subscriptionid): array { [ 'subscriptionid' => $subscriptionid ] = self::validate_parameters(self::execute_parameters(), [ 'subscriptionid' => $subscriptionid ]); $status = false; $warnings = []; if (calendar_can_edit_subscription($subscriptionid)) { // Fetch the subscription from the database making sure it exists. $sub = calendar_get_subscription($subscriptionid); calendar_delete_subscription($subscriptionid); $status = true; } else { $warnings = [ 'item' => $subscriptionid, 'warningcode' => 'errordeletingsubscription', 'message' => get_string('nopermissions', 'error') ]; } return [ 'status' => $status, 'warnings' => $warnings ]; } /** * Describes the data returned from the external function. * * @return external_single_structure * @since Moodle 4.0 */ public static function execute_returns(): external_single_structure { return new external_single_structure([ 'status' => new external_value(PARAM_BOOL, 'status: true if success'), 'warnings' => new external_warnings() ]); } } calendar_event_exporter.php 0000644 00000036176 15152011771 0012174 0 ustar 00 <?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 event class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \core_calendar\local\event\container; use \core_course\external\course_summary_exporter; use \renderer_base; require_once($CFG->dirroot . '/course/lib.php'); /** * Class for displaying a calendar event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class calendar_event_exporter extends event_exporter_base { /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { $values = parent::define_other_properties(); $values['url'] = ['type' => PARAM_URL]; $values['islastday'] = [ 'type' => PARAM_BOOL, 'default' => false, ]; $values['popupname'] = [ 'type' => PARAM_RAW, ]; $values['mindaytimestamp'] = [ 'type' => PARAM_INT, 'optional' => true ]; $values['mindayerror'] = [ 'type' => PARAM_TEXT, 'optional' => true ]; $values['maxdaytimestamp'] = [ 'type' => PARAM_INT, 'optional' => true ]; $values['maxdayerror'] = [ 'type' => PARAM_TEXT, 'optional' => true ]; $values['draggable'] = [ 'type' => PARAM_BOOL, 'default' => false ]; return $values; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { global $CFG; $values = parent::get_other_values($output); $event = $this->event; $course = $this->related['course']; $hascourse = !empty($course); // By default all events that can be edited are // draggable. $values['draggable'] = $values['canedit']; if ($moduleproxy = $event->get_course_module()) { $modulename = $moduleproxy->get('modname'); $moduleid = $moduleproxy->get('id'); $url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]); // Build edit event url for action events. $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey()); $editurl = new \moodle_url('/course/mod.php', $params); $values['editurl'] = $editurl->out(false); } else if ($event->get_type() == 'category') { $url = $event->get_category()->get_proxied_instance()->get_view_link(); } else { $url = course_get_url($hascourse ? $course : SITEID); } $values['url'] = $url->out(false); $values['islastday'] = false; $today = $this->related['type']->timestamp_to_date_array($this->related['today']); if ($hascourse) { $values['popupname'] = external_format_string($this->event->get_name(), \context_course::instance($course->id), true); } else { $values['popupname'] = external_format_string($this->event->get_name(), \context_system::instance(), true); } $times = $this->event->get_times(); if ($duration = $times->get_duration()) { $enddate = $this->related['type']->timestamp_to_date_array($times->get_end_time()->getTimestamp()); $values['islastday'] = true; $values['islastday'] = $values['islastday'] && $enddate['year'] == $today['year']; $values['islastday'] = $values['islastday'] && $enddate['mon'] == $today['mon']; $values['islastday'] = $values['islastday'] && $enddate['mday'] == $today['mday']; } $subscription = $this->event->get_subscription(); if ($subscription && !empty($subscription->get('id')) && $CFG->calendar_showicalsource) { $a = (object) [ 'name' => $values['popupname'], 'source' => $subscription->get('name'), ]; $values['popupname'] = get_string('namewithsource', 'calendar', $a); } else { if ($values['islastday']) { $startdate = $this->related['type']->timestamp_to_date_array($times->get_start_time()->getTimestamp()); $samedate = true; $samedate = $samedate && $startdate['mon'] == $enddate['mon']; $samedate = $samedate && $startdate['year'] == $enddate['year']; $samedate = $samedate && $startdate['mday'] == $enddate['mday']; if (!$samedate) { $values['popupname'] = get_string('eventendtimewrapped', 'calendar', $values['popupname']); } } } // Include category name into the event name, if applicable. $proxy = $this->event->get_category(); if ($proxy && $proxy->get('id')) { $category = $proxy->get_proxied_instance(); $eventnameparams = (object) [ 'name' => $values['popupname'], 'category' => $category->get_formatted_name(), ]; $values['popupname'] = get_string('eventnameandcategory', 'calendar', $eventnameparams); } // Include course's shortname into the event name, if applicable. if ($hascourse && $course->id !== SITEID) { $eventnameparams = (object) [ 'name' => $values['popupname'], 'course' => $values['course']->shortname, ]; $values['popupname'] = get_string('eventnameandcourse', 'calendar', $eventnameparams); } if ($event->get_course_module()) { $values = array_merge($values, $this->get_module_timestamp_limits($event)); } else if ($hascourse && $course->id != SITEID && empty($event->get_group())) { // This is a course event. $values = array_merge($values, $this->get_course_timestamp_limits($event)); } return $values; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { $related = parent::define_related(); $related['daylink'] = \moodle_url::class; $related['type'] = '\core_calendar\type_base'; $related['today'] = 'int'; $related['moduleinstance'] = 'stdClass?'; return $related; } /** * Return the normalised event type. * Activity events are normalised to be course events. * * @return string */ public function get_calendar_event_type() { if ($this->event->get_course_module()) { return 'course'; } return $this->event->get_type(); } /** * Return the set of minimum and maximum date timestamp values * for the given event. * * @param event_interface $event * @return array */ protected function get_course_timestamp_limits($event) { $values = []; $mapper = container::get_event_mapper(); $starttime = $event->get_times()->get_start_time(); list($min, $max) = component_callback( 'core_course', 'core_calendar_get_valid_event_timestart_range', [$mapper->from_event_to_legacy_event($event), $event->get_course()->get_proxied_instance()], [false, false] ); // The callback will return false for either of the // min or max cutoffs to indicate that there are no // valid timestart values. In which case the event is // not draggable. if ($min === false || $max === false) { return ['draggable' => false]; } if ($min) { $values = array_merge($values, $this->get_timestamp_min_limit($starttime, $min)); } if ($max) { $values = array_merge($values, $this->get_timestamp_max_limit($starttime, $max)); } return $values; } /** * Return the set of minimum and maximum date timestamp values * for the given event. * * @param event_interface $event * @return array */ protected function get_module_timestamp_limits($event) { $values = []; $mapper = container::get_event_mapper(); $starttime = $event->get_times()->get_start_time(); $modname = $event->get_course_module()->get('modname'); $moduleinstance = $this->related['moduleinstance']; list($min, $max) = component_callback( 'mod_' . $modname, 'core_calendar_get_valid_event_timestart_range', [$mapper->from_event_to_legacy_event($event), $moduleinstance], [false, false] ); // The callback will return false for either of the // min or max cutoffs to indicate that there are no // valid timestart values. In which case the event is // not draggable. if ($min === false || $max === false) { return ['draggable' => false]; } if ($min) { $values = array_merge($values, $this->get_timestamp_min_limit($starttime, $min)); } if ($max) { $values = array_merge($values, $this->get_timestamp_max_limit($starttime, $max)); } return $values; } /** * Get the correct minimum midnight day limit based on the event start time * and the minimum timestamp limit of what the event belongs to. * * @param DateTimeInterface $starttime The event start time * @param array $min The module's minimum limit for the event * @return array Returns an array with mindaytimestamp and mindayerror keys. */ protected function get_timestamp_min_limit(\DateTimeInterface $starttime, $min) { // We need to check that the minimum valid time is earlier in the // day than the current event time so that if the user drags and drops // the event to this day (which changes the date but not the time) it // will result in a valid time start for the event. // // For example: // An event that starts on 2017-01-10 08:00 with a minimum cutoff // of 2017-01-05 09:00 means that 2017-01-05 is not a valid start day // for the drag and drop because it would result in the event start time // being set to 2017-01-05 08:00, which is invalid. Instead the minimum // valid start day would be 2017-01-06. $values = []; $timestamp = $min[0]; $errorstring = $min[1]; $mindate = (new \DateTimeImmutable())->setTimestamp($timestamp); $minstart = $mindate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($mindate <= $minstart) { $values['mindaytimestamp'] = $midnight; } else { $tomorrow = (new \DateTime())->setTimestamp($midnight)->modify('+1 day'); $values['mindaytimestamp'] = $tomorrow->getTimestamp(); } // Get the human readable error message to display if the min day // timestamp is violated. $values['mindayerror'] = $errorstring; return $values; } /** * Get the correct maximum midnight day limit based on the event start time * and the maximum timestamp limit of what the event belongs to. * * @param DateTimeInterface $starttime The event start time * @param array $max The module's maximum limit for the event * @return array Returns an array with maxdaytimestamp and maxdayerror keys. */ protected function get_timestamp_max_limit(\DateTimeInterface $starttime, $max) { // We're doing a similar calculation here as we are for the minimum // day timestamp. See the explanation above. $values = []; $timestamp = $max[0]; $errorstring = $max[1]; $maxdate = (new \DateTimeImmutable())->setTimestamp($timestamp); $maxstart = $maxdate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($maxdate >= $maxstart) { $values['maxdaytimestamp'] = $midnight; } else { $yesterday = (new \DateTime())->setTimestamp($midnight)->modify('-1 day'); $values['maxdaytimestamp'] = $yesterday->getTimestamp(); } // Get the human readable error message to display if the max day // timestamp is violated. $values['maxdayerror'] = $errorstring; return $values; } /** * Get the correct minimum midnight day limit based on the event start time * and the module's minimum timestamp limit. * * @deprecated since Moodle 3.6. Please use get_timestamp_min_limit(). * @todo final deprecation. To be removed in Moodle 3.10 * @param DateTimeInterface $starttime The event start time * @param array $min The module's minimum limit for the event * @return array Returns an array with mindaytimestamp and mindayerror keys. */ protected function get_module_timestamp_min_limit(\DateTimeInterface $starttime, $min) { debugging('get_module_timestamp_min_limit() has been deprecated. Please call get_timestamp_min_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_min_limit($starttime, $min); } /** * Get the correct maximum midnight day limit based on the event start time * and the module's maximum timestamp limit. * * @deprecated since Moodle 3.6. Please use get_timestamp_max_limit(). * @todo final deprecation. To be removed in Moodle 3.10 * @param DateTimeInterface $starttime The event start time * @param array $max The module's maximum limit for the event * @return array Returns an array with maxdaytimestamp and maxdayerror keys. */ protected function get_module_timestamp_max_limit(\DateTimeInterface $starttime, $max) { debugging('get_module_timestamp_max_limit() has been deprecated. Please call get_timestamp_max_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_max_limit($starttime, $max); } } export/token.php 0000644 00000005512 15152011771 0007721 0 ustar 00 <?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/>. /** * This is the external method for exporting a calendar token. * * @package core_calendar * @since Moodle 3.10 * @copyright 2020 Juan Leyva <juan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external\export; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->libdir . '/externallib.php'); require_once($CFG->dirroot . '/calendar/lib.php'); use context_system; use external_api; use external_function_parameters; use external_multiple_structure; use external_single_structure; use external_value; use external_warnings; use moodle_exception; /** * This is the external method for exporting a calendar token. * * @copyright 2020 Juan Leyva <juan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class token extends external_api { /** * Returns description of method parameters. * * @return external_function_parameters. * @since Moodle 3.10 */ public static function execute_parameters() { return new external_function_parameters([]); } /** * Return the auth token required for exporting a calendar. * * @return array The access information * @throws moodle_exception * @since Moodle 3.10 */ public static function execute() { global $CFG, $USER; $context = context_system::instance(); self::validate_context($context); if (empty($CFG->enablecalendarexport)) { throw new moodle_exception('Calendar export is disabled in this site.'); } return [ 'token' => calendar_get_export_token($USER), 'warnings' => [], ]; } /** * Returns description of method result value. * * @return external_description. * @since Moodle 3.10 */ public static function execute_returns() { return new external_single_structure( [ 'token' => new external_value(PARAM_RAW, 'The calendar permanent access token for calendar export.'), 'warnings' => new external_warnings(), ] ); } } calendar_upcoming_exporter.php 0000644 00000014133 15152011771 0012661 0 ustar 00 <?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 event class for displaying the upcoming view. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; use moodle_url; use \core_calendar\local\event\container; /** * Class for displaying the day view. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class calendar_upcoming_exporter extends exporter { /** * @var \calendar_information $calendar The calendar to be rendered. */ protected $calendar; /** * @var moodle_url $url The URL for the upcoming view page. */ protected $url; /** * Constructor for upcoming exporter. * * @param \calendar_information $calendar The calendar being represented. * @param array $related The related information */ public function __construct(\calendar_information $calendar, $related) { $this->calendar = $calendar; parent::__construct([], $related); } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'events' => [ 'type' => calendar_event_exporter::read_properties_definition(), 'multiple' => true, ], 'defaulteventcontext' => [ 'type' => PARAM_INT, 'default' => 0, ], 'filter_selector' => [ 'type' => PARAM_RAW, ], 'courseid' => [ 'type' => PARAM_INT, ], 'categoryid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => 0, ], 'isloggedin' => [ 'type' => PARAM_BOOL, ], 'date' => [ 'type' => date_exporter::read_properties_definition(), ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $timestamp = $this->calendar->time; $cache = $this->related['cache']; $url = new moodle_url('/calendar/view.php', [ 'view' => 'upcoming', 'time' => $timestamp, 'course' => $this->calendar->course->id, ]); $this->url = $url; $return['isloggedin'] = isloggedin(); $return['events'] = array_map(function($event) use ($cache, $output, $url) { $context = $cache->get_context($event); $course = $cache->get_course($event); $moduleinstance = $cache->get_module_instance($event); $exporter = new calendar_event_exporter($event, [ 'context' => $context, 'course' => $course, 'moduleinstance' => $moduleinstance, 'daylink' => $url, 'type' => $this->related['type'], 'today' => $this->calendar->time, ]); $data = $exporter->export($output); // We need to override default formatted time because it differs from day view. // Formatted time for upcoming view adds a link to the day view. $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event); $data->formattedtime = calendar_format_event_time($legacyevent, time(), null); return $data; }, $this->related['events']); if ($context = $this->get_default_add_context()) { $return['defaulteventcontext'] = $context->id; } $return['filter_selector'] = $this->get_course_filter_selector($output); $return['courseid'] = $this->calendar->courseid; $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $return['date'] = (new date_exporter($date))->export($output); if ($this->calendar->categoryid) { $return['categoryid'] = $this->calendar->categoryid; } return $return; } /** * Get the default context for use when adding a new event. * * @return null|\context */ protected function get_default_add_context() { if (calendar_user_can_add_event($this->calendar->course)) { return \context_course::instance($this->calendar->course->id); } return null; } /** * Get the course filter selector. * * @param renderer_base $output * @return string The html code for the course filter selector. */ protected function get_course_filter_selector(renderer_base $output) { return $output->course_filter_selector($this->url, '', $this->calendar->course->id); } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } } day_exporter.php 0000644 00000022002 15152011771 0007756 0 ustar 00 <?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 event class for displaying the day view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/calendar/lib.php'); use core\external\exporter; use renderer_base; use moodle_url; /** * Class for displaying the day view. * * @package core_calendar * @copyright 2017 Andrew Nicols <andrew@nicols.co.uk> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class day_exporter extends exporter { /** * @var \calendar_information $calendar The calendar being displayed. */ protected $calendar; /** * @var moodle_url */ protected $url; /** * Constructor. * * @param \calendar_information $calendar The calendar information for the period being displayed * @param mixed $data Either an stdClass or an array of values. * @param array $related Related objects. */ public function __construct(\calendar_information $calendar, $data, $related) { $this->calendar = $calendar; $url = new moodle_url('/calendar/view.php', [ 'view' => 'day', 'time' => $calendar->time, ]); if ($this->calendar->course && SITEID !== $this->calendar->course->id) { $url->param('course', $this->calendar->course->id); } else if ($this->calendar->categoryid) { $url->param('category', $this->calendar->categoryid); } $this->url = $url; parent::__construct($data, $related); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { // These are the default properties as returned by getuserdate() // but without the formatted month and week names. return [ 'seconds' => [ 'type' => PARAM_INT, ], 'minutes' => [ 'type' => PARAM_INT, ], 'hours' => [ 'type' => PARAM_INT, ], 'mday' => [ 'type' => PARAM_INT, ], 'wday' => [ 'type' => PARAM_INT, ], 'year' => [ 'type' => PARAM_INT, ], 'yday' => [ 'type' => PARAM_INT, ], ]; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'timestamp' => [ 'type' => PARAM_INT, ], 'neweventtimestamp' => [ 'type' => PARAM_INT, ], 'viewdaylink' => [ 'type' => PARAM_URL, 'optional' => true, ], 'viewdaylinktitle' => [ 'type' => PARAM_RAW, 'optional' => true, ], 'events' => [ 'type' => calendar_event_exporter::read_properties_definition(), 'multiple' => true, ], 'hasevents' => [ 'type' => PARAM_BOOL, 'default' => false, ], 'calendareventtypes' => [ 'type' => PARAM_RAW, 'multiple' => true, ], 'previousperiod' => [ 'type' => PARAM_INT, ], 'nextperiod' => [ 'type' => PARAM_INT, ], 'navigation' => [ 'type' => PARAM_RAW, ], 'haslastdayofevent' => [ 'type' => PARAM_BOOL, 'default' => false, ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $daytimestamp = $this->calendar->time; $timestamp = $this->data[0]; // Need to account for user's timezone. $usernow = usergetdate(time()); $today = new \DateTimeImmutable(); // The start time should use the day's date but the current // time of the day (adjusted for user's timezone). $neweventstarttime = $today->setTimestamp($timestamp)->setTime( $usernow['hours'], $usernow['minutes'], $usernow['seconds'] ); $return = [ 'timestamp' => $timestamp, 'neweventtimestamp' => $neweventstarttime->getTimestamp(), 'previousperiod' => $this->get_previous_day_timestamp($daytimestamp), 'nextperiod' => $this->get_next_day_timestamp($daytimestamp), 'navigation' => $this->get_navigation(), 'viewdaylink' => $this->url->out(false), ]; if ($viewdaylinktitle = $this->get_view_link_title()) { $return['viewdaylinktitle'] = $viewdaylinktitle; } $cache = $this->related['cache']; $eventexporters = array_map(function($event) use ($cache, $output) { $context = $cache->get_context($event); $course = $cache->get_course($event); $moduleinstance = $cache->get_module_instance($event); $exporter = new calendar_event_exporter($event, [ 'context' => $context, 'course' => $course, 'moduleinstance' => $moduleinstance, 'daylink' => $this->url, 'type' => $this->related['type'], 'today' => $this->data[0], ]); return $exporter; }, $this->related['events']); $return['events'] = array_map(function($exporter) use ($output) { return $exporter->export($output); }, $eventexporters); $return['hasevents'] = !empty($return['events']); $return['calendareventtypes'] = array_map(function($exporter) { return $exporter->get_calendar_event_type(); }, $eventexporters); $return['calendareventtypes'] = array_values(array_unique($return['calendareventtypes'])); $return['haslastdayofevent'] = false; foreach ($return['events'] as $event) { if ($event->islastday) { $return['haslastdayofevent'] = true; break; } } return $return; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } /** * Get the previous day timestamp. * * @param int $daytimestamp The current day timestamp. * @return int The previous day timestamp. */ protected function get_previous_day_timestamp($daytimestamp) { return $this->related['type']->get_prev_day($daytimestamp); } /** * Get the next day timestamp. * * @param int $daytimestamp The current day timestamp. * @return int The next day timestamp. */ protected function get_next_day_timestamp($daytimestamp) { return $this->related['type']->get_next_day($daytimestamp); } /** * Get the calendar navigation controls. * * @return string The html code to the calendar top navigation. */ protected function get_navigation() { return calendar_top_controls('day', [ 'id' => $this->calendar->courseid, 'time' => $this->calendar->time, ]); } /** * Get the title for view link. * * @return string */ protected function get_view_link_title() { $title = null; $userdate = userdate($this->data[0], get_string('strftimedayshort')); if ($this->data['istoday']) { $title = get_string('todayplustitle', 'calendar', $userdate); } else if (count($this->related['events'])) { $title = get_string('eventsfor', 'calendar', $userdate); } return $title; } } events_same_course_exporter.php 0000644 00000005206 15152011771 0013101 0 ustar 00 <?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 event class for displaying a list of calendar events for a single course. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \renderer_base; /** * Class for displaying a list of calendar events for a single course. * * This class uses the events relateds cache in order to get the related * data for exporting an event without having to naively hit the database * for each event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class events_same_course_exporter extends events_exporter { /** * @var array $courseid The id of the course for these events. */ protected $courseid; /** * Constructor. * * @param int $courseid The course id for these events * @param array $events An array of event_interface objects * @param array $related An array of related objects */ public function __construct($courseid, array $events, $related = []) { parent::__construct($events, $related); $this->courseid = $courseid; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { $properties = parent::define_other_properties(); $properties['courseid'] = ['type' => PARAM_INT]; return $properties; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $values = parent::get_other_values($output); $values['courseid'] = $this->courseid; return $values; } } event_action_exporter.php 0000644 00000007562 15152011771 0011675 0 ustar 00 <?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 event class for displaying a calendar event's action. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use core_calendar\local\event\entities\action_interface; use core_calendar\local\event\container; use renderer_base; /** * Class for displaying a calendar event's action. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class event_action_exporter extends exporter { /** * Constructor. * * @param action_interface $action The action object. * @param array $related Related data. */ public function __construct(action_interface $action, $related = []) { $data = new \stdClass(); $data->name = $action->get_name(); $data->url = $action->get_url()->out(false); $data->itemcount = $action->get_item_count(); $data->actionable = $action->is_actionable(); parent::__construct($data, $related); } /** * Return the list of properties. * * @return array */ protected static function define_properties() { return [ 'name' => ['type' => PARAM_TEXT], 'url' => ['type' => PARAM_URL], 'itemcount' => ['type' => PARAM_INT], 'actionable' => ['type' => PARAM_BOOL] ]; } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'showitemcount' => ['type' => PARAM_BOOL, 'default' => false] ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $event = $this->related['event']; if (!$event->get_component()) { return ['showitemcount' => false]; } $showitemcountcallback = 'core_calendar_event_action_shows_item_count'; $mapper = container::get_event_mapper(); $calevent = $mapper->from_event_to_legacy_event($event); $params = [$calevent, $this->data->itemcount]; $showitemcount = component_callback($event->get_component(), $showitemcountcallback, $params, false); // Prepare other values data. $data = [ 'showitemcount' => $showitemcount ]; return $data; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'context' => 'context', 'event' => '\\core_calendar\\local\\event\\entities\\event_interface' ]; } /** * Magic method returning parameters for formatting 'name' property * * @return bool[] */ protected function get_format_parameters_for_name() { return ['escape' => false]; } } calendar_day_exporter.php 0000644 00000023153 15152011771 0011617 0 ustar 00 <?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 event class for displaying the day view. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use core\external\exporter; use renderer_base; use moodle_url; use \core_calendar\local\event\container; /** * Class for displaying the day view. * * @package core_calendar * @copyright 2017 Simey Lameze <simey@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class calendar_day_exporter extends exporter { /** * @var \calendar_information $calendar The calendar to be rendered. */ protected $calendar; /** * @var moodle_url $url The URL for the day view page. */ protected $url; /** * Constructor for day exporter. * * @param \calendar_information $calendar The calendar being represented. * @param array $related The related information */ public function __construct(\calendar_information $calendar, $related) { $this->calendar = $calendar; parent::__construct([], $related); } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'events' => [ 'type' => calendar_event_exporter::read_properties_definition(), 'multiple' => true, ], 'defaulteventcontext' => [ 'type' => PARAM_INT, 'default' => 0, ], 'filter_selector' => [ 'type' => PARAM_RAW, ], 'courseid' => [ 'type' => PARAM_INT, ], 'categoryid' => [ 'type' => PARAM_INT, 'optional' => true, 'default' => 0, ], 'neweventtimestamp' => [ 'type' => PARAM_INT, ], 'date' => [ 'type' => date_exporter::read_properties_definition(), ], 'periodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'previousperiod' => [ 'type' => date_exporter::read_properties_definition(), ], 'previousperiodlink' => [ 'type' => PARAM_URL, ], 'previousperiodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'nextperiod' => [ 'type' => date_exporter::read_properties_definition(), ], 'nextperiodname' => [ // Note: We must use RAW here because the calendar type returns the formatted month name based on a // calendar format. 'type' => PARAM_RAW, ], 'nextperiodlink' => [ 'type' => PARAM_URL, ], 'larrow' => [ // The left arrow defined by the theme. 'type' => PARAM_RAW, ], 'rarrow' => [ // The right arrow defined by the theme. 'type' => PARAM_RAW, ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $timestamp = $this->calendar->time; $cache = $this->related['cache']; $url = new moodle_url('/calendar/view.php', [ 'view' => 'day', 'time' => $timestamp, ]); if ($this->calendar->course && SITEID !== $this->calendar->course->id) { $url->param('course', $this->calendar->course->id); } else if ($this->calendar->categoryid) { $url->param('category', $this->calendar->categoryid); } $this->url = $url; $return['events'] = array_map(function($event) use ($cache, $output, $url) { $context = $cache->get_context($event); $course = $cache->get_course($event); $moduleinstance = $cache->get_module_instance($event); $exporter = new calendar_event_exporter($event, [ 'context' => $context, 'course' => $course, 'moduleinstance' => $moduleinstance, 'daylink' => $url, 'type' => $this->related['type'], 'today' => $this->calendar->time, ]); $data = $exporter->export($output); // We need to override default formatted time because it differs from day view. // Formatted time for day view adds a link to the day view. $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event); $data->formattedtime = calendar_format_event_time($legacyevent, time(), null); return $data; }, $this->related['events']); if ($context = $this->get_default_add_context()) { $return['defaulteventcontext'] = $context->id; } if ($this->calendar->categoryid) { $return['categoryid'] = $this->calendar->categoryid; } $return['filter_selector'] = $this->get_course_filter_selector($output); $return['courseid'] = $this->calendar->courseid; $previousperiod = $this->get_previous_day_data(); $nextperiod = $this->get_next_day_data(); $date = $this->related['type']->timestamp_to_date_array($this->calendar->time); $nextperiodlink = new moodle_url($this->url); $nextperiodlink->param('time', $nextperiod[0]); $previousperiodlink = new moodle_url($this->url); $previousperiodlink->param('time', $previousperiod[0]); $days = calendar_get_days(); $return['date'] = (new date_exporter($date))->export($output); $return['periodname'] = userdate($this->calendar->time, get_string('strftimedaydate')); $return['previousperiod'] = (new date_exporter($previousperiod))->export($output); $return['previousperiodname'] = $days[$previousperiod['wday']]['fullname']; $return['previousperiodlink'] = $previousperiodlink->out(false); $return['nextperiod'] = (new date_exporter($nextperiod))->export($output); $return['nextperiodname'] = $days[$nextperiod['wday']]['fullname']; $return['nextperiodlink'] = $nextperiodlink->out(false); $return['larrow'] = $output->larrow(); $return['rarrow'] = $output->rarrow(); // Need to account for user's timezone. $usernow = usergetdate(time()); $today = new \DateTimeImmutable(); $neweventtimestamp = $today->setTimestamp($date[0])->setTime( $usernow['hours'], $usernow['minutes'], $usernow['seconds'] ); $return['neweventtimestamp'] = $neweventtimestamp->getTimestamp(); return $return; } /** * Get the default context for use when adding a new event. * * @return null|\context */ protected function get_default_add_context() { if (calendar_user_can_add_event($this->calendar->course)) { return \context_course::instance($this->calendar->course->id); } return null; } /** * Get the course filter selector. * * @param renderer_base $output * @return string The html code for the course filter selector. */ protected function get_course_filter_selector(renderer_base $output) { return $output->course_filter_selector($this->url, '', $this->calendar->course->id); } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'events' => '\core_calendar\local\event\entities\event_interface[]', 'cache' => '\core_calendar\external\events_related_objects_cache', 'type' => '\core_calendar\type_base', ]; } /** * Get the previous day timestamp. * * @return int The previous day timestamp. */ protected function get_previous_day_data() { $type = $this->related['type']; $time = $type->get_prev_day($this->calendar->time); return $type->timestamp_to_date_array($time); } /** * Get the next day timestamp. * * @return int The next day timestamp. */ protected function get_next_day_data() { $type = $this->related['type']; $time = $type->get_next_day($this->calendar->time); return $type->timestamp_to_date_array($time); } } events_grouped_by_course_exporter.php 0000644 00000006373 15152011771 0014321 0 ustar 00 <?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 event class for displaying a list of calendar events grouped by course id. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \core\external\exporter; use \renderer_base; /** * Class for displaying a list of calendar events grouped by course id. * * This class uses the events relateds cache in order to get the related * data for exporting an event without having to naively hit the database * for each event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class events_grouped_by_course_exporter extends exporter { /** * @var array $events An array of event_interface objects * grouped and index by course id. */ protected $eventsbycourse; /** * Constructor. * * @param array $eventsbycourse An array of event_interface objects * @param array $related An array of related objects */ public function __construct(array $eventsbycourse, $related = []) { $this->eventsbycourse = $eventsbycourse; parent::__construct([], $related); } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'groupedbycourse' => [ 'type' => events_same_course_exporter::read_properties_definition(), 'multiple' => true, 'default' => [], ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $return = []; $cache = $this->related['cache']; foreach ($this->eventsbycourse as $courseid => $events) { $eventsexporter = new events_same_course_exporter( $courseid, $events, ['cache' => $cache]); $return['groupedbycourse'][] = $eventsexporter->export($output); } return $return; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'cache' => 'core_calendar\external\events_related_objects_cache', ]; } } events_exporter.php 0000644 00000007144 15152011771 0010517 0 ustar 00 <?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 event class for displaying a list of calendar events. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_calendar\external; defined('MOODLE_INTERNAL') || die(); use \core\external\exporter; use \renderer_base; /** * Class for displaying a list of calendar events. * * This class uses the events relateds cache in order to get the related * data for exporting an event without having to naively hit the database * for each event. * * @package core_calendar * @copyright 2017 Ryan Wyllie <ryan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class events_exporter extends exporter { /** * @var array $events An array of event_interface objects. */ protected $events; /** * Constructor. * * @param array $events An array of event_interface objects * @param array $related An array of related objects */ public function __construct(array $events, $related = []) { $this->events = $events; parent::__construct([], $related); } /** * Return the list of additional properties. * * @return array */ protected static function define_other_properties() { return [ 'events' => [ 'type' => event_exporter::read_properties_definition(), 'multiple' => true, ], 'firstid' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, 'default' => null, ], 'lastid' => [ 'type' => PARAM_INT, 'null' => NULL_ALLOWED, 'default' => null, ], ]; } /** * Get the additional values to inject while exporting. * * @param renderer_base $output The renderer. * @return array Keys are the property names, values are their values. */ protected function get_other_values(renderer_base $output) { $return = []; $cache = $this->related['cache']; $return['events'] = array_map(function($event) use ($cache, $output) { $context = $cache->get_context($event); $course = $cache->get_course($event); $exporter = new event_exporter($event, ['context' => $context, 'course' => $course]); return $exporter->export($output); }, $this->events); if ($count = count($return['events'])) { $return['firstid'] = $return['events'][0]->id; $return['lastid'] = $return['events'][$count - 1]->id; } return $return; } /** * Returns a list of objects that are related. * * @return array */ protected static function define_related() { return [ 'cache' => 'core_calendar\external\events_related_objects_cache', ]; } } get_tool_types_and_proxies_count.php 0000644 00000005575 15152024014 0014126 0 ustar 00 <?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/>. namespace mod_lti\external; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/mod/lti/locallib.php'); /** * External function for fetching the count of all tool types and proxies. * * @package mod_lti * @author Andrew Madden <andrewmadden@catalyst-au.net> * @copyright 2021 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class get_tool_types_and_proxies_count extends \external_api { /** * Get parameter definition for get_tool_types_and_proxies_count(). * * @return \external_function_parameters */ public static function execute_parameters(): \external_function_parameters { return new \external_function_parameters( [ 'toolproxyid' => new \external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0), 'orphanedonly' => new \external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0), ] ); } /** * Get count of every tool type and tool proxy. * * @param int $toolproxyid The tool proxy id * @param bool $orphanedonly Whether to get orphaned proxies only. * @return array */ public static function execute($toolproxyid, $orphanedonly): array { $params = self::validate_parameters(self::execute_parameters(), [ 'toolproxyid' => $toolproxyid, 'orphanedonly' => $orphanedonly, ]); $toolproxyid = $params['toolproxyid']; $orphanedonly = $params['orphanedonly']; $context = \context_system::instance(); self::validate_context($context); require_capability('moodle/site:config', $context); return [ 'count' => lti_get_lti_types_and_proxies_count($orphanedonly, $toolproxyid), ]; } /** * Get return definition for get_tool_types_and_proxies_count. * * @return \external_single_structure */ public static function execute_returns(): \external_single_structure { return new \external_single_structure([ 'count' => new \external_value(PARAM_INT, 'Total number of tool types and proxies', VALUE_REQUIRED), ]); } } get_tool_types_and_proxies.php 0000644 00000007726 15152024014 0012716 0 ustar 00 <?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/>. namespace mod_lti\external; defined('MOODLE_INTERNAL') || die(); /** * External function for fetching all tool types and proxies. * * @package mod_lti * @author Andrew Madden <andrewmadden@catalyst-au.net> * @copyright 2021 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class get_tool_types_and_proxies extends \external_api { /** * Get parameter definition for get_tool_types_and_proxies(). * * @return \external_function_parameters */ public static function execute_parameters(): \external_function_parameters { return new \external_function_parameters( [ 'toolproxyid' => new \external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0), 'orphanedonly' => new \external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0), 'limit' => new \external_value(PARAM_INT, 'How many tool types displayed per page', VALUE_DEFAULT, 60, NULL_NOT_ALLOWED), 'offset' => new \external_value(PARAM_INT, 'Current offset of tool elements', VALUE_DEFAULT, 0, NULL_NOT_ALLOWED), ] ); } /** * Get data for all tool types and tool proxies. * * @param int $toolproxyid The tool proxy id * @param bool $orphanedonly Whether to get orphaned proxies only. * @param int $limit How many elements to return if using pagination. * @param int $offset Which chunk of elements to return is using pagination. * @return array */ public static function execute($toolproxyid, $orphanedonly, $limit, $offset): array { $params = self::validate_parameters(self::execute_parameters(), [ 'toolproxyid' => $toolproxyid, 'orphanedonly' => $orphanedonly, 'limit' => $limit, 'offset' => $offset, ]); $toolproxyid = $params['toolproxyid'] !== null ? $params['toolproxyid'] : 0; $orphanedonly = $params['orphanedonly'] !== null ? $params['orphanedonly'] : false; $limit = $params['limit'] !== null ? $params['limit'] : 0; $offset = $params['offset'] !== null ? $params['offset'] : 0; $context = \context_system::instance(); self::validate_context($context); require_capability('moodle/site:config', $context); list($proxies, $types) = lti_get_lti_types_and_proxies($limit, $offset, $orphanedonly, $toolproxyid); return [ 'types' => $types, 'proxies' => $proxies, 'limit' => $limit, 'offset' => $offset, ]; } /** * Get return definition for get_tool_types_and_proxies. * * @return \external_single_structure */ public static function execute_returns(): \external_single_structure { return new \external_single_structure([ 'types' => \mod_lti_external::get_tool_types_returns(), 'proxies' => \mod_lti_external::get_tool_proxies_returns(), 'limit' => new \external_value(PARAM_INT, 'Limit of how many tool types to show', VALUE_OPTIONAL), 'offset' => new \external_value(PARAM_INT, 'Offset of tool types', VALUE_OPTIONAL), ]); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�