2014-02-19 34 views
0

我需要直接在数据库中创建一些moodle的itens。如何在moodle中创建新的课程类别?

我有查询插入新的Moodle课程,并创建课程上下文的规则(在mdl_context),它的工作很好。

INSERT INTO mdl_course (category,fullname,shortname) VALUES (1,'NewCourse','C1')  

也需要插入一个新的moodle category,但在这种情况下,一个简单的插入查询不要工作

我不知道如何去发现这些参数来创建一个新的mdl_context类别方面

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

关于参数,aparently在上下文中的path大约是在什么类别何去何从,以及depth'2'categories'3'courses。但我没有关于contextlevel

INSERT INTO `unasus_ava`.`mdl_context` (`contextlevel`, `instanceid`, `path`, `depth`) VALUES (40, 3, '/1/20', 2); 

回答

0

使用Moodle的REST API

解决我的问题IDEIA我没有在这里找到sample-ws-clients

$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); 

这个脚本基于示例这个方法创建了自动上下文

相关问题