2007-08-03 00:07:11 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Represents a set of widgets shown on a page.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage widgets
|
|
|
|
*/
|
2007-08-03 00:07:11 +02:00
|
|
|
class WidgetArea extends DataObject {
|
2009-02-02 00:49:53 +01:00
|
|
|
|
2007-08-03 00:07:11 +02:00
|
|
|
static $db = array();
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
static $has_one = array();
|
|
|
|
|
2007-08-03 00:07:11 +02:00
|
|
|
static $has_many = array(
|
|
|
|
"Widgets" => "Widget"
|
|
|
|
);
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
static $many_many = array();
|
|
|
|
|
|
|
|
static $belongs_many_many = array();
|
|
|
|
|
2009-09-07 05:28:23 +02:00
|
|
|
/**
|
|
|
|
* Used in template instead of {@link Widgets()}
|
|
|
|
* to wrap each widget in its controller, making
|
|
|
|
* it easier to access and process form logic
|
|
|
|
* and actions stored in {@link Widget_Controller}.
|
|
|
|
*
|
|
|
|
* @return DataObjectSet Collection of {@link Widget_Controller}
|
|
|
|
*/
|
|
|
|
function WidgetControllers() {
|
|
|
|
$controllers = new DataObjectSet();
|
2009-11-21 02:42:44 +01:00
|
|
|
// var_dump($this->Items());
|
|
|
|
foreach($this->ItemsToRender() as $widget) {
|
2009-09-07 05:28:23 +02:00
|
|
|
// find controller
|
|
|
|
$controllerClass = '';
|
|
|
|
foreach(array_reverse(ClassInfo::ancestry($widget->class)) as $widgetClass) {
|
|
|
|
$controllerClass = "{$widgetClass}_Controller";
|
|
|
|
if(class_exists($controllerClass)) break;
|
|
|
|
}
|
2009-09-14 07:16:34 +02:00
|
|
|
$controller = new $controllerClass($widget);
|
|
|
|
$controller->init();
|
|
|
|
$controllers->push($controller);
|
2009-09-07 05:28:23 +02:00
|
|
|
}
|
2009-11-21 02:42:44 +01:00
|
|
|
|
2009-09-07 05:28:23 +02:00
|
|
|
return $controllers;
|
|
|
|
}
|
|
|
|
|
2009-11-21 02:42:44 +01:00
|
|
|
function Items() {
|
|
|
|
return $this->Widgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ItemsToRender() {
|
|
|
|
return $this->Items();
|
|
|
|
}
|
|
|
|
|
2007-08-03 00:07:11 +02:00
|
|
|
function forTemplate() {
|
2008-11-04 03:21:09 +01:00
|
|
|
return $this->renderWith($this->class);
|
2007-08-03 00:07:11 +02:00
|
|
|
}
|
2009-11-02 03:00:52 +01:00
|
|
|
|
|
|
|
function onBeforeDelete() {
|
|
|
|
parent::onBeforeDelete();
|
|
|
|
foreach($this->Widgets() as $widget) {
|
|
|
|
$widget->delete();
|
|
|
|
}
|
|
|
|
}
|
2007-08-03 00:07:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|