php - Create Moodle activities programmatically -
does know if it’s possible add activity programmatically course in moodle?
i thinking maybe use class module_add_instance()
lib.php of custom plugin...
e.g.
function feedback_add_instance(stdclass $mod) { global $db; $newmodule->timecreated = time(); // may have add stuff in here. $newmodule->id = $db->insert_record('exams', $newmodule); unicexams_grade_item_update($newmodule); return $newmodule->id; }
but again: $mod
variable? contain , how construct it?
does has knowledge on subject? or advise?
add_moduleinfo()
better. below use facetoface.
to started, edit /course/modedit.php
temporarily add following, add required activity via front end - give list of of properties required:
var_dump($fromform); die(); $fromform = add_moduleinfo($fromform, $course, $mform);
code create facetoface instance
$newfacetoface = new stdclass(); $newfacetoface->name = $facetoface->facetofacename; $newfacetoface->intro = ''; $newfacetoface->thirdparty = ''; $newfacetoface->display = 6; $newfacetoface->approvalreqd = 0; $newfacetoface->selfapprovaltandc = $strmgr->get_string('selfapprovaltandccontents', 'facetoface', $facetoface->langcode); $newfacetoface->allowcancellationsdefault = 1; $newfacetoface->cancellationscutoffdefault = 0; $newfacetoface->multiplesessions = 1; // allow multiple sessions. $newfacetoface->managerreserve = '0'; $newfacetoface->maxmanagerreserves = '1'; $newfacetoface->reservecancel = '1'; $newfacetoface->reservecanceldays = '1'; $newfacetoface->reservedays = '2'; $newfacetoface->showoncalendar = '1'; $newfacetoface->usercalentry = '1'; $newfacetoface->shortname = ''; $newfacetoface->published = $facetoface->visible; $newfacetoface->branches = $facetoface->branches; $newfacetoface->visible = $facetoface->visible; $newfacetoface->cmidnumber = $facetoface->facetofaceid; $newfacetoface->idnumber = $facetoface->facetofaceid; $newfacetoface->groupmode = '0'; $newfacetoface->availabilityconditionsjson = '{"op":"&","c":[],"showc":[]}'; $newfacetoface->completionunlocked = 1; $newfacetoface->completionunlockednoreset = 0; $newfacetoface->completion = completion_tracking_automatic; $newfacetoface->completionstatusrequired = '{"100":1}'; $newfacetoface->completionexpected = 0; $newfacetoface->course = $course->id; $newfacetoface->coursemodule = 0; $newfacetoface->section = 1; $newfacetoface->module = $moduleid; $newfacetoface->modulename = 'facetoface'; $newfacetoface->instance = 0; $newfacetoface->add = 'facetoface'; $newfacetoface->update = 0; $newfacetoface->return = 0; $newfacetoface->sr = 0; $moduleinfo = add_moduleinfo($newfacetoface, $course);
Comments
Post a Comment