Moodle устанавливает последовательность модулей грамматически - PullRequest
0 голосов
/ 09 мая 2018

после того, как мне удалось программно добавить модули в Moodle (см. Мой старый вопрос здесь ) Теперь мне также нужно добавить модуль в определенном месте.

Давайте возьмем, к примеру, учебный курс по Moodle, у меня есть:

Section 0
 - Module 1
 - --> ADD NEW MODULE HERE <--
 - Module 2
Section 1
 - Module 1
 - Module 2
Section 2

Так что мне нужно добавить новый модуль, который я создаю программно между модулями 1 и 2 раздела 0.

Я знаю, что порядок модулей взят из таблицы mdl_course_sections и указан в столбце sequence , где идентификаторы модулей существуют в значениях, разделенных запятыми

Есть ли в Moodle функция, которая это делает? Установить последовательность раздела? Я не хочу связываться с БД напрямую.

1 Ответ

0 голосов
/ 10 мая 2018

После того, как я получил некоторую помощь от сообщества Moodle (спасибо Сэму Чаффи), вот решение

//...Do stuff to create module object...
// ...

$moduleinfo = add_moduleinfo($newlabel, $section);

//lets get all sections and modules of the course
$coursemodinfo = get_fast_modinfo($course->id, 0, false);

//get all sections of the course
$coursesections = $coursemodinfo->get_sections();

//get the first section, get_section will return an array of sections so I get position 0 to get section 1
$section01 = $coursesections[0];

//get the first module in the section so we can add on top of it
$firstmodid = $section01[0];

//We need to get cm_info for the specific mod
$mod = $coursemodinfo->get_cm($moduleinfo->coursemodule);

//we also need section_info for the section we want to move to
$sectioninfo = $coursemodinfo->get_section_info(0);

//move the newly created module to section 01 but before $firstmodid
moveto_module($mod, $sectioninfo, $firstmodid);
...