Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Provides the API of the policies plugin. More...
Static Public Member Functions | |
static | accept_policies ($policyversionid, $userid=null, $note=null, $lang=null) |
Mark the given policy versions as accepted by the user. | |
static | can_accept_policies (array $versionids, $userid=null, $throwexception=false) |
Check if given policies can be accepted by the current user (eventually on behalf of the other user) | |
static | can_decline_policies (array $versionids, $userid=null, $throwexception=false) |
Check if given policies can be declined by the current user (eventually on behalf of the other user) | |
static | can_delete_version ($version) |
Can the current version be deleted. | |
static | can_revoke_policies (array $versionids, $userid=null, $throwexception=false) |
Check if acceptances to given policies can be revoked by the current user (eventually on behalf of the other user) | |
static | can_user_view_policy_version ($policy, $behalfid=null, $userid=null) |
Can the user view the given policy version document? | |
static | count_total_users () |
Returns total number of users who are expected to accept site policy. | |
static | create_acceptances_user_created (\core\event\user_created $event) |
Create user policy acceptances when the user is created. | |
static | decline_policies ($policyversionid, $userid=null, $note=null, $lang=null) |
Mark the given policy versions as declined by the user. | |
static | delete ($versionid) |
Delete the given version (if it is a draft). | |
static | fix_revision_values (array $versions) |
Make sure that each version has a unique revision value. | |
static | form_policydoc_add (stdClass $form) |
Save the data from the policydoc form as a new policy document. | |
static | form_policydoc_data (policy_version $version) |
Prepare data for the tool_policy::form::policydoc form. | |
static | form_policydoc_update_new (stdClass $form) |
Save the data from the policydoc form as a new policy document version. | |
static | form_policydoc_update_overwrite (stdClass $form) |
Save the data from the policydoc form, overwriting the existing policy document version. | |
static | get_agreement_optional ($versionid) |
Returns the value of the optional flag for the given policy version. | |
static | get_current_versions_ids ($audience=null) |
Checks if there are any current policies defined and returns their ids only. | |
static | get_policies_with_acceptances ($userid) |
Get the list of policies and versions that current user is able to see and the respective acceptance records for the selected user. | |
static | get_policy_version ($versionid, $policies=null) |
Load a particular policy document version. | |
static | get_user_acceptances ($userid, $versions=null) |
Returns list of acceptances for this user. | |
static | get_user_minors ($userid, array $extrafields=null) |
Return the user's minors - other users on which behalf we can accept policies. | |
static | get_user_version_acceptance ($userid, $versionid, $acceptances=null) |
Returns version acceptance for this user. | |
static | inactivate ($policyid) |
Inactivate the policy document - no version marked as current and the document does not apply. | |
static | is_user_version_accepted ($userid, $versionid, $acceptances=null) |
Did the user accept the given policy version? | |
static | list_current_versions ($audience=null) |
Return current (active) policies versions. | |
static | list_policies ($ids=null, $countacceptances=false) |
Returns a list of all policy documents and their versions. | |
static | make_current ($versionid) |
Make the given version the current active one. | |
static | move_down ($policyid) |
Move the given policy document down in the list. | |
static | move_up ($policyid) |
Move the given policy document up in the list. | |
static | policy_content_field_options () |
Editor field options for the policy content text. | |
static | policy_summary_field_options () |
Editor field options for the policy summary text. | |
static | revert_to_draft ($versionid) |
Create a new draft policy document from an archived version. | |
static | revoke_acceptance ($policyversionid, $userid, $note=null) |
May be used to revert accidentally granted acceptance for another user. | |
static | update_policyagreed ($user=null) |
Make sure that $user->policyagreed matches the agreement to the policies. | |
Static Protected Member Functions | |
static | distribute_policy_document_sortorder () |
Re-sets the sortorder field of the policy documents to even values. | |
static | move_policy_document ($policyid, $step) |
Change the policy document's sortorder. | |
static | set_acceptances_status ($policyversionid, $userid=null, $note=null, $lang=null, $status=1) |
Mark the given policy versions as accepted or declined by the user. | |
Provides the API of the policies plugin.
|
static |
Mark the given policy versions as accepted by the user.
array | int | $policyversionid | Policy version id(s) to set acceptance status for. |
int | null | $userid | Id of the user accepting the policy version, defaults to the current one. |
string | null | $note | Note to be recorded. |
string | null | $lang | Language in which the policy was shown, defaults to the current one. |
|
static |
Check if given policies can be accepted by the current user (eventually on behalf of the other user)
Currently, the version ids are not relevant and the check is based on permissions only. In the future, additional conditions can be added (such as policies applying to certain users only).
array | $versionids | int[] List of policy version ids to check |
int | $userid | Accepting policies on this user's behalf (defaults to accepting on self) |
bool | $throwexception | Throw exception instead of returning false |
bool |
|
static |
Check if given policies can be declined by the current user (eventually on behalf of the other user)
Only optional policies can be declined. Otherwise, the permissions are same as for accepting policies.
array | $versionids | int[] List of policy version ids to check |
int | $userid | Declining policies on this user's behalf (defaults to declining by self) |
bool | $throwexception | Throw exception instead of returning false |
bool |
|
static |
Can the current version be deleted.
stdClass | $version | object describing version, contains fields policyid, id, status, archived, audience, ... |
|
static |
Check if acceptances to given policies can be revoked by the current user (eventually on behalf of the other user)
Revoking optional policies is controlled by the same rules as declining them. Compulsory policies can be revoked only by users with the permission to accept policies on other's behalf. The reasoning behind this is to make sure the user communicates with the site's privacy officer and is well aware of all consequences of the decision (such as losing right to access the site).
array | $versionids | int[] List of policy version ids to check |
int | $userid | Revoking policies on this user's behalf (defaults to revoking by self) |
bool | $throwexception | Throw exception instead of returning false |
bool |
|
static |
Can the user view the given policy version document?
stdClass | $policy | - exported tool_policy::policy_exporter instance |
int | $behalfid | The id of user on whose behalf the user is viewing the policy |
int | $userid | The user whom access is evaluated, defaults to the current one |
bool |
|
static |
Returns total number of users who are expected to accept site policy.
int|null |
|
static |
Create user policy acceptances when the user is created.
core\event\user_created | $event |
|
static |
Mark the given policy versions as declined by the user.
array | int | $policyversionid | Policy version id(s) to set acceptance status for. |
int | null | $userid | Id of the user accepting the policy version, defaults to the current one. |
string | null | $note | Note to be recorded. |
string | null | $lang | Language in which the policy was shown, defaults to the current one. |
|
static |
Delete the given version (if it is a draft).
Also delete policy if this is the only version.
int | $versionid |
|
static |
Make sure that each version has a unique revision value.
Empty value are replaced with a timecreated date. Duplicates are suffixed with v1, v2, v3, ... etc.
array | $versions | List of objects with id, timecreated and revision properties |
|
static |
Save the data from the policydoc form as a new policy document.
stdClass | $form | data submitted from the tool_policy::form::policydoc form. |
tool_policy\policy_version | persistent |
|
static |
Prepare data for the tool_policy::form::policydoc form.
tool_policy\policy_version | $version | persistent representing the version. |
stdClass | form data |
|
static |
Save the data from the policydoc form as a new policy document version.
stdClass | $form | data submitted from the tool_policy::form::policydoc form. |
tool_policy\policy_version | persistent |
|
static |
Save the data from the policydoc form, overwriting the existing policy document version.
stdClass | $form | data submitted from the tool_policy::form::policydoc form. |
tool_policy\policy_version | persistent |
|
static |
Returns the value of the optional flag for the given policy version.
Optimised for being called multiple times by making use of a request cache. The cache is normally populated as a side effect of calling self::list_policies() and in most cases should be warm enough for hits.
int | $versionid |
int | policy_version\AGREEMENT_COMPULSORY | policy_version\AGREEMENT_OPTIONAL |
|
static |
Checks if there are any current policies defined and returns their ids only.
array | $audience | If defined, filter against the given audience (AUDIENCE_ALL always included) |
array | of version ids indexed by policies ids |
|
static |
Get the list of policies and versions that current user is able to see and the respective acceptance records for the selected user.
int | $userid |
array | array with the same structure that list_policies() returns with additional attribute acceptance for versions |
|
static |
Load a particular policy document version.
int | $versionid | ID of the policy document version. |
array | $policies | cached result of self\list_policies() in case this function needs to be called in a loop |
stdClass | - exported tool_policy::policy_exporter instance |
|
static |
Returns list of acceptances for this user.
int | $userid | id of a user. |
int | array | $versions | list of policy versions. |
array | list of acceptances indexed by versionid. |
|
static |
Return the user's minors - other users on which behalf we can accept policies.
Returned objects contain all the standard user name and picture fields as well as the context instanceid.
int | $userid | The id if the user with parental responsibility |
array | $extrafields | Extra fields to be included in result |
array | of objects |
|
static |
Returns version acceptance for this user.
int | $userid | User identifier. |
int | $versionid | Policy version identifier. |
array | null | $acceptances | List of policy version acceptances indexed by versionid. |
stdClass|null | Acceptance object if the user has ever accepted this version or null if not. |
|
static |
Inactivate the policy document - no version marked as current and the document does not apply.
int | $policyid |
|
static |
Did the user accept the given policy version?
int | $userid | User identifier. |
int | $versionid | Policy version identifier. |
array | null | $acceptances | Pre-loaded list of policy version acceptances indexed by versionid. |
bool|null | True/false if this user accepted/declined the policy; null otherwise. |
|
static |
Return current (active) policies versions.
array | $audience | If defined, filter against the given audience (AUDIENCE_ALL always included) |
array | of stdClass - exported tool_policy::policy_version_exporter instances |
|
static |
Returns a list of all policy documents and their versions.
array | int | null | $ids | Load only the given policies, defaults to all. |
int | $countacceptances | return number of user acceptances for each version |
array | of stdClass - exported tool_policy::policy_exporter instances |
|
static |
Make the given version the current active one.
int | $versionid |
|
static |
Move the given policy document down in the list.
id | $policyid |
|
staticprotected |
Change the policy document's sortorder.
int | $policyid | |
int | $step |
|
static |
Move the given policy document up in the list.
id | $policyid |
|
static |
Editor field options for the policy content text.
array |
|
static |
Editor field options for the policy summary text.
array |
|
static |
Create a new draft policy document from an archived version.
int | $versionid |
tool_policy\policy_version | persistent |
|
static |
May be used to revert accidentally granted acceptance for another user.
int | $policyversionid | |
int | $userid | |
null | $note |
|
staticprotected |
Mark the given policy versions as accepted or declined by the user.
array | int | $policyversionid | Policy version id(s) to set acceptance status for. |
int | null | $userid | Id of the user accepting the policy version, defaults to the current one. |
string | null | $note | Note to be recorded. |
string | null | $lang | Language in which the policy was shown, defaults to the current one. |
int | $status | The acceptance status, defaults to 1 = accepted |
|
static |
Make sure that $user->policyagreed matches the agreement to the policies.
int | stdClass | null | $user | user to check (null for current user) |