Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00010 class tripal_views_handler_filter_textarea extends views_handler_filter { 00011 00016 function value_form(&$form, &$form_state) { 00017 parent::value_form($form, $form_state); 00018 00019 $this->value_form = array( 00020 '#type' => 'textarea', 00021 '#title' => t('%label', array('%label' => $this->options['expose']['label'])), 00022 '#default_value' => $this->value, 00023 '#multiple' => FALSE, 00024 '#description' => t('Provide search values for %label. Please place each search 00025 item on a separate line or separated by commas.', array('%label' => $this->options['expose']['label'])), 00026 ); 00027 $form['value'] = &$this->value_form; 00028 } 00029 00033 function exposed_form(&$form, &$form_state) { 00034 00035 // don't do anything if the form isn't exposed. 00036 if (empty($this->options['exposed'])) { 00037 return; 00038 } 00039 // rebuild the form elements 00040 $value = $this->options['expose']['identifier']; 00041 $this->value_form($form, $form_state); 00042 00043 $form[$value] = $form['value']; 00044 unset($form[$value]['#title']); 00045 00046 00047 $this->exposed_translate($form[$value], 'value'); 00048 00049 if ($value != 'value') { 00050 unset($form['value']); 00051 } 00052 00053 } 00054 00058 function exposed_validate(&$form, &$form_state) { 00059 //dpm($form_state); 00060 } 00061 00065 function query() { 00066 $this->ensure_my_table(); 00067 $field = "$this->table.$this->real_field"; 00068 00069 // get the form element value 00070 if (is_array($this->value)) { 00071 $value = $this->value[0]; 00072 } 00073 else { 00074 $value = $this->value; 00075 } 00076 00077 // remove extra spaces and new lines 00078 $value = preg_replace("/\s+,/", ",", $value); 00079 $value = preg_replace("/\s+\n/", "\n", $value); 00080 $value = preg_replace("/,\n/", "\n", $value); 00081 $values = preg_split("/[\n,]+/", $value); 00082 00083 // iterate through all of the values and generate the corresponding 00084 // sprintf style holders 00085 $holders = array(); 00086 for ($i = 0 ; $i < count($values); $i++) { 00087 $values[$i] = trim($values[$i]); 00088 $holders[] = "'%s'"; 00089 } 00090 00091 // if we have any values supplied then update the where clause for 00092 // the views query 00093 if (count($holders) > 0) { 00094 $where = "$field IN (" . implode(", ", $holders) . ")"; 00095 $this->query->add_where($this->options['group'], $where, $values); 00096 } 00097 } 00098 }