MINOR Adding docblocks for class methods.

This commit is contained in:
Stig Lindqvist 2012-10-06 10:47:26 +13:00
parent c2788985e7
commit 135792bd96
4 changed files with 205 additions and 33 deletions

View File

@ -4,6 +4,10 @@
*/
class WidgetContentControllerExtension extends Extension {
/**
*
* @var array
*/
public static $allowed_actions = array(
'handleWidget'
);

View File

@ -6,19 +6,34 @@
*/
class WidgetAreaEditor extends FormField {
/**
*
* @param string $name
* @param array $widgetClasses
* @param int $maxWidgets
*/
public function __construct($name, $widgetClasses = array('Widget'), $maxWidgets = 0) {
$this->MaxWidgets = $maxWidgets;
$this->widgetClasses = $widgetClasses;
parent::__construct($name);
}
/**
*
* @param array $properties
* @return string - HTML for this formfield
*/
public function FieldHolder($properties = array()) {
Requirements::css('widgets/css/WidgetAreaEditor.css');
Requirements::javascript('widgets/javascript/WidgetAreaEditor.js');
return $this->renderWith("WidgetAreaEditor");
}
/**
*
* @return ArrayList
*/
public function AvailableWidgets() {
$widgets= new ArrayList();
@ -33,7 +48,11 @@ class WidgetAreaEditor extends FormField {
return $widgets;
}
/**
*
* @return HasManyList
*/
public function UsedWidgets() {
// Call class_exists() to load Widget.php earlier and avoid a segfault
class_exists('Widget');
@ -42,16 +61,28 @@ class WidgetAreaEditor extends FormField {
$widgets = $this->form->getRecord()->getComponent($relationName)->Items();
return $widgets;
}
/**
*
* @return string
*/
public function IdxField() {
return $this->id() . 'ID';
}
/**
*
* @return int
*/
public function Value() {
$relationName = $this->name;
return $this->form->getRecord()->getComponent($relationName)->ID;
}
/**
*
* @param DataObjectInterface $record
*/
public function saveInto(DataObjectInterface $record) {
$name = $this->name;
$idName = $name . "ID";

View File

@ -12,29 +12,77 @@
*/
class Widget extends DataObject {
/**
*
* @var array
*/
public static $db = array(
"Sort" => "Int",
"Enabled" => "Boolean"
);
/**
*
* @var array
*/
public static $defaults = array(
'Enabled' => true
);
/**
*
* @var array
*/
public static $has_one = array(
"Parent" => "WidgetArea",
);
/**
*
* @var array
*/
public static $has_many = array();
/**
*
* @var array
*/
public static $many_many = array();
/**
*
* @var array
*/
public static $belongs_many_many = array();
/**
*
* @var string
*/
public static $default_sort = "\"Sort\"";
/**
*
* @var string
*/
public static $title = "Widget Title";
/**
*
* @var string
*/
public static $cmsTitle = "Name of this widget";
/**
*
* @var string
*/
public static $description = "Description of what this widget does.";
/**
*
* @return FieldList
*/
public function getCMSFields() {
$fields = new FieldList();
$this->extend('updateCMSFields', $fields);
@ -64,30 +112,51 @@ class Widget extends DataObject {
public function Content() {
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->class)));
}
/**
*
* @return string
*/
public function Title() {
return _t($this->class.'.TITLE', Object::get_static($this->class, 'title'));
}
/**
*
* @return string
*/
public function CMSTitle() {
return _t($this->class.'.CMSTITLE', Object::get_static($this->class, 'cmsTitle'));
}
/**
*
* @return string
*/
public function Description() {
return _t($this->class.'.DESCRIPTION', Object::get_static($this->class, 'description'));
}
/**
*
* @return string - HTML
*/
public function DescriptionSegment() {
return $this->renderWith('WidgetDescription');
}
/**
* @see Widget_Controller->editablesegment()
* @return string - HTML
*/
public function EditableSegment() {
return $this->renderWith('WidgetEditor');
}
/**
*
* @return FieldList
*/
public function CMSEditor() {
$fields = $this->getCMSFields();
$outputFields = new FieldList();
@ -103,15 +172,27 @@ class Widget extends DataObject {
}
return $outputFields;
}
/**
*
* @return string
*/
public function ClassName() {
return $this->class;
}
/**
*
* @return string
*/
public function Name() {
return "Widget[".$this->ID."]";
}
/**
*
* @param array $data
*/
public function populateFromPostData($data) {
$fields = $this->getCMSFields();
foreach($data as $name => $value) {
@ -159,11 +240,19 @@ class Widget_Controller extends Controller {
* @var Widget
*/
protected $widget;
/**
*
* @var array
*/
public static $allowed_actions = array(
'editablesegment'
);
/**
*
* @param Widget $widget
*/
public function __construct($widget = null) {
// TODO This shouldn't be optional, is only necessary for editablesegment()
if($widget) {
@ -173,7 +262,12 @@ class Widget_Controller extends Controller {
parent::__construct();
}
/**
*
* @param string $action
* @return string
*/
public function Link($action = null) {
$segment = Controller::join_links('widget', ($this->widget ? $this->widget->ID : null), $action);

View File

@ -5,19 +5,43 @@
* @subpackage widgets
*/
class WidgetArea extends DataObject {
/**
*
* @var array
*/
public static $db = array();
/**
*
* @var array
*/
public static $has_one = array();
/**
*
* @var array
*/
public static $has_many = array(
"Widgets" => "Widget"
);
/**
*
* @var array
*/
public static $many_many = array();
/**
*
* @var array
*/
public static $belongs_many_many = array();
/**
*
* @var string
*/
public $template = __CLASS__;
/**
@ -45,23 +69,42 @@ class WidgetArea extends DataObject {
return $controllers;
}
/**
*
* @return HasManyList
*/
public function Items() {
return $this->getComponents('Widgets');
}
/**
*
* @return HasManyList
*/
public function ItemsToRender() {
return $this->getComponents('Widgets', "\"Widget\".\"Enabled\" = 1");
}
/**
*
* @return string - HTML
*/
public function forTemplate() {
return $this->renderWith($this->template);
}
/**
*
* @param string $template
*/
public function setTemplate($template) {
$this->template = $template;
}
/**
* Delete all connected Widgets when this WidgetArea gets deleted
*/
public function onBeforeDelete() {
parent::onBeforeDelete();
foreach($this->Widgets() as $widget) {