[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project_issue/includes/ -> autocomplete.inc (source)

   1  <?php
   2  // $Id: autocomplete.inc,v 1.2 2009/02/07 04:50:28 dww Exp $
   3  
   4  
   5  /**
   6   * @file
   7   * Autocomplete callback functions for the Project issue tracking module.
   8   *
   9   * Each function returns a JSON string for use with JS autocomplete fields.
  10   */
  11  
  12  /**
  13   * Return valid issue-enabled project names for comma-separated input.
  14   */
  15  function project_issue_autocomplete_issue_project($string = '') {
  16    $matches = array();
  17  
  18    // The user enters a comma-separated list of projects. We only autocomplete
  19    // the last one.
  20    $array = drupal_explode_tags($string);
  21    $last_string = trim(array_pop($array));
  22  
  23    if ($last_string != '') {
  24      $result = db_query_range(db_rewrite_sql("SELECT n.title FROM {node} n INNER JOIN {project_issue_projects} p ON n.nid = p.nid WHERE n.status = %d AND LOWER(n.title) LIKE LOWER('%%%s%%') AND p.issues = %d"), 1, $last_string, 1, 0, 10);
  25  
  26      $prefix = count($array) ? implode(', ', $array) .', ' : '';
  27      while ($project = db_fetch_object($result)) {
  28        $title = $project->title;
  29        // Commas and quotes in terms are special cases, so encode 'em.
  30        if (strpos($title, ',') !== FALSE || strpos($title, '"') !== FALSE) {
  31          $title = '"'. str_replace('"', '""', $project->title) .'"';
  32        }
  33        $matches[$prefix . $title] = check_plain($project->title);
  34      }
  35    }
  36  
  37    drupal_json($matches);
  38  }
  39  
  40  
  41  /**
  42   * Return valid issue-enabled project names based on a user's own projects.
  43   *
  44   * Only returns matches for project titles from issues the user has either
  45   * submitted or commented on.
  46   */
  47  function project_issue_autocomplete_user_issue_project($uid, $string = '') {
  48    $matches = array();
  49  
  50    // The user enters a comma-separated list of projects. We only autocomplete
  51    // the last one.
  52    $array = drupal_explode_tags($string);
  53    $last_string = trim(array_pop($array));
  54  
  55    if ($last_string != '') {
  56      // We have to do a DISTINCT() here because with the LEFT JOIN on
  57      // {comments}, we can get a lot of duplicate matches, and then our range
  58      // limit will prevent us from showing all the distinct options.
  59      $result = db_query_range(db_rewrite_sql("SELECT DISTINCT(n.title) FROM {node} n INNER JOIN {project_issue_projects} pip ON n.nid = pip.nid INNER JOIN {project_issues} pi ON n.nid = pi.pid INNER JOIN {node} pin ON pi.nid = pin.nid LEFT JOIN {comments} c ON c.nid = pi.nid WHERE pip.issues = %d AND n.status = %d AND pin.status = %d AND (pin.uid = %d OR c.uid = %d) AND LOWER(n.title) LIKE LOWER('%%%s%%')"), 1, 1, 1, $uid, $uid, $last_string, 0, 10);
  60  
  61      $prefix = count($array) ? implode(', ', $array) .', ' : '';
  62      while ($project = db_fetch_object($result)) {
  63        $title = $project->title;
  64        // Commas and quotes in terms are special cases, so encode 'em.
  65        if (strpos($title, ',') !== FALSE || strpos($title, '"') !== FALSE) {
  66          $title = '"'. str_replace('"', '""', $project->title) .'"';
  67        }
  68        $matches[$prefix . $title] = check_plain($project->title);
  69      }
  70    }
  71  
  72    drupal_json($matches);
  73  }
  74  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7