mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-64820 forum: add new classes for rendering to local namespace
- Loading branch information
1 parent
2f6f339
commit 47d3830
Showing
81 changed files
with
14,232 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Container class. | ||
* | ||
* @package mod_forum | ||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_forum\local; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use mod_forum\local\factories\renderer as renderer_factory; | ||
use mod_forum\local\factories\legacy_data_mapper as legacy_data_mapper_factory; | ||
use mod_forum\local\factories\entity as entity_factory; | ||
use mod_forum\local\factories\exporter as exporter_factory; | ||
use mod_forum\local\factories\manager as manager_factory; | ||
use mod_forum\local\factories\vault as vault_factory; | ||
use mod_forum\local\factories\builder as builder_factory; | ||
use mod_forum\local\factories\url as url_factory; | ||
|
||
/** | ||
* Container class. | ||
* | ||
* This class provides helper methods with static configurations to get any | ||
* of the factories from the "local" namespace. | ||
* | ||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class container { | ||
/** | ||
* Create the renderer factory. | ||
* | ||
* @return renderer_factory | ||
*/ | ||
public static function get_renderer_factory() : renderer_factory { | ||
global $PAGE; | ||
|
||
return new renderer_factory( | ||
self::get_legacy_data_mapper_factory(), | ||
self::get_exporter_factory(), | ||
self::get_vault_factory(), | ||
self::get_manager_factory(), | ||
self::get_entity_factory(), | ||
self::get_builder_factory(), | ||
self::get_url_factory(), | ||
$PAGE | ||
); | ||
} | ||
|
||
/** | ||
* Create the legacy data mapper factory. | ||
* | ||
* @return legacy_data_mapper_factory | ||
*/ | ||
public static function get_legacy_data_mapper_factory() : legacy_data_mapper_factory { | ||
return new legacy_data_mapper_factory(); | ||
} | ||
|
||
/** | ||
* Create the exporter factory. | ||
* | ||
* @return exporter_factory | ||
*/ | ||
public static function get_exporter_factory() : exporter_factory { | ||
return new exporter_factory( | ||
self::get_legacy_data_mapper_factory(), | ||
self::get_manager_factory(), | ||
self::get_url_factory() | ||
); | ||
} | ||
|
||
/** | ||
* Create the vault factory. | ||
* | ||
* @return vault_factory | ||
*/ | ||
public static function get_vault_factory() : vault_factory { | ||
global $DB; | ||
|
||
return new vault_factory( | ||
$DB, | ||
self::get_entity_factory(), | ||
get_file_storage() | ||
); | ||
} | ||
|
||
/** | ||
* Create the manager factory. | ||
* | ||
* @return manager_factory | ||
*/ | ||
public static function get_manager_factory() : manager_factory { | ||
return new manager_factory( | ||
self::get_legacy_data_mapper_factory() | ||
); | ||
} | ||
|
||
/** | ||
* Create the entity factory. | ||
* | ||
* @return entity_factory | ||
*/ | ||
public static function get_entity_factory() : entity_factory { | ||
return new entity_factory(); | ||
} | ||
|
||
/** | ||
* Create the builder factory. | ||
* | ||
* @return builder_factory | ||
*/ | ||
public static function get_builder_factory() : builder_factory { | ||
global $PAGE; | ||
|
||
return new builder_factory( | ||
self::get_legacy_data_mapper_factory(), | ||
self::get_exporter_factory(), | ||
self::get_vault_factory(), | ||
self::get_manager_factory(), | ||
$PAGE->get_renderer('mod_forum') | ||
); | ||
} | ||
|
||
/** | ||
* Create the URL factory. | ||
* | ||
* @return url_factory | ||
*/ | ||
public static function get_url_factory() : url_factory { | ||
return new url_factory( | ||
self::get_legacy_data_mapper_factory() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Author data mapper. | ||
* | ||
* @package mod_forum | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_forum\local\data_mappers\legacy; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use mod_forum\local\entities\author as author_entity; | ||
use stdClass; | ||
|
||
/** | ||
* Convert an author entity into an stdClass. | ||
* | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class author { | ||
/** | ||
* Convert a list of author entities into stdClasses. | ||
* | ||
* @param author_entity[] $authors The authors to convert. | ||
* @return stdClass[] | ||
*/ | ||
public function to_legacy_objects(array $authors) : array { | ||
return array_map(function(author_entity $author) { | ||
return (object) [ | ||
'id' => $author->get_id(), | ||
'picture' => $author->get_picture_item_id(), | ||
'firstname' => $author->get_first_name(), | ||
'lastname' => $author->get_last_name(), | ||
'fullname' => $author->get_full_name(), | ||
'email' => $author->get_email(), | ||
'middlename' => $author->get_middle_name(), | ||
'firstnamephonetic' => $author->get_first_name_phonetic(), | ||
'lastnamephonetic' => $author->get_last_name_phonetic(), | ||
'alternatename' => $author->get_alternate_name(), | ||
'imagealt' => $author->get_image_alt() | ||
]; | ||
}, $authors); | ||
} | ||
|
||
/** | ||
* Convert an author entity into an stdClass. | ||
* | ||
* @param author_entity $author The author to convert. | ||
* @return stdClass | ||
*/ | ||
public function to_legacy_object(author_entity $author) : stdClass { | ||
return $this->to_legacy_objects([$author])[0]; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
mod/forum/classes/local/data_mappers/legacy/discussion.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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/>. | ||
|
||
/** | ||
* Discussion data mapper. | ||
* | ||
* @package mod_forum | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_forum\local\data_mappers\legacy; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use mod_forum\local\entities\discussion as discussion_entity; | ||
use stdClass; | ||
|
||
/** | ||
* Convert a discussion entity into an stdClass. | ||
* | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class discussion { | ||
/** | ||
* Convert a list of discussion entities into stdClasses. | ||
* | ||
* @param discussion_entity[] $authors The authors to convert. | ||
* @return stdClass[] | ||
*/ | ||
public function to_legacy_objects(array $discussions) : array { | ||
return array_map(function(discussion_entity $discussion) { | ||
return (object) [ | ||
'id' => $discussion->get_id(), | ||
'course' => $discussion->get_course_id(), | ||
'forum' => $discussion->get_forum_id(), | ||
'name' => $discussion->get_name(), | ||
'firstpost' => $discussion->get_first_post_id(), | ||
'userid' => $discussion->get_user_id(), | ||
'groupid' => $discussion->get_group_id(), | ||
'assessed' => $discussion->is_assessed(), | ||
'timemodified' => $discussion->get_time_modified(), | ||
'usermodified' => $discussion->get_user_modified(), | ||
'timestart' => $discussion->get_time_start(), | ||
'timeend' => $discussion->get_time_end(), | ||
'pinned' => $discussion->is_pinned() | ||
]; | ||
}, $discussions); | ||
} | ||
|
||
/** | ||
* Convert a discussion entity into an stdClass. | ||
* | ||
* @param discussion_entity $discussion The discussion to convert. | ||
* @return stdClass | ||
*/ | ||
public function to_legacy_object(discussion_entity $discussion) : stdClass { | ||
return $this->to_legacy_objects([$discussion])[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Forum data mapper. | ||
* | ||
* @package mod_forum | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_forum\local\data_mappers\legacy; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use mod_forum\local\entities\forum as forum_entity; | ||
use stdClass; | ||
|
||
/** | ||
* Convert a forum entity into an stdClass. | ||
* | ||
* @copyright 2019 Ryan Wyllie <ryan@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class forum { | ||
/** | ||
* Convert a list of forum entities into stdClasses. | ||
* | ||
* @param forum_entity[] $forums The forums to convert. | ||
* @return stdClass[] | ||
*/ | ||
public function to_legacy_objects(array $forums) : array { | ||
return array_map(function(forum_entity $forum) { | ||
return (object) [ | ||
'id' => $forum->get_id(), | ||
'course' => $forum->get_course_id(), | ||
'type' => $forum->get_type(), | ||
'name' => $forum->get_name(), | ||
'intro' => $forum->get_intro(), | ||
'introformat' => $forum->get_intro_format(), | ||
'assessed' => $forum->get_rating_aggregate(), | ||
'assesstimestart' => $forum->get_assess_time_start(), | ||
'assesstimefinish' => $forum->get_assess_time_finish(), | ||
'scale' => $forum->get_scale(), | ||
'maxbytes' => $forum->get_max_bytes(), | ||
'maxattachments' => $forum->get_max_attachments(), | ||
'forcesubscribe' => $forum->is_subscription_forced(), | ||
'trackingtype' => $forum->get_tracking_type(), | ||
'rsstype' => $forum->get_rss_type(), | ||
'rssarticles' => $forum->get_rss_articles(), | ||
'timemodified' => $forum->get_time_modified(), | ||
'warnafter' => $forum->get_warn_after(), | ||
'blockafter' => $forum->get_block_after(), | ||
'blockperiod' => $forum->get_block_period(), | ||
'completiondiscussions' => $forum->get_completion_discussions(), | ||
'completionreplies' => $forum->get_completion_replies(), | ||
'completionposts' => $forum->get_completion_posts(), | ||
'displaywordcount' => $forum->should_display_word_count(), | ||
'lockdiscussionafter' => $forum->get_lock_discussions_after() | ||
]; | ||
}, $forums); | ||
} | ||
|
||
/** | ||
* Convert a forum entity into an stdClass. | ||
* | ||
* @param forum_entity $forum The forum to convert. | ||
* @return stdClass | ||
*/ | ||
public function to_legacy_object(forum_entity $forum) : stdClass { | ||
return $this->to_legacy_objects([$forum])[0]; | ||
} | ||
} |
Oops, something went wrong.