<commit_before><?php
/**
 * Содержит класс FeedEditor
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 * @copyright Energine 2007
 * @version $Id$
 */

/**
 * Класс для построения редакторов управляющихся из панели управления
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 */
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 = $this->document->isEditable();
		$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->setRowData($i, $info['Name']);
			}
		}
		return $result;
	}

	/**
	 * Убираем все лишнее
	 *
	 * @return void
	 * @access protected
	 */

	protected function main() {
		$_SESSION['feed_smap_id'] =
		$this->document->componentManager->getComponentByName(
		$this->getParam('linkTo')
		)->getFilter();
		$this->addToolbar($this->createToolbar());
		$this->js = $this->buildJS();
	}

	protected function changeOrder($direction){
		$this->setFilter($_SESSION['feed_smap_id']);
		//unset($_SESSION['feed_smap_id']);

		return parent::changeOrder($direction);
	}

	/**
	 * Для метода 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'));
				$tbs = $this->getToolbar();
				if(!empty($tbs))
				foreach($tbs as $tb)
				if($toolbar = $toolbar->build())
				$result->documentElement->appendChild($result->importNode($toolbar, true));
				 
			}
		}
		else {
			if ($this->getType() !== self::COMPONENT_TYPE_LIST ) {
				$this->setProperty('exttype', 'grid');
			}<commit_msg>Fixed fatal error in feededitor<commit_after><?php
/**
 * Содержит класс FeedEditor
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 * @copyright Energine 2007
 * @version $Id$
 */

/**
 * Класс для построения редакторов управляющихся из панели управления
 *
 * @package energine
 * @subpackage share
 * @author dr.Pavka
 */
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 = $this->document->isEditable();
		$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->setRowData($i, $info['Name']);
			}
		}
		return $result;
	}

	/**
	 * Убираем все лишнее
	 *
	 * @return void
	 * @access protected
	 */

	protected function main() {
		$_SESSION['feed_smap_id'] =
		$this->document->componentManager->getComponentByName(
		$this->getParam('linkTo')
		)->getFilter();
		$this->addToolbar($this->createToolbar());
		$this->js = $this->buildJS();
	}

	protected function changeOrder($direction){
		$this->setFilter($_SESSION['feed_smap_id']);
		//unset($_SESSION['feed_smap_id']);

		return parent::changeOrder($direction);
	}

	/**
	 * Для метода 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 (($tbs = $this->getToolbar()) && (!empty($tbs))) {
				    foreach($tbs as $tb)
					if($toolbar = $tb->build()) {
					    $result->documentElement->appendChild($result->importNode($toolbar, true));
					}
				}
				 
			}
		}
		else {
			if ($this->getType() !== self::COMPONENT_TYPE_LIST ) {
				$this->setProperty('exttype', 'grid');
			}
{'fraction_non_alphanumeric': 0.1741160773849233, 'fraction_numerical': 0.00133422281521014, 'mean_word_length': 4.212795549374131, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6882565', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2502, 'n_words': 455}