2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-06-18 00:21:43 +02:00
|
|
|
* Plug-ins for additional functionality in your DataObjects.
|
|
|
|
*
|
|
|
|
* Note: DataObjectDecorators are not actually Decorators in the GoF Design Patterns sense of the
|
|
|
|
* word. A better name for this class would be DataExtension. However, in the interests of
|
|
|
|
* backward compatibility we haven't renamed the class.
|
2007-09-16 18:55:47 +02:00
|
|
|
*
|
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.
|
|
|
|
*
|
2009-05-26 02:52:54 +02:00
|
|
|
* Keys are the static names, and the values are whether or not the value is an array that should
|
|
|
|
* be merged.
|
|
|
|
*
|
2008-03-10 22:28:35 +01:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $decoratable_statics = array(
|
2009-05-26 02:52:54 +02:00
|
|
|
'db' => true,
|
|
|
|
'has_one' => true,
|
|
|
|
'indexes' => true,
|
|
|
|
'defaults' => true,
|
|
|
|
'has_many' => true,
|
|
|
|
'many_many' => true,
|
|
|
|
'belongs_many_many' => true,
|
|
|
|
'many_many_extraFields' => true,
|
|
|
|
'searchable_fields' => true,
|
|
|
|
'api_access' => false,
|
2008-03-10 22:28:35 +01:00
|
|
|
);
|
|
|
|
|
2009-05-26 05:46:04 +02:00
|
|
|
private static $extra_statics_loaded = array();
|
|
|
|
|
2009-03-31 21:31:21 +02:00
|
|
|
/**
|
2009-06-17 09:01:28 +02:00
|
|
|
* Load the extra static definitions for the given extension
|
|
|
|
* class name, called by {@link Object::add_extension()}
|
|
|
|
*
|
|
|
|
* @param string $class Class name of the owner class (or owner base class)
|
|
|
|
* @param string $extension Class name of the extension class
|
2009-03-31 21:31:21 +02:00
|
|
|
*/
|
2009-06-17 09:01:28 +02:00
|
|
|
public static function load_extra_statics($class, $extension) {
|
|
|
|
if(!empty(self::$extra_statics_loaded[$class][$extension])) return;
|
|
|
|
self::$extra_statics_loaded[$class][$extension] = true;
|
|
|
|
|
2009-06-19 02:58:02 +02:00
|
|
|
// @deprecated 2.4 - use extraStatics() now, not extraDBFields()
|
|
|
|
if(method_exists($extension, 'extraDBFields')) {
|
|
|
|
user_error('DataObjectDecorator::extraDBFields() is deprecated. Please use extraStatics() instead.', E_USER_NOTICE);
|
|
|
|
$extraStaticsMethod = 'extraDBFields';
|
|
|
|
} else {
|
|
|
|
$extraStaticsMethod = 'extraStatics';
|
|
|
|
}
|
2009-03-31 21:31:21 +02:00
|
|
|
|
2009-05-26 05:46:04 +02:00
|
|
|
// If the extension has been manually applied to a subclass, we should ignore that.
|
2009-06-17 09:01:28 +02:00
|
|
|
if(Object::has_extension(get_parent_class($class), $extension)) return;
|
|
|
|
|
2009-06-19 02:58:02 +02:00
|
|
|
$statics = call_user_func(array($extension, $extraStaticsMethod));
|
|
|
|
|
2009-06-17 09:01:28 +02:00
|
|
|
if($statics) {
|
|
|
|
foreach($statics as $name => $newVal) {
|
|
|
|
if(isset(self::$decoratable_statics[$name])) {
|
|
|
|
|
2009-05-26 02:52:54 +02:00
|
|
|
// Array to be merged
|
2009-06-17 09:01:28 +02:00
|
|
|
if(self::$decoratable_statics[$name]) {
|
2009-08-11 10:35:14 +02:00
|
|
|
$origVal = Object::uninherited_static($class, $name);
|
2009-05-26 02:52:54 +02:00
|
|
|
// Can't use add_static_var() here as it would merge the array rather than replacing
|
2009-08-11 10:35:14 +02:00
|
|
|
Object::set_static($class, $name, array_merge((array)$origVal, $newVal));
|
2009-06-17 09:01:28 +02:00
|
|
|
|
|
|
|
// Value to be overwritten
|
2009-05-26 02:52:54 +02:00
|
|
|
} else {
|
2009-06-17 09:01:28 +02:00
|
|
|
Object::set_static($class, $name, $newVal);
|
2009-05-26 02:52:54 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2009-03-14 01:16:32 +01:00
|
|
|
|
2009-06-17 09:01:28 +02:00
|
|
|
DataObject::$cache_has_own_table[$class] = null;
|
|
|
|
DataObject::$cache_has_own_table_field[$class] = null;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2008-11-02 01:36:57 +01: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-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.
|
|
|
|
*
|
|
|
|
* @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() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return array();
|
|
|
|
}
|
2009-06-17 09:01:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
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
|
|
|
?>
|