total_found() public method

Fetch the total row count total
Since: 2.0
public total_found ( ) : integer
return integer Number of rows found by select()
Beispiel #1
0
 /**
  * Fetch the total amount of rows found by the last call to find(), regardless of the 'limit' parameter set.
  *
  * This is different than the total number of rows limited by the current call, which you can get with total().
  *
  * @see PodsData::total_found
  *
  * @return int Number of rows returned by find(), regardless of the 'limit' parameter
  * @since 2.0
  * @link http://pods.io/docs/total-found/
  */
 public function total_found()
 {
     $this->do_hook('total_found');
     $this->data->total_found();
     $this->total_found =& $this->data->total_found;
     return $this->total_found;
 }
Beispiel #2
0
 /**
  * Fetch the total amount of rows found by the last call to find(), regardless of the 'limit' parameter set.
  *
  * This is different than the total number of rows limited by the current call, which you can get with total().
  *
  * @see PodsData::total_found
  *
  * @return int Number of rows returned by find(), regardless of the 'limit' parameter
  * @since 2.0
  * @link http://pods.io/docs/total-found/
  */
 public function total_found()
 {
     /**
      * Runs directly before the value of total_found() is determined and returned.
      *
      * @since unknown
      *
      * @param object|Pods $this Current Pods object.
      *
      */
     do_action('pods_pods_total_found', $this);
     $this->data->total_found();
     $this->total_found =& $this->data->total_found;
     return $this->total_found;
 }
 /**
  * @param bool $full Whether to get ALL data or use pagination
  *
  * @return bool
  */
 public function get_data($params = null)
 {
     $action = $this->action;
     $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => '');
     if (!empty($params) && is_array($params)) {
         $params = (object) array_merge($defaults, $params);
     } else {
         $params = (object) $defaults;
     }
     if (!in_array($action, array('manage', 'reorder'))) {
         $action = 'manage';
     }
     $find_params = $this->get_params($params);
     if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) {
         $this->pod->find($find_params);
         if (!$params->full) {
             $data = $this->pod->data();
             $this->data = $data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pod->total();
             $this->total_found = $this->pod->total_found();
         } else {
             $this->data_full = array();
             $export_params = array('fields' => $params->fields, 'flatten' => true);
             if (in_array($params->type, array('json', 'xml'))) {
                 $export_params['flatten'] = false;
             }
             $export_params = $this->do_hook('export_options', $export_params, $params);
             while ($this->pod->fetch()) {
                 $this->data_full[$this->pod->id()] = $this->pod->export($export_params);
             }
             $this->pod->reset();
             return $this->data_full;
         }
     } else {
         if (!empty($this->data)) {
             return $this->data;
         }
         if (empty($this->sql['table'])) {
             return $this->data;
         }
         $this->pods_data->select($find_params);
         if (!$params->full) {
             $this->data = $this->pods_data->data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pods_data->total();
             $this->total_found = $this->pods_data->total_found();
         } else {
             $this->data_full = $this->pods_data->data;
             if (!empty($this->data_full)) {
                 $this->data_keys = array_keys($this->data_full);
             }
             return $this->data_full;
         }
     }
     return $this->data;
 }
Beispiel #4
0
 /**
  * @param bool $full Whether to get ALL data or use pagination
  *
  * @return bool
  */
 public function get_data($params = null)
 {
     $action = $this->action;
     $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => '');
     if (!empty($params) && is_array($params)) {
         $params = (object) array_merge($defaults, $params);
     } else {
         $params = (object) $defaults;
     }
     if (!in_array($action, array('manage', 'reorder'))) {
         $action = 'manage';
     }
     if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) {
         $orderby = array();
         $limit = $this->limit;
         $sql = null;
         if ('reorder' == $this->action) {
             if (!empty($this->reorder['orderby'])) {
                 $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir'];
             } else {
                 $orderby[$this->reorder['on']] = $this->reorder['orderby_dir'];
             }
             if (!empty($this->reorder['limit'])) {
                 $limit = $this->reorder['limit'];
             }
             if (!empty($this->reorder['sql'])) {
                 $sql = $this->reorder['sql'];
             }
         }
         if (!empty($this->orderby)) {
             $this->orderby = (array) $this->orderby;
             foreach ($this->orderby as $order) {
                 if (false === strpos(' ', $order) && !isset($orderby[$order])) {
                     $orderby[$order] = $this->orderby_dir;
                 }
             }
         }
         $find_params = array('where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql);
         if (empty($find_params['where']) && $this->restricted($this->action)) {
             $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null);
         }
         if ($params->full) {
             $find_params['limit'] = -1;
         }
         $find_params = array_merge($find_params, (array) $this->params);
         // Debug purposes
         if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug($find_params);
         }
         $this->pod->find($find_params);
         if (!$params->full) {
             $data = $this->pod->data();
             $this->data = $data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pod->total();
             $this->total_found = $this->pod->total_found();
         } else {
             $this->data_full = array();
             $export_params = array('fields' => $params->fields, 'flatten' => true);
             if (in_array($params->type, array('json', 'xml'))) {
                 $export_params['flatten'] = false;
             }
             $export_params = $this->do_hook('export_options', $export_params, $params);
             while ($this->pod->fetch()) {
                 $this->data_full[$this->pod->id()] = $this->pod->export($export_params);
             }
             $this->pod->reset();
             return $this->data_full;
         }
     } else {
         if (!empty($this->data)) {
             return $this->data;
         }
         if (empty($this->sql['table'])) {
             return $this->data;
         }
         $orderby = '';
         if (!empty($this->orderby)) {
             $orderby = '`' . $this->orderby . '` ' . (false === strpos($this->orderby, ' ') ? strtoupper($this->orderby_dir) : '');
         }
         $find_params = array('table' => $this->sql['table'], 'where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $this->limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search']);
         if (empty($find_params['where']) && $this->restricted($this->action)) {
             $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null);
         }
         if ($params->full) {
             $find_params['limit'] = -1;
         }
         // Debug purposes
         if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug($find_params);
         }
         $this->pods_data->select($find_params);
         if (!$params->full) {
             $this->data = $this->pods_data->data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pods_data->total();
             $this->total_found = $this->pods_data->total_found();
         } else {
             $this->data_full = $this->pods_data->data;
             return $this->data_full;
         }
     }
     return $this->data;
 }
Beispiel #5
0
 /**
  * @param bool $full Whether to get ALL data or use pagination
  *
  * @return bool
  */
 public function get_data($params = null)
 {
     $action = $this->action;
     $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => '');
     if (!empty($params) && is_array($params)) {
         $params = (object) array_merge($defaults, $params);
     } else {
         $params = (object) $defaults;
     }
     if (!in_array($action, array('manage', 'reorder'))) {
         $action = 'manage';
     }
     if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) {
         $orderby = array();
         $limit = $this->limit;
         $sql = null;
         if ('reorder' == $this->action) {
             if (!empty($this->reorder['orderby'])) {
                 $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir'];
             } else {
                 $orderby[$this->reorder['on']] = $this->reorder['orderby_dir'];
             }
             if (!empty($this->reorder['limit'])) {
                 $limit = $this->reorder['limit'];
             }
             if (!empty($this->reorder['sql'])) {
                 $sql = $this->reorder['sql'];
             }
         }
         if (!empty($this->orderby)) {
             $this->orderby = (array) $this->orderby;
             foreach ($this->orderby as $order) {
                 if (false === strpos(' ', $order) && !isset($orderby[$order])) {
                     $orderby[$order] = $this->orderby_dir;
                 }
             }
         }
         $find_params = array('where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql);
         if (empty($find_params['where']) && $this->restricted($this->action)) {
             $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null);
         }
         if ($params->full) {
             $find_params['limit'] = -1;
         }
         $find_params = array_merge($find_params, (array) $this->params);
         // Debug purposes
         if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug($find_params);
         }
         $this->pod->find($find_params);
         if (!$params->full) {
             $data = $this->pod->data();
             $this->data = $data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pod->total();
             $this->total_found = $this->pod->total_found();
         } else {
             $this->data_full = array();
             $export_params = array('fields' => $params->fields, 'flatten' => true);
             if (in_array($params->type, array('json', 'xml'))) {
                 $export_params['flatten'] = false;
             }
             $export_params = $this->do_hook('export_options', $export_params, $params);
             while ($this->pod->fetch()) {
                 $this->data_full[$this->pod->id()] = $this->pod->export($export_params);
             }
             $this->pod->reset();
             return $this->data_full;
         }
     } else {
         if (!empty($this->data)) {
             return $this->data;
         }
         if (empty($this->sql['table'])) {
             return $this->data;
         }
         $orderby = array();
         if (!empty($this->orderby)) {
             $this->orderby = (array) $this->orderby;
             foreach ($this->orderby as $k => $order) {
                 if (false === strpos($order, ' ')) {
                     if (in_array(strtoupper($order), array('ASC', 'DESC'))) {
                         $orderby[$k] = $order;
                     } elseif (!isset($orderby[$order])) {
                         $orderby[$order] = $this->orderby_dir;
                     }
                 } else {
                     $orderby[] = $order;
                 }
             }
         }
         // Allow orderby array ( 'field' => 'asc|desc' )
         if (!empty($orderby) && is_array($orderby)) {
             foreach ($orderby as $k => &$orderby_value) {
                 if (!is_numeric($k)) {
                     $order = 'ASC';
                     if ('DESC' == strtoupper($orderby_value)) {
                         $order = 'DESC';
                     }
                     if (false !== strpos($k, '.')) {
                         $key = $k;
                         if (false === strpos($key, ' ') && false === strpos($key, '`')) {
                             $key = '`' . str_replace('.', '`.`', $key) . '`';
                         }
                     } else {
                         $key = "`t`.`{$k}`";
                     }
                     $orderby_value = $key;
                     if (false === strpos($orderby_value, ' ')) {
                         $orderby_value .= ' ' . $order;
                     }
                 }
             }
         }
         // Add prefix to $orderby if needed
         if (!empty($orderby)) {
             if (!is_array($orderby)) {
                 $orderby = array($orderby);
             }
             foreach ($orderby as &$prefix_orderby) {
                 if (false === strpos($prefix_orderby, ',') && false === strpos($prefix_orderby, '(') && false === stripos($prefix_orderby, ' AS ') && false === strpos($prefix_orderby, '`') && false === strpos($prefix_orderby, '.')) {
                     if (false !== stripos($prefix_orderby, ' DESC')) {
                         $k = trim(str_ireplace(array('`', ' DESC'), '', $prefix_orderby));
                         $dir = 'DESC';
                     } else {
                         $k = trim(str_ireplace(array('`', ' ASC'), '', $prefix_orderby));
                         $dir = 'ASC';
                     }
                     $key = "`t`.`{$k}`";
                     $prefix_orderby = "{$key} {$dir}";
                 }
             }
         }
         $find_params = array('table' => $this->sql['table'], 'id' => $this->sql['field_id'], 'index' => $this->sql['field_index'], 'where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $this->limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search']);
         if (empty($find_params['where']) && $this->restricted($this->action)) {
             $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null);
         }
         if ($params->full) {
             $find_params['limit'] = -1;
         }
         // Debug purposes
         if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug($find_params);
         }
         $this->pods_data->select($find_params);
         if (!$params->full) {
             $this->data = $this->pods_data->data;
             if (!empty($this->data)) {
                 $this->data_keys = array_keys($this->data);
             }
             $this->total = $this->pods_data->total();
             $this->total_found = $this->pods_data->total_found();
         } else {
             $this->data_full = $this->pods_data->data;
             if (!empty($this->data_full)) {
                 $this->data_keys = array_keys($this->data_full);
             }
             return $this->data_full;
         }
     }
     return $this->data;
 }