Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
|
Class for loading/storing plans from the DB. More...
Public Member Functions | |
__call ($method, $arguments) | |
Magic method to capture getters and setters. | |
can_be_edited () | |
Check if plan can be edited. | |
can_comment () | |
Whether the current user can comment on this plan. | |
can_manage () | |
Whether the current user can manage the plan. | |
can_read () | |
Whether the current user can read the plan. | |
can_read_comments () | |
Whether the current user can read comments on this plan. | |
can_request_review () | |
Whether the current user can request a review of the plan. | |
can_review () | |
Whether the current user can review the plan. | |
create () | |
Insert a record in the DB. | |
delete () | |
Delete an entry from the database. | |
from_record (stdClass $record) | |
Populate this class with data from a DB record. | |
get ($property) | |
Data getter. | |
get_comment_object () | |
Get the comment object. | |
get_competencies () | |
Get the competencies in this plan. | |
get_competency ($competencyid) | |
Get a single competency from this plan. | |
get_context () | |
Get the context in which the plan is attached. | |
get_errors () | |
Returns the validation errors. | |
get_statusname () | |
Human readable status name. | |
get_template () | |
Get the plan template. | |
is_based_on_template () | |
Check if a template is associated to the plan. | |
is_draft () | |
Is the plan in draft mode? | |
is_valid () | |
Returns whether or not the model is valid. | |
read () | |
Load the data from the DB. | |
save () | |
Saves the record to the database. | |
set ($property, $value) | |
Data setter. | |
set_many (array $values) | |
Data setter for multiple properties. | |
to_record () | |
Create a DB record from this class. | |
update () | |
Update the existing record in the DB. | |
validate () | |
Validates the data. | |
Static Public Member Functions | |
static | can_comment_user ($planuserid) |
Can the current user comment on a user's plan? | |
static | can_manage_user ($planuserid) |
Can the current user manage a user's plan? | |
static | can_manage_user_draft ($planuserid) |
Can the current user manage a user's draft plan? | |
static | can_read_comments_user ($planuserid) |
Can the current user read the comments on a user's plan? | |
static | can_read_user ($planuserid) |
Can the current user view a user's plan? | |
static | can_read_user_draft ($planuserid) |
Can the current user view a user's draft plan? | |
static | can_request_review_user ($planuserid) |
Can the current user request the draft to be reviewed. | |
static | can_review_user ($planuserid) |
Can the current user review the plan. | |
static | count_records (array $conditions=array()) |
Count a list of records. | |
static | count_records_for_template ($templateid, $status) |
Count the number of plans for a template, optionally filtering by status. | |
static | count_records_select ($select, $params=null) |
Count a list of records. | |
static | extract_record ($row, $prefix=null) |
Extract a record from a row of data. | |
static | get_by_user_and_competency ($userid, $competencyid) |
Get the plans of a user containing a specific competency. | |
static | get_draft_statuses () |
Get the list of draft statuses. | |
static | get_formatted_properties () |
Gets all the formatted properties. | |
static | get_record (array $filters=[], int $strictness=IGNORE_MISSING) |
Load a single record. | |
static | get_records ($filters=array(), $sort='', $order='ASC', $skip=0, $limit=0) |
Load a list of records. | |
static | get_records_for_template ($templateid, $status=0, $skip=0, $limit=100) |
Get the plans for a template, optionally filtering by status. | |
static | get_records_select ($select, $params=null, $sort='', $fields=' *', $limitfrom=0, $limitnum=0) |
Load a list of records based on a select query. | |
static | get_recordset_for_due_and_incomplete () |
Get the recordset of the plans that are due, incomplete and not draft. | |
static | get_sql_fields ($alias, $prefix=null) |
Return the list of fields for use in a SELECT clause. | |
static | get_status_list ($userid) |
Return a list of status depending on capabilities. | |
static | has_property ($property) |
Returns whether or not a property was defined. | |
static | has_records_for_template ($templateid) |
Checks if a template has user plan records. | |
static | is_property_required ($property) |
Returns whether or not a property is required. | |
static | properties_definition () |
Get the properties definition of this model. | |
static | properties_filter (stdClass $record) |
For a given record, return an array containing only those properties that are defined by the persistent. | |
static | record_exists ($id) |
Check if a record exists by ID. | |
static | record_exists_select ($select, array $params=null) |
Check if a records exists. | |
static | update_multiple_from_template (template $template) |
Update from template. | |
Protected Member Functions | |
after_create () | |
Hook to execute after a create. | |
after_delete ($result) | |
Hook to execute after a delete. | |
after_update ($result) | |
Hook to execute after an update. | |
before_create () | |
Hook to execute before a create. | |
before_delete () | |
Hook to execute before a delete. | |
before_update () | |
Hook to execute before an update. | |
before_validate () | |
Hook to execute before validate. | |
raw_get ($property) | |
Internal Data getter. | |
raw_set ($property, $value) | |
Data setter. | |
validate_duedate ($value) | |
Validate the due date. | |
validate_templateid ($value) | |
Validate the template ID. | |
validate_userid ($value) | |
Validate the user ID. | |
verify_protected_methods () | |
This function is used to verify that custom getters and setters are declared as protected. | |
Static Protected Member Functions | |
static | define_properties () |
Return the definition of the properties of this model. | |
static | get_property_default_value ($property) |
Gets the default value for a property. | |
static | get_property_error_message ($property) |
Gets the error message for a property. | |
Protected Attributes | |
plan | $beforeupdate = null |
object before update. | |
Class for loading/storing plans from the DB.
|
finalinherited |
Magic method to capture getters and setters.
This is only available for competency persistents for backwards compatibility. It is recommended to use get('propertyname') and set('propertyname', 'value') directly.
string | $method | Callee. |
array | $arguments | List of arguments. |
mixed |
|
protectedinherited |
Hook to execute after a create.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in core_reportbuilder\local\models\audience, core_reportbuilder\local\models\column, core_reportbuilder\local\models\filter, core_reportbuilder\local\models\report, core_reportbuilder\local\models\schedule, quizaccess_seb\seb_quiz_settings, tool_dataprivacy\contextlevel, tool_dataprivacy\purpose, and tool_dataprivacy\purpose_override.
|
protectedinherited |
Hook to execute after a delete.
This is only intended to be used by child classes, do not put any logic here!
bool | $result | Whether or not the delete was successful. |
void |
Reimplemented in core_competency\competency, core_competency\course_competency, core_competency\course_module_competency, core_competency\plan_competency, core_competency\template_competency, core_reportbuilder\local\models\audience, core_reportbuilder\local\models\column, core_reportbuilder\local\models\filter, core_reportbuilder\local\models\report, core_reportbuilder\local\models\schedule, and tool_policy\policy_version.
|
protectedinherited |
Hook to execute after an update.
This is only intended to be used by child classes, do not put any logic here!
bool | $result | Whether or not the update was successful. |
void |
Reimplemented in core_competency\competency, core_competency\template, core_reportbuilder\local\models\audience, core_reportbuilder\local\models\column, core_reportbuilder\local\models\filter, core_reportbuilder\local\models\report, core_reportbuilder\local\models\schedule, quizaccess_seb\seb_quiz_settings, tool_dataprivacy\contextlevel, tool_dataprivacy\purpose, tool_dataprivacy\purpose_override, and tool_policy\policy_version.
|
protectedinherited |
Hook to execute before a create.
Please note that at this stage the data has already been validated and therefore any new data being set will not be validated before it is sent to the database.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in quizaccess_seb\seb_quiz_settings, and quizaccess_seb\template.
|
protectedinherited |
Hook to execute before a delete.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in core_reportbuilder\local\models\report, mod_bigbluebuttonbn\recording, quizaccess_seb\seb_quiz_settings, tool_dataprivacy\contextlevel, tool_dataprivacy\purpose, and tool_dataprivacy\purpose_override.
|
protectedinherited |
Hook to execute before an update.
Please note that at this stage the data has already been validated and therefore any new data being set will not be validated before it is sent to the database.
This is only intended to be used by child classes, do not put any logic here!
void |
Reimplemented in mod_bigbluebuttonbn\recording, quizaccess_seb\seb_quiz_settings, and quizaccess_seb\template.
|
protected |
core_competency\plan::can_be_edited | ( | ) |
Check if plan can be edited.
bool |
core_competency\plan::can_comment | ( | ) |
Whether the current user can comment on this plan.
bool |
|
static |
Can the current user comment on a user's plan?
int | $planuserid | The user ID the plan belongs to. |
bool |
core_competency\plan::can_manage | ( | ) |
Whether the current user can manage the plan.
bool |
|
static |
Can the current user manage a user's plan?
int | $planuserid | The user to whom the plan would belong. |
bool |
|
static |
Can the current user manage a user's draft plan?
int | $planuserid | The user to whom the plan would belong. |
bool |
core_competency\plan::can_read | ( | ) |
Whether the current user can read the plan.
bool |
core_competency\plan::can_read_comments | ( | ) |
Whether the current user can read comments on this plan.
bool |
|
static |
Can the current user read the comments on a user's plan?
int | $planuserid | The user ID the plan belongs to. |
bool |
|
static |
Can the current user view a user's plan?
int | $planuserid | The user to whom the plan would belong. |
bool |
|
static |
Can the current user view a user's draft plan?
int | $planuserid | The user to whom the plan would belong. |
bool |
core_competency\plan::can_request_review | ( | ) |
Whether the current user can request a review of the plan.
bool |
|
static |
Can the current user request the draft to be reviewed.
int | $planuserid | The user to whom the plan would belong. |
bool |
core_competency\plan::can_review | ( | ) |
Whether the current user can review the plan.
bool |
|
static |
Can the current user review the plan.
This means being able to send the plan from draft to active, and vice versa.
int | $planuserid | The user to whom the plan would belong. |
bool |
|
staticinherited |
Count a list of records.
array | $conditions | An array of conditions. |
int |
|
static |
Count the number of plans for a template, optionally filtering by status.
int | $templateid | The template ID |
int | $status | The plan status. 0 means all statuses. |
int |
|
staticinherited |
Count a list of records.
string | $select | |
array | $params |
int |
|
finalinherited |
Insert a record in the DB.
static |
|
staticprotected |
Return the definition of the properties of this model.
array |
Reimplemented from core\persistent.
|
finalinherited |
Delete an entry from the database.
bool | True on success. |
|
staticinherited |
Extract a record from a row of data.
Most likely used in combination with self::get_sql_fields(). This method is simple enough to be used by non-persistent classes, keep that in mind when modifying it.
e.g. persistent\extract_record($row, 'user'); should work.
stdClass | $row | The row of data. |
string | $prefix | The prefix the data fields are prefixed with, defaults to the table name followed by underscore. |
stdClass | The extracted data. |
|
finalinherited |
Populate this class with data from a DB record.
Note that this does not use any custom setter because the data here is intended to represent what is stored in the database.
stdClass | $record | A DB record. |
static |
|
finalinherited |
Data getter.
This is the main getter for all the properties. Developers can implement their own getters (get_propertyname) and they will be called by this function. Custom getters can use raw_get to get the raw value. Internally this is not used by self::to_record() or self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.
string | $property | The property name. |
mixed |
|
static |
Get the plans of a user containing a specific competency.
int | $userid | The user ID. |
int | $competencyid | The competency ID. |
plans[] |
core_competency\plan::get_comment_object | ( | ) |
Get the comment object.
comment |
core_competency\plan::get_competencies | ( | ) |
Get the competencies in this plan.
competency[] |
core_competency\plan::get_competency | ( | $competencyid | ) |
Get a single competency from this plan.
This will throw an exception if the competency does not belong to the plan.
int | $competencyid | The competency ID. |
competency |
core_competency\plan::get_context | ( | ) |
Get the context in which the plan is attached.
context_user |
|
static |
Get the list of draft statuses.
array | Contains the status constants. |
|
finalinherited |
Returns the validation errors.
array |
|
staticfinalinherited |
Gets all the formatted properties.
Formatted properties are properties which have a format associated with them.
array | Keys are property names, values are property format names. |
|
staticfinalprotectedinherited |
Gets the default value for a property.
This assumes that the property exists.
string | $property | The property name. |
mixed |
|
staticfinalprotectedinherited |
Gets the error message for a property.
This assumes that the property exists.
string | $property | The property name. |
lang_string |
|
staticinherited |
Load a single record.
array | $filters | Filters to apply. |
int | $strictness | Similar to the internal DB get_record call, indicate whether a missing record should be ignored/return false ({ |
false|static |
|
staticinherited |
Load a list of records.
array | $filters | Filters to apply. |
string | $sort | Field to sort by. |
string | $order | Sort order. |
int | $skip | Limitstart. |
int | $limit | Number of rows to return. |
static[] |
|
static |
Get the plans for a template, optionally filtering by status.
int | $templateid | The template ID |
int | $status | The plan status. 0 means all statuses. |
int | $skip | The number of plans to skip |
int | $limit | The max number of plans to return |
int |
|
staticinherited |
Load a list of records based on a select query.
string | $select | |
array | $params | |
string | $sort | |
string | $fields | |
int | $limitfrom | |
int | $limitnum |
static[] |
|
static |
Get the recordset of the plans that are due, incomplete and not draft.
moodle_recordset |
|
staticinherited |
Return the list of fields for use in a SELECT clause.
Having the complete list of fields prefixed allows for multiple persistents to be fetched in a single query. Use self::extract_record() to extract the records from the query result.
string | $alias | The alias used for the table. |
string | $prefix | The prefix to use for each field, defaults to the table name followed by underscore. |
string | The SQL fragment. |
|
static |
Return a list of status depending on capabilities.
int | $userid | The user to whom the plan would belong. |
array |
core_competency\plan::get_statusname | ( | ) |
Human readable status name.
string |
core_competency\plan::get_template | ( | ) |
Get the plan template.
template|null |
|
staticfinalinherited |
Returns whether or not a property was defined.
string | $property | The property name. |
boolean |
|
static |
Checks if a template has user plan records.
int | $templateid | The template ID |
boolean |
core_competency\plan::is_based_on_template | ( | ) |
Check if a template is associated to the plan.
bool |
core_competency\plan::is_draft | ( | ) |
Is the plan in draft mode?
This method is convenient to know if the plan is a draft because whilst a draft is being reviewed its status is not "draft" any more, but it still is a draft nonetheless.
boolean |
|
staticfinalinherited |
Returns whether or not a property is required.
By definition a property with a default value is not required.
string | $property | The property name. |
boolean |
|
finalinherited |
Returns whether or not the model is valid.
boolean | True when it is. |
|
staticfinalinherited |
Get the properties definition of this model.
array |
|
staticfinalinherited |
For a given record, return an array containing only those properties that are defined by the persistent.
stdClass | $record |
array |
|
finalprotectedinherited |
Internal Data getter.
This is the main getter for all the properties. Developers can implement their own getters but they should be calling self::get() in order to retrieve the value. Essentially the getters defined by the developers would only ever be used as helper methods and will not be called internally at this stage. In other words, do not expect self::to_record() or self::from_record() to use them.
This is protected because it is only for raw low level access to the data fields. Note this function is named raw_get and not get_raw to avoid naming clashes with a property named raw.
string | $property | The property name. |
mixed |
|
finalprotectedinherited |
Data setter.
This is the main setter for all the properties. Developers can implement their own setters but they should always be calling self::set() in order to set the value. Essentially the setters defined by the developers are helper methods and will not be called internally at this stage. In other words do not expect self::to_record() or self::from_record() to use them.
This is protected because it is only for raw low level access to the data fields.
string | $property | The property name. |
mixed | $value | The value. |
$this |
|
finalinherited |
Load the data from the DB.
static |
|
staticinherited |
Check if a record exists by ID.
int | $id | Record ID. |
bool |
|
staticinherited |
Check if a records exists.
string | $select | |
array | $params |
bool |
|
finalinherited |
Saves the record to the database.
If this record has an ID, then self::update() is called, otherwise self::create() is called. Before and after hooks for create() or update() will be called appropriately.
void |
|
finalinherited |
Data setter.
This is the main setter for all the properties. Developers can implement their own setters (set_propertyname) and they will be called by this function. Custom setters should call internal_set() to finally set the value. Internally this is not used self::to_record() or self::from_record() because the data is not expected to be validated or changed when reading/writing raw records from the DB.
string | $property | The property name. |
$this |
coding_exception |
|
finalinherited |
Data setter for multiple properties.
Internally calls {
array | $values | Array of property => value elements |
$this |
|
finalinherited |
Create a DB record from this class.
Note that this does not use any custom getter because the data here is intended to represent what is stored in the database.
stdClass |
|
finalinherited |
Update the existing record in the DB.
bool | True on success. |
|
static |
Update from template.
Bulk update a lot of plans from a template
template | $template |
bool |
|
finalinherited |
Validates the data.
Developers can implement addition validation by defining a method as follows. Note that the method MUST return a lang_string() when there is an error, and true when the data is valid.
protected function validate_propertyname($value) { if ($value !== 'My expected value') { return new lang_string('invaliddata', 'error'); } return true }
It is OK to use other properties in your custom validation methods when you need to, however note they might not have been validated yet, so try not to rely on them too much.
Note that the validation methods should be protected. Validating just one field is not recommended because of the possible dependencies between one field and another,also the field ID can be used to check whether the object is being updated or created.
When validating foreign keys the persistent should only check that the associated model exists. The validation methods should not be used to check for a change in that relationship. The API method setting the attributes on the model should be responsible for that. E.g. On a course model, the method validate_categoryid will check that the category exists. However, if a course can never be moved outside of its category it would be up to the calling code to ensure that the category ID will not be altered.
array|true | Returns true when the validation passed, or an array of properties with errors. |
|
protected |
Validate the due date.
When setting a due date it must not exceed the DUEDATE_THRESHOLD.
int | $value | The due date. |
bool|lang_string |
|
protected |
Validate the template ID.
mixed | $value | The value. |
true|lang_string |
|
protected |
Validate the user ID.
int | $value |
true|lang_string |
|
finalprotectedinherited |
This function is used to verify that custom getters and setters are declared as protected.
Persistent properties should always be accessed via get('property') and set('property', 'value') which will call the custom getter or setter if it exists. We do not want to allow inconsistent access to the properties.