/** * @param $page * @param $resultsPerPage * @param array $filters * @return RokGallery_Model_File[]|bool */ public function &getFiles($page, $resultsPerPage, $filters = array(), $order_by = null, $order_direction = null) { $this->setupPager($page, $resultsPerPage, $filters, $order_by, $order_direction); /** @var RokGallery_Model_File $file */ $files = $this->pager->execute(array(), Doctrine_Core::HYDRATE_RECORD); return $files; }
public function indexAction() { //$this->_forward('index', 'index', 'default'); // set filters and validators for GET input $filters = array('page' => array('HtmlEntities', 'StripTags', 'StringTrim')); $validators = array('page' => array('Int')); $input = new Zend_Filter_Input($filters, $validators); $input->setData($this->getRequest()->getParams()); if ($input->isValid()) { $q = Doctrine_Query::create()->from('Webteam_Model_Video i')->where('i.UserName = ?', $this->identity['UserName']); //$result = $q->fetchArray(); //$this->view->records = $result; // configure pager $perPage = 10; $numPageLinks = 9; // initialize pager $pager = new Doctrine_Pager($q, $input->page, $perPage); // execute paged query $result = $pager->execute(array(), Doctrine::HYDRATE_ARRAY); // initialize pager layout $pagerRange = new Doctrine_Pager_Range_Sliding(array('chunk' => $numPageLinks), $pager); $pagerUrlBase = $this->view->url(array(), 'user-catalog-index', 1) . "/{%page}"; $pagerLayout = new Doctrine_Pager_Layout($pager, $pagerRange, $pagerUrlBase); // set page link display template $pagerLayout->setTemplate('<a href="{%url}">{%page}</a>'); $pagerLayout->setSelectedTemplate('<span class="current">{%page}</span>'); $pagerLayout->setSeparatorTemplate(' '); // set view variables $this->view->records = $result; $this->view->pages = $pagerLayout->display(null, true); } else { throw new Zend_Controller_Action_Exception('Invalid input'); } }
public function testTest() { $q = Doctrine_Query::create()->from('Ticket_1523_User u')->innerJoin('u.Ticket_1523_Group g')->where('EXISTS (SELECT uu.id FROM Ticket_1523_User uu WHERE uu.id = u.id)')->orderBy('u.code ASC'); $pager = new Doctrine_Pager($q, 1, 10); $pager->execute(array()); $this->assertEqual($pager->getQuery()->getSqlQuery(), 'SELECT t.id AS t__id, t.code AS t__code, t2.id AS t2__id, t2.tmp_id AS t2__tmp_id FROM ticket_1523__user t INNER JOIN ticket_1523__group t2 ON t.id = t2.tmp_id WHERE t.id IN (SELECT DISTINCT t3.id FROM ticket_1523__user t3 INNER JOIN ticket_1523__group t4 ON t3.id = t4.tmp_id WHERE EXISTS (SELECT t5.id AS t3__id FROM ticket_1523__user t5 WHERE t5.id = t3.id) ORDER BY t3.code ASC LIMIT 10) AND EXISTS (SELECT t3.id AS t3__id FROM ticket_1523__user t3 WHERE t3.id = t.id) ORDER BY t.code ASC'); }
public static function getAllBySearch($Condition = array(), $currentPage = 1, $recordPerPage = 10, $order = 'trainersListId') { $Trainer = Doctrine_Query::create()->from(__CLASS__)->orderBy($order); foreach ($Condition as $key => $item) { $Trainer->orWhere($key, $item); } $pager = new Doctrine_Pager($Trainer, $currentPage, $recordPerPage); $Data = $pager->execute(); return array($pager, $Data); }
public static function getAll($Condition = array(), $currentPage = 1, $recordPerPage = 20, $orderBy = 'id') { $Content = Doctrine_Query::create()->from(__CLASS__)->orderBy($orderBy); foreach ($Condition as $key => $item) { $Content->addWhere($key, $item); } $pager = new Doctrine_Pager($Content, $currentPage, $recordPerPage); $Data = $pager->execute(); return array($pager, $Data); }
public function index() { $page = $this->getParam('page', 1); $orderby = $this->getParam('orderby', 'id'); $dir = $this->getParam('dir', 'desc'); $perpage = Config::get('pagination.perpage'); $Pager = new Doctrine_Pager(Doctrine::getTable('Library')->createQuery()->orderby($orderby . ' ' . $dir), $page, $perpage); $this->View->set('Pictures', $Pager->execute()); $this->View->set('Pager', $Pager); }
public function testTest() { Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true); $adapter = new Doctrine_Adapter_Mock('pgsql'); $conn = Doctrine_Manager::connection($adapter); $profiler = new Doctrine_Connection_Profiler(); $conn->setListener($profiler); $query = Doctrine_Query::create()->from('User2 u')->leftJoin('u.Roles')->orderBy('u.id'); $pager = new Doctrine_Pager($query, 1, 20); $records = $pager->execute($conn); $queries = $adapter->getAll(); $this->assertEqual($queries[0], 'SELECT COUNT(*) AS "num_results" FROM (SELECT "u"."id" FROM "user2" "u" LEFT JOIN "user_role2" "u2" ON ("u"."id" = "u2"."user_id") LEFT JOIN "role2" "r" ON "r"."id" = "u2"."role_id" GROUP BY "u"."id") "dctrn_count_query"'); $this->assertEqual($queries[1], 'SELECT "u"."id" AS "u__id", "u"."username" AS "u__username", "r"."id" AS "r__id", "r"."name" AS "r__name" FROM "user2" "u" LEFT JOIN "user_role2" "u2" ON ("u"."id" = "u2"."user_id") LEFT JOIN "role2" "r" ON "r"."id" = "u2"."role_id" WHERE "u"."id" IN (SELECT "doctrine_subquery_alias"."id" FROM (SELECT DISTINCT "u3"."id" FROM "user2" "u3" LEFT JOIN "user_role2" "u4" ON ("u3"."id" = "u4"."user_id") LEFT JOIN "role2" "r2" ON "r2"."id" = "u4"."role_id" ORDER BY "u3"."id" LIMIT 20) AS "doctrine_subquery_alias") ORDER BY "u"."id"'); Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, false); }
public function testTicket() { Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true); $query1 = Doctrine_Query::create()->select('u.*')->from('Ticket_1860_User u'); $this->assertEqual(count($query1->fetchArray()), 0); $query2 = Doctrine_Query::create()->select('u.*')->from('Ticket_1860_User u'); // Defining initial variables $currentPage = 1; $resultsPerPage = 5; // Creating pager object $pager = new Doctrine_Pager($query2, $currentPage, $resultsPerPage); $this->assertEqual(count($pager->execute()->toArray()), 0); $this->assertEqual($pager->getQuery()->getSqlQuery(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t.deleted_at AS t__deleted_at FROM ticket_1860_users t WHERE (t.deleted_at IS NULL) LIMIT 5'); Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, false); }
protected function getPagination() { $filter = new RokGallery_Site_DetailFilter($this->gallery_id, $this->order_by, $this->order_direction); $query = $filter->getQuery(); $current_pager = new Doctrine_Pager($query, $this->current_page, $this->items_per_page); $current_page_ids = $current_pager->execute(array(), Doctrine_Core::HYDRATE_SCALAR); $current_index = 0; foreach ($current_page_ids as $index => $id_holder) { if ($this->id == $id_holder['s_id']) { $current_index = $index; break; } } if ($current_pager->getFirstIndice() + $current_index > $current_pager->getFirstIndice()) { $this->prev_page = $this->current_page; $this->prev_id = $current_page_ids[$current_index - 1]['s_id']; } if ($current_pager->getFirstIndice() + $current_index < $current_pager->getLastIndice()) { $this->next_page = $this->current_page; $this->next_id = $current_page_ids[$current_index + 1]['s_id']; } if ($current_pager->getFirstIndice() + $current_index == $current_pager->getFirstIndice()) { $this->prev_page = $current_pager->getPreviousPage(); if ($current_pager->getFirstPage() != $this->current_page) { $prev_pager = new Doctrine_Pager($query, $this->current_page - 1, $this->items_per_page); $prev_page_ids = $prev_pager->execute(array(), Doctrine_Core::HYDRATE_SCALAR); $this->prev_id = $prev_page_ids[count($prev_page_ids) - 1]['s_id']; } } if ($current_pager->getFirstIndice() + $current_index == $current_pager->getLastIndice()) { $this->next_page = $current_pager->getNextPage(); if ($current_pager->getLastPage() != $this->current_page) { $next_pager = new Doctrine_Pager($query, $this->current_page + 1, $this->items_per_page); $next_page_ids = $next_pager->execute(array(), Doctrine_Core::HYDRATE_SCALAR); $this->next_id = $next_page_ids[0]['s_id']; } } }
function getResult() { // order $sort = DeepCI_Page_PageBar_Data::getDqlSort(); if (!empty($sort)) { $this->dql->orderBy($sort['field'] . ' ' . $sort['type']); } /** 查詢數據 **/ $offset = $this->offset; $currentPage = floor($offset / $this->per_page) + 1; $resultsPerPage = $this->per_page; $pager = new Doctrine_Pager($this->dql, $currentPage, $resultsPerPage); $result =& $pager->execute(); $this->numResults = $pager->getNumResults(); return $result; }
/** * This performs the actual doctrine query and returns a json object * * @return json object */ public function getGridJson($q = NULL) { // If this is not a request for this grids data, exit if (empty($_REQUEST['gridName']) || $_REQUEST['gridName'] != $this->gridName) { return false; } /** * * THIS SECTION INITIALIZES ANY VARS EXPECTED FROM THE GRID * */ self::_orderColumns(); // These are the standard sort and page requests from the grid $currentPage = empty($_REQUEST['page']) ? 1 : $_REQUEST['page']; $resultsPerPage = empty($_REQUEST['rows']) ? 10 : $_REQUEST['rows']; $sidx =& $_REQUEST['sidx']; $sord =& $_REQUEST['sord']; // If the user has not supplied a Doctrine query then create one if (empty($q)) { $q = self::_autoQuery(); } /** * * THIS SECTION GETS A DOCTRINE QUERY, ADDS A ORDERBY ARGUMENT AND WRAPS IT IN A PAGER * */ // This handles the possible search request from the grid if (!empty($_REQUEST['_search'])) { self::_search($q); } // Add order to this mess :) if (!empty($sidx) && !empty($sord)) { $q->orderby($sidx . ' ' . $sord); } // Set up doctrine page for pagnation $pager = new Doctrine_Pager($q, $currentPage, $resultsPerPage); // Execute the query Kohana::log('debug', "JGRID QUERY IS: " . $q->getSqlQuery()); $results = $pager->execute(array(), Doctrine::HYDRATE_SCALAR); /** * * THIS SECTION BUILDS AN ARRAY THAT REPRESENTS A JSON RESPONSE TO THE GRID * */ $encodeArray['page'] = $pager->getPage(); $encodeArray['total'] = $pager->getLastPage(); $encodeArray['records'] = $pager->getNumResults(); // For each of our results start building an array we can use to generate json foreach ($results as $result) { // Build a pointer to a new rows array $ptEncodeArray =& $encodeArray['rows'][]; // Loop through each requested column foreach ($this->query['columns'] as $hydrateName => $model) { // Load a new cell with the value from the query, or blank if empty $cell =& $ptEncodeArray['cell'][]; $cell = empty($result[$hydrateName]) ? '' : $result[$hydrateName]; if (is_string($cell)) { $cell = htmlspecialchars($cell); } // Check if this field has a callback... if (!empty($this->query['callbacks'][$hydrateName])) { $cell = self::_cellCallback($cell, $this->query['callbacks'][$hydrateName], $result); } // Check if this field should be displayed as a link... if (!empty($cell) && !empty($this->query['links'][$hydrateName])) { $cell = self::_cellToAnchor($cell, $this->query['links'][$hydrateName], $result); } } if (!empty($this->query['actions'])) { $ptEncodeArray['cell'][] = self::_cellActions($this->query['actions'], $result); } } // Encode the results into a json object $json = json_encode($encodeArray); // These hacks let you pass an anchor in the json without it exploding.... $json = str_replace('\\/', '/', $json); $json = str_replace('\\"', '', $json); // Return the json return $json; }
/** * Retrieve Resources By State * * @param integer $city State ID * @param integer $page Page Number Desired | Default = 1 * @param integer $noPerPage Results Per Page | Default = 5 * @return bool | array */ public function fetchByState($state, $page = 1, $noPerPage = 5) { $pager = new Doctrine_Pager(Doctrine_Query::create()->from('Model_Resource r')->leftJoin('r.Bookmarkers b')->where('r.state = ?', $state)->orderby('r.created DESC'), $page, $noPerPage); try { $results['resources'] = $pager->execute(); $results['total'] = $pager->getNumResults(); } catch (Doctrine_Exception $e) { return $e->getMessage(); } $results['resources'] = $results['resources']->toArray(); return $results; }
/** * Retrieves Bookmarked Articles * * @param integer $user User ID * @param integer $page Page Number Desired | Default = 1 * @param integer $noPerPage Results Per Page | Default = 10 * @return array | bool */ public function fetchBookmarked($user, $page = 1, $noPerPage = 10) { $pager = new Doctrine_Pager(Doctrine_Query::create()->from('Model_Featuredarticles a')->select('a.date, a.title, a.uri, t.name')->innerJoin('a.Followers f')->innerJoin('a.Topic t')->where('f.id = ?', $user)->orderby('a.date DESC'), $page, $noPerPage); try { $results = $pager->execute(); } catch (Doctrine_Exception $e) { return $e->getMessage(); } return $results->toArray(); }
public function videoTraceAction() { // set filters and validators for GET input $filters = array('VideoID' => array('HtmlEntities', 'StripTags', 'StringTrim')); $validators = array('VideoID' => array('Int')); $input = new Zend_Filter_Input($filters, $validators); $data = array('VideoID' => $this->getRequest()->getParam('q')); $input->setData($data); if ($input->isValid()) { //check if vidoe id exists $q = Doctrine_Query::create()->from('Webteam_Model_Video i')->where('i.VideoID = ?', $input->VideoID); $result = $q->fetchArray(); $count = count($result); if ($count >= 1) { $q = Doctrine_Query::create()->from('Webteam_Model_Log i')->where('i.VideoID = ?', $input->VideoID); $result = $q->fetchArray(); //$this->view->records = $result; //$this->view->VideoID = $input->VideoID; $this->view->VideoID = $input->VideoID; $filters = array('page' => array('HtmlEntities', 'StripTags', 'StringTrim')); $validators = array('page' => array('Int')); $input = new Zend_Filter_Input($filters, $validators); $page = $this->getRequest()->getParam('page'); if (!isset($page)) { $data = array('page' => 1); } else { $data = array('page' => $this->getRequest()->getParam('page')); } $input->setData($data); if ($input->isValid()) { $perPage = 10; $numPageLinks = 9; // initialize pager $pager = new Doctrine_Pager($q, $input->page, $perPage); // execute paged query $result = $pager->execute(array(), Doctrine::HYDRATE_ARRAY); // initialize pager layout $pagerRange = new Doctrine_Pager_Range_Sliding(array('chunk' => $numPageLinks), $pager); $pagerUrlBase = $this->view->url(array(), 'report-video-trace', 1) . '?q=' . $this->view->VideoID . '&page=' . "{%page}"; $pagerLayout = new Doctrine_Pager_Layout($pager, $pagerRange, $pagerUrlBase); // set page link display template $pagerLayout->setTemplate('<a href="{%url}">{%page}</a>'); $pagerLayout->setSelectedTemplate('<span class="current">{%page}</span>'); $pagerLayout->setSeparatorTemplate(' '); // set view variables $this->view->records = $result; $this->view->pages = $pagerLayout->display(null, true); } else { //invalid page } } else { //die('VideoID does not exits'); $this->_helper->getHelper('FlashMessenger')->addMessage('Vidoe ID does not exists.'); $this->_redirect('/report'); } } else { //die('invalid user'); $this->_helper->getHelper('FlashMessenger')->addMessage('Invalid Video ID.'); $this->_redirect('/report'); } }
/** * Fetches Messages Sent By User * * @param integer $user User ID * @param integer $page Page Number Desired | Default = 1 * @param integer $noPerPage Results Per Page | Default = 20 * @return array | bool */ public function fetchSent($user, $page = 1, $noPerPage = 20) { $pager = new Doctrine_Pager(Doctrine_Query::create()->from('Model_Messages m')->innerJoin('m.Recipients r')->innerJoin('r.User u')->innerJoin('u.Profile p')->where('m.sender = ?', $user)->orderby('m.date DESC'), $page, $noPerPage); try { $results = $pager->execute(); } catch (Doctrine_Exception $e) { return $e->getMessage(); } return $results->toArray(); }
public static function getList($page = 1) { $query = Doctrine_Query::create()->select()->from('Blog b')->orderBy('b.best desc, b.count desc'); if ($page !== 'count') { $query = new Doctrine_Pager($query, $page, sfConfig::get('app_blogs_per_page')); return $query->execute(); } else { return $query->count(); } }
public static function getOnlineList($page = 1) { $query = Doctrine_Query::create()->select('u.*')->from('sfGuardUser u, u.Profile p')->where('time_to_sec(timediff(now(), u.last_login)) < ?', sfConfig::get('app_user_online_period', 480))->andWhere('u.is_active = ?', true)->orderBy('time_to_sec(timediff(now(), u.last_login)) asc'); if ($page !== 'count') { $query = new Doctrine_Pager($query, $page, sfConfig::get('app_users_per_page', 10)); return $query->execute(); } else { return $query->count(); } }
} if (!isset($_SESSION['changeNoteFolderId'])) { $_SESSION['changeNoteFolderId'] = getRootFolderForUser($user_id, 'ChangeNote'); } $folderId = $_SESSION['changeNoteFolderId']; $smarty->assign('folderId', $_SESSION['changeNoteFolderId']); $folderTree = getFolderTree($user_id, 'ChangeNote'); $smarty->assign('folderTree', $folderTree); try { $q = Doctrine_Query::create()->from('ChangeNote c, c.ChangeNoteFolder f')->groupBy('c.Id'); if ($folderId > -1 && hasPermission('ChangeNote', $folderId, PERMISSION_READ)) { $q->andWhere('c.ChangeNoteFolderId = ?', $folderId); } else { $q->andWhere('c.UserId = ?', $user_id)->orWhere('c.Public = ?', true); } $pager = new Doctrine_Pager($q, $changeNotesCurrentPage, $resultsPerPage); $result = $pager->execute(); // $changeNoteTable = Doctrine_Core::getTable('ChangeNote'); // $changeNotes = $changeNoteTable->findAll(); $smarty->assign('result', $result); } catch (Exception $e) { error_log("[WPTMonitor] Failed while Listing Change Notes: " . $e->getMessage()); } unset($changeNotes); $smarty->assign('userId', getCurrentUserId()); $shares = getFolderShares($user_id, 'ChangeNote'); $smarty->assign('shares', $shares); $smarty->display('changenote/listChangeNotes.tpl'); ?>
function pager_noresults(Doctrine_Pager $pager, $strong = true) { $ret = ''; if ($pager->getNumResults() == 0) { $nothing = '<span class="pager_noresults">Nothing found.</span>'; if ($strong) { $ret = '<strong>' . $nothing . '</strong>'; } else { $ret = $nothing; } } return $ret; }
$orderBy = $_SESSION['orderScriptsBy']; } else { $orderBy = "s.Id"; } // $orderBy = "s." . $orderBy; $smarty->assign('orderScriptsBy', $orderBy); $q = Doctrine_Query::create()->from('WPTScript s, s.WPTScriptFolder f')->orderBy($orderBy); if ($scriptsFilterField && $scriptsFilterValue) { $q->andWhere('s.' . $scriptsFilterField . ' LIKE ?', '%' . $scriptsFilterValue . '%'); } if ($folderId > -1 && hasPermission('WPTScript', $folderId, PERMISSION_READ)) { $q->andWhere('s.WPTScriptFolderId = ?', $folderId); } else { $q->andWhere('s.UserId = ?', $user_id); } $pager = new Doctrine_Pager($q, $scriptsCurrentPage, $resultsPerPage); $result = $pager->execute(); $shares = getFolderShares($user_id, 'WPTScript'); $smarty->assign('shares', $shares); $smarty->assign('scriptsFilterField', $scriptsFilterField); $smarty->assign('scriptsFilterValue', $scriptsFilterValue); $smarty->assign('scriptsCurrentPage', $scriptsCurrentPage); $smarty->assign('currentPage', $scriptsCurrentPage); $smarty->assign('maxpages', $pager->getLastPage()); $smarty->assign('result', $result); } catch (Exception $e) { error_log("[WPTMonitor] Failed while Listing scripts message: " . $e->getMessage()); print 'Exception : ' . $e->getMessage(); } unset($pager); unset($result);
public static function getDateLine($date, $page = 1) { $query = Doctrine_Query::create()->select('p.*')->from('Post p, p.User u')->where('date(p.created_at) = date(?)', $date)->andWhere('u.is_active = ?', 1)->andWhere('p.type = ?', "post")->orderBy('p.created_at desc'); if (sfContext::getInstance()->getUser()->isAnonymous()) { $query->addWhere('p.rating >= ?', sfConfig::get('app_post_worstpage_threshold')); } if ($page !== 'count') { $query = new Doctrine_Pager($query, $page, sfConfig::get('app_posts_per_page', 10)); return $query->execute(); } else { return $query->count(); } }
/** * Retrieve User Stories * * @param integer $user User ID * @param integer $page Page Number Desired | Default = 1 * @param integer $noPerPage Results Per Page | No of Results Per Page = 5 * @return array | bool */ public function fetch($user, $page = 1, $noPerPage = 5) { $pager = new Doctrine_Pager(Doctrine_Query::create()->from('Model_Userstory s')->leftJoin('s.Media m')->leftJoin('s.Comments c')->leftJoin('c.User u')->leftJoin('u.Profile p')->where('s.user = ?', $user)->orderby('s.date DESC'), $page, $noPerPage); try { $results = $pager->execute(); } catch (Doctrine_Exception $e) { return $e->getMessage(); } for ($i = 0; $i < count($results); $i++) { if (isset($results[$i]->Media)) { $results[$i]->Media->photos = unserialize($results[$i]->Media->photos); $results[$i]->Media->videos = unserialize($results[$i]->Media->videos); } } return $results->toArray(); }
/** * @param $gallery_id * @param int $page * @param int $maxPerPage * @param string $order_by * @param string $order_direction */ public function __construct(RokGallery_Site_GalleryFilter $filter, $page = 1, $maxPerPage = 0) { $this->filter = $filter; parent::__construct($this->filter->getQuery(), $page, $maxPerPage); }