2013-10-01 13:26:39 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ModuleProperty_EntityValueTypeTags extends ModuleProperty_EntityValueType {
|
|
|
|
|
|
|
|
public function getValueForDisplay() {
|
2014-01-08 13:15:46 +02:00
|
|
|
return htmlspecialchars($this->getValueObject()->getValueVarchar());
|
2013-10-01 13:26:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function validate() {
|
|
|
|
return $this->validateStandart('tags');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setValue($mValue) {
|
|
|
|
$this->resetAllValue();
|
|
|
|
$oValue=$this->getValueObject();
|
|
|
|
$oValue->setValueVarchar($mValue ? $mValue : null);
|
2013-12-06 10:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Дополнительная обработка перед сохранением значения
|
|
|
|
*/
|
|
|
|
public function beforeSaveValue() {
|
2013-10-01 13:26:39 +03:00
|
|
|
/**
|
|
|
|
* Заливаем теги в отдельную таблицу
|
|
|
|
*/
|
|
|
|
if ($aTags=$this->getTagsArray()) {
|
2013-12-06 10:32:39 +02:00
|
|
|
$oValue=$this->getValueObject();
|
2013-10-01 13:26:39 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTagsArray() {
|
|
|
|
$sTags=$this->getValueObject()->getValueVarchar();
|
|
|
|
if ($sTags) {
|
|
|
|
return explode(',',$sTags);
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareValidateRulesRaw($aRulesRaw) {
|
|
|
|
$aRules=array();
|
|
|
|
$aRules['allowEmpty']=isset($aRulesRaw['allowEmpty']) ? false : true;
|
|
|
|
|
|
|
|
if (isset($aRulesRaw['count']) and ($iCount=(int)$aRulesRaw['count']) > 0) {
|
|
|
|
$aRules['count']=$iCount;
|
|
|
|
}
|
|
|
|
return $aRules;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|