Пример #1
0
 /**
  * assign $paginate var values
  *
  * @param obj &$smarty the smarty object reference
  * @param string $var the name of the assigned var
  * @param string $id the pagination id
  */
 public static function assign(&$smarty, $var = 'paginate', $id = 'default')
 {
     if (is_object($smarty) && (strtolower(get_class($smarty)) == 'smarty' || is_subclass_of($smarty, 'smarty'))) {
         $_paginate['total'] = SmartyPaginate::getTotal($id);
         $_paginate['first'] = SmartyPaginate::getCurrentItem($id);
         $_paginate['last'] = SmartyPaginate::getLastItem($id);
         $_paginate['page_current'] = ceil(SmartyPaginate::getLastItem($id) / SmartyPaginate::getLimit($id));
         $_paginate['page_total'] = ceil(SmartyPaginate::getTotal($id) / SmartyPaginate::getLimit($id));
         $_paginate['size'] = $_paginate['last'] - $_paginate['first'];
         $_paginate['url'] = SmartyPaginate::getUrl($id);
         $_paginate['urlvar'] = SmartyPaginate::getUrlVar($id);
         $_paginate['current_item'] = SmartyPaginate::getCurrentItem($id);
         $_paginate['prev_text'] = SmartyPaginate::getPrevText($id);
         $_paginate['next_text'] = SmartyPaginate::getNextText($id);
         $_paginate['limit'] = SmartyPaginate::getLimit($id);
         $_item = 1;
         $_page = 1;
         while ($_item <= $_paginate['total']) {
             $_paginate['page'][$_page]['number'] = $_page;
             $_paginate['page'][$_page]['item_start'] = $_item;
             $_paginate['page'][$_page]['item_end'] = $_item + $_paginate['limit'] - 1 <= $_paginate['total'] ? $_item + $_paginate['limit'] - 1 : $_paginate['total'];
             $_paginate['page'][$_page]['is_current'] = $_item == $_paginate['current_item'];
             $_item += $_paginate['limit'];
             $_page++;
         }
         $smarty->assign($var, $_paginate);
     } else {
         trigger_error("SmartyPaginate: [assign] I need a valid Smarty object.");
         return false;
     }
 }