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 { class WidgetContentControllerExtension extends Extension {
/**
*
* @var array
*/
public static $allowed_actions = array( public static $allowed_actions = array(
'handleWidget' 'handleWidget'
); );

View File

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

View File

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

View File

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