Hello people,
I am trying to create a label in my moodle course with the following code.
$module = $DB->get_record('modules', array('name' => 'label'));
foreach($courses_to_add_actibity as $course){
$customLabel = new stdClass();
$customLabel->name = "Instructions";
$customLabel->introeditor = array("text" => "Test", "format" => "1", "itemid" => 0);
$customLabel->grade = 100;
$customLabel->gradecat = 60;
$customLabel->gradepass = 0;
$customLabel->visible = "1";
$customLabel->visibleoncoursepage = "1";
$customLabel->availabilityconditionsjson = '{"op":"&","c":[],"showc":[]}';
$customLabel->course = $course->id;
$customLabel->coursemodule = 0;
$customLabel->section = 0;
$customLabel->module = $module->id;
$customLabel->modulename = "label";
$customLabel->instance = 0;
$customLabel->add = "label";
$customLabel->update = 0;
$customLabel->return = 0;
$customLabel->sr = 0;
$moduleinfo = add_moduleinfo($customLabel, $course);
}
After i execute above code i get the error:
!!! Invalid user !!!
!! SELECT id FROM {user} WHERE id = ? AND deleted = ?
[array (
0 => 0,
1 => 0,
)]
Error code: invaliduser !!
!! Stack trace: * line 1599 of \lib\dml\moodle_database.php: dml_missing_record_exception thrown
* line 1575 of \lib\dml\moodle_database.php: call to moodle_database->get_record_select()
* line 6496 of \lib\accesslib.php: call to moodle_database->get_record()
* line 1051 of \lib\filelib.php: call to context_user::instance()
* line 159 of \course\modlib.php: call to file_save_draft_area_files()
* line 128 of \custompage\createlabel\addActivity.php: call to add_moduleinfo()
!!
What am i missing?
I am using moodle 3.9.1+
I really appreciate any response.
Regards
Marios