Just started to dwell in the same question, was wondering what was the outcome of this ?
cheers.
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=newstdClass(); |
$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); |
I just want to know how to get course contents using webservice. I know the function "core_course_get_contents" Which returns the title and page views as link say
The function core_course_get_contents returns:
- Modules in each section (activities or resources)
-- If the module is a resource it returns a list of the files used by this resource in the "contents" attribute
That attribute is an array of files, there you will have a fileurl attribute that is the downloadURL for the file (if you are using Web Services you should append the WS token)
Example of URL returned:
How you need to modify the URL to download the file:
Here you have a sample response of that WS:
https://github.com/moodlehq/moodlemobile/blob/master/emulator/core_course_get_contents.json
Cheers, Juan
Interesting. Thanks for sharing.. will give that idea a spin...
Hi!
Can anybody let me know the steps to create new functions in a moodle?
Thanks juan. I found it out thru documentation.
BTW, is there option exists to download/view the activities via webservice..
Thanks
Jai
You should:
First: core_enrol_get_users_courses for returning all the courses
Next: Get all the participants of that courses using the function: core_enrol_get_enrolled_users (passing as argument withcapability a capability your teachers must have)
And then iterate the courses/users and discard the courses where the user was not returned by the enrolled_users funciton
Thanks a lot.
It solved my issue.
One more Query , can i upload a file for a course through the same service?
One More problem i noticed is that, i am getting a responce after uploading the file like
"http://localhost:8099/pluginfile.php/24/user/private/sample.txt"
But,when i click on this link,i am getting file not found Error .
Hello guys,How to Upload a File and Map it to Course via web service using the
Seconded. Is there any example code for this? Relevant service/function?
Any relevant information would be much appreciated. Thank you very much.
-Ryan Chausse
My Moodle installation on "Site administration - Plugins - Web services - External services - Functions" lists all the function available for external API - to be exact, to the service "Moodle mobile web service".
The list has only 20% from all the functions described in API documentation. For example, it has moodle_user_get_users_by_id function which returns a correct result when called from API. But when I try to call the function I need - core_user_get_users - which is not listed on that page, I get webservice_access_exception as result.
There are on buttons or links which could add API access rights to the required functions.
I don't say the API rights system is overcomplicated (while it is) - please anyone tell me how to make API calls for core_user_get_users done right?
What is the difference between using the web services like REST, Soap, OSLC etc and Web RTc. I am doing a project for college, where i have a simulated network of wind turbines and a user front end to show their performances. I need to consider which web services will work best for this project and i need it to be near real time. Do I need to consider Web RTC, would it be too expensive, or should i just stick to Web services and protocol
Hello,
We are trying to develop an application which will create and manage moodle users.
What we are looking for is a plugin in moodle that allows it to authenticate against external web services provided by this custom application.
The user puts his credentials on Moodle.
Moodle will contact the external database via webservices for authentication.
Appreciate the help!
thnx,
amer
Dear Johan Reinalda,
is there a solution for this? if you have found a solution can you please share that knowledge?
i have a similar requirement and your reply will help me.
Thanks
Vignesh
Hi Joshua,
I'm having trouble with this REST service too. I haven't written any code yet, I'm trying to call the web service directly using a Chrome extension called Postman (see screenshot).
I've followed the instructions precisely to enable the service:
However, when passing in my wstoken, wsfunction (core_course_create_courses) and moodlewsrestformat (json), and the following values:
I'm getting this error: Missing required key in single structure: courses.
Can you tell me how you got past this error? What other errors did you resolve? I know this was a while ago but I can't seem to find much information (on forums or otherwise) about core_course_create_courses.
Thanks in advance,
Jerry
Hi All
I'm working on querying course data from a 3rd party web portal and am having trouble getting the course contents for some courses.
I've enabled the REST endpoint, added the necessary functions to it, got a user token and its working with a simple course I've created through the Moodle UI. However another course which has been imported through the backup/restore process is returning a "cannotgetcoursecontents" exception with no other detail.
Now I'm not too familiar with Moodle, or PHP, but I've tried a couple of things that looked promising, but cant seem to get any more info.
I've tried enabling php logging in the config.php file using :
ini_set ('log_errors', 'on');
ini_set("error_log", "/tmp/php-error.log");
ini_set ('error_reporting', E_ALL);
This is logging errors encountered when browsing Moodle, but nothing is recorded when calling the web service...
In the I've tried changing the define('NO_DEBUG_DISPLAY', true); line to define('NO_DEBUG_DISPLAY', false); in the /webservice/rest.server.php file in the hopes that this caused the web services to write to the above log file. Nope.
I've also enabled/disabled debugging in the Moodle site settings, nothing.
Am I missing something here? Is it possible to debug the web service call and narrow down what's going wrong, rather than a generic "it broke" error ??
Any help is much appreciated.
Cheers,
Hello,
Facing the same problem.
Any hint is appreciated.
thnx,
amer