Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthordpinte
     
    Hi,

    I successfully made a pagination with some filtering on data. I found an annoying thing. Here is the details :

    Trying to have a filtered paginated view on the name contact, i had to do the following code :

    ---------------------------------------------------------------------------------------------------------------------------------------
    // this is the search_option array that will be used to filter the contacts using conditions
    $search_options = array('conditions' => array('lastname like ?', '%'.$this->params['search'].'%'));
    // get the paginator using the filtered contacts using the conditions
    $this->contact_pages =
    $this->pagination_helper->getPaginator($this->Contact,
    array('items_per_page'=> 15,
    'count_conditions' => "lastname like %". $this->params['search'] .'%'));
    // --> here is the annoying thing : i had to rewrite the conditions array in a simple string
    $pagination_options = $this->pagination_helper->getFindOptions($this->Contact);
    // add the pagination_options to the search_options
    $options = array_merge($search_options, $pagination_options);
    // load the filtered contact list
    $this->contacts =& $this->Contact->find('all', $options);
    ---------------------------------------------------------------------------------------------------------------------------------------

    Thus pagination count_conditions cannot use the same conditions has models.

    Worst, when using a joined table :

    My Contacts model has_many Companies. Trying to get a filtered contact list on a company name, I had to write the following code :
    ---------------------------------------------------------------------------------------------------------------------------------------
    $search_options = array('include'=>'company',
    'conditions' => array('_companies.name like ? ', '%'.$this->params['search'].'%'));
    $this->contact_pages =
    $this->pagination_helper->getPaginator($this->Contact,
    array('items_per_page'=> 15,
    'count_conditions' => "_companies.name like %" . $this->params['search'] .'%',
    'count_joins' => " LEFT OUTER JOIN
    companies_contacts AS _CompanyContact ON contacts.id = _CompanyContact.contact_id LEFT OUTER JOIN companies AS _companies ON _companies.id = _CompanyContact.company_id"));
    // --> here is the annoying thing : i had to rewrite the conditions array in a simple string and the include became ugly for Akelos ;-)
    $pagination_options = $this->pagination_helper->getFindOptions($this->Contact);
    // add the pagination_options to the search_options
    $options = array_merge($search_options, $pagination_options);
    // load the filtered contact list
    $this->contacts =& $this->Contact->find('all', $options);
    ---------------------------------------------------------------------------------------------------------------------------------------

    The count_joins cannot use the same include attribute as the $search_option for models.

    Is this a bug ? Or was it intented. Anyway, it works like this !

    Thanks

    Didrik
    • CommentAuthorGKSR
     
    Yes, i am facing the same type of problem,
    My query: (In controller)

    $this->user_pages = $this->pagination_helper->getPaginator($this->User, array('items_per_page' => 10));
    $this->users = $this->User->find('all', array_merge( array('conditions' => 'is_employee = 0 and is_enabled = 1'), $this->pagination_helper->getFindOptions($this->User)));

    In views():

    {?user_pages.links}
    <div id="UserPagination">
    <div id="paginationHeader"><?=translate('Showing page %page of %number_of_pages',array('%page'=>$user_pages->getCurrentPage(),'%number_of_pages'=>$user_pages->pages))?></div>
    {user_pages.links?}
    </div>
    {end}

    In the view, even though there are less than 10 items(say 8/9/10), its showing the 2nd page link, which is empty. It should show the second page, if the items are more than 10.
    Where am i wrong?
    • CommentAuthorinsanet
     
    this happened to me as well. so im very upset too.

    just kidding. well just when you thought finally simple pagination. but that monster never seem to go away, wherever you go.
    • CommentAuthorasejua
     

    Hello,

    I founded a solution time ago for this problem applying the patches for pagination_helper.php and AkAssociatedActiveRecord.php as described in http://trac.akelos.org/attachment/ticket/61

    (I did not patch AkBelongsTo and AkHasOne)

    After this modification, seems the count_conditions parameter in the getPaginator function works, displaying the correct number of pages in the listing view when doing a find with conditions.

    As an example:

    $_filter_pager = array('items_per_page' => 10, 'count_conditions' => 'name = '.$this->params['search']);
    $_filter = array( 'conditions' => array('name = ?',$this->params['search']));
    $_include = array();
    // Pager
    $_pager_options = array_merge($_filter_pager,$_include);
    $this->pages = $this->pagination_helper->getPaginator($this->User, $_pager_options);
    $_find_options = $this->pagination_helper->getFindOptions($this->User);
    // List
    $options = array_merge($_filter,$_include,$_find_options);
    $this->users =& $this->User->find('all',$options);
    

    Obviously, don't know if it is the best solution, but at least it works for me.

    Hope it helps.

    Jose