MDL-67813 core_contentbank: Add content name parameter in the generator

This commit is contained in:
Mihail Geshoski 2020-05-01 10:49:32 +08:00
parent 4f442eeaba
commit 1bb6231b32

View file

@ -45,10 +45,12 @@ class core_contentbank_generator extends \component_generator_base {
* @param context $context The context where the content will be created. * @param context $context The context where the content will be created.
* @param bool $convert2class Whether the class should return stdClass or plugin instance. * @param bool $convert2class Whether the class should return stdClass or plugin instance.
* @param string $filepath The filepath of the file associated to the content to create. * @param string $filepath The filepath of the file associated to the content to create.
* @param string $contentname The name of the content that will be created.
* @return array An array with all the records added to the content bank. * @return array An array with all the records added to the content bank.
*/ */
public function generate_contentbank_data(?string $contenttype, int $itemstocreate = 1, int $userid = 0, public function generate_contentbank_data(?string $contenttype, int $itemstocreate = 1, int $userid = 0,
?\context $context = null, bool $convert2class = true, string $filepath = 'contentfile.h5p'): array { ?\context $context = null, bool $convert2class = true, string $filepath = 'contentfile.h5p',
string $contentname = 'Test content '): array {
global $DB, $USER; global $DB, $USER;
$records = []; $records = [];
@ -67,7 +69,8 @@ class core_contentbank_generator extends \component_generator_base {
for ($i = 0; $i < $itemstocreate; $i++) { for ($i = 0; $i < $itemstocreate; $i++) {
// Create content. // Create content.
$record = new stdClass(); $record = new stdClass();
$record->name = 'Test content ' . $i; // If only 1 item is being created, do not add a number suffix to the content name.
$record->name = ($itemstocreate === 1) ? $contentname : $contentname . $i;
$record->configdata = ''; $record->configdata = '';
$record->usercreated = $userid ?? $USER->id; $record->usercreated = $userid ?? $USER->id;