internals
The primitives the operations are built from, imported from @falkenslab/moodle-driver/internals,
for a program that goes lower level than them: a service the driver doesn't wrap, a form of its
own, a page read by hand. Stable as the main entry is, but closer to Moodle: they take pages and
form field names.
Interfaces
| Interface | Description |
|---|---|
| ActivityDetails | What the course page shows of an activity, in the site's language. |
| CourseState | core_courseformat_get_state as Moodle 4.0–5.2 returns it, the fields read. |
| PageConfig | What M.cfg says about the logged-in person. |
| SessionFacts | What a Moodle page says about its session, read without depending on the interface's language. |
Type Aliases
| Type Alias | Description |
|---|---|
| EditorAction | The course editor's actions this server uses (core_courseformat\stateactions, Moodle 4.0–5.2). |
Functions
| Function | Description |
|---|---|
| activityDetails | Details for the given activities: from the course page, then from the section pages of those it doesn't show (courses with one section per page). |
| callService | Calls one of Moodle's AJAX services as the logged-in person: a request to lib/ajax/service.php with the profile's session and its sesskey, as Moodle's pages make them, without a tab (ADR-004, ADR-011). Throws NotLoggedInError when there's no session, MoodleServiceError when the service fails. |
| courseState | The course page's own state: sections and activities, as a JSON string (ADR-004). |
| dateSelectorDate | The date a Moodle date selector holds (name[day]… in the person's time zone), or undefined when it's off. |
| dateSelectorValues | The values of a Moodle date selector's parts (name[day], [month], [year], [hour], [minute]) for date, in the person's time zone (M.cfg.usertimezone), which is how Moodle reads them. Its "enable" checkbox, when it has one, is the caller's to set first. timeZone is for a form without Moodle's page around it (a fragment), which has no M.cfg: readPageConfig() gives it. |
| decodeEntities | Moodle formats names for HTML (format_string): plain text for the client. |
| deleteDraftFile | Deletes a file from a form's draft area by its path in it ("week1/notes.pdf"); the activity changes when the form is saved. |
| draftFiles | The files in a form's draft area, subfolders included, as the file manager lists them (draftfiles_ajax.php?action=list): what an activity holds while its form is open. |
| editCourse | Runs one of the course editor's actions through its own service (ADR-004), as the editor does: ids of activities or sections, and a target section (cm_move: at its end; section_add, section_move_after: after it) or a target activity (cm_move: before it). |
| fetchSitePage | A page of the site over HTTP with the profile's session, without a tab (ADR-011): its final URL and HTML. Throws NotLoggedInError when Moodle answers with its login page. While the browser is shown, the working tab shows the page afterwards (ADR-007), unless follow is false. |
| fileNameFor | A file name from Content-Disposition, else the URL's last segment; never a path. |
| formValue | A hidden field's value in the form (a draft area id, the course id…). |
| htmlSessionFacts | What a page's HTML says about its session, read as readSessionFacts reads a page. |
| inPage | Runs fn(arg) in the page, like page.evaluate, but with a __name helper defined first: tsx (the tests) compiles with esbuild's keepNames, which wraps named inner functions in __name(...) calls the page doesn't have (confirmed empirically). The bundle doesn't, and the helper is unused there. arg must be JSON. |
| isLoggedIn | Whether a page at url, with these facts (readSessionFacts, htmlSessionFacts), belongs to the site and has a real user logged in: false off the site (an SSO provider's page), on its login pages, for nobody logged in and for a guest. It decides from what it's given, opening nothing, so a program that reads pages its own way can tell an expired session (where the driver's functions throw NotLoggedInError) without asking Moodle again; pageIsLoggedIn does both steps on a page. |
| moodleErrorMessage | Moodle's message on an error page (its fatal error box: no permission, no such record), which keeps the page's body id. |
| openForm | Opens a Moodle form page and waits for its editors to be ready. |
| openSitePage | Opens a page of the site (path relative to it) in a new tab and checks the session; throws NotLoggedInError, closing the tab, when Moodle answers with its login page. |
| pageIsLoggedIn | Whether page, as it is now, shows the site with a real user logged in. |
| pause | Waits seconds, calling onProgress every few seconds so clients keep waiting. |
| readImages | The images (<img>) in each element matching selector, one list per element, each URL once; data: URLs are left out. An image of the site downloads with the session (downloadFile). |
| readingSeconds | How long a person would take to read text, in seconds. |
| readMedia | The media in the elements matching selector: <video>/<audio> and their sources, players in iframes, video.js's data-setup sources (Moodle's media filter turns a YouTube link into one), and plain links to media. YouTube URLs come back as watch?v= links. Read in the page. |
| readMoodleConfig | M.cfg as a Moodle page's HTML sets it (M.cfg = {…};), parsed; undefined when it has none. |
| readOwnProfile | The logged-in user, read from their own profile page (user/profile.php). |
| readPageConfig | The logged-in person's id, interface language and time zone, from M.cfg, read now: someone else may have logged in since. |
| readSessionFacts | What page, as it is now, says about its session: Moodle's body class, M.cfg.userId and its login and logout links, which mean the same in any interface language. Give them to isLoggedIn; a page fetched as HTML goes through htmlSessionFacts instead. |
| readTexts | The text of the elements matching selector in page, one string each: paragraphs, line breaks and list items kept, scripts and styles left out. Runs in the page with no named functions inside (see the conventions on page.evaluate). |
| readWwwroot | M.cfg.wwwroot in a Moodle page, JSON-escaped as Moodle writes it ("http://host"). |
| removeFromDraft | Removes files by their path in a form's draft area ("notes.pdf", "week1/notes.pdf"), as the file manager's delete does; the files the area had stay until the form is saved. Throws FormError naming the files the area doesn't have, before removing any. |
| renameActivity | Renames an activity, as the course page's in-place editor does. |
| renameSection | Renames a section through its course format's in-place editor. |
| setFields | Sets fields by their form name: text inputs and textareas (through TinyMCE when it edits them), selects (several values for a multiple one), checkboxes and radios, in the order given (a field can enable the next one). Throws FormError naming the fields the form doesn't have, and those it has disabled: Moodle wouldn't send them, and the change would be lost unnoticed. |
| submitForm | Submits the form with one of its buttons and waits for the next page. Throws FormError with Moodle's messages by field (#id_error_<field>) when the form comes back with errors. |
| uploadToDraft | Uploads local files to a form's draft area, as the file picker's "Upload a file" does: the upload repository's id comes from the page's file picker settings, the context from M.cfg. A DraftUpload names the file in the area, in a subfolder when its to has one (created first). With overwrite, a file of the same name is replaced; without it, Moodle keeps both, renaming the new one. Returns each file's draft URL (draftfile.php/<user context>/user/draft/<item>/<name>), in order: what an editor writes into its HTML for a file in its draft area. |
References
DraftFile
Re-exports DraftFile
DraftUpload
Re-exports DraftUpload