00001 <?php
00002
00003
00004
00005 class WidgetAlphaList implements IWidget {
00006
00007
00008
00009 const LINK_TO_FRAGMENT = 0;
00010
00011
00012
00013 const LINK_TO_SUBPAGES = 256;
00014
00015
00016
00017 const NO_PAGER = 512;
00018
00019
00020
00021 const LINK_TO_SUBPAGE_BELOW_SECTION = 1024;
00022
00023 const INCLUDE_NUMERIC = 4096;
00024
00025 public $items;
00026 public $params;
00027
00028
00029
00030
00031
00032
00033 public static function output($items, $params = array(), $policy = self::LINK_TO_SUBPAGES) {
00034 if (is_string($params)) {
00035 $params = array('css_class' => $params);
00036 }
00037 $w = new WidgetAlphaList($items, $params);
00038 return $w->render($policy);
00039 }
00040
00041 public function __construct($items, $params) {
00042 $this->items = $items;
00043 $this->params = $params;
00044 }
00045
00046 public function render($policy = self::NONE) {
00047 $ret = '';
00048 if (count($this->items) > 10) {
00049 if (!Common::flag_is_set($policy, self::NO_PAGER)) {
00050 $ret .= WidgetAlphaPager::output($policy);
00051 }
00052
00053 $data = array_fill_keys(range('a', 'z'), array());
00054 if (Common::flag_is_set($policy, self::INCLUDE_NUMERIC)) {
00055 $data = array_merge(array('0-9' => array()), $data);
00056 }
00057
00058 foreach($this->items as $key => $value) {
00059 $clean = String::plain_ascii($key);
00060 $data[substr($clean, 0, 1)][] = $value;
00061 }
00062
00063 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'widgets/alphalist', false);
00064 $view->assign('data', $data);
00065 $view->assign('items', $this->items);
00066 $view->assign('params', $this->params);
00067 $view->assign('policy', $policy);
00068 }
00069 else {
00070 ksort($this->items);
00071 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'widgets/alphalist/empty', false);
00072 }
00073 $view->assign('items', $this->items);
00074 $view->assign('params', $this->params);
00075 $view->assign('policy', $policy);
00076 $ret .= $view->render();
00077 return $ret;
00078 }
00079 }