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