Пример #1
0
 function applyHook()
 {
     if (!isset($this->source)) {
         if ($this->owner->dq) {
             $this->setSource($this->owner->dq);
         }
     }
     if (!isset($this->source)) {
         throw $this->exception('Unable to find source for Paginator');
     }
     if ($this->source instanceof DB_dsql || $this->source instanceof Model_Array) {
         // Set the limit first, then execute
         $this->source->limit($this->ipp, $this->skip);
         if (!$this->source->stmt) {
             $this->source->execute();
         }
         // execute early but not fetch
         $this->found_rows = $this->source->foundRows();
         $this->cur_page = floor($this->skip / $this->ipp) + 1;
         $this->total_pages = ceil($this->found_rows / $this->ipp);
         if ($this->cur_page > $this->total_pages) {
             $this->cur_page = 1;
             $this->skip = $this->ipp * ($this->cur_page - 1);
             $this->source->limit($this->ipp, $this->skip);
             $this->source->rewind()->execute();
             // re-execute the query
         }
     } else {
         // TODO: array_slice
         $this->found_rows = count($this->source);
     }
     if ($this->total_pages <= 1) {
         return $this->destroy();
     }
     if ($this->cur_page > 1) {
         $this->add('View', null, 'prev')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = max(0, $this->skip - $this->ipp))))->setAttr('data-skip', $pn)->set('← Prev');
     }
     if ($this->cur_page < $this->total_pages) {
         $this->add('View', null, 'next')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = $this->skip + $this->ipp)))->setAttr('data-skip', $pn)->set('Next →');
     }
     //
     // generate our source now
     $data = array();
     foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) {
         $data[] = array('href' => $this->api->url(null, array($this->name . '_skip' => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? $this->template->get('cur') : '', 'label' => $p);
     }
     $this->js('click', $this->owner->js()->reload(array($this->name . '_skip' => $this->js()->_selectorThis()->attr('data-skip'))))->_selector('#' . $this->name . ' a');
     parent::setSource($data);
 }
Пример #2
0
 function recursiveRender()
 {
     if (!$this->source) {
         if ($this->owner->model) {
             if ($this->owner instanceof Grid_Advanced) {
                 $this->owner->getIterator();
             }
             // force grid->model sorting implemented in Grid_Advanced
             $this->setSource($this->owner->model);
         }
     }
     if (!isset($this->source)) {
         throw $this->exception('Unable to find source for Paginator');
     }
     if ($this->source instanceof DB_dsql) {
         $this->source->preexec();
         $this->found_rows = $this->source->foundRows();
     } else {
         $this->found_rows = count($this->source);
     }
     $this->cur_page = floor($this->skip / $this->ipp) + 1;
     $this->total_pages = ceil($this->found_rows / $this->ipp);
     if ($this->cur_page > $this->total_pages || $this->cur_page == 1 && $this->skip != 0) {
         $this->cur_page = 1;
         $this->learn('skip', $this->skip = 0);
         $this->source->limit($this->ipp, $this->skip);
         $this->source->rewind();
         // re-execute the query
     }
     if ($this->total_pages <= 1) {
         return $this->destroy();
     }
     if ($this->cur_page > 1) {
         $this->add('View', null, 'prev')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = max(0, $this->skip - $this->ipp))))->setAttr('data-skip', $pn)->set('← Prev');
     }
     if ($this->cur_page < $this->total_pages) {
         $this->add('View', null, 'next')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = $this->skip + $this->ipp)))->setAttr('data-skip', $pn)->set('Next →');
     }
     // generate our source now
     $data = array();
     foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) {
         $data[] = array('href' => $this->api->url(null, array($this->name . '_skip' => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? $this->template->get('cur') : '', 'label' => $p);
     }
     $this->js('click', $this->owner->js()->reload(array($this->name . '_skip' => $this->js()->_selectorThis()->attr('data-skip'))))->_selector('#' . $this->name . ' a');
     parent::setSource($data);
     return parent::recursiveRender();
 }
Пример #3
0
 function recursiveRender()
 {
     if ($ipp = $this->api->stickyGET($this->name . '_ipp')) {
         $this->ipp = $ipp;
     }
     // get data source
     if (!$this->source) {
         // force grid sorting implemented in Grid_Advanced
         if ($this->owner instanceof \Grid_Advanced) {
             $this->owner->getIterator();
         }
         // set data source for Paginator
         if ($this->owner->model) {
             $this->setSource($this->owner->model);
         } elseif ($this->owner->dq) {
             $this->setSource($this->owner->dq);
         } else {
             throw $this->exception('Unable to find source for Paginator');
         }
     }
     // calculate found rows
     if ($this->source instanceof \DB_dsql) {
         $this->source->preexec();
         $this->found_rows = $this->source->foundRows();
     } elseif ($this->source instanceof \Model) {
         $this->found_rows = (string) $this->source->count();
     } else {
         $this->found_rows = count($this->source);
     }
     // calculate current page and total pages
     $this->cur_page = floor($this->skip / $this->ipp) + 1;
     $this->total_pages = ceil($this->found_rows / $this->ipp);
     if ($this->cur_page > $this->total_pages || $this->cur_page == 1 && $this->skip != 0) {
         $this->cur_page = 1;
         if ($this->memorize) {
             $this->memorize('skip', $this->skip = 0);
         }
         if ($this->source instanceof \DB_dsql) {
             $this->source->limit($this->ipp, $this->skip);
             $this->source->rewind();
             // re-execute the query
         } elseif ($this->source instanceof \Model) {
             $this->source->setLimit($this->ipp, $this->skip);
         } else {
             // Imants: not sure if this is correct, but it was like this before
             $this->source->setLimit($this->ipp, $this->skip);
         }
     }
     // no need for paginator if there is only one page
     if ($this->total_pages <= 1) {
         return $this->destroy();
     }
     if ($this->cur_page > 1) {
         $this->add('View', null, 'prev', 'prev')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, $this->skip - $this->ipp))))->set('pn', $pn)->set('label', '« Prev');
     } else {
         $this->template->tryDel('prev');
     }
     if ($this->cur_page < $this->total_pages) {
         $this->add('View', null, 'next', 'next')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = $this->skip + $this->ipp)))->set('pn', $pn)->set('label', 'Next »');
     } else {
         $this->template->tryDel('next');
     }
     // First page
     if ($this->cur_page > $this->range + 1) {
         $this->add('View', null, 'first', 'first')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, 0))))->set('pn', $pn)->set('label', '1');
         if ($this->cur_page > $this->range + 2) {
             $this->add('View', null, 'points_left', 'points_left')->template->set('label', '...');
         }
     } else {
         $this->template->del('first');
         $this->template->tryDel('points_left');
     }
     // Last page
     if ($this->cur_page < $this->total_pages - $this->range) {
         $this->add('View', null, 'last', 'last')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, ($this->total_pages - 1) * $this->ipp))))->set('pn', $pn)->set('label', $this->total_pages);
         if ($this->cur_page < $this->total_pages - $this->range - 1) {
             $this->add('View', null, 'points_right', 'points_right')->template->set('label', '...');
         }
     } else {
         $this->template->del('last');
         $this->template->tryDel('points_right');
     }
     // generate source for Paginator Lister (pages, links, labels etc.)
     $data = array();
     //setting cur as array seems not working in atk4.3. String is working
     $tplcur = $this->template->get('cur');
     $tplcur = isset($tplcur[0]) ? $tplcur[0] : '';
     foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) {
         $data[] = array('href' => $this->app->url($this->base_page, array($this->skip_var => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? 'active' : '', 'label' => $p);
     }
     if ($this->ajax_reload) {
         $this->js('click', $this->owner->js()->reload(array($this->skip_var => $this->js()->_selectorThis()->attr('data-skip'), $this->name . '_ipp' => $this->js()->_selector('#ipp-selector-' . $this->name)->val())))->_selector('#' . $this->name . ' a');
         $this->js(true)->_load('select2.min')->_css('libs/select2');
         $this->js(true)->_selector('#ipp-selector-' . $this->name)->select2();
         $this->js(true)->_selector('#ipp-selector-' . $this->name)->select2('val', $this->ipp);
         $this->js('change', $this->owner->js()->reload(array($this->skip_var => 0, $this->name . '_ipp' => $this->js()->_selector('#ipp-selector-' . $this->name)->val())))->_selector('#ipp-selector-' . $this->name);
     }
     parent::setSource($data);
     return parent::recursiveRender();
 }
Пример #4
0
 function recursiveRender()
 {
     // get data source
     if (!$this->source) {
         // force grid sorting implemented in Grid_Advanced
         if ($this->owner instanceof Grid_Advanced) {
             $this->owner->getIterator();
         }
         // set data source for Paginator
         if ($this->owner->model) {
             $this->setSource($this->owner->model);
         } elseif ($this->owner->dq) {
             $this->setSource($this->owner->dq);
         } else {
             throw $this->exception('Unable to find source for Paginator');
         }
     }
     // calculate found rows
     if ($this->source instanceof DB_dsql) {
         $this->source->preexec();
         $this->found_rows = $this->source->foundRows();
     } elseif ($this->source instanceof Model) {
         $this->found_rows = $this->source->count();
     } else {
         $this->found_rows = count($this->source);
     }
     // calculate current page and total pages
     $this->cur_page = floor($this->skip / $this->ipp) + 1;
     $this->total_pages = ceil($this->found_rows / $this->ipp);
     // no need for paginator if there is only one page
     if ($this->total_pages <= 1) {
         return $this->destroy();
     }
     if ($this->cur_page > $this->total_pages || $this->cur_page == 1 && $this->skip != 0) {
         $this->cur_page = 1;
         if ($this->memorize) {
             $this->memorize('skip', $this->skip = 0);
         }
         if ($this->source instanceof DB_dsql) {
             $this->source->limit($this->ipp, $this->skip);
             $this->source->rewind();
             // re-execute the query
         } elseif ($this->source instanceof Model) {
             $this->source->setLimit($this->ipp, $this->skip);
         } else {
             // Imants: not sure if this is correct, but it was like this before
             $this->source->setLimit($this->ipp, $this->skip);
         }
     }
     if ($this->cur_page > 1) {
         $this->add('View', null, 'prev')->setElement('a')->setAttr('href', $this->api->url($this->base_page, $u = array($this->skip_var => $pn = max(0, $this->skip - $this->ipp))))->setAttr('data-skip', $pn)->set('<');
     }
     if ($this->cur_page < $this->total_pages) {
         $this->add('View', null, 'next')->setElement('a')->setAttr('href', $this->api->url($this->base_page, $u = array($this->skip_var => $pn = $this->skip + $this->ipp)))->setAttr('data-skip', $pn)->set('>');
     }
     // First page
     if ($this->cur_page > $this->range + 1) {
         $this->add('View', null, 'first')->setElement('a')->setAttr('href', $this->api->url($this->base_page, $u = array($this->skip_var => $pn = max(0, 0))))->setAttr('data-skip', $pn)->set('1');
         if ($this->cur_page > $this->range + 2) {
             $this->add('View', null, 'points_left')->setElement('span')->set('...');
         }
     }
     // Last page
     if ($this->cur_page < $this->total_pages - $this->range) {
         $this->add('View', null, 'last')->setElement('a')->setAttr('href', $this->api->url($this->base_page, $u = array($this->skip_var => $pn = max(0, ($this->total_pages - 1) * $this->ipp))))->setAttr('data-skip', $pn)->set($this->total_pages);
         if ($this->cur_page < $this->total_pages - $this->range - 1) {
             $this->add('View', null, 'points_right')->setElement('span')->set('...');
         }
     }
     // generate source for Paginator Lister (pages, links, labels etc.)
     $data = array();
     foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) {
         $data[] = array('href' => $this->api->url($this->base_page, array($this->skip_var => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? $this->template->get('cur') : '', 'label' => $p);
     }
     if ($this->ajax_reload) {
         $this->js('click', $this->owner->js()->reload(array($this->skip_var => $this->js()->_selectorThis()->attr('data-skip'))))->_selector('#' . $this->name . ' a');
     }
     parent::setSource($data);
     return parent::recursiveRender();
 }
Пример #5
0
 function setSource($table, $db_fields = null)
 {
     parent::setSource($table, $db_fields);
     //we always need to calc rows
     $this->dq->calc_found_rows();
     return $this;
 }