예제 #1
0
파일: uList.php 프로젝트: axoquen/tt780
 function generate($function_print, $filtered = null, $ordered = null, $context = null, $parameters = null)
 {
     if (!is_array($context)) {
         $context = array();
     }
     $list_context = $context;
     list($where, $ccontexto) = $this->generateWhere($filtered, $function_print);
     list($orderby, $ocontexto) = $this->generateOrderBy($ordered, $function_print);
     $list_context = array_merge($list_context, $ccontexto);
     $list_context = array_merge($list_context, $ocontexto);
     $cursor = intval($this->__HTTPRequest_getParameter($this->variable_cursor, $this->cursor));
     $perpage = intval($this->__HTTPRequest_getParameter($this->variable_perpage, $this->perpage));
     if ($cursor < 0 || intval($cursor) == 0) {
         $cursor = 1;
     }
     if ($perpage <= 0) {
         $perpage = 1;
     }
     if ($this->perpage != $perpage) {
         $list_context[$this->variable_perpage] = $perpage;
     }
     $start = ($cursor - 1) * $perpage;
     $end = $start + $perpage;
     // render
     if (is_callable($function_print)) {
         $aux = call_user_func($function_print, $start, $end, $where, $orderby, $list_context, $parameters);
     } else {
         if ($this->control && $this->control->isExecutable($function_print)) {
             $pl = new Parameters($parameters);
             $pl->setParameter(array('start' => $start, 'end' => $end, 'where' => $where, 'order' => $orderby, 'list_context' => $list_context));
             $aux = $this->control->execute($function_print, $pl);
         } else {
             return "uList can't execute: <b>" . print_r($function_print, true) . "</b>";
         }
     }
     if (!is_array($aux) || count($aux) != 2) {
         return $aux;
     }
     list($list, $total) = $aux;
     if (!is_string($list) || trim($list) == '') {
         return '';
     }
     if (!is_integer($total)) {
         $total = intval($total);
     }
     $controls = array('PAGES' => 'printPages', 'INFO' => 'printInfo', 'ORDER' => 'printAnchor', 'PARAMETER' => 'printParameter');
     if (!preg_match_all('/__(\\w+)(?:\\((.*)\\))?__/', $list, $entry)) {
         return $list;
     }
     $pre_perpage = $this->perpage;
     $this->perpage = $perpage;
     $replaces = array();
     for ($i = 0; $i < count($entry[0]); $i++) {
         $entry[1][$i] = strtoupper($entry[1][$i]);
         if (!isset($controls[$entry[1][$i]])) {
             continue;
         }
         $attribs = array();
         if (isset($entry[2][$i]) && is_string($entry[2][$i]) && preg_match_all('/(\\w+)\\s*=\\s*"([^"]+)"/', $entry[2][$i], $aux)) {
             for ($j = 0; $j < count($aux[0]); $j++) {
                 $attribs[strtolower($aux[1][$j])] = isset($aux[1][$j]) ? $aux[2][$j] : true;
             }
         }
         $replaces[$entry[0][$i]] = $this->{$controls[$entry[1][$i]]}($attribs, $context, $list_context, array('start' => $start, 'end' => $end, 'total' => $total, 'cursor' => $cursor));
     }
     $this->perpage = $pre_perpage;
     return str_replace(array_keys($replaces), $replaces, $list);
 }