You are here

public function SalesforceSelectQuery::__toString in Salesforce Suite 7.3

File

includes/salesforce.select_query.inc, line 64
Class representing a Salesforce SELECT SOQL query.

Class

SalesforceSelectQuery
@file Class representing a Salesforce SELECT SOQL query.

Code

public function __toString() {
  $query = 'SELECT+';
  $query .= implode(',+', $this->fields);
  $query .= "+FROM+" . $this->objectType;
  if (count($this->conditions) > 0) {
    $where = array();
    foreach ($this->conditions as $condition) {
      $where[] = implode('+', $condition);
    }
    $query .= '+WHERE+' . implode('+AND+', $where);
  }
  if ($this->order) {
    $query .= "+ORDER+BY+";
    $fields = array();
    foreach ($this->order as $field => $direction) {
      $fields[] = $field . '+' . $direction;
    }
    $query .= implode(',+', $fields);
  }
  if ($this->limit) {
    $query .= "+LIMIT+" . (int) $this->limit;
  }
  if ($this->offset) {
    $query .= "+OFFSET+" . (int) $this->offset;
  }

  // Replaces spaces with + signs for custom filters.
  $query = str_replace(" ", "+", $query);
  return $query;
}