00001 <?php
00002
00003
00004
00005
00006
00007
00008 class WidgetList implements IWidget {
00009 protected $page_data;
00010 protected $parent_view;
00011 protected $items;
00012 protected $empty_message;
00013
00014 public static function output(PageData $page_data, IView $parent_view, $items, $empty_message = '', $policy = self::NONE) {
00015 $widget = new WidgetList($page_data, $parent_view, $items, $empty_message);
00016 return $widget->render($policy);
00017 }
00018
00019 public function __construct(PageData $page_data, IView $parent_view, $items, $empty_message = '') {
00020 $this->page_data = $page_data;
00021 $this->parent_view = $parent_view;
00022 $this->items = $items;
00023 $this->empty_message = $empty_message;
00024 }
00025
00026 public function render($policy = self::NONE) {
00027 $ret = '';
00028 $items = Arr::force($this->items, false);
00029 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'widgets/list');
00030 $view->assign('page_data', $this->page_data);
00031 $view->assign('parent_view', $this->parent_view);
00032 $view->assign('items', $this->render_items($this->page_data, $items, $policy));
00033 $view->assign('policy', $policy);
00034 $view->assign('empty_message', $this->empty_message);
00035 $ret = $view->render();
00036 return $ret;
00037 }
00038
00039 protected function render_items($page_data, $items, $policy) {
00040 $ret = array();
00041 $i = 1;
00042 $c = count($items);
00043 foreach($items as $item) {
00044 $cls = array('listitem');
00045 if ($item instanceof IDataObject) {
00046 $cls[] = 'listitem-' . $item->get_table_name();
00047 }
00048 if ($i == 1) { $cls[] = 'first'; }
00049 if ($i == $c) { $cls[] = 'last'; }
00050 $ret[] = html::div(WidgetListItem::output($item, $policy), implode(' ', $cls));
00051 $i++;
00052 }
00053 return $ret;
00054 }
00055 }