_draftPrefix = $draftPrefix;
}
protected function _getFromDb($key, $field = false)
{
$rows = call_user_func_array(array($this->{"table{$this->_draftPrefix}{$this->_tableAlias}"}, 'find'), $key);
if (count($rows)) {
$row = $rows->current()->toArray();
$content = $this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->select()
->where('`idBlock` = ?', $row['id'])
->where('`language` = ?', $this->getLanguage())
->query()
->fetch();
if ($content) {
$row = array_merge($row, $content);
}
$this->_arrayParseTag2Url($row);
return Qs_Array::get($row, $field);
}
return false;
}
public function clearData()
{
$this->_data = null;
$this->_dataEx = null;
return $this;
}
public function insert($data = null, $files = null)
{
unset($data['id']);
$this->_arrayParseUrl2Tag($data);
$data['idBlock'] = $id = $this->{"table{$this->_draftPrefix}{$this->_tableAlias}"}->insert($data);
if (empty($data['language'])) {
$data['language'] = $this->getLanguage();
}
$this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->insert($data);
return $id;
}
public function delete()
{
$idBlock = intval($this->getPrimaryKey());
$this->{"table{$this->_draftPrefix}{$this->_tableAlias}"}->delete('`id` = ' . $idBlock);
$this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->delete('`idBlock` = ' . $idBlock);
}
public function update($data = null, $files = null)
{
unset($data['id']);
$this->_arrayParseUrl2Tag($data);
$where = 'idBlock = ' . $this->db->quote($this->id, Zend_Db::INT_TYPE)
. ' AND language = ' . $this->db->quote($this->getLanguage());
if ($row = $this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->fetchRow($where)) {
$row->setFromArray($data);
$row->save();
} else {
$data['idBlock'] = $this->id;
$data['language'] = $this->getLanguage();
$this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->insert($data);
}
}
public function getDataEx()
{
$rows = call_user_func_array(array($this->{"table{$this->_draftPrefix}{$this->_tableAlias}"}, 'find'),
$this->getPrimaryKey());
if (count($rows)) {
$row = $rows->current()->toArray();
$stmt = $this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->select()
->where('idBlock = ?', $row['id'])
->query();
$row['content'] = array();
while ($contentRow = $stmt->fetch()) {
$this->_arrayParseTag2Url($contentRow);
$row['content'][$contentRow['language']] = $contentRow['content'];
}
return Qs_array::exclude($row, 'id', 'added', 'changed');
}
return false;
}
public function insertDataEx(array $data)
{
$data = Qs_Array::exclude($data, 'id');
$idBlock = $this->{"table{$this->_draftPrefix}{$this->_tableAlias}"}->insert($data);
foreach ($data['content'] as $language => $content) {
$contentData = array('idBlock' => $idBlock, 'language' => $language, 'content' => $content);
$this->_arrayParseUrl2Tag($contentData);
$this->{"table{$this->_draftPrefix}{$this->_tableAlias}Content"}->insert($contentData);
}
return $idBlock;
}
protected function _arrayParseUrl2Tag(&$array)
{
parent::_arrayParseUrl2Tag($array);
$array['searchContent'] = strip_tags(preg_replace(array("''si"), '',
$array['content']));
return true;
}
}