<?php
/**
* СодеÑÐ¶Ð¸Ñ ÐºÐ»Ð°ÑÑ FeedEditor
*
* @package energine
* @subpackage share
* @author dr.Pavka
* @copyright ColoCall 2007
* @version $Id: FeedEditor.class.php,v 1.4 2008/04/03 09:56:15 pavka Exp $
*/
/**
* ÐлаÑÑ Ð´Ð»Ñ Ð¿Ð¾ÑÑÑÐ¾ÐµÐ½Ð¸Ñ ÑедакÑоÑов ÑпÑавлÑÑÑиÑ
ÑÑ Ð¸Ð· панели ÑпÑавлениÑ
*
* @package energine
* @subpackage share
* @abstract
*/
abstract class FeedEditor extends Grid {
/**
* ÐклÑÑен ли Ñежим ÑедакÑиÑованиÑ
*
* @var boolean
* @access private
*/
private $isEditable;
/**
* ÐонÑÑÑÑкÑÐ¾Ñ ÐºÐ»Ð°ÑÑа
*
* @param string $name
* @param string $module
* @param Document $document
* @param array $params
* @access public
*/
public function __construct($name, $module, Document $document, array $params = null) {
parent::__construct($name, $module, $document, $params);
$this->isEditable = isset($_REQUEST['editMode']);
$this->setProperty('exttype', 'feededitor');
}
/**
* ÐобавлÑем паÑамеÑÑ - Ð¸Ð¼Ñ ÑвÑзанного компоненÑа
*
* @return array
* @access protected
*/
protected function defineParams() {
return array_merge(
parent::defineParams(),
array(
'linkTo' => false
)
);
}
/**
* ÐÐ»Ñ ÑоÑм поле smap_id вÑводим как string
*
* @return DataDescription
* @access protected
*/
protected function createDataDescription() {
$result = parent::createDataDescription();
if (in_array($this->getType(), array(self::COMPONENT_TYPE_FORM_ADD, self::COMPONENT_TYPE_FORM_ALTER))) {
$field = $result->getFieldDescriptionByName('smap_id');
$field->setType(FieldDescription::FIELD_TYPE_STRING);
$field->setMode(FieldDescription::FIELD_MODE_READ);
}
return $result;
}
/**
* ÐпÑеделÑем даннÑе Ð´Ð»Ñ smap_id
*
* @return Data
* @access protected
*/
protected function createData() {
$result = parent::createData();
if (in_array($this->getType(), array(self::COMPONENT_TYPE_FORM_ADD, self::COMPONENT_TYPE_FORM_ALTER))) {
$info = Sitemap::getInstance()->getDocumentInfo($this->document->getID());
$field = $result->getFieldByName('smap_id');
for($i=0; $i<sizeof(Language::getInstance()->getLanguages()); $i++) {
$field->setRowProperty($i, 'segment', Sitemap::getInstance()->getURLByID($this->document->getID()));
$field->changeRowData($i, $info['Name']);
}
}
return $result;
}
/**
* УбиÑаем вÑе лиÑнее
*
* @return void
* @access protected
*/
protected function main() {
if ($toolbar = $this->createToolbar()) {
$this->setToolbar($toolbar);
}
$this->js = $this->buildJS();
}
/**
* ÐÐ»Ñ Ð¼ÐµÑода main ÑбиÑаем вÑзов поÑÑÑоиÑелÑ
*
* @return DOMDocument
* @access public
*/
public function build() {
if ($this->getAction() == 'main') {
if ($param = $this->getParam('linkTo')) {
$this->setProperty('linkedComponent', $param);
}
$result = Component::build();
if (($component = $this->document->componentManager->getComponentByName($param)) && ($component->getAction() != 'view') && $this->isEditable) {
if ($this->js) {
$result->documentElement->appendChild($result->importNode($this->js, true));
}
$result->documentElement->appendChild($result->createElement('recordset'));
if (($toolbar = $this->getToolbar()) && ($toolbar = $toolbar->build())) {
$toolbar = $result->importNode($toolbar, true);
$result->documentElement->appendChild($toolbar);
}
}
}
else {
if ($this->getType() !== self::COMPONENT_TYPE_LIST ) {
$this->setProperty('exttype', 'grid');
}
$result = parent::build();
}
return $result;
}
/**
* ÐÑÑÑавлÑем smap_id в ÑекÑÑее знаÑение
*
* @return mixed
* @access protected
*/
protected function saveData() {
$_POST[$this->getTableName()]['smap_id'] = $this->document->getID();
$result = parent::saveData();
return $result;
}
}