Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FromRenderer.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  protected $quote;
17 
21  public function __construct(
23  ) {
24  $this->quote = $quote;
25  }
26 
35  public function render(Select $select, $sql = '')
36  {
37  /*
38  * If no table specified, use RDBMS-dependent solution
39  * for table-less query. e.g. DUAL in Oracle.
40  */
41  $source = $select->getPart(Select::FROM);
42  if (empty($source)) {
43  $source = [];
44  }
45  $from = [];
46  foreach ($source as $correlationName => $table) {
47  $tmp = '';
48  $joinType = ($table['joinType'] == Select::FROM) ? Select::INNER_JOIN : $table['joinType'];
49  // Add join clause (if applicable)
50  if (!empty($from)) {
51  $tmp .= ' ' . strtoupper($joinType) . ' ';
52  }
53  $tmp .= $this->getQuotedSchema($table['schema']);
54  $tmp .= $this->getQuotedTable($table['tableName'], $correlationName);
55 
56  // Add join conditions (if applicable)
57  if (!empty($from) && !empty($table['joinCondition'])) {
58  $tmp .= ' ' . Select::SQL_ON . ' ' . $table['joinCondition'];
59  }
60  // Add the table name and condition add to the list
61  $from[] = $tmp;
62  }
63  // Add the list of all joins
64  if (!empty($from)) {
65  $sql .= ' ' . Select::SQL_FROM . ' ' . implode("\n", $from);
66  }
67  return $sql;
68  }
69 
76  protected function getQuotedSchema($schema = null)
77  {
78  if ($schema === null) {
79  return null;
80  }
81  return $this->quote->quoteIdentifier($schema) . '.';
82  }
83 
91  protected function getQuotedTable($tableName, $correlationName = null)
92  {
93  return $this->quote->quoteTableAs($tableName, $correlationName);
94  }
95 }
$tableName
Definition: trigger.php:13
const SQL_ON
Definition: Select.php:80
const SQL_FROM
Definition: Select.php:70
$source
Definition: source.php:23
const FROM
Definition: Select.php:49
const INNER_JOIN
Definition: Select.php:59
$table
Definition: trigger.php:14
getQuotedTable($tableName, $correlationName=null)