Guest User

PHP Quickbase do_query

a guest
May 19th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.51 KB | None | 0 0
  1. /* API_DoQuery: http://www.quickbase.com/api-guide/index.html#do_query.html */
  2.     public function do_query($queries = 0, $qid = 0, $qname = 0, $clist = 0, $slist = 0, $fmt = 'structured', $options = "")
  3.     {
  4.         if ($this->xml) {
  5.             //A query in queries has the following items in this order:
  6.             //field id, evaluator, criteria, and/or
  7.             //The first element will not have an and/or
  8.             $xml_packet = '<qdbapi>';
  9.             $pos        = 0;
  10.             if ($queries) {
  11.                 $xml_packet .= '<query>';
  12.                 foreach ($queries as $query) {
  13.                     $criteria = "";
  14.                     if (isset($query['cx'])) {
  15.                         $xml_packet .= $query['cx']; //append any parentheses and boolean connectors
  16.                     } else {
  17.                         if ($pos > 0) {
  18.                             if(isset($query['ao'])) {                          
  19.                                 $criteria .= $query['ao'];
  20.                             }
  21.                         }
  22.                         $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri'] . "'}";
  23.                         $xml_packet .= $criteria;
  24.                     }
  25.                     $pos++;
  26.                 }
  27.                 $xml_packet .= '</query>';
  28.             } else if ($qid) {
  29.                 $xml_packet .= '<qid>' . $qid . '</qid>';
  30.             } else if ($qname) {
  31.                 $xml_packet .= '<qname>' . $qname . '</qname>';
  32.             } else {
  33.                 return false;
  34.             }
  35.             $xml_packet .= '<fmt>' . $fmt . '</fmt>';
  36.             if ($clist) {
  37.                 $xml_packet .= '<clist>' . $clist . '</clist>';
  38.             }
  39.  
  40.             if ($slist) {
  41.                 $xml_packet .= '<slist>' . $slist . '</slist>';
  42.                 $xml_packet .= '<options>' . $options . '</options>';
  43.             }
  44.             if ($this->app_token) {
  45.                 $xml_packet .= '<apptoken>' . $this->app_token . '</apptoken>';
  46.             }
  47.  
  48.             $xml_packet .= '<ticket>' . $this->ticket . '</ticket></qdbapi>';
  49.             $response = $this->transmit($xml_packet, 'API_DoQuery');
  50.         } else {
  51.             // If not an xml packet
  52.             $url_string = $this->qb_ssl . $this->db_id . "?act=API_DoQuery&ticket=" . $this->ticket . "&fmt=" . $fmt;
  53.             $pos        = 0;
  54.             if ($queries) {
  55.                 $url_string .= "&query=";
  56.                 foreach ($queries as $query) {
  57.                     $criteria = "";
  58.                     if ($pos > 0) {
  59.                         $criteria .= $query['ao'];
  60.                     }
  61.                     $criteria .= "{'" . $query['fid'] . "'." . $query['ev'] . ".'" . $query['cri'] . "'}";
  62.                     $url_string .= $criteria;
  63.                     $pos++;
  64.                 }
  65.             } else if ($qid) {
  66.                 $url_string .= "&qid=" . $qid;
  67.             } else if ($qname) {
  68.                 $url_string .= "&qname=" . $qname;
  69.             } else {
  70.                 return false;
  71.             }
  72.             if ($clist) {
  73.                 $url_string .= "&clist=" . $clist;
  74.             }
  75.  
  76.             if ($slist) {
  77.                 $url_string .= "&slist=" . $slist;
  78.             }
  79.  
  80.             if ($options) {
  81.                 $url_string .= "&options=" . $options;
  82.             }
  83.  
  84.             $response = $this->transmit($url_string);
  85.         }
  86.         if ($response) {
  87.             return $response;
  88.         }
  89.         return false;
  90.     }
Add Comment
Please, Sign In to add comment