Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Select.php
Go to the documentation of this file.
1 <?php
2 
28 #require_once 'Zend/Db/Select.php';
29 
30 
34 #require_once 'Zend/Db/Table/Abstract.php';
35 
36 
47 {
53  protected $_info;
54 
60  protected $_integrityCheck = true;
61 
67  protected $_table;
68 
75  {
76  parent::__construct($table->getAdapter());
77 
78  $this->setTable($table);
79  }
80 
86  public function getTable()
87  {
88  return $this->_table;
89  }
90 
98  {
99  $this->_adapter = $table->getAdapter();
100  $this->_info = $table->info();
101  $this->_table = $table;
102 
103  return $this;
104  }
105 
115  public function setIntegrityCheck($flag = true)
116  {
117  $this->_integrityCheck = $flag;
118  return $this;
119  }
120 
126  public function isReadOnly()
127  {
128  $readOnly = false;
130  $cols = $this->_info[Zend_Db_Table_Abstract::COLS];
131 
132  if (!count($fields)) {
133  return $readOnly;
134  }
135 
136  foreach ($fields as $columnEntry) {
137  $column = $columnEntry[1];
138  $alias = $columnEntry[2];
139 
140  if ($alias !== null) {
141  $column = $alias;
142  }
143 
144  switch (true) {
145  case ($column == self::SQL_WILDCARD):
146  break;
147 
148  case ($column instanceof Zend_Db_Expr):
149  case (!in_array($column, $cols)):
150  $readOnly = true;
151  break 2;
152  }
153  }
154 
155  return $readOnly;
156  }
157 
171  public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
172  {
173  if ($name instanceof Zend_Db_Table_Abstract) {
174  $info = $name->info();
178  }
179  }
180 
181  return $this->joinInner($name, null, $cols, $schema);
182  }
183 
190  public function assemble()
191  {
193  $primary = $this->_info[Zend_Db_Table_Abstract::NAME];
194  $schema = $this->_info[Zend_Db_Table_Abstract::SCHEMA];
195 
196 
197  if (count($this->_parts[self::UNION]) == 0) {
198 
199  // If no fields are specified we assume all fields from primary table
200  if (!count($fields)) {
201  $this->from($primary, self::SQL_WILDCARD, $schema);
203  }
204 
205  $from = $this->getPart(Zend_Db_Table_Select::FROM);
206 
207  if ($this->_integrityCheck !== false) {
208  foreach ($fields as $columnEntry) {
209  list($table, $column) = $columnEntry;
210 
211  // Check each column to ensure it only references the primary table
212  if ($column) {
213  if (!isset($from[$table]) || $from[$table]['tableName'] != $primary) {
214  #require_once 'Zend/Db/Table/Select/Exception.php';
215  throw new Zend_Db_Table_Select_Exception('Select query cannot join with another table');
216  }
217  }
218  }
219  }
220  }
221 
222  return parent::assemble();
223  }
224 }
from($name, $cols=self::SQL_WILDCARD, $schema=null)
Definition: Select.php:171
$fields
Definition: details.phtml:14
getPart($part)
Definition: Select.php:688
setIntegrityCheck($flag=true)
Definition: Select.php:115
const FROM
Definition: Select.php:49
setTable(Zend_Db_Table_Abstract $table)
Definition: Select.php:97
joinInner($name, $cond, $cols=self::SQL_WILDCARD, $schema=null)
Definition: Select.php:355
const COLUMNS
Definition: Select.php:48
__construct(Zend_Db_Table_Abstract $table)
Definition: Select.php:74
if(!trim($html)) $alias
Definition: details.phtml:20
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$table
Definition: trigger.php:14
if(!isset($_GET['name'])) $name
Definition: log.php:14