atkOneToManyRelation atkOneToManyRelation(
String
$name, String
$destination, [mixed
$refKey = ""], [int
$flags = 0]
)
|
|
Default constructor.
Example: Suppose a department has many employees. To edit the list of employees in a department, this relationship can be built like this, in the department node:
Parameters:
|
String |
$name: |
The unique name of this relation within a node. In contrast with most other attributes, the name does not correspond to a database field. (Because in one2many relations, the databasefield that stores the link, is in the destination node and not in the owner node). |
|
String |
$destination: |
The node to which the relationship is made (in module.nodename notation). |
|
mixed |
$refKey: |
For regular oneToMany relationships, $refKey is name of the referential key in the destination node. In the case of multi-foreign key relationships, $refKey can be an array of fields. |
|
int |
$flags: |
Attribute flags that influence this attributes' behavior. |
atkDataGrid createGrid(
array
$record, string
$mode, string
$action, [boolean
$useSession = true]
)
|
|
Create the datagrid for the edit and display actions. The datagrid is configured with the correct node filter, excludes etc.
The datagrid uses for both the edit and display actions the partial_grid method to update it's view.
Parameters:
|
array |
$record: |
the record |
|
string |
$mode: |
the mode |
|
string |
$action: |
the action |
|
boolean |
$useSession: |
use session? |
API Tags:
| Return: | grid |
| Access: | protected |
boolean delete(
array
$record
)
|
|
The delete method is called by the framework to inform the attribute that the master record is deleted.
Note that the framework only calls the method when the AF_CASCADE_DELETE flag is set. When calling this method, all detail records belonging to the master record are deleted.
Parameters:
|
array |
$record: |
The record that is deleted. |
API Tags:
| Return: | true if cleanup was successful, false otherwise. |
Redefinition of:
- atkAttribute::delete()
- The delete method is called by the framework to inform the attribute that a record is deleted.
Are we allowed to delete a record?
API Tags:
| Return: | bool if allowed or string with not allowed message |
Redefinition of:
- atkAttribute::deleteAllowed()
- Check if delete of the record is allowed.
boolean destinationHasRelation(
)
|
|
Determine the type of the foreign key on the other side.
On the other side of a oneToManyRelation (in the destination node), there may be a regular atkAttribute for the referential key, or an atkManyToOneRelation pointing back at the source. This method discovers which of the 2 cases we are dealing with.
API Tags:
| Return: | True if the foreign key on the other side is a relation, false if not. |
String display(
array
$record, [String
$mode = "list"]
)
|
|
Returns a displayable string for this value, to be used in HTML pages.
The atkOneToManyRelation displays a list of detail records in "view" mode, in the form of a read-only data grid. In "list" mode, a plain list of detail record descriptors is displayed.
Parameters:
|
array |
$record: |
The record that holds the value for this attribute |
|
String |
$mode: |
The display mode ("view" for viewpages, or "list" for displaying in recordlists) |
API Tags:
| Return: | HTML String |
| Access: | public |
Redefinition of:
- atkRelation::display()
- Return a displayable string for a record.
String edit(
[array
$record = ""], [String
$fieldprefix = ""], [String
$mode = '']
)
|
|
Returns a piece of html code that can be used in a form to edit this attribute's value.
The atkOneToManyRelation's edit method returns a recordlist in which detail records can be removed, added and edited.
Parameters:
|
array |
$record: |
The record that holds the value for this attribute. |
|
String |
$fieldprefix: |
The fieldprefix to put in front of the name of any html form element for this attribute. |
|
String |
$mode: |
The mode we're in ('add' or 'edit') |
API Tags:
| Return: | A piece of htmlcode for editing this attribute |
| Access: | public |
Redefinition of:
- atkAttribute::edit()
- Returns a piece of html code that can be used in a form to edit this attribute's value.
String editFooter(
[array
$record = NULL], [array
$childrecords = NULL]
)
|
|
Retrieve footer for the recordlist.
The regular atkOneToManyRelation has no implementation for this method, but it may be overridden in derived classes to add extra information (text, links, whatever) to the bottom of the attribute, just after the recordlist. This is similar to the adminFooter() method in atkNode.
Parameters:
|
array |
$record: |
The master record that is being edited. |
|
array |
$childrecords: |
The childrecords in this master/detail relationship. |
API Tags:
| Return: | a String to be added at the bottom of the recordlist. |
String editHeader(
[array
$record = NULL], [array
$childrecords = NULL]
)
|
|
Retrieve header for the recordlist.
The regular atkOneToManyRelation has no implementation for this method, but it may be overridden in derived classes to add extra information (text, links, whatever) to the top of the attribute, right before the recordlist. This is similar to the adminHeader() method in atkNode.
Parameters:
|
array |
$record: |
The master record that is being edited. |
|
array |
$childrecords: |
The childrecords in this master/detail relationship. |
API Tags:
| Return: | a String to be added to the header of the recordlist. |
string getAddFilterString(
array
$record
)
|
|
Uses the given record to create an add filter string.
Parameters:
API Tags:
Attempts to get a translated label which can be used when composing an "add" link
API Tags:
| Return: | Localised "add" label |
Redefinition of:
- atkRelation::getAddLabel()
- Attempts to get a translated label which can be used when composing an "add" link
void getAddURL(
[
$params = array()]
)
|
|
Parameters:
API Tags:
Get the exclude fields for the grid
API Tags:
| Return: | with exclude fields |
String getJoinCondition(
&$query, [String
$ownerAlias = ""], [String
$destAlias = ""], atkQuery
$query
)
|
|
Returns the condition (SQL) that should be used when we want to join an owner node with the destination node of the atkOneToManyRelation.
Parameters:
|
atkQuery |
$query: |
The query object. |
|
String |
$ownerAlias: |
The owner table alias. |
|
String |
$destAlias: |
The destination table alias. |
|
|
&$query: |
|
API Tags:
| Return: | SQL string for joining the owner with the destination. |
Redefinition of:
- atkRelation::getJoinCondition()
- Returns the condition (SQL) that should be used when we want to join a relation's owner node with the parent node.
Get the owner fields
API Tags:
| Return: | Array or String with ownerfield(s) |
void getPartialSaveUrl(
)
|
|
assamble the partial save handler url
this allows dynamically updating the attribute
API Tags:
String getSearchCondition(
&$query, String
$table, mixed
$value, String
$searchmode, atkQuery
$query
)
|
|
Creates a searchcondition for the field, was once part of searchCondition, however, searchcondition() also immediately adds the search condition.
Parameters:
|
atkQuery |
$query: |
The query object where the search condition should be placed on |
|
String |
$table: |
The name of the table in which this attribute is stored |
|
mixed |
$value: |
The value the user has entered in the searchbox |
|
String |
$searchmode: |
The searchmode to use. This can be any one of the supported modes, as returned by this attribute's getSearchModes() method. |
|
|
&$query: |
|
API Tags:
| Return: | The searchcondition to use. |
Redefinition of:
- atkAttribute::getSearchCondition()
- Creates a searchcondition for the field, was once part of searchCondition, however, searchcondition() also immediately adds the search condition.
Retrieve the list of searchmodes supported by the attribute.
Note that not all modes may be supported by the database driver. Compare this list to the one returned by the databasedriver, to determine which searchmodes may be used.
API Tags:
| Return: | List of supported searchmodes |
Redefinition of:
- atkRelation::getSearchModes()
- Retrieve the searchmodes supported by the relation.
string getSessionAddFakeId(
)
|
|
Return a fake ID for adding to the session.
We use a high negative number because we have to sneak this in as if it's a REAL id for the owner, tricking MTOs in the destination that point back to us into thinking they already have an id. But we also have to make sure it's recognizable, so when we persist the records from the session to the database, then we can set the proper id.
API Tags:
string getSessionStoreKey(
)
|
|
Return the key to use when storing records for the OTM destination in the session if the OTM is used in add mode.
API Tags:
String hide(
[
$record = ''], [
$fieldprefix = '']
)
|
|
Returns a piece of html code for hiding this attribute in an HTML form.
Because the oneToMany has nothing to hide, we override the default hide() implementation with a dummy method.
Parameters:
API Tags:
Redefinition of:
- atkAttribute::hide()
- Returns a piece of html code for hiding this attribute in an HTML form, while still posting its value. (<input type="hidden">)
bool isEmpty(
$record, array
&$record
)
|
|
Override isEmpty function - in a oneToMany relation we should check if the relation contains any records. When there aren't any, the relation is empty, otherwise it isn't
Parameters:
|
array |
&$record: |
The record to check |
|
|
$record: |
|
API Tags:
| Return: | true if a destination record is present. False if not. |
Redefinition of:
- atkRelation::isEmpty()
- Check if the relation is empty
array load(
&$db, array
$record, [String
$mode = ""], [bool
$paging = false], atkDb
$db
)
|
|
Retrieve detail records from the database.
Called by the framework to load the detail records.
Parameters:
|
atkDb |
$db: |
The database used by the node. |
|
array |
$record: |
The master record |
|
String |
$mode: |
The mode for loading (admin, select, copy, etc) |
|
bool |
$paging: |
divide the result records on multiple pages ($config_recordsperpage) |
|
|
&$db: |
|
API Tags:
| Return: | Recordset containing detailrecords, or NULL if no detail records are present. Note: when $mode is edit, this method will always return NULL. This is a framework optimization because in edit pages, the records are loaded on the fly. |
Modify grid.
Parameters:
API Tags:
void partial_addorcopy_dialog(
)
|
|
Add or copy dialog.
void partial_addorcopy_process(
)
|
|
Process add or copy action.
void partial_add_dialog(
)
|
|
Add dialog.
void partial_add_process(
)
|
|
Process add dialog save action.
void partial_edit_dialog(
)
|
|
Edit dialog.
void partial_edit_process(
)
|
|
Process edit dialog update action.
Updates the datagrid for the edit and display actions.
API Tags:
| Return: | grid html |
| Access: | public |
void searchCondition(
&$query, String
$table, mixed
$value, String
$searchmode, [string
$fieldaliasprefix = ''], atkQuery
$query
)
|
|
Adds a search condition for a given search value
Parameters:
|
atkQuery |
$query: |
The query to which the condition will be added. |
|
String |
$table: |
The name of the table in which this attribute is stored |
|
mixed |
$value: |
The value the user has entered in the searchbox |
|
String |
$searchmode: |
The searchmode to use. This can be any one of the supported modes, as returned by this attribute's getSearchModes() method. |
|
string |
$fieldaliasprefix: |
optional prefix for the fieldalias in the table |
|
|
&$query: |
|
Redefinition of:
- atkAttribute::searchCondition()
- Creates a search condition for a given search value, and adds it to the query that will be used for performing the actual search.
void setFooter(
String
$name
)
|
|
Set footer generation function name.
Parameters:
|
String |
$name: |
The footder generation function name. |
void setGridExcludes(
array
$excludes
)
|
|
Set the exclude fields for the grid
Parameters:
void setHeader(
String
$name
)
|
|
Set header generation function name.
Parameters:
|
String |
$name: |
The header generation function name. |
void setOwnerFields(
array
$ownerfields
)
|
|
Set the ownerfields
Parameters:
void setUseFilterForAddLink(
boolean
$useFilter
)
|
|
Use destination filter for auto add link?
Parameters:
|
boolean |
$useFilter: |
use destination filter for add link? |
void setUseFilterForEditLink(
boolean
$useFilter
)
|
|
Use destination filter for edit link (edit button)?
Parameters:
|
boolean |
$useFilter: |
use destnation filter for edit link (edit button)? |
void setUseRefKeyForFilter(
bool
$useRefKey
)
|
|
Use referential key for filtering the records. If you disable this only the explicitly set destination filter will be used.
Parameters:
API Tags:
void smartSearchCondition(
Integer
$id, Integer
$nr, Array
$path,
&$query, String
$ownerAlias, Mixed
$value, String
$mode, atkQuery
$query
)
|
|
Creates a smart search condition for a given search value, and adds it to the query that will be used for performing the actual search.
Parameters:
|
Integer |
$id: |
The unique smart search criterium identifier. |
|
Integer |
$nr: |
The element number in the path. |
|
Array |
$path: |
The remaining attribute path. |
|
atkQuery |
$query: |
The query to which the condition will be added. |
|
String |
$ownerAlias: |
The owner table alias to use. |
|
Mixed |
$value: |
The value the user has entered in the searchbox. |
|
String |
$mode: |
The searchmode to use. |
|
|
&$query: |
|
Redefinition of:
- atkAttribute::smartSearchCondition()
- Creates a smart search condition for a given search value, and adds it to the query that will be used for performing the actual search.
boolean store(
atkDb
$db, array
$record, string
$mode
)
|
|
Store detail records in the database.
For onetomanyrelation, this function does not have much use, since it stores records using its 'add link'. There are however two modes that use this:
- 'copy' mode
The copyDb function, to clone detail records.
- 'add' mode
When the OTM was used in add mode, we have to transfer
the records stored in the session to the database.
other than those this method does not do anything.
Parameters:
|
atkDb |
$db: |
The database used by the node. |
|
array |
$record: |
The master record which has the detail records embedded. |
|
string |
$mode: |
The mode we're in ("add", "edit", "copy") |
API Tags:
| Return: | true if store was successful, false otherwise. |
bool storeAdd(
atkDb
$db, array
$record, string
$mode
)
|
|
Persist records from the session (in add mode) to the database.
Parameters:
|
atkDb |
$db: |
|
|
array |
$record: |
|
|
string |
$mode: |
|
API Tags:
bool storeCopy(
atkDb
$db, array
$record, string
$mode
)
|
|
Copy detail records.
Parameters:
|
atkDb |
$db: |
Datbase connection to use |
|
array |
$record: |
Owner record |
|
string |
$mode: |
Mode ('copy') |
API Tags:
string translateSelector(
string
$selector
)
|
|
Here we check if the selector is on the owner or on the destination if it's on the destination, we leave it alone.
Otherwise we translate it back to the destination.
Parameters:
|
string |
$selector: |
the selector we have to translate |
API Tags:
Information Tags:
| Todo: | when we translate the selector, we get the last used refKey but how do we know what is the right one? |
void updateSessionAddFakeId(
&$row, mixed
$id, array
$record, array
$row
)
|
|
Recursive method to look for the fake id in the record and replace it with the proper id.
Parameters:
|
array |
$row: |
Destination record |
|
mixed |
$id: |
Fake id to look for |
|
array |
$record: |
Owner record |
|
|
&$row: |
|
API Tags:
void _addAddToEditOutput(
&$output, Array
$myrecords, array
$record, [
$mode = ""], [
$fieldprefix = ""], String
$output
)
|
|
Adds the 'add' option to the onetomany, either integrated or as a link
Parameters:
|
String |
$output: |
The HTML output of the edit function |
|
Array |
$myrecords: |
The records that are loaded into the recordlist |
|
array |
$record: |
The master record that is being edited. |
|
|
&$output: |
|
|
|
$mode: |
|
|
|
$fieldprefix: |
|
string _addTablePrefix(
string
$columnName, [string
$destAlias = '']
)
|
|
Prefix the passed column name with the table name if there is no prefix in the column name yet.
Parameters:
|
string |
$columnName: |
|
|
string |
$destAlias: |
|
void _callSearchConditionOnDestField(
atkQuery
&$query, String
$table, mixed
$value, mixed
$searchmode, String
$field, String
$reftable
)
|
|
Calls searchCondition on an attribute in the destination
To hook the destination attribute on the query
Parameters:
|
atkQuery |
&$query: |
The query object |
|
String |
$table: |
The table to search on |
|
mixed |
$value: |
The value to search |
|
mixed |
$searchmode: |
The mode used when searching |
|
String |
$field: |
The name of the attribute |
|
String |
$reftable: |
|
String _getAddLink(
Array
$myrecords, Array
$record, [bool
$saveform = true], [
$mode = ""], [
$fieldprefix = ""]
)
|
|
Internal function to get the add link for a atkOneToManyRelation
Parameters:
|
Array |
$myrecords: |
The load of all attributes (see comment in edit() code) |
|
Array |
$record: |
The record that holds the value for this attribute. |
|
bool |
$saveform: |
Save the form values? |
|
|
$mode: |
|
|
|
$fieldprefix: |
|
API Tags:
| Return: | The link to add records to the onetomany |
string _getDialogAddLink(
array
$record, string
$action, [
$params = array()]
)
|
|
Get the add link when using a dialog
Parameters:
|
array |
$record: |
|
|
string |
$action: |
|
|
|
$params: |
|
API Tags:
| Return: | The dialog add link html-code |
String _getEmbeddedButtons(
)
|
|
Get the buttons for the embedded mode of the onetomany relation.
API Tags:
Information Tags:
| Todo: | Move this to a template |
array _getFilterElements(
array
$record
)
|
|
Get filter elements
Parameters:
API Tags:
| Return: | Array with filter elements |
String _getLoadWhereClause(
array
$record
)
|
|
Create the where clause for the referential key that is used to retrieve the destination records.
Parameters:
|
array |
$record: |
The master record |
API Tags:
| Return: | SQL where clause |
| Access: | private |
String _getNestedAddLink(
Array
$myrecords, Array
$record, [bool
$saveform = true], [
$fieldprefix = ''], [
$params = array()]
)
|
|
Internal function to get the add link for a atkOneToManyRelation.
Parameters:
|
Array |
$myrecords: |
The load of all attributes (see comment in edit() code) |
|
Array |
$record: |
The record that holds the value for this attribute. |
|
bool |
$saveform: |
Save the values of the form? |
|
|
$fieldprefix: |
|
|
|
$params: |
|
API Tags:
| Return: | The link to add records to the onetomany |
Define a dummy function to use as a dummy handler function in load() below
API Tags: