Public Member Functions | |
__construct ($sourceId= '', $destId= '', $version=TSD::VERSION_LIVE) | |
Creates new relationship object. | |
approve () | |
Approve this relationship. | |
cancel () | |
Cancels pending changes to a relationship. | |
commit () | |
Commits relationship to database. | |
delete () | |
Marks relationship as DELETED. | |
getIdentifier () | |
Generates useful identifier for this relationship. | |
isValid () | |
Determines if relationship is valid for the database. | |
Static Public Member Functions | |
static | getList ($constraints=array(), $limit=array(), $order=array(), $cnt=false) |
Retrieves list of relationships based on criteria. | |
static | getRelated ($itemUrlOrId, $mode=TSD::MODE_LIVE, $cnt=false, $limit=array(), $order=array()) |
Retrieves list of relationships for a given resource. |
A relationship between two resources indicates that they have some meaningful connection. For example, in Interactivate, related resources will be listed when viewing an activity or lesson. The relationship, at the very least, simply names the two resources that are being related. You can also provide a description of that relationship (which can also serve as a "reason" for the relationship).
To create a new relationship, first construct either an empty relationship object or create one with the desired resource IDs. Note that the first resource ID (the source ID) must be strictly less than the second resource ID (the dest ID):
# create empty relation and fill it in later $rel = new TSDRelation(); $rel->sourceId = 37; $rel->destId = 48; $rel->description = "Important relationship"; $rel->commit();
# OR $rel = new TSDRelation(37, 48); # ... and the rest is the sameOnce a relationship is created, it must be approved (or canceled), using the approve() (and cancel()) method.
You can modify an existing relationship like so:
$rel = new TSDRelation(37, 48, TSD::VERSION_DEV); $rel->description = 'a new description'; $rel->commit(); $rel->approve();Note that you must specify that the relationship be a TSD::VERSION_DEV relationship, since you cannot modify live versions.
Attributes:
id
[int]: not relevant to the user (-)sourceId
[int]: first of two resource IDs that define the relationship (edit)destId
[int]: second of two resource IDs that define the relationship (edit)description
[string]: description of the relationship (edit)version
[string]: version of this relationship (either TSD::VERSION_DEV or TSD::VERSION_LIVE) (-)status
[string]: status of the version, relevant only for dev versions; is one of TSD::STATUS_NEW, TSD::STATUS_DELETED, TSD::STATUS_CHANGED, TSD::STATUS_APPROVED (live versions are always approved) (-) TSDRelation::__construct | ( | $ | sourceId = '' , |
|
$ | destId = '' , |
|||
$ | version = TSD::VERSION_LIVE | |||
) |
Creates new relationship object.
There are several ways to invoke this constructor:
$sourceId | [int]: source ID of relationship | |
$destId | [int]: dest ID of relationship | |
$version | [string]: which version to instantiate, one of TSD::VERSION_DEV, TSD::VERSION_LIVE |
TSDRelation::approve | ( | ) |
Approve this relationship.
When a relationship is approved, a LIVE version is either created or updated based on the DEV version. If the relationship to be approved is marked as DELETED, then both the DEV version and the LIVE version will be deleted. You cannot approve LIVE versions. You must have the 'approve' permission to approve relationships.
TSDRelation::cancel | ( | ) |
Cancels pending changes to a relationship.
If a DEV relationship has been modified, marked as DELETED, or created (and thus marked as NEW) but not yet approved, then you can cancel those changes and restore the DEV relationship to the value of the LIVE version, or, in the case of a DEV relationship marked as NEW, simply remove the relationship altogether. You must have the 'approve' permission to cancel changes.
TSDRelation::commit | ( | ) |
Commits relationship to database.
If relationship is already in the database, then its information is merely updated. Otherwise, relationship is added to database. New relationships are always marked as DEV and NEW. You cannot commit LIVE relationships. Instead, create a TSDRelation object for the DEV version and then modify that, commit it and then approve it. You cannot change the source and destination ID for a relationship. That would entail creating a new relationship altogether.
TSDRelation::delete | ( | ) |
Marks relationship as DELETED.
You can only delete DEV versions. If the version is NEW, then it is simply removed from the DB. You must have the 'align' permission to delete relationships.
TSDRelation::getIdentifier | ( | ) |
Generates useful identifier for this relationship.
The identifier can be used as a nice way to represent the relationship in text. For this class, the identifier is guaranteed to be unique. Currently, it is the source ID and dest ID as a tuple surrounded by parentheses (e.g.: "(37, 48)")
static TSDRelation::getList | ( | $ | constraints = array() , |
|
$ | limit = array() , |
|||
$ | order = array() , |
|||
$ | cnt = false | |||
) | [static] |
Retrieves list of relationships based on criteria.
See Guide to Database Constraints for more information on how to build the parameters to this method.
$constraints | [array]: additional constraints on the result set | |
$limit | [array]: parameters for the LIMIT clause of the query | |
$order | [array]: how to order the results | |
$cnt | [boolean]: whether to return the number of results (if true) or the results themselves (if false, the default) |
static TSDRelation::getRelated | ( | $ | itemUrlOrId, | |
$ | mode = TSD::MODE_LIVE , |
|||
$ | cnt = false , |
|||
$ | limit = array() , |
|||
$ | order = array() | |||
) | [static] |
Retrieves list of relationships for a given resource.
$itemUrlOrId | [mixed]: specifies the resource for which to retrieve the list of relationships | |
$mode | [int]: only include relationships that have this mode (see TSD::MODE_* constants) | |
$cnt | [boolean]: if true, only return a count of how many relationships would be returned, otherwise, return the full listing | |
$limit | [array]: set limit on number of items returned (see Guide to Database Constraints) | |
$order | [array]: set the ordering on the items returned (see Guide to Database Constraints) |
TSDRelation::isValid | ( | ) |
Determines if relationship is valid for the database.
A relationship is valid if the following requirements are met: