Is it possible to add activity to a course using API is there already something ready to use or it has to be developed?
Having the same question here. Did you find any information about it?
I had created plugin for "Bulk course creations" on local system getting course contents from 2 webservice.
Now I am going to develop a webservice. When a user pass required parameter to this "Bulk Course creation" plugin from another system.
It will collect course content from webservice, create whole new course with new activities/contents etc and return course link.
I am sure it is possible to add activities in courses via webservice/api.
Soon, I will share my experience.
Just started to dwell in the same question, was wondering what was the outcome of this ?
cheers.
I was able to make a plugin to add a quiz to a course page
https://github.com/cytochromec/moodle-block-quizlet_import
The code that actually adds the quiz starts on line 234 of quizlet_import.php (pasted below)
//create an object with all of the neccesary information to build a quiz |
$myQuiz = new stdClass(); |
$myQuiz->modulename='quiz'; |
$myQuiz->name = $title; |
$myQuiz->introformat = 0; |
$myQuiz->quizpassword = ''; |
$myQuiz->course = $id1; |
$myQuiz->section = $sectionNum; |
$myQuiz->timeopen = 0; |
$myQuiz->timeclose = 0; |
$myQuiz->timelimit = 0; |
$myQuiz->grade = $Points; |
$myQuiz->sumgrades = $Points; |
$myQuiz->gradeperiod = 0; |
$myQuiz->attempts = 1; |
$myQuiz->preferredbehaviour = 'deferredfeedback'; |
$myQuiz->attemptonlast = 0; |
$myQuiz->shufflequestions = 0; |
$myQuiz->grademethod = 1; |
$myQuiz->questiondecimalpoints = 2; |
$myQuiz->visible = 1; |
$myQuiz->questionsperpage = 1; |
$myQuiz->introeditor = array('text' => 'A matching quiz','format' => 1); |
//all of the review options |
$myQuiz->attemptduring=1; |
$myQuiz->correctnessduring=1; |
$myQuiz->marksduring=1; |
$myQuiz->specificfeedbackduring=1; |
$myQuiz->generalfeedbackduring=1; |
$myQuiz->rightanswerduring=1; |
$myQuiz->overallfeedbackduring=1; |
$myQuiz->attemptimmediately=1; |
$myQuiz->correctnessimmediately=1; |
$myQuiz->marksimmediately=1; |
$myQuiz->specificfeedbackimmediately=1; |
$myQuiz->generalfeedbackimmediately=1; |
$myQuiz->rightanswerimmediately=1; |
$myQuiz->overallfeedbackimmediately=1; |
$myQuiz->marksopen=1; |
$myQuiz->attemptclosed=1; |
$myQuiz->correctnessclosed=1; |
$myQuiz->marksclosed=1; |
$myQuiz->specificfeedbackclosed=1; |
$myQuiz->generalfeedbackclosed=1; |
$myQuiz->rightanswerclosed=1; |
$myQuiz->overallfeedbackclosed=1; |
//actually make the quiz using the function from course/lib.php |
$myQuiz2 = create_module($myQuiz); |
//print_object($myQuiz2); |
//get the last added random short answer matching question (which will likely be the one we just added) |
$result = $DB->get_records('question',array('qtype'=>'randomsamatch')); |
$keys = array_keys($result); |
$count = count($keys); |
//add the quiz question |
quiz_add_quiz_question($result[$keys[$count-1]]->id, $myQuiz2, $page = 0, $maxmark = null); |
Interesting. Thanks for sharing.. will give that idea a spin...