2013-10-01 13:26:39 +03:00
|
|
|
<?php
|
2014-10-08 08:20:29 +03:00
|
|
|
/*
|
2013-10-01 13:26:39 +03:00
|
|
|
* LiveStreet CMS
|
|
|
|
* Copyright © 2013 OOO "ЛС-СОФТ"
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Official site: www.livestreetcms.com
|
|
|
|
* Contact e-mail: office@livestreetcms.com
|
|
|
|
*
|
|
|
|
* GNU General Public License, version 2:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
*
|
|
|
|
* ------------------------------------------------------
|
|
|
|
*
|
|
|
|
* @link http://www.livestreetcms.com
|
|
|
|
* @copyright 2013 OOO "ЛС-СОФТ"
|
|
|
|
* @author Maxim Mzhelskiy <rus.engine@gmail.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-10-08 08:20:29 +03:00
|
|
|
/**
|
|
|
|
* Объект управления типом tags
|
|
|
|
*
|
|
|
|
* @package application.modules.property
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2014-10-08 11:49:34 +03:00
|
|
|
class ModuleProperty_EntityValueTypeTags extends ModuleProperty_EntityValueType
|
|
|
|
{
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function getValueForDisplay()
|
|
|
|
{
|
|
|
|
return htmlspecialchars($this->getValueObject()->getValueVarchar());
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
return $this->validateStandart('tags');
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function setValue($mValue)
|
|
|
|
{
|
|
|
|
$this->resetAllValue();
|
|
|
|
$oValue = $this->getValueObject();
|
|
|
|
$oValue->setValueVarchar($mValue ? $mValue : null);
|
|
|
|
}
|
2013-12-06 10:32:39 +02:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
/**
|
|
|
|
* Дополнительная обработка перед сохранением значения
|
|
|
|
*/
|
|
|
|
public function beforeSaveValue()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Заливаем теги в отдельную таблицу
|
|
|
|
*/
|
|
|
|
if ($aTags = $this->getTagsArray()) {
|
|
|
|
$oValue = $this->getValueObject();
|
|
|
|
foreach ($aTags as $sTag) {
|
|
|
|
$oTag = Engine::GetEntity('ModuleProperty_EntityValueTag');
|
|
|
|
$oTag->setPropertyId($oValue->getPropertyId());
|
|
|
|
$oTag->setTargetType($oValue->getTargetType());
|
|
|
|
$oTag->setTargetId($oValue->getTargetId());
|
|
|
|
$oTag->setText($sTag);
|
|
|
|
$oTag->Add();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function getTagsArray()
|
|
|
|
{
|
|
|
|
$sTags = $this->getValueObject()->getValueVarchar();
|
|
|
|
if ($sTags) {
|
|
|
|
return explode(',', $sTags);
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function prepareValidateRulesRaw($aRulesRaw)
|
|
|
|
{
|
|
|
|
$aRules = array();
|
|
|
|
$aRules['allowEmpty'] = isset($aRulesRaw['allowEmpty']) ? false : true;
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2015-02-23 14:18:30 +02:00
|
|
|
if (isset($aRulesRaw['countMax']) and ($iCount = (int)$aRulesRaw['countMax']) > 0) {
|
|
|
|
$aRules['countMax'] = $iCount;
|
|
|
|
}
|
|
|
|
if (isset($aRulesRaw['countMin']) and ($iCount = (int)$aRulesRaw['countMin']) > 0) {
|
|
|
|
$aRules['countMin'] = $iCount;
|
2014-10-08 11:49:34 +03:00
|
|
|
}
|
|
|
|
return $aRules;
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
2014-10-08 11:49:34 +03:00
|
|
|
public function removeValue()
|
|
|
|
{
|
|
|
|
$oValue = $this->getValueObject();
|
|
|
|
/**
|
|
|
|
* Удаляем теги из дополнительной таблицы
|
|
|
|
*/
|
|
|
|
if ($aTags = $this->Property_GetValueTagItemsByFilter(array(
|
|
|
|
'property_id' => $oValue->getPropertyId(),
|
|
|
|
'target_id' => $oValue->getTargetId()
|
|
|
|
))
|
|
|
|
) {
|
|
|
|
foreach ($aTags as $oTag) {
|
|
|
|
$oTag->Delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
}
|