Exemple #1
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;
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 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;
 }
Exemple #4
0
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;
}
Exemple #5
0
 /**
  * Retrieves Newest Articles
  * 
  * @param   integer     $topic      Topic ID
  * @param   integer     $page       Page Number Desired | Default = 1
  * @param   integer     $noPerPage  Results Per Page | Default = 5
  * @return  array | bool
  */
 public function fetchNewest($topic, $page = 1, $noPerPage = 5)
 {
     $pager = new Doctrine_Pager(Doctrine_Query::create()->from('Model_Featuredarticles fa')->innerJoin('fa.Topic t')->innerJoin('fa.Author a')->where('t.id = ?', $topic)->orderby('fa.created DESC'), $page, $noPerPage);
     try {
         $results['articles'] = $pager->execute();
         $results['total'] = $pager->getNumResults();
     } catch (Doctrine_Exception $e) {
         return $e->getMessage();
     }
     $results['articles'] = $results['articles']->toArray();
     return $results;
 }