/** * Db tree constructor * * $fields = array( * \Magento\Framework\Data\Tree\Db::ID_FIELD => string, * \Magento\Framework\Data\Tree\Db::PARENT_FIELD => string, * \Magento\Framework\Data\Tree\Db::LEVEL_FIELD => string * \Magento\Framework\Data\Tree\Db::ORDER_FIELD => string * ) * * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection * @param string $table * @param array $fields * @throws \Exception */ public function __construct(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $table, $fields) { parent::__construct(); if (!$connection) { throw new \Exception('Wrong "$connection" parametr'); } $this->_conn = $connection; $this->_table = $table; if (!isset($fields[self::ID_FIELD]) || !isset($fields[self::PARENT_FIELD]) || !isset($fields[self::LEVEL_FIELD]) || !isset($fields[self::ORDER_FIELD])) { throw new \Exception('"$fields" tree configuratin array'); } $this->_idField = $fields[self::ID_FIELD]; $this->_parentField = $fields[self::PARENT_FIELD]; $this->_levelField = $fields[self::LEVEL_FIELD]; $this->_orderField = $fields[self::ORDER_FIELD]; $this->_select = $this->_conn->select(); $this->_select->from($this->_table, array_values($fields)); }
/** * Db tree constructor * * $fields = array( * \Magento\Framework\Data\Tree\Dbp::ID_FIELD => string, * \Magento\Framework\Data\Tree\Dbp::PATH_FIELD => string, * \Magento\Framework\Data\Tree\Dbp::ORDER_FIELD => string * \Magento\Framework\Data\Tree\Dbp::LEVEL_FIELD => string * ) * * @param \Zend_Db_Adapter_Abstract $connection * @param string $table * @param array $fields * @throws \Exception */ public function __construct($connection, $table, $fields) { parent::__construct(); if (!$connection) { throw new \Exception('Wrong "$connection" parametr'); } $this->_conn = $connection; $this->_table = $table; if (!isset($fields[self::ID_FIELD]) || !isset($fields[self::PATH_FIELD]) || !isset($fields[self::LEVEL_FIELD]) || !isset($fields[self::ORDER_FIELD])) { throw new \Exception('"$fields" tree configuratin array'); } $this->_idField = $fields[self::ID_FIELD]; $this->_pathField = $fields[self::PATH_FIELD]; $this->_orderField = $fields[self::ORDER_FIELD]; $this->_levelField = $fields[self::LEVEL_FIELD]; $this->_select = $this->_conn->select(); $this->_select->from($this->_table); }