mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-67264 core_course: Begin set up for Activity chooser
- Loading branch information
1 parent
d6b95b8
commit cd2efd1
Showing
8 changed files
with
181 additions
and
195 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
course/classes/external/course_module_chooser_exporter.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,151 @@ | ||
<?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 exporter. | ||
* | ||
* @package core_course | ||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_course\external; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use core\external\exporter; | ||
use renderer_base; | ||
|
||
/** | ||
* Course module chooser exporter. | ||
* | ||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class course_module_chooser_exporter extends exporter { | ||
|
||
/** @var array $modules Array containing the available modules */ | ||
private $modules; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $modules The available course modules | ||
* @param array $related The related data for the export | ||
*/ | ||
public function __construct(array $modules, array $related = []) { | ||
$this->modules = $modules; | ||
return parent::__construct([], $related); | ||
} | ||
|
||
/** | ||
* Return the list of additional properties. | ||
* | ||
* @return array | ||
*/ | ||
protected static function define_other_properties() { | ||
return [ | ||
'options' => [ | ||
'multiple' => true, | ||
'optional' => true, | ||
'type' => [ | ||
'label' => ['type' => PARAM_TEXT], | ||
'modulename' => ['type' => PARAM_TEXT], | ||
'description' => ['type' => PARAM_TEXT], | ||
'urls' => [ | ||
'type' => [ | ||
'addoption' => [ | ||
'type' => PARAM_URL | ||
] | ||
] | ||
], | ||
'icon' => [ | ||
'type' => PARAM_RAW, | ||
'optional' => true, | ||
'default' => null, | ||
'null' => NULL_ALLOWED | ||
] | ||
] | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Get the additional values to inject while exporting. | ||
* | ||
* @param renderer_base $output The renderer. | ||
* @return array Keys are the property names, values are their values. | ||
*/ | ||
protected function get_other_values(renderer_base $output) { | ||
|
||
$options = new \stdClass(); | ||
$options->trusted = false; | ||
$options->noclean = false; | ||
$options->smiley = false; | ||
$options->filter = false; | ||
$options->para = true; | ||
$options->newlines = false; | ||
$options->overflowdiv = false; | ||
|
||
$context = $this->related['context']; | ||
|
||
$modulesdata = []; | ||
foreach ($this->modules as $module) { | ||
$customiconurl = null; | ||
|
||
// The property 'name' may contain more than just the module, in which case we need to extract the true module name. | ||
$modulename = $module->name; | ||
if ($colon = strpos($modulename, ':')) { | ||
$modulename = substr($modulename, 0, $colon); | ||
} | ||
|
||
if (isset($module->help) || !empty($module->help)) { | ||
list($description) = external_format_text((string) $module->help, FORMAT_MARKDOWN, | ||
$context->id, null, null, null, $options); | ||
} else { | ||
$description = get_string('nohelpforactivityorresource', 'moodle'); | ||
} | ||
|
||
$icon = new \pix_icon('icon', '', $modulename); | ||
|
||
// When exporting check if the title is an object, we assume it's a lang string object otherwise we send the raw string. | ||
$modulesdata[] = [ | ||
'label' => $module->title instanceof \lang_string ? $module->title->out() : $module->title, | ||
'modulename' => $modulename, | ||
'description' => $description, | ||
'urls' => [ | ||
'addoption' => $module->link->out(false), | ||
], | ||
'icon' => $icon->export_for_template($output) | ||
]; | ||
} | ||
|
||
return [ | ||
'options' => $modulesdata | ||
]; | ||
} | ||
|
||
/** | ||
* Returns a list of objects that are related. | ||
* | ||
* @return array | ||
*/ | ||
protected static function define_related() { | ||
return [ | ||
'context' => 'context' | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Oops, something went wrong.