Exemplo n.º 1
0
 public function &find_fields($args = array(), $one = false)
 {
     global $wpdb;
     $res = array();
     $args = wp_parse_args($args, array('association' => null, 'field_type' => null, 'validators' => null, 'display_flags' => null, 'unique' => false));
     if ($one == true) {
         $args['unique'] = true;
     }
     extract($args);
     $validators = $validators ? !is_array($validators) ? array($validators) : $validators : array();
     $display_flags = $display_flags ? !is_array($display_flags) ? array($display_flags) : $display_flags : array();
     $where = '';
     if ($args['association']) {
         $associations_in = array();
         $associations_not_in = array();
         $association = !is_array($association) ? array($association) : $association;
         foreach ($association as &$assoc) {
             if (wpbdp_starts_with($assoc, '-')) {
                 $associations_not_in[] = substr($assoc, 1);
             } else {
                 $associations_in[] = $assoc;
             }
         }
         if ($associations_in) {
             $where .= ' AND ( association IN ( \'' . implode('\',\'', $associations_in) . '\' ) ) ';
         }
         if ($associations_not_in) {
             $where .= ' AND ( association NOT IN ( \'' . implode('\',\'', $associations_not_in) . '\' ) ) ';
         }
         // $where .= $wpdb->prepare( " AND ( association = %s ) ", $args['association'] );
     }
     if ($args['field_type']) {
         $field_types_in = array();
         $field_types_not_in = array();
         $field_type = !is_array($field_type) ? array($field_type) : $field_type;
         foreach ($field_type as $f) {
             if (wpbdp_starts_with($f, '-')) {
                 $field_types_not_in[] = substr($f, 1);
             } else {
                 $field_types_in[] = $f;
             }
         }
         if ($field_types_in) {
             $where .= ' AND ( field_type IN ( \'' . implode('\',\'', $field_types_in) . '\' ) ) ';
         }
         if ($field_types_not_in) {
             $where .= ' AND ( field_type NOT IN ( \'' . implode('\',\'', $field_types_not_in) . '\' ) ) ';
         }
     }
     foreach ($display_flags as $f) {
         if (substr($f, 0, 1) == '-') {
             $where .= $wpdb->prepare(" AND ( display_flags IS NULL OR display_flags NOT LIKE '%%%s%%' )", substr($f, 1));
         } else {
             $where .= $wpdb->prepare(" AND ( display_flags LIKE '%%%s%%' )", $f);
         }
     }
     foreach ($validators as $v) {
         if (substr($v, 0, 1) == '-') {
             $where .= $wpdb->prepare(" AND ( validators IS NULL OR validators NOT LIKE '%%%s%%' )", substr($v, 1));
         } else {
             $where .= $wpdb->prepare(" AND ( validators LIKE '%%%s%%' )", $v);
         }
     }
     if ($where) {
         $sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields WHERE 1=1 {$where} ORDER BY weight DESC";
     } else {
         $sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields ORDER BY weight DESC";
     }
     $ids = $wpdb->get_col($sql);
     foreach ($ids as $id) {
         if ($field = WPBDP_FormField::get($id)) {
             $res[] = $field;
         }
     }
     $res = $unique ? $res ? $res[0] : null : $res;
     return $res;
 }
Exemplo n.º 2
0
 private function deleteField()
 {
     global $wpdb;
     $field = WPBDP_FormField::get($_REQUEST['id']);
     if (!$field || $field->has_behavior_flag('no-delete')) {
         return;
     }
     if (isset($_POST['doit'])) {
         $ret = $field->delete();
         if (is_wp_error($ret)) {
             $this->admin->messages[] = array($ret->get_error_message(), 'error');
         } else {
             $this->admin->messages[] = _x('Field deleted.', 'form-fields admin', 'WPBDM');
         }
         return $this->fieldsTable();
     }
     wpbdp_render_page(WPBDP_PATH . 'admin/templates/form-fields-confirm-delete.tpl.php', array('field' => $field), true);
 }