/**
 * Get the navigation links for given sfDoctrinePager instance
 *
 * @param sfDoctrinePager $pager
 * @param string $uri  The uri to prefix to the links
 * @return string $html
 */
function get_sympal_pager_navigation($pager, $uri, $requestKey = 'page')
{
    sympal_use_stylesheet('/sfSympalPlugin/css/pager.css');
    $navigation = '<div class="sympal_pager_navigation">';
    if ($pager->haveToPaginate()) {
        $uri .= (preg_match('/\\?/', $uri) ? '&' : '?') . $requestKey . '=';
        // First and previous page
        if ($pager->getPage() != 1) {
            $navigation .= link_to(image_tag('/sf/sf_admin/images/first.png', 'align=absmiddle'), $uri . '1');
            $navigation .= link_to(image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle'), $uri . $pager->getPreviousPage()) . ' ';
        }
        // Pages one by one
        $links = array();
        foreach ($pager->getLinks() as $page) {
            $links[] = '<span>' . link_to_unless($page == $pager->getPage(), $page, $uri . $page) . '</span>';
        }
        $navigation .= join('  ', $links);
        // Next and last page
        if ($pager->getPage() != $pager->getLastPage()) {
            $navigation .= ' ' . link_to(image_tag('/sf/sf_admin/images/next.png', 'align=absmiddle'), $uri . $pager->getNextPage());
            $navigation .= link_to(image_tag('/sf/sf_admin/images/last.png', 'align=absmiddle'), $uri . $pager->getLastPage());
        }
    }
    $navigation .= '</div>';
    return $navigation;
}
 public function getPager($page = 1, $size = 20, $isCheckActive = false, $isPc = null, $isMobile = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     $query = Doctrine::getTable('Application')->createQuery('a')->leftJoin('a.Translation t');
     if ($isCheckActive) {
         $query->where('a.is_active = ?', true);
     }
     if (null !== $isPc) {
         $query->andWhere('a.is_pc = ?', $isPc);
     }
     if (null !== $isMobile) {
         $query->andWhere('a.is_mobile = ?', $isMobile);
     }
     $keywords = $this->getValue('keyword');
     if ($keywords) {
         if (!is_array($keywords)) {
             $keywords = array($keywords);
         }
         foreach ($keywords as $keyword) {
             $query->addWhere('t.title LIKE ?', '%' . $keyword . '%');
         }
     }
     $orderBy = $this->getValue('order_by');
     if (!$orderBy) {
         $orderBy = 'created_at_desc';
     }
     $isDesc = false;
     if (preg_match('/_desc$/', $orderBy)) {
         $isDesc = true;
         $orderBy = substr($orderBy, 0, strlen($orderBy) - 5);
     }
     $orderByDql = null;
     switch ($orderBy) {
         case 'created_at':
             $orderByDql = 't.created_at';
             break;
         case 'users':
             $subquery = Doctrine::getTable('MemberApplication')->createQuery('ma')->select('COUNT(*)')->where('ma.application_id = a.id');
             $query->select('*, (' . $subquery->getDql() . ') AS users');
             $orderByDql = 'users';
     }
     if ($orderByDql) {
         if ($isDesc) {
             $orderByDql .= ' DESC';
         }
         $query->orderBy($orderByDql);
     }
     $pager = new sfDoctrinePager('Application', $size);
     $pager->setQuery($query);
     $pager->getPage($page);
     $pager->init();
     return $pager;
 }