Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

Course completion critieria aggregation

Author: Aaron Barnes <aaronb@catalyst.net.nz>
Copyright: 2009 Catalyst IT Ltd
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 393 lines (13 kb)
Included or required:0 times
Referenced: 4 times
Includes or requires: 0 files

Defines 1 class

data_object:: (13 methods):
  __construct()
  load_optional_fields()
  fetch()
  fetch_all()
  fetch_helper()
  fetch_all_helper()
  update()
  delete()
  get_record_data()
  insert()
  update_from_db()
  set_properties()
  notify_changed()


Class: data_object  - X-Ref

A data abstraction object that holds methods and attributes

__construct($params = null, $fetch = true)   X-Ref
Constructor. Optionally (and by default) attempts to fetch corresponding row from DB.

If $fetch is not false, there are a few different things that can happen:
- true:
load corresponding row from the database, using $params as the WHERE clause

- DATA_OBJECT_FETCH_BY_KEY:
load corresponding row from the database, using only the $id in the WHERE clause (if set),
otherwise using the columns listed in $this->unique_fields.

- array():
load corresponding row from the database, using the columns listed in this array
in the WHERE clause

param: array   $params     required parameters and their values for this data object
param: mixed   $fetch      if false, do not attempt to fetch from the database, otherwise see notes

load_optional_fields()   X-Ref
Makes sure all the optional fields are loaded.

If id present (==instance exists in db) fetches data from db.
Defaults are used for new instances.

fetch($params)   X-Ref
Finds and returns a data_object instance based on params.

This function MUST be overridden by all deriving classes.

param: array $params associative arrays varname => value
return: data_object instance  of data_object or false if none found.

fetch_all($params)   X-Ref
Finds and returns all data_object instances based on params.

This function MUST be overridden by all deriving classes.

param: array $params associative arrays varname => value
return: array array of data_object instances or false if none found.

fetch_helper($table, $classname, $params)   X-Ref
Factory method - uses the parameters to retrieve matching instance from the DB.

param: string $table The table name to fetch from
param: string $classname The class that you want the result instantiated as
param: array $params Any params required to select the desired row
return: object Instance of $classname or false.

fetch_all_helper($table, $classname, $params)   X-Ref
Factory method - uses the parameters to retrieve all matching instances from the DB.

param: string $table The table name to fetch from
param: string $classname The class that you want the result instantiated as
param: array $params Any params required to select the desired row
return: mixed array of object instances or false if not found

update()   X-Ref
Updates this object in the Database, based on its object variables. ID must be set.

return: bool success

delete()   X-Ref
Deletes this object from the database.

return: bool success

get_record_data()   X-Ref
Returns object with fields and values that are defined in database

return: stdClass

insert()   X-Ref
Records this object in the Database, sets its id to the returned value, and returns that value.
If successful this function also fetches the new object data from database and stores it
in object properties.

return: int PK ID if successful, false otherwise

update_from_db()   X-Ref
Using this object's id field, fetches the matching record in the DB, and looks at
each variable in turn. If the DB has different data, the db's data is used to update
the object. This is different from the update() function, which acts on the DB record
based on the object.

return: bool True for success, false otherwise.

set_properties(&$instance, $params)   X-Ref
Given an associated array or object, cycles through each key/variable
and assigns the value to the corresponding variable in this object.

param: data_object $instance
param: array $params

notify_changed($deleted)   X-Ref
Called immediately after the object data has been inserted, updated, or
deleted in the database. Default does nothing, can be overridden to
hook in special behaviour.

param: bool $deleted Set this to true if it has been deleted.