在Moodle课程中插入部分(Insert sections in a Moodle course)

编程入门 行业动态 更新时间:2024-10-27 07:21:32
在Moodle课程中插入部分(Insert sections in a Moodle course)

我正在尝试使用脚本Moodle课程中创建部分,但我不能。 我正在使用Moodle course_create_sections_if_missing函数但无法获取部分显示在Web上但在数据库中它们是创建的。

我正在使用的代码如下:

if($numSections >0){ foreach ($sections as $nameSection) { $idSection = checkSections($moodle_course , $nameSection); if($idSection == -1){ m("crear section: ". $nameSection); $maxSection = getMaxSections($moodle_course ); if($maxSection != -1){ m("max section: " . $maxSection); $idSec = $maxSection + 1; course_create_sections_if_missing($moodle_course , $idSec); $res = updateNameSection($moodle_course , $nameSection, $idSec); m("result update: " . $res); }else{ m("There aren't sections for the course"); } }else{ m("section already exists: ". $nameSection); } } }else{ m("No sections for the course. "); }

注意:m(“”)函数负责在控制台上显示文本。

函数checkSections是这样的:

/** * Check if there is a section. * * @param $course id of the course. * @param $section name of the section * * @return id of section */ function checkSections($course , $section){ global $DB; $id = null; $sql = "SELECT id FROM mdl_course_sections where course = ? and name = ? "; $sections = $DB->get_records_sql($sql, array($course, $section)); foreach ( $sections as $r ) { $id = $r->id; } if(is_null($id)) return -1; else return $id; }

函数getMaxSections是这样的:

/** * Returns the id of the highest section for a course. * * @param $course id of the course. * * @return max id of section */ function getMaxSections($course){ global $DB; $id = null; $sql = "SELECT max(section) as sec FROM mdl_course_sections where course = ? "; $sections = $DB->get_records_sql($sql, array($course)); foreach ( $sections as $r ) { $id = $r->sec; } if(is_null($id)) return -1; else return $id; }

函数updateNameSection是这样的:

/** * Update the name of a section . * * @param $course id of the course. * @param $nameSection name of the section. * @param $idSection id of the section. * * @return result */ function updateNameSection($course, $nameSection , $idSection){ global $DB; $id = null; $sql = "update mdl_course_sections set name = ? where course = ? and section = ?"; $result = $DB->execute($sql, array($nameSection , $course, $idSection)); return $result; }

因此,如果有人知道如何做或有任何可能有用的示例或文档,这将是有帮助的。

提前致谢。

I am trying to create sections within a Moodle course using a script but I can not. I am using Moodle course_create_sections_if_missing function but can not get sections are displayed on the web but in the database they are created.

The code I'm using is as follows:

if($numSections >0){ foreach ($sections as $nameSection) { $idSection = checkSections($moodle_course , $nameSection); if($idSection == -1){ m("crear section: ". $nameSection); $maxSection = getMaxSections($moodle_course ); if($maxSection != -1){ m("max section: " . $maxSection); $idSec = $maxSection + 1; course_create_sections_if_missing($moodle_course , $idSec); $res = updateNameSection($moodle_course , $nameSection, $idSec); m("result update: " . $res); }else{ m("There aren't sections for the course"); } }else{ m("section already exists: ". $nameSection); } } }else{ m("No sections for the course. "); }

Note: the m ( "") function is responsible for displaying the text on the console.

the function checkSections is this:

/** * Check if there is a section. * * @param $course id of the course. * @param $section name of the section * * @return id of section */ function checkSections($course , $section){ global $DB; $id = null; $sql = "SELECT id FROM mdl_course_sections where course = ? and name = ? "; $sections = $DB->get_records_sql($sql, array($course, $section)); foreach ( $sections as $r ) { $id = $r->id; } if(is_null($id)) return -1; else return $id; }

the function getMaxSections is this:

/** * Returns the id of the highest section for a course. * * @param $course id of the course. * * @return max id of section */ function getMaxSections($course){ global $DB; $id = null; $sql = "SELECT max(section) as sec FROM mdl_course_sections where course = ? "; $sections = $DB->get_records_sql($sql, array($course)); foreach ( $sections as $r ) { $id = $r->sec; } if(is_null($id)) return -1; else return $id; }

the function updateNameSection is this:

/** * Update the name of a section . * * @param $course id of the course. * @param $nameSection name of the section. * @param $idSection id of the section. * * @return result */ function updateNameSection($course, $nameSection , $idSection){ global $DB; $id = null; $sql = "update mdl_course_sections set name = ? where course = ? and section = ?"; $result = $DB->execute($sql, array($nameSection , $course, $idSection)); return $result; }

So if anyone knows how to do it or have any examples or documentation that may be useful, it would be helpful.

Thanks in advance.

最满意答案

您需要更新表mdl_course_format_options上的节号

尝试这个:

$sql = "update mdl_course_format_options set value = ? where courseid = ? and name ='numsections'"; $result = $DB->execute($sql, array($numSections , $course));

You need to update the sections number on the table mdl_course_format_options

Try this:

$sql = "update mdl_course_format_options set value = ? where courseid = ? and name ='numsections'"; $result = $DB->execute($sql, array($numSections , $course));

更多推荐

本文发布于:2023-07-04 10:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:课程   Moodle   sections   Insert

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!