本文整理汇总了PHP中GFCache::set方法的典型用法代码示例。如果您正苦于以下问题:PHP GFCache::set方法的具体用法?PHP GFCache::set怎么用?PHP GFCache::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFCache
的用法示例。
在下文中一共展示了GFCache::set方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_lead_field_value
/**
* @param $lead
* @param $field GF_Field
*
* @return array|bool|mixed|string|void
*/
public static function get_lead_field_value($lead, $field)
{
if (empty($lead)) {
return;
}
$field_id = $field instanceof GF_Field ? $field->id : $field['id'];
//returning cache entry if available
$cache_key = 'GFFormsModel::get_lead_field_value_' . $lead['id'] . '_' . $field_id;
$cache_value = GFCache::get($cache_key);
if ($cache_value !== false) {
return $cache_value;
}
$max_length = GFORMS_MAX_FIELD_LENGTH;
$value = array();
$inputs = $field instanceof GF_Field ? $field->get_entry_inputs() : rgar($field, 'inputs');
if (is_array($inputs)) {
//making sure values submitted are sent in the value even if
//there isn't an input associated with it
$lead_field_keys = array_keys($lead);
natsort($lead_field_keys);
foreach ($lead_field_keys as $input_id) {
if (is_numeric($input_id) && absint($input_id) == absint($field->id)) {
$val = $lead[$input_id];
if (strlen($val) >= $max_length - 10) {
if (empty($form)) {
$form = RGFormsModel::get_form_meta($lead['form_id']);
}
$long_choice = self::get_field_value_long($lead, $input_id, $form);
} else {
$long_choice = $val;
}
$value[$input_id] = !empty($long_choice) ? $long_choice : $val;
}
}
} else {
$val = rgget($field_id, $lead);
//To save a database call to get long text, only getting long text if regular field is 'somewhat' large (i.e. max - 50)
if (strlen($val) >= $max_length - 50) {
if (empty($form)) {
$form = RGFormsModel::get_form_meta($lead['form_id']);
}
$long_text = self::get_field_value_long($lead, $field_id, $form);
}
$value = !empty($long_text) ? $long_text : $val;
}
//filtering lead value
$value = apply_filters('gform_get_field_value', $value, $lead, $field);
//saving value in global variable to optimize performance
GFCache::set($cache_key, $value);
return $value;
}
示例2: get_payment_feed
public function get_payment_feed($entry, $form = false)
{
$submission_feed = GFCache::get('payment_feed');
if (!$submission_feed) {
if ($entry['id']) {
$feeds = $this->get_feeds_by_entry($entry['id']);
$submission_feed = $this->get_feed($feeds[0]);
} else {
if ($form) {
// getting all active feeds
$feeds = $this->get_feeds($form['id']);
foreach ($feeds as $feed) {
if ($this->is_feed_condition_met($feed, $form, $entry)) {
$submission_feed = $feed;
break;
}
}
}
}
// if called without $form, there is assumption that cache has already been set; let's avoid issues where the cache has not been set and form was not provided
// so that the cache will only be set when an $entry and $form object are provided
if ($entry && $form) {
GFCache::set('payment_feed', $submission_feed);
}
}
return $submission_feed;
}
示例3: field_value
/**
* Given an entry and a form field id, calculate the entry value for that field.
*
* @access public
* @param array $entry
* @param integer $field
* @return null|string
*/
public static function field_value($entry, $field_settings, $format = 'html')
{
if (empty($entry['form_id']) || empty($field_settings['id'])) {
return NULL;
}
$gravityview_view = GravityView_View::getInstance();
if (class_exists('GFCache')) {
/**
* Gravity Forms' GFCache function was thrashing the database, causing double the amount of time for the field_value() method to run.
*
* The reason is that the cache was checking against a field value stored in a transient every time `GFFormsModel::get_lead_field_value()` is called.
*
* What we're doing here is telling the GFCache that it's already checked the transient and the value is false, forcing it to just use the non-cached data, which is actually faster.
*
* @hack
* @since 1.3
* @param string $cache_key Field Value transient key used by Gravity Forms
* @param mixed false Setting the value of the cache to false so that it's not used by Gravity Forms' GFFormsModel::get_lead_field_value() method
* @param boolean false Tell Gravity Forms not to store this as a transient
* @param int 0 Time to store the value. 0 is maximum amount of time possible.
*/
GFCache::set("GFFormsModel::get_lead_field_value_" . $entry["id"] . "_" . $field_settings["id"], false, false, 0);
}
$field_id = $field_settings['id'];
$form = $gravityview_view->getForm();
$field = gravityview_get_field($form, $field_id);
$field_type = RGFormsModel::get_input_type($field);
if ($field_type) {
$field_type = $field['type'];
$value = RGFormsModel::get_lead_field_value($entry, $field);
} else {
// For non-integer field types (`id`, `date_created`, etc.)
$field_type = $field_id;
$field['type'] = $field_id;
$value = isset($entry[$field_type]) ? $entry[$field_type] : NULL;
}
// Prevent any PHP warnings that may be generated
ob_start();
$display_value = GFCommon::get_lead_field_display($field, $value, $entry["currency"], false, $format);
if ($errors = ob_get_clean()) {
do_action('gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors);
}
$display_value = apply_filters("gform_entry_field_value", $display_value, $field, $entry, $form);
// prevent the use of merge_tags for non-admin fields
if (!empty($field['adminOnly'])) {
$display_value = self::replace_variables($display_value, $form, $entry);
}
// Check whether the field exists in /includes/fields/{$field_type}.php
// This can be overridden by user template files.
$field_exists = $gravityview_view->locate_template("fields/{$field_type}.php");
// Set the field data to be available in the templates
$gravityview_view->setCurrentField(array('form' => $form, 'field_id' => $field_id, 'field' => $field, 'field_settings' => $field_settings, 'value' => $value, 'display_value' => $display_value, 'format' => $format, 'entry' => $entry, 'field_type' => $field_type));
if ($field_exists) {
do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_exists));
ob_start();
load_template($field_exists, false);
$output = ob_get_clean();
} else {
// Backup; the field template doesn't exist.
$output = $display_value;
}
$field_settings = $gravityview_view->getCurrentField('field_settings');
/**
* Link to the single entry by wrapping the output in an anchor tag
*
* Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
*
*/
if (!empty($field_settings['show_as_link'])) {
$output = self::entry_link_html($entry, $output, array(), $field_settings);
}
/**
* @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
* @since 1.6
* @param string $output HTML value output
* @param array $entry The GF entry array
* @param array $field_settings Settings for the particular GV field
*/
$output = apply_filters('gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField());
/**
* @filter `gravityview_field_entry_value` Modify the field value output for all field types
* @param string $output HTML value output
* @param array $entry The GF entry array
* @param array $field_settings Settings for the particular GV field
* @param array $field_data {@since 1.6}
*/
$output = apply_filters('gravityview_field_entry_value', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
return $output;
}
示例4: is_section_empty
public static function is_section_empty($section_field, $form, $lead)
{
$cache_key = "GFCommon::is_section_empty_" . $form["id"] . "_" . $section_field["id"];
$value = GFCache::get($cache_key);
if ($value !== false) {
return $value == true;
}
$fields = self::get_section_fields($form, $section_field["id"]);
if (!is_array($fields)) {
GFCache::set($cache_key, 1);
return true;
}
foreach ($fields as $field) {
$val = RGFormsModel::get_lead_field_value($lead, $field);
$val = GFCommon::get_lead_field_display($field, $val, rgar($lead, 'currency'));
if (!self::is_product_field($field["type"]) && !rgblank($val)) {
GFCache::set($cache_key, 0);
return false;
}
}
GFCache::set($cache_key, 1);
return true;
}
示例5: update_lock_request_meta
protected function update_lock_request_meta($object_id, $lock_request_value)
{
GFCache::set(self::PREFIX_EDIT_LOCK_REQUEST . $this->_object_type . '_' . $object_id, $lock_request_value, true, 120);
}
示例6: is_field_hidden
/**
* Check whether a field is hidden via conditional logic.
*
* @param array $form Form object.
* @param GF_Field $field Field object.
* @param array $field_values Default field values for this form. Used when form has not yet been submitted. Pass an array if no default field values are available/required.
* @param array $lead Optional, default is null. If lead object is available, pass the lead.
*
* @return mixed
*/
public static function is_field_hidden($form, $field, $field_values, $lead = null)
{
if (empty($field)) {
return false;
}
$cache_key = 'GFFormsModel::is_field_hidden_' . $form['id'] . '_' . $field->id;
$display = GFCache::get($cache_key);
if ($display !== false) {
return $display;
}
$section = self::get_section($form, $field->id);
$section_display = self::get_field_display($form, $section, $field_values, $lead);
//if section is hidden, hide field no matter what. if section is visible, see if field is supposed to be visible
if ($section_display == 'hide') {
$display = 'hide';
} else {
if (self::is_page_hidden($form, $field->pageNumber, $field_values, $lead)) {
$display = 'hide';
} else {
$display = self::get_field_display($form, $field, $field_values, $lead);
return $display == 'hide';
}
}
GFCache::set($cache_key, $display);
return $display == 'hide';
}
示例7: is_section_empty
public static function is_section_empty($section_field, $form, $entry)
{
$cache_key = "GFCommon::is_section_empty_{$form['id']}_{$section_field['id']}";
$value = GFCache::get($cache_key);
if ($value !== false) {
return $value == true;
}
$fields = self::get_section_fields($form, $section_field['id']);
if (!is_array($fields)) {
GFCache::set($cache_key, 1);
return true;
}
foreach ($fields as $field) {
$value = GFFormsModel::get_lead_field_value($entry, $field);
$value = GFCommon::get_lead_field_display($field, $value, rgar($entry, 'currency'));
if (rgblank($value)) {
continue;
}
// most fields are displayed in the section by default, exceptions are handled below
$is_field_displayed_in_section = true;
// by default, product fields are not displayed in their containing section (displayed in a product summary table)
// if the filter is used to disable this, product fields are displayed in the section like other fields
if (self::is_product_field($field['type'])) {
$display_product_summary = apply_filters('gform_display_product_summary', true, $field, $form, $entry);
$is_field_displayed_in_section = !$display_product_summary;
}
if ($is_field_displayed_in_section) {
GFCache::set($cache_key, 0);
return false;
}
}
GFCache::set($cache_key, 1);
return true;
}
示例8: get_feeds
public function get_feeds($form_id = null)
{
global $wpdb;
$cache_key = implode('_', array_filter(array($this->_slug, 'get_feeds', $form_id)));
$feeds = GFCache::get($cache_key);
if (is_array($feeds)) {
return $feeds;
}
$form_filter = is_numeric($form_id) ? $wpdb->prepare("AND form_id=%d", absint($form_id)) : "";
$sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}gf_addon_feed\n WHERE addon_slug=%s {$form_filter}", $this->_slug);
$results = $wpdb->get_results($sql, ARRAY_A);
foreach ($results as &$result) {
$result["meta"] = json_decode($result["meta"], true);
}
GFCache::set($cache_key, $results);
return $results;
}
示例9: get_group_setting_key
public function get_group_setting_key($grouping_id, $group_name)
{
$plugin_settings = GFCache::get('mailchimp_plugin_settings');
if (empty($plugin_settings)) {
$plugin_settings = $this->get_plugin_settings();
GFCache::set('mailchimp_plugin_settings', $plugin_settings);
}
$key = 'group_key_' . $grouping_id . '_' . str_replace('%', '', sanitize_title_with_dashes($group_name));
if (!isset($plugin_settings[$key])) {
$group_key = 'mc_group_' . uniqid();
$plugin_settings[$key] = $group_key;
$this->update_plugin_settings($plugin_settings);
GFCache::set('mailchimp_plugin_settings', $plugin_settings);
}
return $plugin_settings[$key];
}
示例10: update_cache
/**
* Update the results cache.
*
* @param int $form_id The form ID.
*
* @return array
*/
public function update_cache($form_id)
{
$gpoll_data = $this->gpoll_get_data($form_id);
GFCache::set('gpoll_data_' . $form_id, $gpoll_data, true);
return $gpoll_data;
}
示例11: get_payment_feed
public function get_payment_feed($entry, $form)
{
$submission_feed = GFCache::get("payment_feed");
if (!$submission_feed) {
if (!empty($entry["id"])) {
$feeds = $this->get_processed_feeds($entry["id"]);
$submission_feed = $this->get_feed($feeds[0]);
} else {
// getting all active feeds
$feeds = $this->get_feeds($form['id']);
foreach ($feeds as $feed) {
if ($this->is_feed_condition_met($feed, $form, $entry)) {
$submission_feed = $feed;
break;
}
}
}
GFCache::set("payment_feed", $submission_feed);
}
return $submission_feed;
}
示例12: get_clients
/**
* Return the clients.
*
* @return mixed
*/
private function get_clients()
{
$clients = GFCache::get('campaignmonitor_clients');
if (!$clients) {
$this->include_api();
$api = new CS_REST_General($this->get_key());
//getting all clients
$response = $api->get_clients();
if ($response->http_status_code == 200) {
$clients = $response->response;
GFCache::set('campaignmonitor_clients', $clients);
}
}
return $clients;
}
示例13: get_lead_field_value
public static function get_lead_field_value($lead, $field){
if(empty($lead))
return;
//returning cache entry if available
$cache_key = "GFFormsModel::get_lead_field_value_" . $lead["id"] . "_" . $field["id"];
$cache_value = GFCache::get($cache_key);
if($cache_value !== false)
return $cache_value;
$max_length = GFORMS_MAX_FIELD_LENGTH;
$value = array();
if(is_array(rgar($field, "inputs"))){
//making sure values submitted are sent in the value even if
//there isn't an input associated with it
$lead_field_keys = array_keys($lead);
foreach($lead_field_keys as $input_id){
if(is_numeric($input_id) && absint($input_id) == absint($field["id"])){
$val = $lead[$input_id];
if(strlen($val) >= ($max_length-10)) {
if(empty($form))
$form = RGFormsModel::get_form_meta($lead["form_id"]);
$long_choice = self::get_field_value_long($lead, $input_id, $form);
}
else{
$long_choice = $val;
}
$value[$input_id] = !empty($long_choice) ? $long_choice : $val;
}
}
}
else{
$val = rgget($field["id"], $lead);
//To save a database call to get long text, only getting long text if regular field is "somewhat" large (i.e. max - 50)
if(strlen($val) >= ($max_length - 50)){
if(empty($form))
$form = RGFormsModel::get_form_meta($lead["form_id"]);
$long_text = self::get_field_value_long($lead, $field["id"], $form);
}
$value = !empty($long_text) ? $long_text : $val;
}
//filtering lead value
$value = apply_filters("gform_get_field_value", $value, $lead, $field);
//saving value in global variable to optimize performance
GFCache::set($cache_key, $value);
return $value;
}
示例14: get_freshbooks_items
public function get_freshbooks_items()
{
//non persistent cache
$fb_items = GFCache::get('freshbooks_items');
if (empty($fb_items)) {
$this->init_api();
$items = new FreshBooks_Item();
$result = array();
$result_info = array();
$current_page = 1;
$fb_items = array();
do {
$items->listing($result, $result_info, $current_page, 100);
$pages = $result_info['pages'];
foreach ($result as $line_item) {
$fb_items[] = array('value' => $line_item->itemId, 'label' => $line_item->name);
}
$current_page++;
} while ($current_page <= $pages);
GFCache::set('freshbooks_items', $fb_items);
}
return $fb_items;
}