/[drupal]/contributions/modules/term_queue/term_queue.admin.inc
ViewVC logotype

Diff of /contributions/modules/term_queue/term_queue.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Thu Sep 25 17:56:55 2008 UTC revision 1.1.2.1, Tue Oct 28 16:16:34 2008 UTC
# Line 76  function term_queue_form_submit($form, & Line 76  function term_queue_form_submit($form, &
76  }  }
77    
78  /**  /**
79     * Form to for Term Queue Settings
80     *
81     * @ingroup forms
82     */
83    function term_queue_settings_form(&$form_state, $edit = array()) {
84      $form = array();
85    
86      $form['global_settings'] = array('#type' => 'fieldset', '#title' => t('Global Settings'));
87    
88      $form['global_settings']['term_queue_use_autocomplete'] = array(
89        '#type' => 'checkbox',
90        '#title' => t('Use Autocomplete Textfield When Adding Terms?'),
91        '#default_value' => variable_get('term_queue_use_autocomplete', FALSE),
92        '#description' => t('Enable this when you have a large number of vocabularies'),
93      );
94    
95      // TODO: Add filter for vocabularies
96    
97      return system_settings_form($form);
98    }
99    
100    /**
101   * Form to edit an existing term queue   * Form to edit an existing term queue
102   *   *
103   * @ingroup forms   * @ingroup forms
# Line 144  function term_queue_add_term_form(&$form Line 166  function term_queue_add_term_form(&$form
166      '#value' => $queue->qid,      '#value' => $queue->qid,
167    );    );
168    
169    $form['tid'] = array(    // use a different form field for autocomplete
170      '#type' => 'select',    if(is_autocomplete()) {
171      '#title' => t('Term'),      $form['tid'] = array(
172      '#options' => $options,        '#type' => 'textfield',
173      '#description' => t('Select a term to be added to the queue.'),        '#title' => t('Term'),
174      '#weight' => -15,        '#autocomplete_path' => 'term_queue/autocomplete',
175      '#theme' => 'taxonomy_term_select',        '#description' => t('Begin typing the term name and choices will appear.  Terms are displayed as "termname (category)"'),
176    );      );
177      }
178      else {
179        $form['tid'] = array(
180          '#type' => 'select',
181          '#title' => t('Term'),
182          '#options' => $options,
183          '#description' => t('Select a term to be added to the queue.'),
184          '#weight' => -15,
185          '#theme' => 'taxonomy_term_select',
186        );
187      }
188    
189    $form['submit'] = array('#type' => 'submit', '#value' => 'Add Term');    $form['submit'] = array('#type' => 'submit', '#value' => 'Add Term');
190    $form['cancel'] = array(    $form['cancel'] = array(
# Line 170  function term_queue_add_term_form(&$form Line 203  function term_queue_add_term_form(&$form
203   */   */
204  function term_queue_add_term_form_submit($form, &$form_state) {  function term_queue_add_term_form_submit($form, &$form_state) {
205    $qid = $form_state['values']['qid'];    $qid = $form_state['values']['qid'];
206    $tid = $form_state['values']['tid'];  
207      // handle the tid value if using autocomplete
208      if(is_autocomplete()) {
209        // value comes in as 'Charterhouse Group (Company) [tid:5193]', parse the tid.
210        $value = preg_match("/tid:\d+/", $form_state['values']['tid'], $matches);
211        $tid_array = explode(":", $matches[0]);
212        $tid = $tid_array[1];
213      }
214      else
215        $tid = $form_state['values']['tid'];
216    
217    term_queue_add_term($qid, $tid);    term_queue_add_term($qid, $tid);
218    $form_state['redirect'] = "admin/build/term_queue/$qid/add";    $form_state['redirect'] = "admin/build/term_queue/$qid/add";
219    
# Line 303  function term_queue_delete_term_form_sub Line 346  function term_queue_delete_term_form_sub
346    return;    return;
347  }  }
348    
349    /**
350     * Callback for the term name autocomplete.
351     *
352     */
353    function term_queue_autocomplete_term($string = '') {
354      $matches = array();
355      if($string) {
356        $sql = "SELECT td.tid, td.name as termname, v.name as category FROM {term_data} td ";
357        $sql .= "JOIN {vocabulary} v ON v.vid = td.vid ";
358        $sql .= "WHERE td.name LIKE '%s%' LIMIT 20";
359        $params = array("$string");
360    
361        $result = db_query($sql, $params);
362    
363        while($term = db_fetch_object($result)) {
364          $key = "$term->termname ($term->category) [tid:$term->tid]";
365          $matches[$key] = "$term->termname (<b>$term->category</b>)";
366        }
367      }
368    
369      drupal_json($matches);
370    }
371    
372    /**
373     * helper to check if autocomplete is enabled.
374     */
375    function is_autocomplete() {
376      return variable_get('term_queue_use_autocomplete', FALSE);
377    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2