first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+123
View File
@@ -0,0 +1,123 @@
<?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/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
*
* @package mod_page
* @copyright 2011 Andrew Davis <andrew@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Page conversion handler. This resource handler is called by moodle1_mod_resource_handler
*/
class moodle1_mod_page_handler extends moodle1_resource_successor_handler {
/** @var moodle1_file_manager instance */
protected $fileman = null;
/**
* Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
* Called by moodle1_mod_resource_handler::process_resource()
*/
public function process_legacy_resource(array $data, array $raw = null) {
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid, 'resource');
$moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// convert the legacy data onto the new page record
$page = array();
$page['id'] = $data['id'];
$page['name'] = $data['name'];
$page['intro'] = $data['intro'];
$page['introformat'] = $data['introformat'];
$page['content'] = $data['alltext'];
if ($data['type'] === 'html') {
// legacy Resource of the type Web page
$page['contentformat'] = FORMAT_HTML;
} else {
// legacy Resource of the type Plain text page
$page['contentformat'] = (int)$data['reference'];
if ($page['contentformat'] < 0 or $page['contentformat'] > 4) {
$page['contentformat'] = FORMAT_MOODLE;
}
}
$page['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE;
$page['legacyfileslast'] = null;
$page['revision'] = 1;
$page['timemodified'] = $data['timemodified'];
// populate display and displayoptions fields
$options = array('printintro' => 0);
if ($data['popup']) {
$page['display'] = RESOURCELIB_DISPLAY_POPUP;
$rawoptions = explode(',', $data['popup']);
foreach ($rawoptions as $rawoption) {
list($name, $value) = explode('=', trim($rawoption), 2);
if ($value > 0 and ($name == 'width' or $name == 'height')) {
$options['popup'.$name] = $value;
continue;
}
}
} else {
$page['display'] = RESOURCELIB_DISPLAY_OPEN;
}
$page['displayoptions'] = serialize($options);
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_page');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$page['intro'] = moodle1_converter::migrate_referenced_files($page['intro'], $this->fileman);
// convert course files embedded into the content
$this->fileman->filearea = 'content';
$this->fileman->itemid = 0;
$page['content'] = moodle1_converter::migrate_referenced_files($page['content'], $this->fileman);
// write page.xml
$this->open_xml_writer("activities/page_{$moduleid}/page.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
'modulename' => 'page', 'contextid' => $contextid));
$this->write_xml('page', $page, array('/page/id'));
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml for migrated resource file.
$this->open_xml_writer("activities/page_{$moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
}
@@ -0,0 +1,70 @@
<?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/>.
/**
* Defines backup_page_activity_task class
*
* @package mod_page
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/mod/page/backup/moodle2/backup_page_stepslib.php');
/**
* Provides the steps to perform one complete backup of the Page instance
*/
class backup_page_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the page.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_page_activity_structure_step('page_structure', 'page.xml'));
}
/**
* Encodes URLs to the index.php and view.php scripts
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
// Link to the list of pages
$search="/(".$base."\/mod\/page\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEINDEX*$2@$', $content);
// Link to page view by moduleid
$search="/(".$base."\/mod\/page\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEVIEWBYID*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,63 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_page
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Define all the backup steps that will be used by the backup_page_activity_task
*/
/**
* Define the complete page structure for backup, with file and id annotations
*/
class backup_page_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$page = new backup_nested_element('page', array('id'), array(
'name', 'intro', 'introformat', 'content', 'contentformat',
'legacyfiles', 'legacyfileslast', 'display', 'displayoptions',
'revision', 'timemodified'));
// Build the tree
// (love this)
// Define sources
$page->set_source_table('page', array('id' => backup::VAR_ACTIVITYID));
// Define id annotations
// (none)
// Define file annotations
$page->annotate_files('mod_page', 'intro', null); // This file areas haven't itemid
$page->annotate_files('mod_page', 'content', null); // This file areas haven't itemid
// Return the root element (page), wrapped into standard activity structure
return $this->prepare_activity_structure($page);
}
}
@@ -0,0 +1,109 @@
<?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/>.
/**
* @package mod_page
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/page/backup/moodle2/restore_page_stepslib.php'); // Because it exists (must)
/**
* page restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_page_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// label only has one structure step
$this->add_step(new restore_page_activity_structure_step('page_structure', 'page.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('page', array('intro', 'content'), 'page');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('PAGEVIEWBYID', '/mod/page/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('PAGEINDEX', '/mod/page/index.php?id=$1', 'course');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* page logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('page', 'add', 'view.php?id={course_module}', '{page}');
$rules[] = new restore_log_rule('page', 'update', 'view.php?id={course_module}', '{page}');
$rules[] = new restore_log_rule('page', 'view', 'view.php?id={course_module}', '{page}');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('page', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,64 @@
<?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/>.
/**
* @package mod_page
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_page_activity_task
*/
/**
* Structure step to restore one page activity
*/
class restore_page_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('page', '/activity/page');
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_page($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
// insert the page record
$newitemid = $DB->insert_record('page', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function after_execute() {
// Add page related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_page', 'intro', null);
$this->add_related_files('mod_page', 'content', null);
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Activity base class.
*
* @package mod_page
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Activity base class.
*
* @package mod_page
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
/**
* No need to fetch grades for resources.
*
* @param \core_analytics\course $course
* @return void
*/
public function fetch_student_grades(\core_analytics\course $course) {
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Cognitive depth indicator - page.
*
* @package mod_page
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Cognitive depth indicator - page.
*
* @package mod_page
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cognitive_depth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_page');
}
public function get_indicator_type() {
return self::INDICATOR_COGNITIVE;
}
public function get_cognitive_depth_level(\cm_info $cm) {
return self::COGNITIVE_LEVEL_1;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Social breadth indicator - page.
*
* @package mod_page
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Social breadth indicator - page.
*
* @package mod_page
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class social_breadth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_page');
}
public function get_indicator_type() {
return self::INDICATOR_SOCIAL;
}
public function get_social_breadth_level(\cm_info $cm) {
return self::SOCIAL_LEVEL_1;
}
}
+67
View File
@@ -0,0 +1,67 @@
<?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/>.
/**
* Content export definition.
*
* @package mod_page
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\content;
use core\content\export\exportable_items\exportable_textarea;
use core\content\export\exporters\abstract_mod_exporter;
/**
* A class which assists a component to export content.
*
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class exporter extends abstract_mod_exporter {
/**
* Get the exportable items for mod_page.
*
* @param bool $includeuserdata Whether to include user data, in addition to shared content.
* @return \core\content\export\exportable_item[]
*/
public function get_exportables(bool $includeuserdata = false): array {
$contentitems = [];
$contentitems[] = new exportable_textarea(
$this->get_context(),
$this->get_component(),
get_string('content', 'mod_page'),
// Content is in the 'content' field of the 'page' table.
$this->get_modname(),
'content',
// The record ID in the database is the CMID.
$this->cm->instance,
'contentformat',
// The mod_page content has files in 'content/0', and the itemid (0) is present in the URL.
'content',
0,
0
);
return $contentitems;
}
}
@@ -0,0 +1,38 @@
<?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/>.
/**
* The mod_page instance list viewed event.
*
* @package mod_page
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_page instance list viewed event class.
*
* @package mod_page
* @since Moodle 2.7
* @copyright 2013 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
}
@@ -0,0 +1,51 @@
<?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/>.
/**
* The mod_page course module viewed event.
*
* @package mod_page
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\event;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_page course module viewed event class.
*
* @package mod_page
* @since Moodle 2.6
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {
/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'page';
}
public static function get_objectid_mapping() {
return array('db' => 'page', 'restore' => 'page');
}
}
+211
View File
@@ -0,0 +1,211 @@
<?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/>.
/**
* Page external API
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
use core_course\external\helper_for_get_mods_by_courses;
use core_external\external_api;
use core_external\external_files;
use core_external\external_format_value;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\util;
/**
* Page external functions
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class mod_page_external extends external_api {
/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.0
*/
public static function view_page_parameters() {
return new external_function_parameters(
array(
'pageid' => new external_value(PARAM_INT, 'page instance id')
)
);
}
/**
* Simulate the page/view.php web interface page: trigger events, completion, etc...
*
* @param int $pageid the page instance id
* @return array of warnings and status result
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function view_page($pageid) {
global $DB, $CFG;
require_once($CFG->dirroot . "/mod/page/lib.php");
$params = self::validate_parameters(self::view_page_parameters(),
array(
'pageid' => $pageid
));
$warnings = array();
// Request and permission validation.
$page = $DB->get_record('page', array('id' => $params['pageid']), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($page, 'page');
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/page:view', $context);
// Call the page/lib API.
page_view($page, $course, $cm, $context);
$result = array();
$result['status'] = true;
$result['warnings'] = $warnings;
return $result;
}
/**
* Returns description of method result value
*
* @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_page_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'warnings' => new external_warnings()
)
);
}
/**
* Describes the parameters for get_pages_by_courses.
*
* @return external_function_parameters
* @since Moodle 3.3
*/
public static function get_pages_by_courses_parameters() {
return new external_function_parameters (
array(
'courseids' => new external_multiple_structure(
new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, array()
),
)
);
}
/**
* Returns a list of pages in a provided list of courses.
* If no list is provided all pages that the user can view will be returned.
*
* @param array $courseids course ids
* @return array of warnings and pages
* @since Moodle 3.3
*/
public static function get_pages_by_courses($courseids = array()) {
$warnings = array();
$returnedpages = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_pages_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the pages in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$pages = get_all_instances_in_courses("page", $courses);
foreach ($pages as $page) {
helper_for_get_mods_by_courses::format_name_and_intro($page, 'mod_page');
$context = context_module::instance($page->coursemodule);
list($page->content, $page->contentformat) = \core_external\util::format_text(
$page->content, $page->contentformat,
$context, 'mod_page', 'content', $page->revision, ['noclean' => true]);
$page->contentfiles = util::get_area_files($context->id, 'mod_page', 'content');
$returnedpages[] = $page;
}
}
$result = array(
'pages' => $returnedpages,
'warnings' => $warnings
);
return $result;
}
/**
* Describes the get_pages_by_courses return value.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function get_pages_by_courses_returns() {
return new external_single_structure(
array(
'pages' => new external_multiple_structure(
new external_single_structure(array_merge(
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
[
'content' => new external_value(PARAM_RAW, 'Page content'),
'contentformat' => new external_format_value('content'),
'contentfiles' => new external_files('Files in the content'),
'legacyfiles' => new external_value(PARAM_INT, 'Legacy files flag'),
'legacyfileslast' => new external_value(PARAM_INT, 'Legacy files last control flag'),
'display' => new external_value(PARAM_INT, 'How to display the page'),
'displayoptions' => new external_value(PARAM_RAW, 'Display options (width, height)'),
'revision' => new external_value(PARAM_INT, 'Incremented when after each file changes, to avoid cache'),
'timemodified' => new external_value(PARAM_INT, 'Last time the page was modified'),
]
))
),
'warnings' => new external_warnings(),
)
);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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/>.
/**
* Privacy Subsystem implementation for mod_page.
*
* @package mod_page
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_page module does not store any data.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+97
View File
@@ -0,0 +1,97 @@
<?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/>.
/**
* Search area for mod_page activities.
*
* @package mod_page
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_page\search;
defined('MOODLE_INTERNAL') || die();
/**
* Search area for mod_page activities.
*
* @package mod_page
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns the document associated with this activity.
*
* Overwriting base_activity method as page contents field is required,
* description field is not.
*
* @param stdClass $record
* @param array $options
* @return \core_search\document
*/
public function get_document($record, $options = array()) {
try {
$cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
$context = \context_module::instance($cm->id);
} catch (\dml_missing_record_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
$ex->getMessage(), DEBUG_DEVELOPER);
return false;
} catch (\dml_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
return false;
}
// Prepare associative array with data from DB.
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
$doc->set('title', content_to_text($record->name, false));
$doc->set('content', content_to_text($record->content, $record->contentformat));
$doc->set('contextid', $context->id);
$doc->set('courseid', $record->course);
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
$doc->set('modified', $record->timemodified);
$doc->set('description1', content_to_text($record->intro, $record->introformat));
return $doc;
}
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
/**
* Return the context info required to index files for
* this search area.
*
* @return array
*/
public function get_search_fileareas() {
$fileareas = array('intro', 'content'); // Fileareas.
return $fileareas;
}
}
+61
View File
@@ -0,0 +1,61 @@
<?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/>.
/**
* Page module capability definition
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$capabilities = array(
'mod/page:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'guest' => CAP_ALLOW,
'user' => CAP_ALLOW,
)
),
'mod/page:addinstance' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
/* TODO: review public portfolio API first!
'mod/page:portfolioexport' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
*/
);
+36
View File
@@ -0,0 +1,36 @@
<?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/>.
/**
* Page module post install function
*
* This file replaces:
* - STATEMENTS section in db/install.xml
* - lib.php/modulename_install() post installation hook
* - partially defaults.php
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
function xmldb_page_install() {
global $CFG;
}
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/page/db" VERSION="20120122" COMMENT="XMLDB file for Page module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="page" COMMENT="Each record is one page and its config data">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="content" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="contentformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="legacyfiles" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="legacyfileslast" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="displayoptions" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="incremented when after each file changes, solves browser caching issues"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
+34
View File
@@ -0,0 +1,34 @@
<?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/>.
/**
* Definition of log events
*
* @package mod_page
* @category log
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$logs = array(
array('module'=>'page', 'action'=>'view', 'mtable'=>'page', 'field'=>'name'),
array('module'=>'page', 'action'=>'view all', 'mtable'=>'page', 'field'=>'name'),
array('module'=>'page', 'action'=>'update', 'mtable'=>'page', 'field'=>'name'),
array('module'=>'page', 'action'=>'add', 'mtable'=>'page', 'field'=>'name'),
);
+49
View File
@@ -0,0 +1,49 @@
<?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/>.
/**
* Page external functions and service definitions.
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
defined('MOODLE_INTERNAL') || die;
$functions = array(
'mod_page_view_page' => array(
'classname' => 'mod_page_external',
'methodname' => 'view_page',
'description' => 'Simulate the view.php web interface page: trigger events, completion, etc...',
'type' => 'write',
'capabilities' => 'mod/page:view',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'mod_page_get_pages_by_courses' => array(
'classname' => 'mod_page_external',
'methodname' => 'get_pages_by_courses',
'description' => 'Returns a list of pages in a provided list of courses, if no list is provided all pages that the user
can view will be returned.',
'type' => 'read',
'capabilities' => 'mod/page:view',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
);
+59
View File
@@ -0,0 +1,59 @@
<?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/>.
/**
* Page module upgrade code
*
* This file keeps track of upgrades to
* the resource module
*
* Sometimes, changes between versions involve
* alterations to database structures and other
* major things that may break installations.
*
* The upgrade function in this file will attempt
* to perform all the necessary actions to upgrade
* your older installation to the current version.
*
* If there's something it cannot do itself, it
* will tell you what you need to do.
*
* The commands in here will all be database-neutral,
* using the methods of database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_page_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+100
View File
@@ -0,0 +1,100 @@
<?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/>.
/**
* List of all pages in course
*
* @package mod_page
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
// Trigger instances list viewed event.
$event = \mod_page\event\course_module_instance_list_viewed::create(array('context' => context_course::instance($course->id)));
$event->add_record_snapshot('course', $course);
$event->trigger();
$strpage = get_string('modulename', 'page');
$strpages = get_string('modulenameplural', 'page');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/page/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strpages);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strpages);
echo $OUTPUT->header();
echo $OUTPUT->heading($strpages);
if (!$pages = get_all_instances_in_course('page', $course)) {
notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($usesections) {
$strsectionname = get_string('sectionname', 'format_'.$course->format);
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($pages as $page) {
$cm = $modinfo->cms[$page->coursemodule];
if ($usesections) {
$printsection = '';
if ($page->section !== $currentsection) {
if ($page->section) {
$printsection = get_section_name($course, $page->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $page->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($page->timemodified)."</span>";
}
$class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($page->name)."</a>",
format_module_intro('page', $page, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();
+74
View File
@@ -0,0 +1,74 @@
<?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/>.
/**
* Strings for component 'page', language 'en', branch 'MOODLE_20_STABLE'
*
* @package mod_page
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['configdisplayoptions'] = 'Select all options that should be available, existing settings are not modified. Hold CTRL key to select multiple fields.';
$string['content'] = 'Page content';
$string['contentheader'] = 'Content';
$string['createpage'] = 'Create a new page resource';
$string['displayoptions'] = 'Available display options';
$string['displayselect'] = 'Display';
$string['displayselectexplain'] = 'Select display type.';
$string['indicator:cognitivedepth'] = 'Page cognitive';
$string['indicator:cognitivedepth_help'] = 'This indicator is based on the cognitive depth reached by the student in a Page resource.';
$string['indicator:cognitivedepthdef'] = 'Page cognitive';
$string['indicator:cognitivedepthdef_help'] = 'The participant has reached this percentage of the cognitive engagement offered by the Page resources during this analysis interval (Levels = No view, View)';
$string['indicator:cognitivedepthdef_link'] = 'Learning_analytics_indicators#Cognitive_depth';
$string['indicator:socialbreadth'] = 'Page social';
$string['indicator:socialbreadth_help'] = 'This indicator is based on the social breadth reached by the student in a Page resource.';
$string['indicator:socialbreadthdef'] = 'Page social';
$string['indicator:socialbreadthdef_help'] = 'The participant has reached this percentage of the social engagement offered by the Page resources during this analysis interval (Levels = No participation, Participant alone)';
$string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth';
$string['legacyfiles'] = 'Migration of old course file';
$string['legacyfilesactive'] = 'Active';
$string['legacyfilesdone'] = 'Finished';
$string['modulename'] = 'Page';
$string['modulename_help'] = 'The page module enables a teacher to create a web page resource using the text editor. A page can display text, images, sound, video, web links and embedded code, such as Google maps.
Advantages of using the page module rather than the file module include the resource being more accessible (for example to users of mobile devices) and easier to update.
For large amounts of content, it\'s recommended that a book is used rather than a page.
A page may be used
* To present the terms and conditions of a course or a summary of the course syllabus
* To embed several videos or sound files together with some explanatory text';
$string['modulename_link'] = 'mod/page/view';
$string['modulenameplural'] = 'Pages';
$string['optionsheader'] = 'Display options';
$string['page-mod-page-x'] = 'Any page module page';
$string['page:addinstance'] = 'Add a new page resource';
$string['page:view'] = 'View page content';
$string['pluginadministration'] = 'Page module administration';
$string['pluginname'] = 'Page';
$string['popupheight'] = 'Pop-up height (in pixels)';
$string['popupheightexplain'] = 'Specifies default height of popup windows.';
$string['popupwidth'] = 'Pop-up width (in pixels)';
$string['popupwidthexplain'] = 'Specifies default width of popup windows.';
$string['printintro'] = 'Display page description';
$string['printintroexplain'] = 'Display page description above content?';
$string['printlastmodified'] = 'Display last modified date';
$string['printlastmodifiedexplain'] = 'Display last modified date below content?';
$string['privacy:metadata'] = 'The Page resource plugin does not store any personal data.';
$string['search:activity'] = 'Page';
+595
View File
@@ -0,0 +1,595 @@
<?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/>.
/**
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* List of features supported in Page module
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, false if not, null if doesn't know or string for the module purpose.
*/
function page_supports($feature) {
switch($feature) {
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;
case FEATURE_MOD_PURPOSE: return MOD_PURPOSE_CONTENT;
default: return null;
}
}
/**
* This function is used by the reset_course_userdata function in moodlelib.
* @param $data the data submitted from the reset course.
* @return array status array
*/
function page_reset_userdata($data) {
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
return array();
}
/**
* List the actions that correspond to a view of this module.
* This is used by the participation report.
*
* Note: This is not used by new logging system. Event with
* crud = 'r' and edulevel = LEVEL_PARTICIPATING will
* be considered as view action.
*
* @return array
*/
function page_get_view_actions() {
return array('view','view all');
}
/**
* List the actions that correspond to a post of this module.
* This is used by the participation report.
*
* Note: This is not used by new logging system. Event with
* crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
* will be considered as post action.
*
* @return array
*/
function page_get_post_actions() {
return array('update', 'add');
}
/**
* Add page instance.
* @param stdClass $data
* @param mod_page_mod_form $mform
* @return int new page instance id
*/
function page_add_instance($data, $mform = null) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
$cmid = $data->coursemodule;
$data->timemodified = time();
$displayoptions = array();
if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
$displayoptions['popupwidth'] = $data->popupwidth;
$displayoptions['popupheight'] = $data->popupheight;
}
$displayoptions['printintro'] = $data->printintro;
$displayoptions['printlastmodified'] = $data->printlastmodified;
$data->displayoptions = serialize($displayoptions);
if ($mform) {
$data->content = $data->page['text'];
$data->contentformat = $data->page['format'];
}
$data->id = $DB->insert_record('page', $data);
// we need to use context now, so we need to make sure all needed info is already in db
$DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid));
$context = context_module::instance($cmid);
if ($mform and !empty($data->page['itemid'])) {
$draftitemid = $data->page['itemid'];
$data->content = file_save_draft_area_files($draftitemid, $context->id, 'mod_page', 'content', 0, page_get_editor_options($context), $data->content);
$DB->update_record('page', $data);
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'page', $data->id, $completiontimeexpected);
return $data->id;
}
/**
* Update page instance.
* @param object $data
* @param object $mform
* @return bool true
*/
function page_update_instance($data, $mform) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
$cmid = $data->coursemodule;
$draftitemid = $data->page['itemid'];
$data->timemodified = time();
$data->id = $data->instance;
$data->revision++;
$displayoptions = array();
if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
$displayoptions['popupwidth'] = $data->popupwidth;
$displayoptions['popupheight'] = $data->popupheight;
}
$displayoptions['printintro'] = $data->printintro;
$displayoptions['printlastmodified'] = $data->printlastmodified;
$data->displayoptions = serialize($displayoptions);
$data->content = $data->page['text'];
$data->contentformat = $data->page['format'];
$DB->update_record('page', $data);
$context = context_module::instance($cmid);
if ($draftitemid) {
$data->content = file_save_draft_area_files($draftitemid, $context->id, 'mod_page', 'content', 0, page_get_editor_options($context), $data->content);
$DB->update_record('page', $data);
}
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'page', $data->id, $completiontimeexpected);
return true;
}
/**
* Delete page instance.
* @param int $id
* @return bool true
*/
function page_delete_instance($id) {
global $DB;
if (!$page = $DB->get_record('page', array('id'=>$id))) {
return false;
}
$cm = get_coursemodule_from_instance('page', $id);
\core_completion\api::update_completion_date_event($cm->id, 'page', $id, null);
// note: all context files are deleted automatically
$DB->delete_records('page', array('id'=>$page->id));
return true;
}
/**
* Given a course_module object, this function returns any
* "extra" information that may be needed when printing
* this activity in a course listing.
*
* See {@link course_modinfo::get_array_of_activities()}
*
* @param stdClass $coursemodule
* @return cached_cm_info Info to customise main page display
*/
function page_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance),
'id, name, display, displayoptions, intro, introformat')) {
return NULL;
}
$info = new cached_cm_info();
$info->name = $page->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('page', $page, $coursemodule->id, false);
}
if ($page->display != RESOURCELIB_DISPLAY_POPUP) {
return $info;
}
$fullurl = "$CFG->wwwroot/mod/page/view.php?id=$coursemodule->id&amp;inpopup=1";
$options = empty($page->displayoptions) ? [] : (array) unserialize_array($page->displayoptions);
$width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
$height = empty($options['popupheight']) ? 450 : $options['popupheight'];
$wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
$info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
return $info;
}
/**
* Lists all browsable file areas
*
* @package mod_page
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @return array
*/
function page_get_file_areas($course, $cm, $context) {
$areas = array();
$areas['content'] = get_string('content', 'page');
return $areas;
}
/**
* File browsing support for page module content area.
*
* @package mod_page
* @category files
* @param file_browser $browser file browser instance
* @param stdClass $areas file areas
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info instance or null if not found
*/
function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
global $CFG;
if (!has_capability('moodle/course:managefiles', $context)) {
// students can not peak here!
return null;
}
$fs = get_file_storage();
if ($filearea === 'content') {
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
$urlbase = $CFG->wwwroot.'/pluginfile.php';
if (!$storedfile = $fs->get_file($context->id, 'mod_page', 'content', 0, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($context->id, 'mod_page', 'content', 0);
} else {
// not found
return null;
}
}
require_once("$CFG->dirroot/mod/page/locallib.php");
return new page_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, true, false);
}
// note: page_intro handled in file_browser automatically
return null;
}
/**
* Serves the page files.
*
* @package mod_page
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - just send the file
*/
function page_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
if ($context->contextlevel != CONTEXT_MODULE) {
return false;
}
require_course_login($course, true, $cm);
if (!has_capability('mod/page:view', $context)) {
return false;
}
if ($filearea !== 'content') {
// intro is handled automatically in pluginfile.php
return false;
}
// $arg could be revision number or index.html
$arg = array_shift($args);
if ($arg == 'index.html' || $arg == 'index.htm') {
// serve page content
$filename = $arg;
if (!$page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST)) {
return false;
}
// We need to rewrite the pluginfile URLs so the media filters can work.
$content = file_rewrite_pluginfile_urls($page->content, 'webservice/pluginfile.php', $context->id, 'mod_page', 'content',
$page->revision);
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
$formatoptions->context = $context;
$content = format_text($content, $page->contentformat, $formatoptions);
// Remove @@PLUGINFILE@@/.
$options = array('reverse' => true);
$content = file_rewrite_pluginfile_urls($content, 'webservice/pluginfile.php', $context->id, 'mod_page', 'content',
$page->revision, $options);
$content = str_replace('@@PLUGINFILE@@/', '', $content);
send_file($content, $filename, 0, 0, true, true);
} else {
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_page/$filearea/0/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
$page = $DB->get_record('page', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST);
if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
return false;
}
if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_page', 'content', 0)) {
return false;
}
//file migrate - update flag
$page->legacyfileslast = time();
$DB->update_record('page', $page);
}
// finally send the file
send_stored_file($file, null, 0, $forcedownload, $options);
}
}
/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function page_page_type_list($pagetype, $parentcontext, $currentcontext) {
$module_pagetype = array('mod-page-*'=>get_string('page-mod-page-x', 'page'));
return $module_pagetype;
}
/**
* Export page resource contents
*
* @return array of file content
*/
function page_export_contents($cm, $baseurl) {
global $CFG, $DB;
$contents = array();
$context = context_module::instance($cm->id);
$page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
// page contents
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_page', 'content', 0, 'sortorder DESC, id ASC', false);
foreach ($files as $fileinfo) {
$file = array();
$file['type'] = 'file';
$file['filename'] = $fileinfo->get_filename();
$file['filepath'] = $fileinfo->get_filepath();
$file['filesize'] = $fileinfo->get_filesize();
$file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_page/content/'.$page->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true);
$file['timecreated'] = $fileinfo->get_timecreated();
$file['timemodified'] = $fileinfo->get_timemodified();
$file['sortorder'] = $fileinfo->get_sortorder();
$file['userid'] = $fileinfo->get_userid();
$file['author'] = $fileinfo->get_author();
$file['license'] = $fileinfo->get_license();
$file['mimetype'] = $fileinfo->get_mimetype();
$file['isexternalfile'] = $fileinfo->is_external_file();
if ($file['isexternalfile']) {
$file['repositorytype'] = $fileinfo->get_repository_type();
}
$contents[] = $file;
}
// page html conent
$filename = 'index.html';
$pagefile = array();
$pagefile['type'] = 'file';
$pagefile['filename'] = $filename;
$pagefile['filepath'] = '/';
$pagefile['filesize'] = 0;
$pagefile['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_page/content/' . $filename, true);
$pagefile['timecreated'] = null;
$pagefile['timemodified'] = $page->timemodified;
// make this file as main file
$pagefile['sortorder'] = 1;
$pagefile['userid'] = null;
$pagefile['author'] = null;
$pagefile['license'] = null;
$contents[] = $pagefile;
return $contents;
}
/**
* Register the ability to handle drag and drop file uploads
* @return array containing details of the files / types the mod can handle
*/
function page_dndupload_register() {
return array('types' => array(
array('identifier' => 'text/html', 'message' => get_string('createpage', 'page')),
array('identifier' => 'text', 'message' => get_string('createpage', 'page'))
));
}
/**
* Handle a file that has been uploaded
* @param object $uploadinfo details of the file / content that has been uploaded
* @return int instance id of the newly created mod
*/
function page_dndupload_handle($uploadinfo) {
// Gather the required info.
$data = new stdClass();
$data->course = $uploadinfo->course->id;
$data->name = $uploadinfo->displayname;
$data->intro = '<p>'.$uploadinfo->displayname.'</p>';
$data->introformat = FORMAT_HTML;
if ($uploadinfo->type == 'text/html') {
$data->contentformat = FORMAT_HTML;
$data->content = clean_param($uploadinfo->content, PARAM_CLEANHTML);
} else {
$data->contentformat = FORMAT_PLAIN;
$data->content = clean_param($uploadinfo->content, PARAM_TEXT);
}
$data->coursemodule = $uploadinfo->coursemodule;
// Set the display options to the site defaults.
$config = get_config('page');
$data->display = $config->display;
$data->popupheight = $config->popupheight;
$data->popupwidth = $config->popupwidth;
$data->printintro = $config->printintro;
$data->printlastmodified = $config->printlastmodified;
return page_add_instance($data, null);
}
/**
* Mark the activity completed (if required) and trigger the course_module_viewed event.
*
* @param stdClass $page page object
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @since Moodle 3.0
*/
function page_view($page, $course, $cm, $context) {
// Trigger course_module_viewed event.
$params = array(
'context' => $context,
'objectid' => $page->id
);
$event = \mod_page\event\course_module_viewed::create($params);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('page', $page);
$event->trigger();
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
}
/**
* Check if the module has any update that affects the current user since a given time.
*
* @param cm_info $cm course module data
* @param int $from the time to check updates from
* @param array $filter if we need to check only specific updates
* @return stdClass an object with the different type of areas indicating if they were updated or not
* @since Moodle 3.2
*/
function page_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
return $updates;
}
/**
* This function receives a calendar event and returns the action associated with it, or null if there is none.
*
* This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
* is not displayed on the block.
*
* @param calendar_event $event
* @param \core_calendar\action_factory $factory
* @return \core_calendar\local\event\entities\action_interface|null
*/
function mod_page_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory, $userid = 0) {
global $USER;
if (empty($userid)) {
$userid = $USER->id;
}
$cm = get_fast_modinfo($event->courseid, $userid)->instances['page'][$event->instance];
$completion = new \completion_info($cm->get_course());
$completiondata = $completion->get_data($cm, false, $userid);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/page/view.php', ['id' => $cm->id]),
1,
true
);
}
/**
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
*
* @param string $filearea The filearea.
* @param array $args The path (the part after the filearea and before the filename).
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
*/
function mod_page_get_path_from_pluginfile(string $filearea, array $args): array {
// Page never has an itemid (the number represents the revision but it's not stored in database).
array_shift($args);
// Get the filepath.
if (empty($args)) {
$filepath = '/';
} else {
$filepath = '/' . implode('/', $args) . '/';
}
return [
'itemid' => 0,
'filepath' => $filepath,
];
}
+54
View File
@@ -0,0 +1,54 @@
<?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/>.
/**
* Private page module utility functions
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/filelib.php");
require_once("$CFG->libdir/resourcelib.php");
require_once("$CFG->dirroot/mod/page/lib.php");
/**
* File browsing support class
*/
class page_content_file_info extends file_info_stored {
public function get_parent() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->browser->get_file_info($this->context);
}
return parent::get_parent();
}
public function get_visible_name() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->topvisiblename;
}
return parent::get_visible_name();
}
}
function page_get_editor_options($context) {
global $CFG;
return array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'changeformat'=>1, 'context'=>$context, 'noclean'=>1, 'trusttext'=>0);
}
+147
View File
@@ -0,0 +1,147 @@
<?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/>.
/**
* Page configuration form
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/page/locallib.php');
require_once($CFG->libdir.'/filelib.php');
class mod_page_mod_form extends moodleform_mod {
function definition() {
global $CFG, $DB;
$mform = $this->_form;
$config = get_config('page');
//-------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->standard_intro_elements();
//-------------------------------------------------------
$mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
$mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
$mform->addRule('page', get_string('required'), 'required', null, 'client');
//-------------------------------------------------------
$mform->addElement('header', 'appearancehdr', get_string('appearance'));
if ($this->current->instance) {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
} else {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
}
if (count($options) == 1) {
$mform->addElement('hidden', 'display');
$mform->setType('display', PARAM_INT);
reset($options);
$mform->setDefault('display', key($options));
} else {
$mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
$mform->setDefault('display', $config->display);
}
if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
$mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
if (count($options) > 1) {
$mform->hideIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
}
$mform->setType('popupwidth', PARAM_INT);
$mform->setDefault('popupwidth', $config->popupwidth);
$mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
if (count($options) > 1) {
$mform->hideIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
}
$mform->setType('popupheight', PARAM_INT);
$mform->setDefault('popupheight', $config->popupheight);
}
$mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
$mform->setDefault('printintro', $config->printintro);
$mform->addElement('advcheckbox', 'printlastmodified', get_string('printlastmodified', 'page'));
$mform->setDefault('printlastmodified', $config->printlastmodified);
// add legacy files flag only if used
if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
$options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
$mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
$mform->setAdvanced('legacyfiles', 1);
}
//-------------------------------------------------------
$this->standard_coursemodule_elements();
//-------------------------------------------------------
$this->add_action_buttons();
//-------------------------------------------------------
$mform->addElement('hidden', 'revision');
$mform->setType('revision', PARAM_INT);
$mform->setDefault('revision', 1);
}
/**
* Enforce defaults here.
*
* @param array $defaultvalues Form defaults
* @return void
**/
public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$draftitemid = file_get_submitted_draft_itemid('page');
$defaultvalues['page']['format'] = $defaultvalues['contentformat'];
$defaultvalues['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
$defaultvalues['page']['itemid'] = $draftitemid;
}
if (!empty($defaultvalues['displayoptions'])) {
$displayoptions = (array) unserialize_array($defaultvalues['displayoptions']);
if (isset($displayoptions['printintro'])) {
$defaultvalues['printintro'] = $displayoptions['printintro'];
}
if (isset($displayoptions['printlastmodified'])) {
$defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
}
if (!empty($displayoptions['popupwidth'])) {
$defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
}
if (!empty($displayoptions['popupheight'])) {
$defaultvalues['popupheight'] = $displayoptions['popupheight'];
}
}
}
}
+3
View File
@@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMid meet">
<path fill-rule="evenodd" clip-rule="evenodd" d="M13.2426 3.90637H7.8501C7.02167 3.90637 6.3501 4.57794 6.3501 5.40637V18.4109C6.3501 19.2393 7.02167 19.9109 7.8501 19.9109H16.856C17.6844 19.9109 18.356 19.2393 18.356 18.4109V8.88903V8.42232C18.356 8.14618 18.1321 7.92232 17.856 7.92232H15.8465C15.0181 7.92232 14.3465 7.25075 14.3465 6.42232V4.40637C14.3465 4.13122 14.1242 3.90797 13.8495 3.90638C13.8485 3.90637 13.8475 3.90637 13.8465 3.90637L13.2486 3.90641C13.2466 3.90641 13.2446 3.9064 13.2426 3.90637ZM15.3465 4.58847V6.42232C15.3465 6.69847 15.5704 6.92232 15.8465 6.92232H17.668L15.3465 4.58847ZM19.356 8.42232V8.88903V18.4109C19.356 19.7916 18.2367 20.9109 16.856 20.9109H7.8501C6.46939 20.9109 5.3501 19.7916 5.3501 18.4109V5.40637C5.3501 4.02566 6.46939 2.90637 7.8501 2.90637H13.8465C13.8482 2.90637 13.8499 2.90637 13.8516 2.90638L14.0443 2.90637C14.7096 2.90634 15.3476 3.17156 15.8168 3.64331L18.6284 6.46987C19.0944 6.93833 19.356 7.5722 19.356 8.23294V8.42232ZM8.34912 11.4062C8.34912 11.1301 8.57298 10.9062 8.84912 10.9062H15.8511C16.1272 10.9062 16.3511 11.1301 16.3511 11.4062C16.3511 11.6824 16.1272 11.9062 15.8511 11.9062H8.84912C8.57298 11.9062 8.34912 11.6824 8.34912 11.4062ZM8.34912 14.4062C8.34912 14.1301 8.57298 13.9062 8.84912 13.9062H15.8511C16.1272 13.9062 16.3511 14.1301 16.3511 14.4062C16.3511 14.6824 16.1272 14.9062 15.8511 14.9062H8.84912C8.57298 14.9062 8.34912 14.6824 8.34912 14.4062ZM8.84912 16.9087C8.57298 16.9087 8.34912 17.1325 8.34912 17.4087C8.34912 17.6848 8.57298 17.9087 8.84912 17.9087H15.8511C16.1272 17.9087 16.3511 17.6848 16.3511 17.4087C16.3511 17.1325 16.1272 16.9087 15.8511 16.9087H8.84912Z" fill="#212529"/>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

+28
View File
@@ -0,0 +1,28 @@
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/>.
copyright 2009 Petr Skoda (http://skodak.org)
license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Page module
=============
Page module is a successor to original 'html' and 'text' type plugins of Resource module.
TODO:
* implement portfolio support (MDL-20076)
* new backup/restore and old restore migration (MDL-20077)
+52
View File
@@ -0,0 +1,52 @@
<?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/>.
/**
* Page module admin settings and defaults
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once("$CFG->libdir/resourcelib.php");
$displayoptions = resourcelib_get_displayoptions(array(RESOURCELIB_DISPLAY_OPEN, RESOURCELIB_DISPLAY_POPUP));
$defaultdisplayoptions = array(RESOURCELIB_DISPLAY_OPEN);
//--- general settings -----------------------------------------------------------------------------------
$settings->add(new admin_setting_configmultiselect('page/displayoptions',
get_string('displayoptions', 'page'), get_string('configdisplayoptions', 'page'),
$defaultdisplayoptions, $displayoptions));
//--- modedit defaults -----------------------------------------------------------------------------------
$settings->add(new admin_setting_heading('pagemodeditdefaults', get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin')));
$settings->add(new admin_setting_configcheckbox('page/printintro',
get_string('printintro', 'page'), get_string('printintroexplain', 'page'), 0));
$settings->add(new admin_setting_configcheckbox('page/printlastmodified',
get_string('printlastmodified', 'page'), get_string('printlastmodifiedexplain', 'page'), 1));
$settings->add(new admin_setting_configselect('page/display',
get_string('displayselect', 'page'), get_string('displayselectexplain', 'page'), RESOURCELIB_DISPLAY_OPEN, $displayoptions));
$settings->add(new admin_setting_configtext('page/popupwidth',
get_string('popupwidth', 'page'), get_string('popupwidthexplain', 'page'), 620, PARAM_INT, 7));
$settings->add(new admin_setting_configtext('page/popupheight',
get_string('popupheight', 'page'), get_string('popupheightexplain', 'page'), 450, PARAM_INT, 7));
}
@@ -0,0 +1,92 @@
@mod @mod_page @core_completion
Feature: View activity completion information in the Page resource
In order to have visibility of page completion requirements
As a student
I need to be able to view my page completion progress
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Vinnie | Student1 | student1@example.com |
| teacher1 | Darrell | Teacher1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion | showcompletionconditions |
| Course 1 | C1 | 0 | 1 | 1 |
| Course 2 | C2 | 0 | 1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
Scenario: View automatic completion items as teacher
Given the following "activity" exists:
| activity | page |
| course | C1 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 2 |
| completionview | 1 |
When I am on the "Music history" "page activity" page logged in as teacher1
Then "Music history" should have the "View" completion condition
Scenario: View automatic completion items as student
Given the following "activity" exists:
| activity | page |
| course | C1 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 2 |
| completionview | 1 |
When I am on the "Music history" "page activity" page logged in as student1
Then the "View" completion condition of "Music history" is displayed as "done"
@javascript
Scenario: Use manual completion as teacher
Given the following "activity" exists:
| activity | page |
| course | C1 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 1 |
# Teacher view.
When I am on the "Music history" "page activity" page logged in as teacher1
Then the manual completion button for "Music history" should be disabled
@javascript
Scenario: Use manual completion as student
Given the following "activity" exists:
| activity | page |
| course | C1 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 1 |
# Teacher view.
When I am on the "Music history" "page activity" page logged in as student1
And I toggle the manual completion state of "Music history"
And the manual completion button of "Music history" is displayed as "Done"
Scenario: The manual completion button will not be shown on the course page if the Show activity completion conditions is set to No as teacher
Given the following "activity" exists:
| activity | page |
| course | C2 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 1 |
When I am on the "Music history" "page activity" page logged in as teacher1
Then the manual completion button for "Music history" should not exist
Scenario: The manual completion button will not be shown on the course page if the Show activity completion conditions is set to No as student
Given the following "activity" exists:
| activity | page |
| course | C2 |
| idnumber | page1 |
| name | Music history |
| intro | A lesson learned in life |
| completion | 1 |
When I am on the "Music history" "page activity" page logged in as student1
Then the manual completion button for "Music history" should not exist
@@ -0,0 +1,28 @@
@mod @mod_page
Feature: Configure page appearance
In order to change the appearance of the page resource
As an admin
I need to configure the page appearance settings
Background:
Given the following "courses" exist:
| shortname | fullname |
| C1 | Course 1 |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| page | PageName1 | PageDesc1 | C1 | PAGE1 |
@javascript
Scenario Outline: Hide and display page features
Given I am on the "PageName1" "page activity editing" page logged in as admin
And I expand all fieldsets
And I set the field "<feature>" to "<value>"
And I press "Save and display"
Then I <shouldornot> see "<lookfor>" in the "region-main" "region"
Examples:
| feature | lookfor | value | shouldornot |
| Display page description | PageDesc1 | 1 | should |
| Display page description | PageDesc1 | 0 | should not |
| Display last modified date | Last modified: | 1 | should |
| Display last modified date | Last modified: | 0 | should not |
+233
View File
@@ -0,0 +1,233 @@
<?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_page;
use core_external\external_api;
use externallib_advanced_testcase;
use mod_page_external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* External mod_page functions unit tests
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class externallib_test extends externallib_advanced_testcase {
/**
* Test view_page
*/
public function test_view_page(): void {
global $DB;
$this->resetAfterTest(true);
// Setup test data.
$course = $this->getDataGenerator()->create_course();
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
$context = \context_module::instance($page->cmid);
$cm = get_coursemodule_from_instance('page', $page->id);
// Test invalid instance id.
try {
mod_page_external::view_page(0);
$this->fail('Exception expected due to invalid mod_page instance id.');
} catch (\moodle_exception $e) {
$this->assertEquals('invalidrecord', $e->errorcode);
}
// Test not-enrolled user.
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
try {
mod_page_external::view_page($page->id);
$this->fail('Exception expected due to not enrolled user.');
} catch (\moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Test user with full capabilities.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = mod_page_external::view_page($page->id);
$result = external_api::clean_returnvalue(mod_page_external::view_page_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_page\event\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodlepage = new \moodle_url('/mod/page/view.php', array('id' => $cm->id));
$this->assertEquals($moodlepage, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Test user with no capabilities.
// We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
assign_capability('mod/page:view', CAP_PROHIBIT, $studentrole->id, $context->id);
// Empty all the caches that may be affected by this change.
accesslib_clear_all_caches_for_unit_testing();
\course_modinfo::clear_instance_cache();
try {
mod_page_external::view_page($page->id);
$this->fail('Exception expected due to missing capability.');
} catch (\moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
}
/**
* Test test_mod_page_get_pages_by_courses
*/
public function test_mod_page_get_pages_by_courses(): void {
global $DB;
$this->resetAfterTest(true);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
$student = self::getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($student->id, $course1->id, $studentrole->id);
// First page.
$record = new \stdClass();
$record->course = $course1->id;
$page1 = self::getDataGenerator()->create_module('page', $record);
// Second page.
$record = new \stdClass();
$record->course = $course2->id;
$page2 = self::getDataGenerator()->create_module('page', $record);
// Execute real Moodle enrolment as we'll call unenrol() method on the instance later.
$enrol = enrol_get_plugin('manual');
$enrolinstances = enrol_get_instances($course2->id, true);
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "manual") {
$instance2 = $courseenrolinstance;
break;
}
}
$enrol->enrol_user($instance2, $student->id, $studentrole->id);
self::setUser($student);
$returndescription = mod_page_external::get_pages_by_courses_returns();
// Create what we expect to be returned when querying the two courses.
$expectedfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles', 'lang',
'content', 'contentformat', 'contentfiles', 'legacyfiles', 'legacyfileslast', 'display',
'displayoptions', 'revision', 'timemodified', 'section', 'visible', 'groupmode', 'groupingid');
// Add expected coursemodule and data.
$page1->coursemodule = $page1->cmid;
$page1->introformat = 1;
$page1->contentformat = 1;
$page1->section = 0;
$page1->visible = true;
$page1->groupmode = 0;
$page1->groupingid = 0;
$page1->introfiles = [];
$page1->contentfiles = [];
$page1->lang = '';
$page2->coursemodule = $page2->cmid;
$page2->introformat = 1;
$page2->contentformat = 1;
$page2->section = 0;
$page2->visible = true;
$page2->groupmode = 0;
$page2->groupingid = 0;
$page2->introfiles = [];
$page2->contentfiles = [];
$page2->lang = '';
foreach ($expectedfields as $field) {
$expected1[$field] = $page1->{$field};
$expected2[$field] = $page2->{$field};
}
$expectedpages = array($expected2, $expected1);
// Call the external function passing course ids.
$result = mod_page_external::get_pages_by_courses(array($course2->id, $course1->id));
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_page_external::get_pages_by_courses();
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
$this->assertCount(0, $result['warnings']);
// Add a file to the intro.
$filename = "file.txt";
$filerecordinline = array(
'contextid' => \context_module::instance($page2->cmid)->id,
'component' => 'mod_page',
'filearea' => 'intro',
'itemid' => 0,
'filepath' => '/',
'filename' => $filename,
);
$fs = get_file_storage();
$timepost = time();
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_page_external::get_pages_by_courses(array($course2->id, $course1->id));
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['pages'][0]['introfiles']);
$this->assertEquals($filename, $result['pages'][0]['introfiles'][0]['filename']);
// Unenrol user from second course.
$enrol->unenrol_user($instance2, $student->id);
array_shift($expectedpages);
// Call the external function without passing course id.
$result = mod_page_external::get_pages_by_courses();
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
// Call for the second course we unenrolled the user from, expected warning.
$result = mod_page_external::get_pages_by_courses(array($course2->id));
$this->assertCount(1, $result['warnings']);
$this->assertEquals('1', $result['warnings'][0]['warningcode']);
$this->assertEquals($course2->id, $result['warnings'][0]['itemid']);
}
}
+76
View File
@@ -0,0 +1,76 @@
<?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/>.
/**
* mod_page data generator
*
* @package mod_page
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Page module data generator class
*
* @package mod_page
* @category test
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_page_generator extends testing_module_generator {
public function create_instance($record = null, array $options = null) {
global $CFG;
require_once($CFG->dirroot . '/lib/resourcelib.php');
$record = (object)(array)$record;
if (!isset($record->content)) {
$record->content = 'Test page content';
}
if (!isset($record->contentformat)) {
$record->contentformat = FORMAT_MOODLE;
}
if (!isset($record->display)) {
$record->display = RESOURCELIB_DISPLAY_AUTO;
}
if (!isset($record->printintro)) {
$record->printintro = 0;
}
if (!isset($record->printlastmodified)) {
$record->printlastmodified = 1;
}
$instance = parent::create_instance($record, (array)$options);
// Insert files for the 'content' file area.
$instance = $this->insert_files(
$instance,
$record,
'page',
\context_module::instance($instance->cmid),
'mod_page',
'content',
0
);
return $instance;
}
}
+53
View File
@@ -0,0 +1,53 @@
<?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_page;
/**
* PHPUnit data generator testcase
*
* @package mod_page
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class generator_test extends \advanced_testcase {
public function test_generator(): void {
global $DB, $SITE;
$this->resetAfterTest(true);
$this->assertEquals(0, $DB->count_records('page'));
/** @var mod_page_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_page');
$this->assertInstanceOf('mod_page_generator', $generator);
$this->assertEquals('page', $generator->get_modulename());
$generator->create_instance(array('course'=>$SITE->id));
$generator->create_instance(array('course'=>$SITE->id));
$page = $generator->create_instance(array('course'=>$SITE->id));
$this->assertEquals(3, $DB->count_records('page'));
$cm = get_coursemodule_from_instance('page', $page->id);
$this->assertEquals($page->id, $cm->instance);
$this->assertEquals('page', $cm->modname);
$this->assertEquals($SITE->id, $cm->course);
$context = \context_module::instance($cm->id);
$this->assertEquals($page->cmid, $context->instanceid);
}
}
+222
View File
@@ -0,0 +1,222 @@
<?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/>.
/**
* Unit tests for mod_page lib
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
namespace mod_page;
defined('MOODLE_INTERNAL') || die();
/**
* Unit tests for mod_page lib
*
* @package mod_page
* @category external
* @copyright 2015 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class lib_test extends \advanced_testcase {
/**
* Prepares things before this test case is initialised
* @return void
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/page/lib.php');
}
/**
* Test page_view
* @return void
*/
public function test_page_view(): void {
global $CFG;
$CFG->enablecompletion = 1;
$this->resetAfterTest();
// Setup test data.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1));
$context = \context_module::instance($page->cmid);
$cm = get_coursemodule_from_instance('page', $page->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$this->setAdminUser();
page_view($page, $course, $cm, $context);
$events = $sink->get_events();
// 2 additional events thanks to completion.
$this->assertCount(3, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\mod_page\event\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/page/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Check completion status.
$completion = new \completion_info($course);
$completiondata = $completion->get_data($cm);
$this->assertEquals(1, $completiondata->completionstate);
}
public function test_page_core_calendar_provide_event_action(): void {
$this->resetAfterTest();
$this->setAdminUser();
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $page->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_page_core_calendar_provide_event_action($event, $factory);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('view'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertTrue($actionevent->is_actionable());
}
public function test_page_core_calendar_provide_event_action_already_completed(): void {
global $CFG;
$this->resetAfterTest();
$this->setAdminUser();
$CFG->enablecompletion = 1;
// Create the activity.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Get some additional data.
$cm = get_coursemodule_from_instance('page', $page->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $page->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Mark the activity as completed.
$completion = new \completion_info($course);
$completion->set_module_viewed($cm);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_page_core_calendar_provide_event_action($event, $factory);
// Ensure result was null.
$this->assertNull($actionevent);
}
/**
* Test mod_page_core_calendar_provide_event_action with user override
*/
public function test_page_core_calendar_provide_event_action_user_override(): void {
global $CFG, $USER;
$this->resetAfterTest();
$this->setAdminUser();
$user = $this->getDataGenerator()->create_user();
$CFG->enablecompletion = 1;
// Create the activity.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Get some additional data.
$cm = get_coursemodule_from_instance('page', $page->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $page->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Mark the activity as completed.
$completion = new \completion_info($course);
$completion->set_module_viewed($cm);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_page_core_calendar_provide_event_action($event, $factory, $USER->id);
// Decorate action with a userid override.
$actionevent2 = mod_page_core_calendar_provide_event_action($event, $factory, $user->id);
// Ensure result was null because it has been marked as completed for the associated user.
// Logic was brought across from the "_already_completed" function.
$this->assertNull($actionevent);
// Confirm the event was decorated.
$this->assertNotNull($actionevent2);
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent2);
$this->assertEquals(get_string('view'), $actionevent2->get_name());
$this->assertInstanceOf('moodle_url', $actionevent2->get_url());
$this->assertEquals(1, $actionevent2->get_item_count());
$this->assertTrue($actionevent2->is_actionable());
}
/**
* Creates an action event.
*
* @param int $courseid The course id.
* @param int $instanceid The instance id.
* @param string $eventtype The event type.
* @return bool|calendar_event
*/
private function create_action_event($courseid, $instanceid, $eventtype) {
$event = new \stdClass();
$event->name = 'Calendar event';
$event->modulename = 'page';
$event->courseid = $courseid;
$event->instance = $instanceid;
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->eventtype = $eventtype;
$event->timestart = time();
return \calendar_event::create($event);
}
}
+5
View File
@@ -0,0 +1,5 @@
This files describes API changes in the mod_page code.
=== 4.0 ===
* Removed printheading from page and admin settings. This will now be handled by the activity header and/or theme.
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Page module version information
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'mod_page'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
+94
View File
@@ -0,0 +1,94 @@
<?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/>.
/**
* Page module version information
*
* @package mod_page
* @copyright 2009 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/page/lib.php');
require_once($CFG->dirroot.'/mod/page/locallib.php');
require_once($CFG->libdir.'/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$p = optional_param('p', 0, PARAM_INT); // Page instance ID
$inpopup = optional_param('inpopup', 0, PARAM_BOOL);
if ($p) {
if (!$page = $DB->get_record('page', array('id'=>$p))) {
throw new \moodle_exception('invalidaccessparameter');
}
$cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST);
} else {
if (!$cm = get_coursemodule_from_id('page', $id)) {
throw new \moodle_exception('invalidcoursemodule');
}
$page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
}
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/page:view', $context);
// Completion and trigger events.
page_view($page, $course, $cm, $context);
$PAGE->set_url('/mod/page/view.php', array('id' => $cm->id));
$options = empty($page->displayoptions) ? [] : (array) unserialize_array($page->displayoptions);
$activityheader = ['hidecompletion' => false];
if (empty($options['printintro'])) {
$activityheader['description'] = '';
}
if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
$PAGE->set_pagelayout('popup');
$PAGE->set_title($course->shortname.': '.$page->name);
$PAGE->set_heading($course->fullname);
} else {
$PAGE->add_body_class('limitedwidth');
$PAGE->set_title($course->shortname.': '.$page->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_activity_record($page);
if (!$PAGE->activityheader->is_title_allowed()) {
$activityheader['title'] = "";
}
}
$PAGE->activityheader->set_attrs($activityheader);
echo $OUTPUT->header();
$content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'mod_page', 'content', $page->revision);
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->overflowdiv = true;
$formatoptions->context = $context;
$content = format_text($content, $page->contentformat, $formatoptions);
echo $OUTPUT->box($content, "generalbox center clearfix");
if (!isset($options['printlastmodified']) || !empty($options['printlastmodified'])) {
$strlastmodified = get_string("lastmodified");
echo html_writer::div("$strlastmodified: " . userdate($page->timemodified), 'modified');
}
echo $OUTPUT->footer();