/** * Select items, eventually building dynamic query * * @param array $params * * @return array|bool|mixed * @since 2.0 */ public function select($params) { global $wpdb; $cache_key = $results = false; // Debug purposes if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($params); } // Get from cache if enabled if (null !== pods_var('expires', $params, null, null, true)) { $cache_key = md5(serialize(get_object_vars($params))); $results = pods_view_get($cache_key, pods_var('cache_mode', $params, 'cache', null, true), 'pods_data_select'); if (empty($results)) { $results = false; } } if (empty($results)) { // Build $this->sql = $this->build($params); // Debug purposes if ((1 == pods_var('pods_debug_sql', 'get', 0) || 1 == pods_var('pods_debug_sql_all', 'get', 0)) && pods_is_admin(array('pods'))) { echo '<textarea cols="100" rows="24">' . str_replace(array('@wp_users', '@wp_'), array($wpdb->users, $wpdb->prefix), $this->sql) . '</textarea>'; } if (empty($this->sql)) { return array(); } // Get Data $results = pods_query($this->sql, $this); // Cache if enabled if (false !== $cache_key) { pods_view_set($cache_key, $results, pods_var('expires', $params, 0, null, true), pods_var('cache_mode', $params, 'cache', null, true), 'pods_data_select'); } } $results = $this->do_hook('select', $results); $this->data = $results; $this->row_number = -1; // Fill in empty field data (if none provided) if ((!isset($this->fields) || empty($this->fields)) && !empty($this->data)) { $this->fields = array(); $data = (array) @current($this->data); foreach ($data as $data_key => $data_value) { $this->fields[$data_key] = array('label' => ucwords(str_replace('-', ' ', str_replace('_', ' ', $data_key)))); } $this->fields = PodsForm::fields_setup($this->fields); } $this->total_found_calculated = false; $this->total = count((array) $this->data); return $this->data; }
/** * Set a cached value * * @see PodsView::set * * @param string $key Key for the cache * @param mixed $value Value to add to the cache * @param int $expires (optional) Time in seconds for the cache to expire, if 0 no expiration. * @param string $group (optional) Key for the group * * @return bool|mixed|null|string|void * * @since 2.3.10 */ function pods_option_cache_set($key, $value, $expires = 0, $group = '') { return pods_view_set($key, $value, $expires, 'option-cache', $group); }
/** * Set a cached value * * @see PodsView::set * * @param string $key Key for the cache * @param mixed $value Value to add to the cache * @param int $expires (optional) Time in seconds for the cache to expire, if 0 caching is disabled. * * @return bool|mixed|null|string|void * * @since 2.0 */ function pods_transient_set($key, $value, $expires = 0) { return pods_view_set($key, $value, $expires, 'transient'); }