Mysql 如何在moodle中创建新的课程类别?

Mysql 如何在moodle中创建新的课程类别?,mysql,moodle,Mysql,Moodle,我需要直接在数据库中创建一些moodle的iTen 我有了插入新moodle课程的查询,以及创建课程上下文的规则(在mdl_context中),而且效果很好 INSERT INTO mdl_course (category,fullname,shortname) VALUES (1,'NewCourse','C1') 还需要插入一个新的moodle类别,,但在这种情况下,简单的插入查询不起作用 我不知道如何在mdl_上下文中发现创建新类别上下文的参数 INSERT INTO `mood

我需要直接在数据库中创建一些moodle的iTen

我有了插入新moodle课程的查询,以及创建课程上下文的规则(在
mdl_context
中),而且效果很好

INSERT INTO mdl_course (category,fullname,shortname) VALUES (1,'NewCourse','C1')    
还需要插入一个新的
moodle类别,
,但在这种情况下,简单的插入查询不起作用

我不知道如何在mdl_上下文中发现创建新类别上下文的参数

INSERT INTO `moodle_db`.`mdl_course_categories` (`name`, `idnumber`, `description`, `descriptionformat`, `sortorder`, `timemodified`, `depth`, `path`) VALUES ('New category', '', '<p>some text</p>', 1, 50000, 1392726085, 1, '/5');

通过使用moodle REST api解决了我的问题

我根据这里的例子编写了这个脚本

$token='my_auth_token';
$domainname='0http://localhost/moodle';
$functionname='core_course_create_categories';
$restformat='json';
$category=新的stdClass();
$category->name='Example';
$category->parent=0;
$category->description='text

'; $category->descriptionformat=1; $categories=数组($categories); $params=数组('categories'=>$categories); ///休息电话 标题(“内容类型:文本/普通”); $serverurl=$domainname'/webservice/rest/server.php'?wstoken='$代币。”&wsfunction='.$functionname; 需要_一次('./curl.php'); $curl=新的curl; //如果rest format='xml',那么我们不添加参数以向后兼容Moodle<2.2 $restformat=($restformat='json')?'&moodlewsrestformat='$REST格式:''; $resp=$curl->post($serverurl.$restformat,$params); 印刷费($resp);
此方法自动创建上下文

INSERT INTO `moodle_db`.`mdl_context` (`contextlevel`, `instanceid`, `path`, `depth`) VALUES (40, 3, '/1/20', 2);
$token = 'my_auth_token';
$domainname = 'http://localhost/moodle';
$functionname = 'core_course_create_categories';
$restformat = 'json';

$category = new stdClass();
$category->name = 'Example';
$category->parent = 0;
$category->description = '<p>text</p>';
$category->descriptionformat = 1;
$categories = array( $category);
$params = array('categories' => $categories);

/// REST CALL
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);