fetch() public method

Fetch a new row for the current pod_data
Since: 2.0
public fetch ( integer $row = null, boolean $explicit_set = true ) : mixed
$row integer Row number to fetch
$explicit_set boolean Whether to set explicitly (use false when in loop)
return mixed
 /**
  * @return array
  */
 public function get_row(&$counter = 0, $method = null)
 {
     if (!empty($this->row) && 0 < (int) $this->id && 'table' != $method) {
         return $this->row;
     }
     if (is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) {
         $this->row = $this->pod->fetch();
     } else {
         $this->row = false;
         if (!empty($this->data)) {
             if (empty($this->data_keys) || count($this->data) != count($this->data_keys)) {
                 $this->data_keys = array_keys($this->data);
             }
             if (count($this->data) == $this->total && isset($this->data_keys[$counter]) && isset($this->data[$this->data_keys[$counter]])) {
                 $this->row = $this->data[$this->data_keys[$counter]];
                 $counter++;
             }
         }
         if (false === $this->row && 0 < (int) $this->id && !empty($this->sql['table'])) {
             $this->pods_data->select(array('table' => $this->sql['table'], 'where' => '`' . $this->sql['field_id'] . '` = ' . (int) $this->id, 'limit' => 1));
             $this->row = $this->pods_data->fetch();
         }
     }
     return $this->row;
 }
Esempio n. 2
0
 /**
  * Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
  * You can rewind the list back to the start by using reset().
  *
  * Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
  *
  * @see PodsData::fetch
  *
  * @param int $id ID or slug of the item to fetch
  * @param bool $explicit_set Whether to set explicitly (use false when in loop)
  *
  * @return array An array of fields from the row
  *
  * @since 2.0
  * @link http://pods.io/docs/fetch/
  */
 public function fetch($id = null, $explicit_set = true)
 {
     $this->do_hook('fetch', $id);
     if (!empty($id)) {
         $this->params = array();
     }
     $this->data->fetch($id, $explicit_set);
     return $this->row;
 }
Esempio n. 3
0
 /**
  * Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
  * You can rewind the list back to the start by using reset().
  *
  * Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
  *
  * @see PodsData::fetch
  *
  * @param int $id ID or slug of the item to fetch
  * @param bool $explicit_set Whether to set explicitly (use false when in loop)
  *
  * @return array An array of fields from the row
  *
  * @since 2.0
  * @link http://pods.io/docs/fetch/
  */
 public function fetch($id = null, $explicit_set = true)
 {
     /**
      * Runs directly before an item is fetched by fetch()
      *
      * @since unknown
      *
      * @param int|string|null $id Item ID being fetched or null.
      * @param object|Pods $this Current Pods object.
      */
     do_action('pods_pods_fetch', $id, $this);
     if (!empty($id)) {
         $this->params = array();
     }
     $this->data->fetch($id, $explicit_set);
     return $this->row;
 }