by Matthew Davidson.
I should also note that even at 16gb of memory allocated to PHP it was still failing.
by Matthew Davidson.
I should also note that even at 16gb of memory allocated to PHP it was still failing.
by Matthew Davidson.
Actual error message:
cache/stores/file/lib.php
PHP Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1052672 bytes) in /var/www/moodle/cache/stores/file/lib.php on line 368" while reading response header from upstream
by Luan Phan.
hello everyone
I using moodle 3.2 and i update moodle 3.4
When I tried Add function in web service of moodle 3.4, I got this error message as " Coding error detected, it must be fixed by a programmer: Can not find file with external function implementation".
Please help me.
Thanks all.
by Sandeep Kohli.
Hi Lovely people,
I want to write a web service to get all the discussions for a forum.
I searched for the apis and i am getting all comments if i give a discussion id, but i want to go one step before and i want to first get a list of all discussions in a forum.
Similarly, I want to get all the posts where the user has posted. Is there a way to get that using web services?
Thanks,
Sandeep
by e sencan.
'We are doing some integration work and are using the built is REST web services.
We want to use the 'enrol_manual_enrol_users' function to sync course enrolment between two systems. One required field to do this 'roleid'. I'd like to pull a list of roles from Moodle and present them to user to select which role the student should be enrolled as. Ican't see any function which returns a list of roles. Is there a built in web service for this?
by e sencan.
Hi
Moodle requires unique emails so if you have the user's email you can do a check to see if that user exists in Moodle.
Call 'core_user_get_users' with 'criteria[0][key]=email' and 'criteria[0][value]={useremail}' where {useremail} is the user's email. Moodle will spit back a list of users matching that email. Since email has to be unique there should would one element if the user exists - the element will provide you with the userid. If no elements come back the user is not in the system and you can add them in.
by Konrad Lorinczi.
Hi,
Is it possible to display course content of Moodle site A to Moodle site B using web services?
by Michael Chan.
I would be interested to hear if anyone has experienced the issue raised by Matthew and found a remedy or workaround. We are a vendor that currently has an integration with Moodle where we call the core_course_get_courses method to get all the courses. Unfortunately, for one school, they experienced the same errors as described in this thread.
There is another thread that sort of delves into the possibility to filter the core_course_get_courses call by something like the "category id": https://moodle.org/mod/forum/discuss.php?d=348752
However, it does not appear that any work has been done in that area.
by Michael Chan.
I'm not sure the solution mentioned by Edwin would work for some. There is an issue described in this thread regarding the core_course_get_courses method: https://moodle.org/mod/forum/discuss.php?d=362784
It would be ideal if there was an additional filter like "category id" for the core_course_get_courses method to prevent the web service call from timing/erroring out. However, it does not look like there has been any work for this issue.
by Marco Carrillo.
Este es un error de redireccionamiento, para solucionarlo tendremos que modificar el archivo "config.php", ubicado en la carpeta principal del moodle.
$CFG->wwwroot = 'http://[direccion_ip_o_nombre_de_maquina]/moodle28';
by Michael Chan.
I've since realized there is the core_course_get_courses_by_field method that was introduced in version 3.2. Here is the syntax to filter by a category value, but you can also filter by id, course id, short name or category:
https://MOODLEURL/webservice/rest/server.php?wstoken=TOKENVALUE&wsfunction=core_course_get_courses_by_field&field=category&value=[###]&moodlewsrestformat=json
Please ensure the new API method is added as a function to the webservice token so you have the proper access.
by Michael Chan.
I've since realized there is the core_course_get_courses_by_field method that was introduced in version 3.2. This new method is the replacement for core_course_get_courses.
Here is the syntax to filter by a category value, but you can also filter by id, course id, short name or category:
https://MOODLEURL/webservice/rest/server.php?wstoken=TOKENVALUE&wsfunction=core_course_get_courses_by_field&field=category&value=[###]&moodlewsrestformat=json
Please ensure the new API method is added as a function to the webservice token so you have the proper access.
by Andre T.
Hi, has somebody an idea what i do wrong? I try to enroll in a user for a course and I got the following error:
stdClass Object
(
[exception] => moodle_exception
[errorcode] => wsnoinstance
[message] => Manual enrolment plugin instance doesn't exist or is disabled for the course (id = {$a->courseid})
)
I enabled manual enrolment. The webservice create user already work fine, just the user enrole dosen't work.
My Code:
token = $token;
$this->domain = $domain;
}
public function enrolUser($userID, $courseID){
$functionname = "enrol_manual_enrol_users";
$enrolment = new stdClass();
$enrolment -> roleid = 5;
$enrolment -> userid = 10;
$enrolment -> courseid = 1;
$params = array("enrolments" => array($enrolment));
$response = $this->connectToMoodle($functionname, $params);
return print_r($response);
}
private function connectToMoodle($functionname, $params){
$restformat = "json";
header("Content-Type: text/plain");
$serverurl = $this->domain . "/webservice/rest/server.php" . "?wstoken=" . $this->token . "&wsfunction=" . $functionname;
require_once("curl.php");
$curl = new curl;
$restformat = ($restformat == "json")?"&moodlewsrestformat=" . $restformat:"";
$response = $curl->post($serverurl . $restformat, $params);
return json_decode($response);
}
}
?>
by A. Obeid.
Did you try this:
$DB->get_field('role', 'shortname', '*');
by Farhan Karmali.
You would need to enable manual enrollment in that course also. Go to the course, course administration -> users -> enrollment methods and enable manual enrollment
by Andre T.
Thanks for your Answer, I already enabled this. My fault was it to take the idnumber of the course as the course id. Now everything works fine.
by Mike Wilson.
I'm putting together a web service to pass student information and assignment feedback comments to another system. It works quite nicely when I just return general student information in my personal_tutor_portal_returns() function, but I want to output a multidimensional array with the feedback data one level down.
I can't seem to get this to work.
Am I right in thinking I need an external_multiple_structure with two external_single_structures within it one for student data and another for feedback data?
Has anyone got a good example of something similar to what I'm trying to do?
Thanks for any help, the finish line is in sight on this one
Moodle 3.3.1
public static function personal_tutor_portal_parameters() {
return new external_function_parameters(
array(
'email' => new external_value(PARAM_TEXT, 'Student email (lowercase)', VALUE_DEFAULT, 'something@blackhole.port.ac.uk'),
'hash' => new external_value(PARAM_TEXT, 'Salted hash of username', VALUE_DEFAULT, '')
)
);
}
public static function personal_tutor_portal($email = 'something@blackhole.port.ac.uk',$hash = '') {
global $USER, $DB;
$salt = 'YC*1!gduQ$jn^4';
//Parameter validation
$params = self::validate_parameters(self::personal_tutor_portal_parameters(),
array('email'=>$email,
'hash'=>$hash));
//do a hash check to ensure no messing with username
if(md5($email.$salt)!=$hash){
return "Sorry, the hash does not match.";
}
$user = $DB->get_record('user',array('email'=>$email));
$sql = "SELECT
greatest(ag.id) AS id,ag.assignment,ag.userid,ag.timecreated,ag.grader,u.firstname,u.lastname,ag.grade,greatest(afc.commenttext) AS commenttext,ag.timemodified,ass.name,ass.duedate,ass.markingworkflow,
c.id AS courseid,c.fullname,c.shortname,ass.teamsubmission,cm.id AS cmid,
auf.workflowstate,auf.id AS workflowstateid,m.name as modulename
FROM
{assign_grades} AS ag
LEFT OUTER JOIN {assignfeedback_comments} AS afc ON afc.assignment = ag.assignment AND afc.grade = ag.id
INNER JOIN {assign} AS ass ON ass.id = ag.assignment
INNER JOIN {user} AS u ON u.id = ag.grader
INNER JOIN {course} AS c ON ass.course = c.id
INNER JOIN {course_modules} AS cm ON cm.instance = ag.assignment AND cm.course = c.id
INNER JOIN {assign_user_flags} AS auf ON auf.assignment = ag.assignment
INNER JOIN {modules} as m ON cm.module = m.id
WHERE
ag.userid = $user->id AND
m.name = 'assign' AND
auf.id = 1
OR auf.id = 6
GROUP BY greatest(ag.id),ag.assignment,ag.userid,ag.grade,ag.grader,ag.timecreated,u.firstname,u.lastname,u.email,ag.grade,afc.commenttext,ag.timemodified,ass.name,ass.duedate,ass.markingworkflow,c.id,
c.fullname,c.shortname,ass.teamsubmission,cm.id,auf.workflowstate,auf.id,m.name
ORDER BY
c.fullname ASC,ag.timemodified DESC";
$feedbacks = $DB->get_records_sql($sql,array());
function academicyear($timestamp){
/* Return academic year from a unix timestamp */
$year = date('Y',$timestamp);
$month = date('m',$timestamp);
if ($month < 9){
$aca = strtotime('-1 year',$timestamp);
$aca = date('Y',$aca);
}
else $aca = $year;
$text = $aca;
return $text;
}
$portal = array(
'source' => 'Moodle',
'username' => $user->username,
'firstname' => $user->firstname,
'lastname' => $user->lastname,
'email' => $user->email
);
foreach($feedbacks as $feedback){
$academicyear = academicyear($feedback->timecreated);
$rawcomment = strip_tags($feedback->commenttext);
$marker = $feedback->firstname.' '.$feedback->lastname;
$feedbackdate = date('d.m.Y',$feedback->timemodified);
}
return $portal;
}
public static function personal_tutor_portal_returns() {
return new external_single_structure(
array(
'source' => new external_value(PARAM_TEXT, 'where data came from - moodle'),
'username' => new external_value(PARAM_TEXT, 'username of student'),
'firstname' => new external_value(PARAM_TEXT, 'first name of student'),
'lastname' => new external_value(PARAM_TEXT, 'last name of student'),
'email' => new external_value(PARAM_TEXT, 'email of student')
)
);
}
by Eric Messick.
Hi, anyone experienced with Myddleware, Magento 2.2.2 , Moodle 3.4.1?
Wanting to make moodle users from Magento Customers. Not working. In Myddleware getting error: "invalidparameter : Invalid parameter value detectedFailed to send document. Status : Error_sending"
The connectors seem to work within Myddleware and I set up a rule to copy Magento customers names into Moodle (to create users). I installed the Myddleware plugin into Moodle and also created a custom web service as per Myddleware documentation.
I'm unclear if I need to do anything more in Moodle. Tried adding webservice capabilities to my Moodle user and making the user authorised for the custom web service and plugin. May not have done this right.
by António Godinho.
I have no idea if this is the correct place.
I've done a webpage that reads a degree data, and builds up a new year for that degree and populate the tree with the classes split by degree year.
I need to add a new enrolment method for the teachers in all the new courses. Manually this a nightmare... This feature would be great!
by Hemant Girdhar.
Hi Everyone,
I am able to access Web service API: gradereport_overview_get_course_grades to get user scores for enrolled courses.
I do not want to get scores for all user.
I just need to get scores for users who have attempted course on specific day only. (today / last day / before 1 week).
Is there any Web Service API available in Moodle to get list of users who have attempted course in specific time frame, so that I can scores for specific list of users, instead of all users.