Пример #1
0
 function getAll($where = '', $order_by = '', $limit = '')
 {
     global $wpdb;
     $query = "SELECT * FROM {$this->table_name} " . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
     if ($limit == ' LIMIT 1') {
         $results = $wpdb->get_row($query);
     } else {
         $results = $wpdb->get_results($query);
     }
     return $results;
 }
Пример #2
0
 public static function getRecordCount($where = '')
 {
     global $wpdb;
     $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
     if (is_numeric($where)) {
         $table_join = 'frm_items';
         $where = array('form_id' => $where);
     }
     if (is_array($where)) {
         $count = FrmDb::get_count($table_join, $where);
     } else {
         global $wpdb;
         $cache_key = 'count_' . maybe_serialize($where);
         $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
         $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
     }
     return $count;
 }
Пример #3
0
 function getRecordCount($where = '')
 {
     global $wpdb;
     if (is_numeric($where)) {
         $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items WHERE form_id=" . $where;
     } else {
         $query = "SELECT COUNT(*) FROM {$wpdb->prefix}frm_items it LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id" . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
     }
     return $wpdb->get_var($query);
 }
Пример #4
0
 public static function getIds($where = '', $order_by = '', $limit = '')
 {
     _deprecated_function(__FUNCTION__, '2.0');
     global $wpdb;
     if (!empty($order_by) && !strpos($order_by, 'ORDER BY') !== false) {
         $order_by = ' ORDER BY ' . $order_by;
     }
     $query = 'SELECT fi.id  FROM ' . $wpdb->prefix . 'frm_fields fi ' . 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
     $method = $limit == ' LIMIT 1' || $limit == 1 ? 'get_var' : 'get_col';
     $cache_key = 'getIds_' . maybe_serialize($where) . $order_by . $limit;
     $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method);
     return $results;
 }
Пример #5
0
 function getIds($where = '', $order_by = '', $limit = '')
 {
     global $wpdb;
     if (!empty($order_by) && !preg_match("/ORDER BY/", $order_by)) {
         $order_by = ' ORDER BY ' . $order_by;
     }
     $query = "SELECT fi.id  FROM {$wpdb->prefix}frm_fields fi " . "LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON fi.form_id=fr.id" . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
     if ($limit == ' LIMIT 1' or $limit == 1) {
         $results = $wpdb->get_var($query);
     } else {
         $results = $wpdb->get_col($query);
     }
     return $results;
 }
Пример #6
0
 private static function filter_entry_ids($args, $where_field, $entry_ids, &$new_ids)
 {
     $where_statement = array('fi.id' => (int) $args['where_opt']);
     $field_key = 'meta_value ' . (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : '') . FrmDb::append_where_is($args['temp_where_is']);
     $nested_where = array($field_key => $args['where_val']);
     if (isset($args['where_val_esc']) && $args['where_val_esc'] != $args['where_val']) {
         $nested_where['or'] = 1;
         $nested_where[' ' . $field_key] = $args['where_val_esc'];
     }
     $where_statement[] = $nested_where;
     $args['entry_ids'] = $entry_ids;
     $where_statement = apply_filters('frm_where_filter', $where_statement, $args);
     $filter_args = array('is_draft' => $args['drafts']);
     self::add_group_by($filter_args, $args);
     // If the field is from a repeating section (or embedded form?) get the parent ID
     $filter_args['return_parent_id'] = $where_field->form_id != $args['form_id'];
     // Add entry IDs to $where_statement. Meant for use when showing one entry.
     if ($args['use_ids']) {
         if (is_array($where_statement)) {
             if ($filter_args['return_parent_id']) {
                 $where_statement['parent_item_id'] = $entry_ids;
             } else {
                 $where_statement['item_id'] = $entry_ids;
             }
         } else {
             // if the filter changed the query to a string, allow it
             $where_statement .= FrmAppHelper::prepend_and_or_where(' AND ', array('item_id' => $entry_ids));
         }
     }
     $new_ids = FrmEntryMeta::getEntryIds($where_statement, '', '', true, $filter_args);
     if ($args['where_is'] != $args['temp_where_is']) {
         $new_ids = array_diff((array) $entry_ids, $new_ids);
     }
 }
Пример #7
0
 /**
  * @return object|array of objects
  */
 public static function getAll($where = array(), $order_by = '', $limit = '')
 {
     if (is_array($where) && !empty($where)) {
         $results = FrmDb::get_results('frm_forms', $where, '*', array('order_by' => $order_by, 'limit' => $limit));
     } else {
         global $wpdb;
         // the query has already been prepared if this is not an array
         $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . FrmAppHelper::esc_order($order_by) . FrmAppHelper::esc_limit($limit);
         $results = $wpdb->get_results($query);
     }
     if ($results) {
         foreach ($results as $result) {
             wp_cache_set($result->id, $result, 'frm_form');
             $result->options = maybe_unserialize($result->options);
         }
     }
     if ($limit == ' LIMIT 1' || $limit == 1) {
         // return the first form object if we are only getting one form
         $results = reset($results);
     }
     return stripslashes_deep($results);
 }
Пример #8
0
 public static function search_entry_metas($search, $field_id = '', $operator)
 {
     $cache_key = 'search_' . maybe_serialize($search) . $field_id . $operator;
     $results = wp_cache_get($cache_key, 'frm_entry');
     if (false !== $results) {
         return $results;
     }
     global $wpdb;
     if (is_array($search)) {
         $where = '';
         foreach ($search as $field => $value) {
             if ($value <= 0 || !in_array($field, array('year', 'month', 'day'))) {
                 continue;
             }
             switch ($field) {
                 case 'year':
                     $value = '%' . $value;
                     break;
                 case 'month':
                     $value .= '%';
                     break;
                 case 'day':
                     $value = '%' . $value . '%';
             }
             $where .= $wpdb->prepare(' meta_value ' . $operator . ' %s and', $value);
         }
         $where .= $wpdb->prepare(' field_id=%d', $field_id);
         $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas" . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
     } else {
         if ($operator == 'LIKE') {
             $search = '%' . $search . '%';
         }
         $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
     }
     $results = $wpdb->get_col($query, 0);
     wp_cache_set($cache_key, $results, 'frm_entry', 300);
     return $results;
 }
Пример #9
0
 function search_entry_metas($search, $field_id = '', $operator)
 {
     global $wpdb;
     if (is_array($search)) {
         $where = '';
         foreach ($search as $field => $value) {
             if ($field == 'year' and $value > 0) {
                 $where .= " meta_value {$operator} '%{$value}' and";
             }
             if ($field == 'month' and $value > 0) {
                 $where .= " meta_value {$operator} '{$value}%' and";
             }
             if ($field == 'day' and $value > 0) {
                 $where .= " meta_value {$operator} '%/{$value}/%' and";
             }
         }
         $where .= " field_id='{$field_id}'";
         $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas" . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
     } else {
         if ($operator == 'LIKE') {
             $search = "%{$search}%";
         }
         $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id);
     }
     return $wpdb->get_col($query, 0);
 }
Пример #10
0
 public static function getRecordCount($where = "", $table_name)
 {
     global $wpdb;
     $query = 'SELECT COUNT(*) FROM ' . $table_name . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
     return $wpdb->get_var($query);
 }
Пример #11
0
 public static function get_view_results($where, $args)
 {
     global $wpdb;
     $defaults = array('order_by_array' => array(), 'order_array' => array(), 'limit' => '', 'posts' => array(), 'display' => false);
     $args = wp_parse_args($args, $defaults);
     $args['time_field'] = false;
     $query = array('select' => 'SELECT it.id FROM ' . $wpdb->prefix . 'frm_items it', 'where' => $where, 'order' => 'ORDER BY it.created_at ASC');
     //If order is set
     if (!empty($args['order_by_array'])) {
         self::prepare_entries_query($query, $args);
     }
     $query = apply_filters('frm_view_order', $query, $args);
     if (!empty($query['where'])) {
         $query['where'] = FrmAppHelper::prepend_and_or_where('WHERE ', $query['where']);
     }
     $query['order'] = rtrim($query['order'], ', ');
     $query = implode($query, ' ') . $args['limit'];
     $entry_ids = $wpdb->get_col($query);
     self::reorder_time_entries($entry_ids, $args['time_field']);
     return $entry_ids;
 }
Пример #12
0
 function getAll($where = array(), $order_by = '', $limit = '')
 {
     global $wpdb, $frmdb;
     if (is_numeric($limit)) {
         $limit = " LIMIT {$limit}";
     }
     $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
     if ($limit == ' LIMIT 1' || $limit == 1) {
         if (is_array($where)) {
             $results = $frmdb->get_one_record($wpdb->prefix . 'frm_forms', $where, '*', $order_by);
         } else {
             $results = $wpdb->get_row($query);
         }
         if ($results) {
             wp_cache_set($results->id, $results, 'frm_form');
             $results->options = maybe_unserialize($results->options);
         }
     } else {
         if (is_array($where) && !empty($where)) {
             $results = $frmdb->get_records($wpdb->prefix . 'frm_forms', $where, $order_by, $limit);
         } else {
             $results = $wpdb->get_results($query);
         }
         if ($results) {
             foreach ($results as $result) {
                 wp_cache_set($result->id, $result, 'frm_form');
                 $result->options = maybe_unserialize($result->options);
             }
         }
     }
     return stripslashes_deep($results);
 }