当前位置 : 主页 > 网络编程 > PHP >

NewPager.class.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
NewPager.class.php '共x页'.note that the 'x' will be replaced by $pageCount.so the 'x' must be seted. */ public $totalPageLable = false; /** * @var bool if is seted true,the goPageLabel can be show in the html. * */ public $goPageLabel =
NewPager.class.php
  '共x页'.note that the 'x' will be replaced by $pageCount.so the 'x' must be seted.
     */
    public $totalPageLable = false;

    /**
     * @var bool if is seted true,the goPageLabel can be show in the html.
     *
     */
    public $goPageLabel = false;

    /**
     * @var array.options about the goPageLabel(input)
     *goPageLabelOptions => [
     *       'class' =>
     *       'data-num' =>
     *       'style' =>
     *   ]
     *
     */
    public $goPageLabelOptions = [];

    /**
     * @var bool | string. weather show in go page button
     *
     */
    public $goButtonLable = false;

    /**
     * @var array.options about the goButton
     *
     */
    public $goButtonLableOptions = [];

    /**
     * @var bool | string. weather exist hidden menu value in go page button
     *
     */
    public $goButtonLabelMenuValue = false;

    /**
     * @var bool | string. weather exist hidden menu value
     */
    public $menuLabel = false;

    /**
     * @var array.options about pages value if set, array can be shown
     *
     */
    public $pageSizeLimits = [];
    
    /**
     * @var bool | string if selected, show value
     */
    public $pageSizeSelected = false;

    /**
     *
     **/
    public function init()
    {
        parent::init();

    }

    public function run()
    {
        if ($this->registerLinkTags) {
            $this->registerLinkTags();
        }
        echo $this->renderPageButtons();
    }

    protected function renderPageButtons()
    {

        $pageCount = $this->pagination->getPageCount();
        if ($pageCount < 2 && $this->hideOnSinglePage) {
            return '';
        }

        $buttons = [];
        $currentPage = $this->pagination->getPage();

        // hidden menu value
        if ($this->goPageLabel) {
            $menuInput = Html::hiddenInput((str_replace('x', $pageCount, $this->menuLabel)), $this->goButtonLabelMenuValue,
                $this->goButtonLableOptions);
            $buttons[] = Html::tag('li', $menuInput, []);
        }

        // first page
        $firstPageLabel = $this->firstPageLabel === true ? '1' : $this->firstPageLabel;
        if ($firstPageLabel !== false) {
            $buttons[] = $this->renderPageButton($firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false);
        }

        // prev page
        if ($this->prevPageLabel !== false) {
            if (($page = $currentPage - 1) < 0) {
                $page = 0;
            }
            $buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false);
        }

        // internal pages
        list($beginPage, $endPage) = $this->getPageRange();
        for ($i = $beginPage; $i <= $endPage; ++$i) {
            $buttons[] = $this->renderPageButton($i + 1, $i, null, false, $i == $currentPage);
        }

        // next page
        if ($this->nextPageLabel !== false) {
            if (($page = $currentPage + 1) >= $pageCount - 1) {
                $page = $pageCount - 1;
            }
            $buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false);
        }

        // last page
        $lastPageLabel = $this->lastPageLabel === true ? $pageCount : $this->lastPageLabel;
        if ($lastPageLabel !== false) {
            $buttons[] = $this->renderPageButton($lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false);
        }

        // total page
        if ($this->totalPageLable) {
            $buttons[] = Html::tag('li', Html::a(str_replace('x', $pageCount, $this->totalPageLable), 'javascript:(0);', []), []);
        }

        //共x条记录
        if ($this->pagination->totalCount) {
            $buttons[] = Html::tag('li', Html::a('共' . $this->pagination->totalCount . '条数据', 'javascript:(0);', []), []);
        }

        //每页显示x条记录
        //$pageCount 页码总数
        //$currentPage 页码总数
        if($this->pageSizeLimits){
            $buttons[] = Html::tag('li', Html::a('每页', 'javascript:(0);',[]), []);
            $buttons[] = Html::dropDownList('select', $this->pageSizeSelected, $this->pageSizeLimits, array_merge([
                'name'=>'per-page',
                'id'=>"listrows",
                'rel'=> $this->pageSizeSelected,
            ], $this->goPageLabelOptions));
            $buttons[] = Html::tag('li', Html::a('条记录','javascript:(0);', ['style'=>'margin-left:0;']), []);
            $buttons[] = Html::script(
                'function changeURLArg(url,arg,arg_val){
                    var pattern=arg+\'=([^&]*)\';
                    var replaceText=arg+\'=\'+arg_val;
                    if(url.match(pattern)){
                        var tmp=\'/(\'+ arg+\'=)([^&]*)/gi\';
                        tmp=url.replace(eval(tmp),replaceText);
                        return tmp;
                    }else{
                        if(url.match(\'[\?]\')){
                            return url+\'&\'+replaceText;
                        }else{
                            return url+\'?\'+replaceText;
                        }
                    }
                    return url+\'\n\'+arg+\'\n\'+arg_val;
                }
                var list_rows = $("#listrows").attr(\'rel\');
                    $("#listrows").val(list_rows);
                    $("#listrows").change(function(){
                        var every_listrows = $(this).val();
                        var this_url = window.location.search;
                        if(this_url.indexOf("listrows") > 0){
                            window.location = changeURLArg(this_url,\'listrows\',every_listrows);
                        }else{
                            window.location = this_url+"&listrows="+every_listrows;
                        }
                });',
            []);
        }
        /*$style = Html::style(
            'position: relative;float: left;padding: 6px 16px;line-height: 1.52857143;text-decoration: none;color: #515253;background-color: #ffffff;border: 1px solid #eeeeee;margin-left: -1px;font-weight: bold;cursor: pointer;', []);
        $pageData = '
 
  
                           每页
  条记录
 ';
        $buttons[] = Html::tag('li', $pageData, []);*/

        //gopage
        if ($this->goPageLabel) {
            $input = Html::input('number', $this->pagination->pageParam, $currentPage + 1, array_merge([
                'min' => 1,
                'max' => $pageCount,
                'style' => 'height:35px;width:80px;display:inline-block;margin:0 3px 0 3px',
                'class' => 'form-control',
            ], $this->goPageLabelOptions));

            $buttons[] = Html::tag('li', $input, []);
        }

        // gobuttonlink
        if ($this->goPageLabel) {
            $submitInput = Html::submitInput($this->goButtonLable ? $this->goButtonLable : '跳转', array_merge([
                'style' => 'height:34px;display:inline-block;',
                'class' => 'btn btn-primary goBtn'
            ], $this->goButtonLableOptions));
            $buttons[] = Html::tag('li', $submitInput, []);
        }

        $ul = Html::tag('ul', implode("\n", $buttons), $this->options);
        return Html::tag('form', $ul, []);
    }
}
上一篇:PowerPointExport.txt
下一篇:feof.php
网友评论