Skip to main content

Examples

Complete programs for real tasks, each explained step by step, with its code commented where Moodle or the driver does something you wouldn't guess. Copy one, change the site, the profile and the ids, and run it.

Every program starts the same way: a Moodle object for the site, created with await using so the browser closes when the program ends, and logIn(), which opens a window only the first time (see Logging in). The ids come from the site: a course's from listCourses(), an activity's from courseStructure() (see Ids).

πŸŽ’ As a student​

ExampleWhat it does
A weekly agendaCourses in progress, deadlines of the week, what's pending, unread notifications
Download a course's filesEvery file and folder of a course, saved in a folder per section
Read a course's contentPages and books at a person's pace, marked done where the course asks
Submit an assignmentOnline text and a file, submitted for grading, the statement accepted by the person
Answer a quizAn attempt page by page, finished, its review printed
Surveys and choicesA feedback or questionnaire survey, and a choice

πŸ§‘β€πŸ« As a teacher​

ExampleWhat it does
Grade submissionsPending submissions graded with feedback, simple or with a rubric
Extensions and overridesMore time for one student: an assignment extension and a quiz override
Message inactive studentsStudents who haven't come in two weeks, each sent a message
A daily reportNotifications, deadlines, what changed in a course, the newest forum discussions
Build a course unitA section with pages, a link and an assignment, from an outline in the program
Export grades to CSVThe grader report as a spreadsheet
Questions into a quizQuestions imported into a bank and added to a quiz, a random one too

πŸ› οΈ For your program​

ExampleWhat it does
Errors and sessionsA program that logs in again when the session ends and reports errors by code
Several sitesOne object per site and person, and showing the browser while someone watches
Moodle servicesWhat the driver doesn't wrap: Moodle's AJAX services, pages and forms, and limiting what may be called
Testing your programTests against the fake Moodle, without a real site