本文整理汇总了PHP中GFAPI::count_entries方法的典型用法代码示例。如果您正苦于以下问题:PHP GFAPI::count_entries方法的具体用法?PHP GFAPI::count_entries怎么用?PHP GFAPI::count_entries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFAPI
的用法示例。
在下文中一共展示了GFAPI::count_entries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gravitywp_count_func
function gravitywp_count_func($atts, $content = null)
{
extract(shortcode_atts(array('formid' => 'formid', 'field' => 'field'), $atts));
$search_criteria = null;
$sorting = null;
$paging = array('offset' => 0, 'page_size' => 200);
$entries = GFAPI::get_entries($formid, $search_criteria, $sorting, $paging);
$countentries = GFAPI::count_entries($formid);
$gwp_count = 0;
for ($row = 0; $row < $countentries; $row++) {
$gwp_count += $entries[$row][$field];
}
return $gwp_count;
}
示例2: test_fire_everything
/**
* @since 1.15
* @covers GravityView_Uninstall::fire_everything()
*/
function test_fire_everything()
{
$create_count = 10;
$form = $this->factory->form->create_and_get();
$all_forms = GFAPI::get_forms();
$views = $this->factory->view->create_many($create_count, array('form_id' => $form['id']));
$entry_ids = $this->factory->entry->create_many($create_count, array('form_id' => $form['id']));
$connected = gravityview_get_connected_views($form['id']);
$entry_count = GFAPI::count_entries($form['id']);
// Make sure the objects were created and connected
$this->assertEquals($create_count, count(array_filter($views)));
$this->assertEquals($create_count, count(array_filter($connected)));
$this->assertEquals($create_count, count(array_filter($entry_ids)));
$this->_set_up_expected_options();
### DO NOT DELETE WHEN THE USER DOESN'T HAVE THE CAPABILITY
$user = $this->factory->user->create_and_set(array('user_login' => 'administrator', 'user_pass' => 'administrator', 'role' => 'administrator'));
$this->assertTrue(GVCommon::has_cap('gravityview_uninstall'));
### DO NOT DELETE WHEN IT IS NOT SET OR SET TO FALSE
// TRY deleting when the settings aren't configured.
$this->_set_up_gravityview_settings(NULL);
$this->uninstall();
$this->_check_deleted_options(false);
// TRY deleting when the Delete setting is set to No
$this->_set_up_gravityview_settings('0');
$this->uninstall();
$this->_check_deleted_options(false);
### REALLY DELETE NOW
// Create the items
$this->_set_up_gravityview_settings('delete');
$this->_set_up_notes($entry_ids);
$this->_set_up_entry_meta($entry_ids, $form);
$this->uninstall();
// No Forms should be deleted
$this->assertEquals($all_forms, GFAPI::get_forms());
$this->_check_posts();
$this->_check_entries($form, $entry_count);
$this->_check_deleted_options();
$this->_check_deleted_entry_notes($entry_ids);
$this->_check_deleted_entry_meta($entry_ids);
}
示例3: get_results_data
public function get_results_data($form, $fields, $search_criteria = array(), $state_array = array(), $max_execution_time = 15)
{
// todo: add hooks to modify $max_execution_time and $page_size?
$page_size = 150;
$time_start = microtime(true);
$form_id = $form["id"];
$data = array();
$offset = 0;
$entry_count = 0;
$field_data = array();
if ($state_array) {
//get counts from state
$data = $state_array;
$offset = (int) rgar($data, "offset");
unset($data["offset"]);
$entry_count = $offset;
$field_data = rgar($data, "field_data");
} else {
//initialize counts
foreach ($fields as $field) {
$field_type = GFFormsModel::get_input_type($field);
if (false === isset($field["choices"])) {
$field_data[$field["id"]] = 0;
continue;
}
$choices = $field["choices"];
if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
foreach ($field["gsurveyLikertRows"] as $row) {
foreach ($choices as $choice) {
$field_data[$field["id"]][$row["value"]][$choice['value']] = 0;
}
}
} else {
foreach ($choices as $choice) {
$field_data[$field["id"]][$choice['value']] = 0;
}
}
if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableScoring")) {
$field_data[$field["id"]]["sum_of_scores"] = 0;
}
}
}
$count_search_leads = GFAPI::count_entries($form_id, $search_criteria);
$data["entry_count"] = $count_search_leads;
$entries_left = $count_search_leads - $offset;
while ($entries_left >= 0) {
$paging = array('offset' => $offset, 'page_size' => $page_size);
$search_leads_time_start = microtime(true);
$leads = GFFormsModel::search_leads($form_id, $search_criteria, null, $paging);
$search_leads_time_end = microtime(true);
$search_leads_time = $search_leads_time_end - $search_leads_time_start;
$leads_in_search = count($leads);
$entry_count += $leads_in_search;
foreach ($leads as $lead) {
foreach ($fields as $field) {
$field_type = GFFormsModel::get_input_type($field);
$field_id = $field["id"];
$value = RGFormsModel::get_lead_field_value($lead, $field);
if ($field_type == "likert" && rgar($field, "gsurveyLikertEnableMultipleRows")) {
if (empty($value)) {
continue;
}
foreach ($value as $value_vector) {
if (empty($value_vector)) {
continue;
}
list($row_val, $col_val) = explode(":", $value_vector, 2);
if (isset($field_data[$field["id"]][$row_val]) && isset($field_data[$field["id"]][$row_val][$col_val])) {
$field_data[$field["id"]][$row_val][$col_val]++;
}
}
} elseif ($field_type == "rank") {
$score = count(rgar($field, "choices"));
$values = explode(",", $value);
foreach ($values as $ranked_value) {
$field_data[$field["id"]][$ranked_value] += $score;
$score--;
}
} else {
if (false === isset($field["choices"])) {
if (false === empty($value)) {
$field_data[$field_id]++;
}
continue;
}
$choices = $field["choices"];
foreach ($choices as $choice) {
$choice_is_selected = false;
if (is_array($value)) {
$choice_value = rgar($choice, "value");
if (in_array($choice_value, $value)) {
$choice_is_selected = true;
}
} else {
if (RGFormsModel::choice_value_match($field, $choice, $value)) {
$choice_is_selected = true;
}
}
if ($choice_is_selected) {
$field_data[$field_id][$choice['value']]++;
//.........这里部分代码省略.........
示例4: get_entries
public function get_entries($entry_ids, $form_ids = null, $schema = "", $field_ids = array())
{
$this->authorize("gravityforms_view_entries");
$status = 200;
$response = array();
$result = array();
if ($entry_ids) {
if (is_array($entry_ids)) {
foreach ($entry_ids as $entry_id) {
$result = GFAPI::get_entry($entry_id);
if (!is_wp_error($result)) {
$response[$entry_id] = $result;
if (!empty($field_ids) && !empty($response[$entry_id])) {
$response[$entry_id] = $this->filter_entry_object($response[$entry_id], $field_ids);
}
}
}
} else {
$result = GFAPI::get_entry($entry_ids);
if (!is_wp_error($result)) {
$response = $result;
if (!empty($field_ids) && !empty($response)) {
$response = $this->filter_entry_object($response, $field_ids);
}
}
}
if ($schema == "mtd") {
$response = self::mtd_transform_entry_data($response);
}
} else {
//sorting parameters
$sort_key = isset($_GET["sorting"]["key"]) && !empty($_GET["sorting"]["key"]) ? $_GET["sorting"]["key"] : "id";
$sort_dir = isset($_GET["sorting"]["direction"]) && !empty($_GET["sorting"]["direction"]) ? $_GET["sorting"]["direction"] : "DESC";
$sorting = array('key' => $sort_key, 'direction' => $sort_dir);
//paging parameters
$page_size = isset($_GET["paging"]["page_size"]) ? intval($_GET["paging"]["page_size"]) : 10;
if (isset($_GET["paging"]["current_page"])) {
$current_page = intval($_GET["paging"]["current_page"]);
$offset = $page_size * ($current_page - 1);
} else {
$offset = isset($_GET["paging"]["offset"]) ? intval($_GET["paging"]["offset"]) : 0;
}
$paging = array('offset' => $offset, 'page_size' => $page_size);
$search = isset($_GET["search"]) ? $_GET["search"] : array();
if (empty($form_ids)) {
$form_ids = 0;
}
// all forms
$entry_count = GFAPI::count_entries($form_ids, $search);
$result = $entry_count > 0 ? GFAPI::get_entries($form_ids, $search, $sorting, $paging) : array();
if (!is_wp_error($result)) {
$response = array("total_count" => $entry_count, "entries" => $result);
if ($schema == "mtd") {
$response = $this->mtd_transform_entries_data($response, $form_ids);
}
}
}
if (is_wp_error($result)) {
$response = $this->get_error_response($result);
$status = $this->get_error_status($result);
}
$this->end($status, $response);
}
示例5: start_export
public static function start_export($form)
{
$form_id = $form['id'];
$fields = $_POST['export_field'];
$start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
$end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
$search_criteria['status'] = 'active';
$search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
if (!empty($start_date)) {
$search_criteria['start_date'] = $start_date;
}
if (!empty($end_date)) {
$search_criteria['end_date'] = $end_date;
}
$sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
$form = self::add_default_export_fields($form);
$entry_count = GFAPI::count_entries($form_id, $search_criteria);
$page_size = 100;
$offset = 0;
//Adding BOM marker for UTF-8
$lines = chr(239) . chr(187) . chr(191);
// set the separater
$separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id);
$field_rows = self::get_field_row_count($form, $fields, $entry_count);
//writing header
$headers = array();
foreach ($fields as $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$value = str_replace('"', '""', GFCommon::get_label($field, $field_id));
GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
$headers[$field_id] = $str = preg_replace('/[^a-z\\d ]/i', '', $value);
$subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
if ($subrow_count == 0) {
$lines .= '"' . $value . '"' . $separator;
} else {
for ($i = 1; $i <= $subrow_count; $i++) {
$lines .= '"' . $value . ' ' . $i . '"' . $separator;
}
}
GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
}
$lines = substr($lines, 0, strlen($lines) - 1) . "\n";
//paging through results for memory issues
while ($entry_count > 0) {
$paging = array('offset' => $offset, 'page_size' => $page_size);
$leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
$leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters('gform_leads_before_export', $leads, $form, $paging), $form, $paging);
foreach ($leads as $lead) {
foreach ($fields as $field_id) {
switch ($field_id) {
case 'date_created':
$lead_gmt_time = mysql2date('G', $lead['date_created']);
$lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
$value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
break;
default:
$long_text = '';
if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) {
$long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form);
}
$value = !empty($long_text) ? $long_text : rgar($lead, $field_id);
$field = RGFormsModel::get_field($form, $field_id);
$input_type = RGFormsModel::get_input_type($field);
if ($input_type == 'checkbox') {
//pass in label value that has not had quotes escaped so the is_checkbox_checked function compares the unchanged label value with the lead value
$header_label_not_escaped = GFCommon::get_label($field, $field_id);
$value = GFFormsModel::is_checkbox_checked($field_id, $header_label_not_escaped, $lead, $form);
if ($value === false) {
$value = '';
}
} else {
if ($input_type == 'fileupload' && $field->multipleFiles) {
$value = !empty($value) ? implode(' , ', json_decode($value, true)) : '';
}
}
$value = preg_replace('/[^a-z\\d ]/i', '', $value);
$value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
break;
}
if (isset($field_rows[$field_id])) {
$list = empty($value) ? array() : unserialize($value);
foreach ($list as $row) {
$row_values = array_values($row);
$row_str = implode('|', $row_values);
$lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
}
//filling missing subrow columns (if any)
$missing_count = intval($field_rows[$field_id]) - count($list);
for ($i = 0; $i < $missing_count; $i++) {
$lines .= '""' . $separator;
}
} else {
$value = maybe_unserialize($value);
if (is_array($value)) {
$value = implode('|', $value);
}
$lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
//.........这里部分代码省略.........
示例6: get_entries
/**
* Retrieve entries given search, sort, paging criteria
*
* @see GFAPI::get_entries()
* @see GFFormsModel::get_field_filters_where()
* @access public
* @param int|array $form_ids The ID of the form or an array IDs of the Forms. Zero for all forms.
* @param mixed $passed_criteria (default: null)
* @param mixed &$total Optional. An output parameter containing the total number of entries. Pass a non-null value to generate the total count. (default: null)
* @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays
*/
public static function get_entries($form_ids = null, $passed_criteria = null, &$total = null)
{
// Filter the criteria before query (includes Adv Filter)
$criteria = self::calculate_get_entries_criteria($passed_criteria, $form_ids);
do_action('gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria);
// Return value
$return = null;
if (!empty($criteria['cache'])) {
$Cache = new GravityView_Cache($form_ids, $criteria);
if ($entries = $Cache->get()) {
// Still update the total count when using cached results
if (!is_null($total)) {
$total = GFAPI::count_entries($form_ids, $criteria['search_criteria']);
}
$return = $entries;
}
}
if (is_null($return) && class_exists('GFAPI') && (is_numeric($form_ids) || is_array($form_ids))) {
$entries = GFAPI::get_entries($form_ids, $criteria['search_criteria'], $criteria['sorting'], $criteria['paging'], $total);
if (is_wp_error($entries)) {
do_action('gravityview_log_error', $entries->get_error_message(), $entries);
return false;
}
if (!empty($criteria['cache']) && isset($Cache)) {
// Cache results
$Cache->set($entries, 'entries');
}
$return = $entries;
}
/**
* @filter `gravityview_entries` Modify the array of entries returned to GravityView after it has been fetched from the cache or from `GFAPI::get_entries()`.
* @param array|null $entries Array of entries as returned by the cache or by `GFAPI::get_entries()`
* @param array $criteria The final search criteria used to generate the request to `GFAPI::get_entries()`
* @param array $passed_criteria The original search criteria passed to `GVCommon::get_entries()`
* @param int|null $total Optional. An output parameter containing the total number of entries. Pass a non-null value to generate
*/
$return = apply_filters('gravityview_entries', $return, $criteria, $passed_criteria, $total);
return $return;
}
示例7: get_entries
public function get_entries($entry_ids, $form_ids = null, $schema = '', $field_ids = array())
{
$this->log_debug(__METHOD__ . '(): Running.');
$capability = apply_filters('gform_web_api_capability_get_entries', 'gravityforms_view_entries');
$this->authorize($capability);
$status = 200;
$response = array();
$result = array();
if ($entry_ids) {
if (is_array($entry_ids)) {
foreach ($entry_ids as $entry_id) {
$result = GFAPI::get_entry($entry_id);
if (!is_wp_error($result)) {
$result = $this->maybe_json_encode_list_fields($result);
$response[$entry_id] = $result;
if (!empty($field_ids) && !empty($response[$entry_id])) {
$response[$entry_id] = $this->filter_entry_object($response[$entry_id], $field_ids);
}
}
}
} else {
$result = GFAPI::get_entry($entry_ids);
if (!is_wp_error($result)) {
$result = $this->maybe_json_encode_list_fields($result);
$response = $result;
if (!empty($field_ids) && !empty($response)) {
$response = $this->filter_entry_object($response, $field_ids);
}
}
}
if ($schema == 'mtd') {
$response = self::mtd_transform_entry_data($response);
}
} else {
//sorting parameters
$sort_key = isset($_GET['sorting']['key']) && !empty($_GET['sorting']['key']) ? $_GET['sorting']['key'] : 'id';
$sort_dir = isset($_GET['sorting']['direction']) && !empty($_GET['sorting']['direction']) ? $_GET['sorting']['direction'] : 'DESC';
$sorting = array('key' => $sort_key, 'direction' => $sort_dir);
if (isset($_GET['sorting']['is_numeric'])) {
$sorting['is_numeric'] = $_GET['sorting']['is_numeric'];
}
//paging parameters
$page_size = isset($_GET['paging']['page_size']) ? intval($_GET['paging']['page_size']) : 10;
if (isset($_GET['paging']['current_page'])) {
$current_page = intval($_GET['paging']['current_page']);
$offset = $page_size * ($current_page - 1);
} else {
$offset = isset($_GET['paging']['offset']) ? intval($_GET['paging']['offset']) : 0;
}
$paging = array('offset' => $offset, 'page_size' => $page_size);
if (isset($_GET['search'])) {
$search = $_GET['search'];
if (!is_array($search)) {
$search = urldecode(stripslashes($search));
$search = json_decode($search, true);
}
} else {
$search = array();
}
if (empty($form_ids)) {
$form_ids = 0;
}
// all forms
$entry_count = GFAPI::count_entries($form_ids, $search);
$result = $entry_count > 0 ? GFAPI::get_entries($form_ids, $search, $sorting, $paging) : array();
if (!is_wp_error($result)) {
foreach ($result as &$entry) {
$entry = $this->maybe_json_encode_list_fields($entry);
}
$response = array('total_count' => $entry_count, 'entries' => $result);
if ($schema == 'mtd') {
$response = $this->mtd_transform_entries_data($response, $form_ids);
}
}
}
if (is_wp_error($result)) {
$response = $this->get_error_response($result);
$status = $this->get_error_status($result);
}
$this->end($status, $response);
}
示例8: wpcampus_get_vote_on_new_name
function wpcampus_get_vote_on_new_name()
{
// Set the form ID
$form_id = 6;
// Build response
$response = array();
// Get form
if (($form = GFAPI::get_form($form_id)) && ($fields = $form['fields'])) {
foreach ($fields as $field) {
// Get our specific field
if ('Vote on New Name' == $field->adminLabel) {
foreach ($field->choices as $choice) {
// Get the count
$search_criteria = array('status' => 'active');
$search_criteria['field_filters'][] = array('key' => $field->id, 'operator' => '=', 'value' => $choice['value']);
$choice_count = GFAPI::count_entries($form_id, $search_criteria);
// Add to response
$response[] = array('text' => $choice['text'], 'count' => $choice_count);
}
break;
}
}
}
return $response;
}
示例9: start_export
public static function start_export($form)
{
$form_id = $form["id"];
$fields = $_POST["export_field"];
$start_date = empty($_POST["export_date_start"]) ? "" : self::get_gmt_date($_POST["export_date_start"] . " 00:00:00");
$end_date = empty($_POST["export_date_end"]) ? "" : self::get_gmt_date($_POST["export_date_end"] . " 23:59:59");
$search_criteria["status"] = "active";
$search_criteria["field_filters"] = GFCommon::get_field_filters_from_post();
if (!empty($start_date)) {
$search_criteria["start_date"] = $start_date;
}
if (!empty($end_date)) {
$search_criteria["end_date"] = $end_date;
}
$sorting = array('key' => "date_created", 'direction' => "DESC", "type" => "info");
GFCommon::log_debug("start date: {$start_date}");
GFCommon::log_debug("end date: {$end_date}");
$form = self::add_default_export_fields($form);
$entry_count = GFAPI::count_entries($form_id, $search_criteria);
$page_size = 100;
$offset = 0;
//Adding BOM marker for UTF-8
$lines = chr(239) . chr(187) . chr(191);
// set the separater
$separator = apply_filters('gform_export_separator_' . $form_id, apply_filters('gform_export_separator', ',', $form_id), $form_id);
$field_rows = self::get_field_row_count($form, $fields, $entry_count);
//writing header
$headers = array();
foreach ($fields as $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$value = str_replace('"', '""', GFCommon::get_label($field, $field_id));
GFCommon::log_debug("Header for field ID {$field_id}: {$value}");
$headers[$field_id] = $value;
$subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
if ($subrow_count == 0) {
$lines .= '"' . $value . '"' . $separator;
} else {
for ($i = 1; $i <= $subrow_count; $i++) {
$lines .= '"' . $value . " " . $i . '"' . $separator;
}
}
GFCommon::log_debug("Lines: {$lines}");
}
$lines = substr($lines, 0, strlen($lines) - 1) . "\n";
//paging through results for memory issues
while ($entry_count > 0) {
//$leads = RGFormsModel::get_leads($form_id,"date_created", "DESC", "", $offset, $page_size, null, null, false, $start_date, $end_date);
$paging = array('offset' => $offset, 'page_size' => $page_size);
$leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
$leads = apply_filters("gform_leads_before_export_{$form_id}", apply_filters("gform_leads_before_export", $leads, $form, $paging), $form, $paging);
foreach ($leads as $lead) {
foreach ($fields as $field_id) {
switch ($field_id) {
case "date_created":
$lead_gmt_time = mysql2date("G", $lead["date_created"]);
$lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
$value = date_i18n("Y-m-d H:i:s", $lead_local_time, true);
break;
default:
$long_text = "";
if (strlen(rgar($lead, $field_id)) >= GFORMS_MAX_FIELD_LENGTH - 10) {
$long_text = RGFormsModel::get_field_value_long($lead, $field_id, $form);
}
$value = !empty($long_text) ? $long_text : rgar($lead, $field_id);
$field = RGFormsModel::get_field($form, $field_id);
$input_type = RGFormsModel::get_input_type($field);
if ($input_type == "checkbox") {
$value = GFFormsModel::is_checkbox_checked($field_id, $headers[$field_id], $lead, $form);
if ($value === false) {
$value = "";
}
} else {
if ($input_type == "fileupload" && rgar($field, "multipleFiles")) {
$value = !empty($value) ? implode(" , ", json_decode($value, true)) : "";
}
}
$value = apply_filters("gform_export_field_value", $value, $form_id, $field_id, $lead);
GFCommon::log_debug("Value for field ID {$field_id}: {$value}");
break;
}
if (isset($field_rows[$field_id])) {
$list = empty($value) ? array() : unserialize($value);
foreach ($list as $row) {
$row_values = array_values($row);
$row_str = implode("|", $row_values);
$lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
}
//filling missing subrow columns (if any)
$missing_count = intval($field_rows[$field_id]) - count($list);
for ($i = 0; $i < $missing_count; $i++) {
$lines .= '""' . $separator;
}
} else {
$value = maybe_unserialize($value);
if (is_array($value)) {
$value = implode("|", $value);
}
$lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
}
}
//.........这里部分代码省略.........
示例10: get_entries
public function get_entries($entry_ids, $form_ids = null, $schema = '', $field_ids = array())
{
$this->authorize('gravityforms_view_entries');
$status = 200;
$response = array();
$result = array();
if ($entry_ids) {
if (is_array($entry_ids)) {
foreach ($entry_ids as $entry_id) {
$result = GFAPI::get_entry($entry_id);
if (!is_wp_error($result)) {
$response[$entry_id] = $result;
if (!empty($field_ids) && !empty($response[$entry_id])) {
$response[$entry_id] = $this->filter_entry_object($response[$entry_id], $field_ids);
}
}
}
} else {
$result = GFAPI::get_entry($entry_ids);
if (!is_wp_error($result)) {
$response = $result;
if (!empty($field_ids) && !empty($response)) {
$response = $this->filter_entry_object($response, $field_ids);
}
}
}
if ($schema == 'mtd') {
$response = self::mtd_transform_entry_data($response);
}
} else {
//sorting parameters
$sort_key = isset($_GET['sorting']['key']) && !empty($_GET['sorting']['key']) ? $_GET['sorting']['key'] : 'id';
$sort_dir = isset($_GET['sorting']['direction']) && !empty($_GET['sorting']['direction']) ? $_GET['sorting']['direction'] : 'DESC';
$sorting = array('key' => $sort_key, 'direction' => $sort_dir);
if (isset($_GET['sorting']['is_numeric'])) {
$sorting['is_numeric'] = $_GET['sorting']['is_numeric'];
}
//paging parameters
$page_size = isset($_GET['paging']['page_size']) ? intval($_GET['paging']['page_size']) : 10;
if (isset($_GET['paging']['current_page'])) {
$current_page = intval($_GET['paging']['current_page']);
$offset = $page_size * ($current_page - 1);
} else {
$offset = isset($_GET['paging']['offset']) ? intval($_GET['paging']['offset']) : 0;
}
$paging = array('offset' => $offset, 'page_size' => $page_size);
$search = isset($_GET['search']) ? $_GET['search'] : array();
if (empty($form_ids)) {
$form_ids = 0;
}
// all forms
$entry_count = GFAPI::count_entries($form_ids, $search);
$result = $entry_count > 0 ? GFAPI::get_entries($form_ids, $search, $sorting, $paging) : array();
if (!is_wp_error($result)) {
$response = array('total_count' => $entry_count, 'entries' => $result);
if ($schema == 'mtd') {
$response = $this->mtd_transform_entries_data($response, $form_ids);
}
}
}
if (is_wp_error($result)) {
$response = $this->get_error_response($result);
$status = $this->get_error_status($result);
}
$this->end($status, $response);
}
示例11: get_counts
function get_counts($args)
{
if (!empty($args['field_filters'])) {
if (isset($args['form-id'])) {
$form_ids = absint($args['form-id']);
} else {
$form_ids = $this->get_workflow_form_ids();
}
$results = new stdClass();
$results->total = 0;
$results->pending = 0;
$results->complete = 0;
$results->cancelled = 0;
if (empty($form_ids)) {
$this->items = array();
return $results;
}
$base_search_criteria = $this->get_search_criteria();
$pending_search_criteria = $base_search_criteria;
$pending_search_criteria['field_filters'][] = array('key' => 'workflow_final_status', 'value' => 'pending');
$complete_search_criteria = $base_search_criteria;
$complete_search_criteria['field_filters'][] = array('key' => 'workflow_final_status', 'operator' => 'not in', 'value' => array('pending', 'cancelled'));
$cancelled_search_criteria = $base_search_criteria;
$cancelled_search_criteria['field_filters'][] = array('key' => 'workflow_final_status', 'value' => 'cancelled');
$results->total = GFAPI::count_entries($form_ids, $base_search_criteria);
$results->pending = GFAPI::count_entries($form_ids, $pending_search_criteria);
$results->complete = GFAPI::count_entries($form_ids, $complete_search_criteria);
$results->cancelled = GFAPI::count_entries($form_ids, $cancelled_search_criteria);
return $results;
}
global $wpdb;
if (!empty($args['form-id'])) {
$form_clause = ' AND l.form_id=' . absint($args['form-id']);
} else {
$form_ids = $this->get_workflow_form_ids();
if (empty($form_ids)) {
$results = new stdClass();
$results->pending = 0;
$results->complete = 0;
$results->cancelled = 0;
return $results;
}
$form_clause = ' AND l.form_id IN(' . join(',', $form_ids) . ')';
}
$start_clause = '';
if (!empty($args['start-date'])) {
$start_clause = $wpdb->prepare(' AND l.date_created >= %s', $args['start-date']);
}
$end_clause = '';
if (!empty($args['end-date'])) {
$end_clause = $wpdb->prepare(' AND l.date_created <= %s', $args['end-date']);
}
$user_id_clause = '';
if (!$this->display_all) {
$user = wp_get_current_user();
$user_id_clause = $wpdb->prepare(' AND created_by=%d', $user->ID);
}
$lead_table = GFFormsModel::get_lead_table_name();
$meta_table = GFFormsModel::get_lead_meta_table_name();
$sql = "SELECT\n\t\t(SELECT count(distinct(l.id)) FROM {$lead_table} l WHERE l.status='active' {$form_clause} {$start_clause} {$end_clause} {$user_id_clause}) as total,\n\t\t(SELECT count(distinct(l.id)) FROM {$lead_table} l INNER JOIN {$meta_table} m ON l.id = m.lead_id WHERE l.status='active' AND meta_key='workflow_final_status' AND meta_value='pending' {$form_clause} {$start_clause} {$end_clause} {$user_id_clause}) as pending,\n\t\t(SELECT count(distinct(l.id)) FROM {$lead_table} l INNER JOIN {$meta_table} m ON l.id = m.lead_id WHERE l.status='active' AND meta_key='workflow_final_status' AND meta_value NOT IN('pending', 'cancelled') {$form_clause} {$start_clause} {$end_clause} {$user_id_clause}) as complete,\n\t\t(SELECT count(distinct(l.id)) FROM {$lead_table} l INNER JOIN {$meta_table} m ON l.id = m.lead_id WHERE l.status='active' AND meta_key='workflow_final_status' AND meta_value='cancelled' {$form_clause} {$start_clause} {$end_clause} {$user_id_clause}) as cancelled\n\t\t";
$results = $wpdb->get_results($sql);
return $results[0];
}
示例12: get_form_entries_json
function get_form_entries_json($gf_form_id, $post_id)
{
$gf_fields = array();
$gf_headers = array();
$gf_field_ids = array();
$i = 0;
while (have_rows('field_column_display_repeater', $post_id)) {
the_row();
$gf_headers[$i] = get_sub_field('form_field_column_header');
$gf_field_ids[$i] = get_sub_field('form_field_column_selector');
$i++;
}
$search_criteria = array();
$sorting = array('key' => $gf_fields[1], 'direction' => 'ASC');
$gf_entries = GFAPI::get_entries($gf_form_id, $search_criteria, $sorting);
$output = array('sColumns' => implode(',', $gf_headers), 'sEcho' => isset($_GET['sEcho']) ? intval($_GET['sEcho']) : null, 'iTotalRecords' => isset($gf_form_id) ? GFAPI::count_entries($gf_form_id) : 0, 'iTotalDisplayRecords' => 10, 'aaData' => array());
foreach ($gf_entries as $gf_entry) {
$columnvalue = $this->get_columnvalues($gf_entry, $gf_field_ids);
$row = array();
for ($i = 0; $i < count($gf_field_ids); $i++) {
$row[$i] = $columnvalue[$i];
}
$output['aaData'][] = $row;
}
return $output;
}
示例13: entry_count
/**
* Returns the number of entries on this step.
*
* @return int|mixed
*/
public function entry_count()
{
if (isset($this->_entry_count)) {
return $this->_entry_count;
}
$form_id = $this->get_form_id();
$search_criteria = array('status' => 'active', 'field_filters' => array(array('key' => 'workflow_step', 'value' => $this->get_id())));
$this->_entry_count = GFAPI::count_entries($form_id, $search_criteria);
return $this->_entry_count;
}
示例14: start_export
public static function start_export($form, $offset = 0, $export_id = '')
{
$time_start = microtime(true);
/***
* Allows the export max execution time to be changed.
*
* When the max execution time is reached, the export routine stop briefly and submit another AJAX request to continue exporting entries from the point it stopped.
*
* @since 2.0.3.10
*
* @param int 20 The amount of time, in seconds, that each request should run for. Defaults to 20 seconds.
* @param array $form The Form Object
*/
$max_execution_time = apply_filters('gform_export_max_execution_time', 20, $form);
// seconds
$page_size = 20;
$form_id = $form['id'];
$fields = $_POST['export_field'];
$start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
$end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
$search_criteria['status'] = 'active';
$search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
if (!empty($start_date)) {
$search_criteria['start_date'] = $start_date;
}
if (!empty($end_date)) {
$search_criteria['end_date'] = $end_date;
}
//$sorting = array( 'key' => 'date_created', 'direction' => 'DESC', 'type' => 'info' );
$sorting = array('key' => 'id', 'direction' => 'DESC', 'type' => 'info');
$form = self::add_default_export_fields($form);
$total_entry_count = GFAPI::count_entries($form_id, $search_criteria);
$remaining_entry_count = $offset == 0 ? $total_entry_count : $total_entry_count - $offset;
// Adding BOM marker for UTF-8
$lines = '';
// Set the separator
$separator = gf_apply_filters(array('gform_export_separator', $form_id), ',', $form_id);
$field_rows = self::get_field_row_count($form, $fields, $remaining_entry_count);
if ($offset == 0) {
//Adding BOM marker for UTF-8
$lines = chr(239) . chr(187) . chr(191);
//writing header
$headers = array();
foreach ($fields as $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$label = gf_apply_filters(array('gform_entries_field_header_pre_export', $form_id, $field_id), GFCommon::get_label($field, $field_id), $form, $field);
$value = str_replace('"', '""', $label);
GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
if (strpos($value, '=') === 0) {
// Prevent Excel formulas
$value = "'" . $value;
}
$headers[$field_id] = $value;
$subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
if ($subrow_count == 0) {
$lines .= '"' . $value . '"' . $separator;
} else {
for ($i = 1; $i <= $subrow_count; $i++) {
$lines .= '"' . $value . ' ' . $i . '"' . $separator;
}
}
//GFCommon::log_debug( "GFExport::start_export(): Lines: {$lines}" );
}
$lines = substr($lines, 0, strlen($lines) - 1) . "\n";
if ($remaining_entry_count == 0) {
self::write_file($lines, $export_id);
}
}
// Paging through results for memory issues
while ($remaining_entry_count > 0) {
$paging = array('offset' => $offset, 'page_size' => $page_size);
$leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
$leads = gf_apply_filters(array('gform_leads_before_export', $form_id), $leads, $form, $paging);
GFCommon::log_debug(__METHOD__ . '(): search criteria: ' . print_r($search_criteria, true));
GFCommon::log_debug(__METHOD__ . '(): sorting: ' . print_r($sorting, true));
GFCommon::log_debug(__METHOD__ . '(): paging: ' . print_r($paging, true));
foreach ($leads as $lead) {
GFCommon::log_debug(__METHOD__ . '(): Processing entry #' . $lead['id']);
foreach ($fields as $field_id) {
switch ($field_id) {
case 'date_created':
$lead_gmt_time = mysql2date('G', $lead['date_created']);
$lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
$value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
break;
default:
$field = RGFormsModel::get_field($form, $field_id);
$value = is_object($field) ? $field->get_value_export($lead, $field_id, false, true) : rgar($lead, $field_id);
$value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
//GFCommon::log_debug( "GFExport::start_export(): Value for field ID {$field_id}: {$value}" );
break;
}
if (isset($field_rows[$field_id])) {
$list = empty($value) ? array() : unserialize($value);
foreach ($list as $row) {
$row_values = array_values($row);
$row_str = implode('|', $row_values);
if (strpos($row_str, '=') === 0) {
// Prevent Excel formulas
$row_str = "'" . $row_str;
//.........这里部分代码省略.........
示例15: start_export
public static function start_export($form)
{
$form_id = $form['id'];
$fields = $_POST['export_field'];
$start_date = empty($_POST['export_date_start']) ? '' : self::get_gmt_date($_POST['export_date_start'] . ' 00:00:00');
$end_date = empty($_POST['export_date_end']) ? '' : self::get_gmt_date($_POST['export_date_end'] . ' 23:59:59');
$search_criteria['status'] = 'active';
$search_criteria['field_filters'] = GFCommon::get_field_filters_from_post($form);
if (!empty($start_date)) {
$search_criteria['start_date'] = $start_date;
}
if (!empty($end_date)) {
$search_criteria['end_date'] = $end_date;
}
$sorting = array('key' => 'date_created', 'direction' => 'DESC', 'type' => 'info');
GFCommon::log_debug("GFExport::start_export(): Start date: {$start_date}");
GFCommon::log_debug("GFExport::start_export(): End date: {$end_date}");
$form = self::add_default_export_fields($form);
$entry_count = GFAPI::count_entries($form_id, $search_criteria);
$page_size = 100;
$offset = 0;
//Adding BOM marker for UTF-8
$lines = chr(239) . chr(187) . chr(191);
// set the separater
$separator = gf_apply_filters('gform_export_separator', $form_id, ',', $form_id);
$field_rows = self::get_field_row_count($form, $fields, $entry_count);
//writing header
$headers = array();
foreach ($fields as $field_id) {
$field = RGFormsModel::get_field($form, $field_id);
$label = gf_apply_filters('gform_entries_field_header_pre_export', array($form_id, $field_id), GFCommon::get_label($field, $field_id), $form, $field);
$value = str_replace('"', '""', $label);
GFCommon::log_debug("GFExport::start_export(): Header for field ID {$field_id}: {$value}");
$headers[$field_id] = $value;
$subrow_count = isset($field_rows[$field_id]) ? intval($field_rows[$field_id]) : 0;
if ($subrow_count == 0) {
$lines .= '"' . $value . '"' . $separator;
} else {
for ($i = 1; $i <= $subrow_count; $i++) {
$lines .= '"' . $value . ' ' . $i . '"' . $separator;
}
}
GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
}
$lines = substr($lines, 0, strlen($lines) - 1) . "\n";
//paging through results for memory issues
while ($entry_count > 0) {
$paging = array('offset' => $offset, 'page_size' => $page_size);
$leads = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging);
$leads = gf_apply_filters('gform_leads_before_export', $form_id, $leads, $form, $paging);
foreach ($leads as $lead) {
foreach ($fields as $field_id) {
switch ($field_id) {
case 'date_created':
$lead_gmt_time = mysql2date('G', $lead['date_created']);
$lead_local_time = GFCommon::get_local_timestamp($lead_gmt_time);
$value = date_i18n('Y-m-d H:i:s', $lead_local_time, true);
break;
default:
$field = RGFormsModel::get_field($form, $field_id);
$value = is_object($field) ? $field->get_value_export($lead, $field_id, false, true) : rgar($lead, $field_id);
$value = apply_filters('gform_export_field_value', $value, $form_id, $field_id, $lead);
GFCommon::log_debug("GFExport::start_export(): Value for field ID {$field_id}: {$value}");
break;
}
if (isset($field_rows[$field_id])) {
$list = empty($value) ? array() : unserialize($value);
foreach ($list as $row) {
$row_values = array_values($row);
$row_str = implode('|', $row_values);
$lines .= '"' . str_replace('"', '""', $row_str) . '"' . $separator;
}
//filling missing subrow columns (if any)
$missing_count = intval($field_rows[$field_id]) - count($list);
for ($i = 0; $i < $missing_count; $i++) {
$lines .= '""' . $separator;
}
} else {
$value = maybe_unserialize($value);
if (is_array($value)) {
$value = implode('|', $value);
}
$lines .= '"' . str_replace('"', '""', $value) . '"' . $separator;
}
}
$lines = substr($lines, 0, strlen($lines) - 1);
GFCommon::log_debug("GFExport::start_export(): Lines: {$lines}");
$lines .= "\n";
}
$offset += $page_size;
$entry_count -= $page_size;
if (!seems_utf8($lines)) {
$lines = utf8_encode($lines);
}
$lines = apply_filters('gform_export_lines', $lines);
echo $lines;
$lines = '';
}
/**
* Fires after exporting all the entries in form
//.........这里部分代码省略.........