Adding activity to courses using API

Adding activity to courses using API

by Luca Gioppo -
Number of replies: 6

Is it possible to add activity to a course using API is there already something ready to use or it has to be developed?

Average of ratings: -
In reply to Luca Gioppo

Re: Adding activity to courses using API

by Jorge Villalon -

Having the same question here. Did you find any information about it?

In reply to Luca Gioppo

Re: Adding activity to courses using API

by Syed Nayab Bukhari -
Picture of Core developers

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. 

In reply to Syed Nayab Bukhari

Re: Adding activity to courses using API

by Samuel Than -

Just started to dwell in the same question, was wondering what was the outcome of this ?

cheers. 

In reply to Samuel Than

Re: Adding activity to courses using API

by Colin Matheson -

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);
Average of ratings: Useful (2)
In reply to Colin Matheson

Re: Adding activity to courses using API

by Samuel Than -

Interesting. Thanks for sharing.. will give that idea a spin...wink

In reply to Colin Matheson

Re: Adding activity to courses using API

by Rt S -

Thanks for sharing.

I am looking for api to add scorm package(external-URL) to existing course.

Average of ratings: Useful (1)