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
|
2009-03-14 01:16:32 +01:00
|
|
|
if(Object::has_extension($this->owner->parentClass(), $this->class)) return;
|
|
|
|
|
|
|
|
if($fields = $this->extraStatics()) {
|
|
|
|
foreach($fields as $relation => $fields) {
|
|
|
|
if(in_array($relation, self::$decoratable_statics)) {
|
|
|
|
Object::set_static (
|
|
|
|
$this->owner->class,
|
|
|
|
$relation,
|
|
|
|
array_merge((array) Object::get_static($this->owner->class, $relation), $fields)
|
|
|
|
);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-14 01:16:32 +01:00
|
|
|
|
|
|
|
DataObject::$cache_has_own_table[$this->owner->class] = null;
|
|
|
|
DataObject::$cache_has_own_table_field[$this->owner->class] = 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
|
|
|
* 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-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
|
2009-02-02 00:49:53 +01:00
|
|
|
* by the decorator. By default, no changes are made. {@link DataObject->getCMSFields()}.
|
|
|
|
*
|
2008-10-03 18:21:09 +02:00
|
|
|
* 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
|
|
|
/**
|
2009-02-02 00:49:53 +01:00
|
|
|
* This function is used to provide modifications to the form used
|
|
|
|
* for front end forms. {@link DataObject->getFrontEndFields()}
|
2008-10-03 18:21:09 +02:00
|
|
|
*
|
|
|
|
* Caution: Use {@link FieldSet->push()} to add fields.
|
|
|
|
*
|
|
|
|
* @param FieldSet $fields FieldSet without TabSet nesting
|
|
|
|
*/
|
2009-02-02 00:49:53 +01:00
|
|
|
function updateFrontEndFields(FieldSet &$fields) {
|
2008-10-03 18:21:09 +02:00
|
|
|
}
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
/**
|
|
|
|
* This is used to provide modifications to the form actions
|
|
|
|
* used in the CMS. {@link DataObject->getCMSActions()}.
|
|
|
|
*
|
|
|
|
* @param FieldSet $actions FieldSet
|
|
|
|
*/
|
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'];
|
2009-02-02 00:49:53 +01:00
|
|
|
|
|
|
|
// if summary_fields were passed in numeric array,
|
|
|
|
// convert to an associative array
|
|
|
|
if($summary_fields && array_key_exists(0, $summary_fields)) {
|
|
|
|
$summary_fields = array_combine(array_values($summary_fields), array_values($summary_fields));
|
|
|
|
}
|
2008-09-05 01:10:20 +02:00
|
|
|
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
|
|
|
}
|
2009-03-14 01:16:32 +01:00
|
|
|
?>
|