moodle |启动$ course并使用add_moduleinfo

时间:2016-01-30 19:56:13

标签: moodle

假设,我在全球页面上,(不在课程页面中)。

我想做一个新的测验。

我得到了课程的内容,我想加入测验。

我使用add_moduleinfo。

我想知道,如何启动$ course参数,我需要在add_moduleinfo中调用。

P.S。它会添加相关部分吗?我明白它会,虽然它对我来说很奇怪。

另一件事,

我像这样使用了add_moduleinfo:

$s=array( 'name' => 'אוטומציה', 'introeditor' => array ( 'text' => '', 'format' => '1', 'itemid' => 892971641, ), 'timeopen' => 0, 'timeclose' => 0, 'timelimit' => 0, 'overduehandling' => 'autosubmit', 'graceperiod' => 0, 'gradecat' => '1', 'gradepass' => NULL, 'grade' => 10, 'attempts' => '0', 'grademethod' => '1', 'questionsperpage' => '1', 'navmethod' => 'free', 'shuffleanswers' => '1', 'preferredbehaviour' => 'deferredfeedback', 'canredoquestions' => '0', 'attemptonlast' => '0', 'attemptimmediately' => '1', 'correctnessimmediately' => '1', 'marksimmediately' => '1', 'specificfeedbackimmediately' => '1', 'generalfeedbackimmediately' => '1', 'rightanswerimmediately' => '1', 'overallfeedbackimmediately' => '1', 'attemptopen' => '1', 'correctnessopen' => '1', 'marksopen' => '1', 'specificfeedbackopen' => '1', 'generalfeedbackopen' => '1', 'rightansweropen' => '1', 'overallfeedbackopen' => '1', 'attemptclosed' => '1', 'correctnessclosed' => '1', 'marksclosed' => '1', 'specificfeedbackclosed' => '1', 'generalfeedbackclosed' => '1', 'rightanswerclosed' => '1', 'overallfeedbackclosed' => '1', 'showuserpicture' => '0', 'decimalpoints' => '2', 'questiondecimalpoints' => '-1', 'showblocks' => '0', 'quizpassword' => '', 'subnet' => '', 'delay1' => 0, 'delay2' => 0, 'browsersecurity' => '-', 'boundary_repeats' => 4, 'feedbacktext' => array ( 0 => array ( 'text' => '', 'format' => '1', 'itemid' => '941466359', ), 1 => array ( 'text' => '', 'format' => '1', 'itemid' => '864816352', ), 2 => array ( 'text' => '', 'format' => '1', 'itemid' => '101278785', ), 3 => array ( 'text' => '', 'format' => '1', 'itemid' => '773833773', ), 4 => array ( 'text' => '', 'format' => '1', 'itemid' => 291053486, ), ), 'feedbackboundaries' => array ( 0 => '', 1 => '', 2 => '', 3 => '', ), 'visible' => '1', 'cmidnumber' => '', 'groupmode' => '0', 'groupingid' => '0', 'course' => 2, 'coursemodule' => 0, 'section' => 0, 'module' => 16, 'modulename' => 'quiz', 'instance' => 0, 'add' => 'quiz', 'update' => 0, 'return' => 0, 'sr' => 0, 'submitbutton2' => 'שמירת שינויים וחזרה לקורס', );

function tt($s,$t=null)

{

if(!$t)

$t=new stdClass();

//the problem is that the interior array wasn't convert into an object, so the sql gests mess with array syntax of php

foreach ($s as $key=>$value)

{

$z=$value;

if(is_array($z))

$z=tt($z);

$t->$key=$z;


}



return $t;

}



//var_dump(tt($s));

$newcm = new stdClass();

$newcm->id=2;

//to fix: making course an object, that fits modlib!!!

var_dump(add_moduleinfo(tt($s),$newcm));

并且数据库中没有任何更改,我错在哪里?

感谢。

1 个答案:

答案 0 :(得分:1)

您可以尝试将内部数组项转换为对象,看看是否有效。同样在过去,我必须声明

global $COURSE; 

在PHP文件的开头,我可以访问其内容,如

$COURSE->id; 

稍后在我的课程中。