2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2007-09-16 18:55:47 +02:00
|
|
|
* Plug-ins for additional functionality in your DataObjects
|
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* DataObject decorators add extra functionality to your data objects.
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-11-02 21:01:49 +01:00
|
|
|
abstract class DataObjectDecorator extends Extension {
|
2007-09-16 02:20:31 +02:00
|
|
|
|
2008-03-10 22:28:35 +01:00
|
|
|
/**
|
|
|
|
* Statics on a {@link DataObject} subclass
|
|
|
|
* which can be decorated onto. This list is
|
|
|
|
* limited for security and performance reasons.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $decoratable_statics = array(
|
|
|
|
'db',
|
|
|
|
'has_one',
|
|
|
|
'indexes',
|
|
|
|
'defaults',
|
|
|
|
'has_many',
|
|
|
|
'many_many',
|
|
|
|
'belongs_many_many',
|
|
|
|
'many_many_extraFields',
|
|
|
|
'searchable_fields',
|
|
|
|
);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-11-02 01:36:57 +01:00
|
|
|
* Load the extra database fields defined in extraStatics.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-11-02 01:36:57 +01:00
|
|
|
function loadExtraStatics() {
|
2008-08-12 04:51:33 +02:00
|
|
|
// Don't apply DB fields if the parent object has this extension too
|
|
|
|
if(singleton(get_parent_class($this->owner))->extInstance($this->class)) return;
|
|
|
|
|
2008-11-02 01:36:57 +01:00
|
|
|
$fields = $this->extraStatics();
|
2007-07-19 12:40:28 +02:00
|
|
|
$className = $this->owner->class;
|
2007-09-16 18:55:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($fields) {
|
|
|
|
foreach($fields as $relationType => $fields) {
|
2008-03-10 22:28:35 +01:00
|
|
|
if(in_array($relationType, self::$decoratable_statics)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
eval("$className::\$$relationType = array_merge((array){$className}::\$$relationType, (array)\$fields);");
|
2008-04-26 08:52:36 +02:00
|
|
|
$this->owner->set_stat($relationType, eval("return $className::\$$relationType;"));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-09-30 02:20:30 +02:00
|
|
|
|
|
|
|
// clear previously set caches from DataObject->hasOwnTableDatabaseField()
|
|
|
|
$this->owner->set_uninherited('_cache_hasOwnTableDatabaseField', null);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-02 01:36:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated 2.3 Use loadExtraStatics()
|
|
|
|
*/
|
|
|
|
function loadExtraDBFields() {
|
|
|
|
return $this->loadExtraStatics();
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-16 18:55:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-16 18:55:47 +02:00
|
|
|
* Edit the given query object to support queries for this extension
|
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param SQLQuery $query Query to augment.
|
|
|
|
*/
|
2007-08-16 08:32:49 +02:00
|
|
|
function augmentSQL(SQLQuery &$query) {
|
|
|
|
}
|
2007-09-16 02:20:31 +02:00
|
|
|
|
2007-09-16 18:55:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Update the database schema as required by this extension.
|
|
|
|
*/
|
2007-08-16 08:32:49 +02:00
|
|
|
function augmentDatabase() {
|
|
|
|
}
|
2008-08-11 04:25:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Augment a write-record request.
|
|
|
|
*
|
|
|
|
* @param SQLQuery $manipulation Query to augment.
|
|
|
|
*/
|
|
|
|
function augmentWrite(&$manipulation) {
|
|
|
|
}
|
2008-11-07 13:18:35 +01:00
|
|
|
|
|
|
|
function onBeforeWrite() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAfterWrite() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBeforeDelete() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAfterDelete() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function requireDefaultRecords() {
|
|
|
|
}
|
2007-09-16 02:20:31 +02:00
|
|
|
|
2008-11-07 13:18:35 +01:00
|
|
|
function populateDefaults() {
|
|
|
|
}
|
|
|
|
|
|
|
|
function can($member) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function canEdit($member) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function canDelete($member) {
|
|
|
|
}
|
|
|
|
|
|
|
|
function canCreate($member) {
|
|
|
|
}
|
2007-09-16 18:55:47 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-16 18:55:47 +02:00
|
|
|
* Define extra database fields
|
|
|
|
*
|
|
|
|
* Return a map where the keys are db, has_one, etc, and the values are
|
|
|
|
* additional fields/relations to be defined.
|
2008-04-09 13:28:32 +02:00
|
|
|
*
|
|
|
|
* Note: please ensure that the static variable that you are overloading is explicitly defined on the class that
|
|
|
|
* you are extending. For example, we have added static $has_one = array() to the Member definition, so that we
|
|
|
|
* can add has_one relationships to Member with decorators.
|
|
|
|
*
|
|
|
|
* If you forget to do this, db/build won't create the new relation. Don't blame us, blame PHP! ;-)
|
2007-09-16 18:55:47 +02:00
|
|
|
*
|
|
|
|
* @return array Returns a map where the keys are db, has_one, etc, and
|
|
|
|
* the values are additional fields/relations to be defined.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-11-02 01:36:57 +01:00
|
|
|
function extraStatics() {
|
|
|
|
return $this->extraDBFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated 2.3 Use extraStatics()
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function extraDBFields() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-09-16 18:55:47 +02:00
|
|
|
* This function is used to provide modifications to the form in the CMS
|
2008-10-03 18:21:09 +02:00
|
|
|
* by the decorator. By default, no changes are made.
|
|
|
|
* Please consider using {@link updateFormFields()} to globally add
|
|
|
|
* formfields to the record. The method {@link updateCMSFields()}
|
|
|
|
* should just be used to add or modify tabs, or fields which
|
|
|
|
* are specific to the CMS-context.
|
|
|
|
*
|
|
|
|
* Caution: Use {@link FieldSet->addFieldToTab()} to add fields.
|
2007-09-16 18:55:47 +02:00
|
|
|
*
|
2008-10-03 18:21:09 +02:00
|
|
|
* @param FieldSet $fields FieldSet with a contained TabSet
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function updateCMSFields(FieldSet &$fields) {
|
|
|
|
}
|
2008-08-27 06:11:58 +02:00
|
|
|
|
2008-10-03 18:21:09 +02:00
|
|
|
/**
|
|
|
|
* This function is used to provide modifications to the form in the CMS
|
|
|
|
* by the decorator.
|
|
|
|
*
|
|
|
|
* Caution: Use {@link FieldSet->push()} to add fields.
|
|
|
|
*
|
|
|
|
* @param FieldSet $fields FieldSet without TabSet nesting
|
|
|
|
*/
|
|
|
|
function updateFormFields(FieldSet &$fields) {
|
|
|
|
}
|
|
|
|
|
2008-11-07 13:18:35 +01:00
|
|
|
function updateCMSActions(FieldSet &$actions) {
|
|
|
|
}
|
|
|
|
|
2008-08-27 06:11:58 +02:00
|
|
|
/**
|
|
|
|
* this function is used to provide modifications to the summary fields in CMS
|
|
|
|
* by the decorator
|
|
|
|
* By default, the summaryField() of its owner will merge more fields defined in the decorator's
|
|
|
|
* $extra_fields['summary_fields']
|
|
|
|
*/
|
|
|
|
function updateSummaryFields(&$fields){
|
2008-11-02 01:36:57 +01:00
|
|
|
$extra_fields = $this->extraStatics();
|
2008-09-05 01:10:20 +02:00
|
|
|
if(isset($extra_fields['summary_fields'])){
|
|
|
|
$summary_fields = $extra_fields['summary_fields'];
|
|
|
|
if($summary_fields) $fields = array_merge($fields, $summary_fields);
|
|
|
|
}
|
2008-08-27 06:11:58 +02:00
|
|
|
}
|
|
|
|
|
2008-10-28 04:03:16 +01:00
|
|
|
/**
|
|
|
|
* this function is used to provide modifications to the fields labels in CMS
|
|
|
|
* by the decorator
|
|
|
|
* By default, the fieldLabels() of its owner will merge more fields defined in the decorator's
|
|
|
|
* $extra_fields['field_labels']
|
|
|
|
*/
|
|
|
|
function updateFieldLabels(&$lables){
|
2008-11-02 01:36:57 +01:00
|
|
|
$extra_fields = $this->extraStatics();
|
2008-10-28 04:03:16 +01:00
|
|
|
if(isset($extra_fields['field_labels'])){
|
|
|
|
$field_labels = $extra_fields['field_labels'];
|
|
|
|
if($field_labels) $lables = array_merge($lables, $field_labels);
|
|
|
|
}
|
|
|
|
}
|
2008-12-17 23:38:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear any internal caches.
|
|
|
|
*/
|
|
|
|
function flushCache() {
|
|
|
|
}
|
2008-11-02 00:00:50 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-08-12 04:51:33 +02:00
|
|
|
?>
|