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'];
         }
     }
 }
    //    $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);
$smarty->display('script/listScripts.tpl');
?>

Exemple #3
0
 /**
  * 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;
 }