_draftPrefix = $draftPrefix; } protected function _getTableAlias($alias = null) { if (null === $alias) { $alias = $this->_tableAlias; } if ($this->_draftPrefix) { $alias = $this->_draftPrefix . $alias; } return $alias; } protected function _getTable($alias = null) { $alias = $this->_getTableAlias($alias); return parent::_getTable($alias); } protected function _getFromDb($key, $field = null) { if (!is_array($key)) { $key = (array) $key; } $select = $this->_db->select(); $select->from($this->_getPair($this->_getTableAlias(), 'h')); $select->joinLeft( $this->_getPair($this->_getTableAlias($this->_tableAlias . 'Content'), 'c'), '`c`.`idBlock` = `h`.`id` AND ' . $this->_db->quoteInto('`c`.`language` = ?', $this->getLanguage()) ); $select->where('`h`.`id` = ?', $key, Qs_Db::INT_TYPE); $row = $this->_db->fetchRow($select); if ($row) { $this->_arrayParseTag2Url($row); return Qs_Array::get($row, $field); } return false; } public function insert(array $data = null, $files = null) { unset($data['id']); if (!array_key_exists('rawContent', $data)) { $data['rawContent'] = Qs_Text_Mark::prepareSearchText($data, 'content'); } $this->_arrayParseUrl2Tag($data); $data['idBlock'] = $id = $this->_getTable()->insert($data); if (empty($data['language'])) { $data['language'] = $this->getLanguage(); } $this->_getSubTable('Content')->insert($data); return $id; } public function delete() { $idBlock = intval($this->getPrimaryKey()); $this->_getTable()->delete('`id` = ' . $idBlock); $this->_getSubTable('Content')->delete('`idBlock` = ' . $idBlock); } public function update(array $data = null, $files = null) { unset($data['id']); if (!array_key_exists('rawContent', $data)) { $data['rawContent'] = Qs_Text_Mark::prepareSearchText($data, 'content'); } $this->_arrayParseUrl2Tag($data); $where = 'idBlock = ' . $this->_db->quote($this->_primaryKey, Zend_Db::INT_TYPE) . ' AND language = ' . $this->_db->quote($this->getLanguage()); if ($row = $this->_getSubTable('Content')->fetchRow($where)) { $row->setFromArray($data); $row->save(); } else { $data['idBlock'] = $this->_primaryKey; $data['language'] = $this->getLanguage(); $this->_getSubTable('Content')->insert($data); } } public function getDataEx() { $key = $this->getPrimaryKey(); if (!is_array($key)) { $key = (array) $key; } /** @var $rows Zend_Db_Table_Rowset */ $rows = call_user_func_array([$this->_getTable(), 'find'], $key); if (count($rows)) { $row = $rows->current()->toArray(); $stmt = $this->_getSubTable('Content')->select() ->where('idBlock = ?', $row['id']) ->query(); $row['content'] = []; while ($contentRow = $stmt->fetch()) { $this->_arrayParseTag2Url($contentRow); $row['content'][$contentRow['language']] = $contentRow['content']; $row['rawContent'][$contentRow['language']] = $contentRow['rawContent']; } return Qs_Array::excludeKey($row, 'id', 'added', 'changed'); } return false; } public function insertDataEx(array $data) { $data = Qs_Array::excludeKey($data, 'id'); $languages = array_keys(Qs_Db_Language::getList()); $idBlock = $this->_getTable()->insert($data); foreach ($languages as $language) { $contentData = [ 'idBlock' => $idBlock, 'language' => $language, 'content' => Qs_Array::get($data['content'], $language, ''), 'rawContent' => Qs_Array::get($data['rawContent'], $language, ''), ]; $this->_arrayParseUrl2Tag($contentData); $this->_getSubTable('Content')->insert($contentData); } return $idBlock; } }