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 HookProperty extends Hook {
|
|
|
|
|
|
|
|
|
|
public function RegisterHook() {
|
|
|
|
|
$this->AddHook('lang_init_start','InitStart',null,-10000);
|
|
|
|
|
$this->AddHook('module_orm_GetItemsByFilter_after','GetItemsByFilterAfter',null,10000);
|
|
|
|
|
$this->AddHook('module_orm_GetItemsByFilter_before','GetItemsByFilterBefore',null,10000);
|
|
|
|
|
$this->AddHook('module_orm_GetByFilter_before','GetItemsByFilterBefore',null,10000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function InitStart() {
|
|
|
|
|
/**
|
|
|
|
|
* Регистрируем кастомный загрузчик классов
|
|
|
|
|
*/
|
|
|
|
|
spl_autoload_register(array($this,'autoload'),true,true);
|
|
|
|
|
/**
|
|
|
|
|
* Добавляем через наследование в объекты необходимый функционал по работе со свойствами EAV
|
|
|
|
|
*/
|
|
|
|
|
$aTargetTypes=$this->Property_GetTargetTypes();
|
2014-01-11 18:27:27 +02:00
|
|
|
|
$aUseEntities=array();
|
2013-10-01 13:26:39 +03:00
|
|
|
|
foreach($aTargetTypes as $sType=>$aParams) {
|
2014-01-11 18:27:27 +02:00
|
|
|
|
/**
|
|
|
|
|
* Защита от дубля при наследовании
|
|
|
|
|
*/
|
|
|
|
|
if (!in_array($aParams['entity'],$aUseEntities)) {
|
|
|
|
|
$this->Plugin_Inherit($aParams['entity'],'ModuleProperty_Target_'.$aParams['entity'],'ModuleProperty');
|
|
|
|
|
$aUseEntities[]=$aParams['entity'];
|
|
|
|
|
}
|
2013-10-01 13:26:39 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Дополнительная пост-обработка результатов запроса ORM
|
|
|
|
|
*
|
|
|
|
|
* @param $aParams
|
|
|
|
|
*/
|
|
|
|
|
public function GetItemsByFilterAfter($aParams) {
|
|
|
|
|
$aEntities=$aParams['aEntities'];
|
|
|
|
|
$aFilter=$aParams['aFilter'];
|
|
|
|
|
$this->Property_RewriteGetItemsByFilter($aEntities,$aFilter);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Обработка фильтра для запросов к ORM
|
|
|
|
|
*
|
|
|
|
|
* @param $aParams
|
|
|
|
|
*/
|
|
|
|
|
public function GetItemsByFilterBefore($aParams) {
|
|
|
|
|
$aFilter=$this->Property_RewriteFilter($aParams['aFilter'],$aParams['sEntityFull']);
|
|
|
|
|
$aParams['aFilter']=$aFilter;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Автозагрузчик классов
|
|
|
|
|
* Создает новый фейковый класс для создания цепочки наследования
|
2014-01-11 18:27:27 +02:00
|
|
|
|
* Поддерживаются только ORM сущности
|
|
|
|
|
* TODO: продумать использование сценариев валидации отличных от дефолтного
|
2013-10-01 13:26:39 +03:00
|
|
|
|
*
|
|
|
|
|
* @param string $sClassName
|
|
|
|
|
*/
|
|
|
|
|
public function autoload($sClassName) {
|
|
|
|
|
if (preg_match("#^ModuleProperty_Target_(.+)$#i",$sClassName,$aMatch)) {
|
|
|
|
|
$sClass="
|
|
|
|
|
class {$sClassName} extends ModuleProperty_Inherit_{$aMatch[1]} {
|
|
|
|
|
public function Init() {
|
|
|
|
|
parent::Init();
|
|
|
|
|
\$this->aValidateRules[]=array('properties','properties_check');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ValidatePropertiesCheck() {
|
|
|
|
|
return \$this->Property_ValidateEntityPropertiesCheck(\$this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function afterSave() {
|
|
|
|
|
parent::afterSave();
|
|
|
|
|
\$this->Property_UpdatePropertiesValue(\$this->getPropertiesObject(),\$this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function afterDelete() {
|
|
|
|
|
parent::afterDelete();
|
|
|
|
|
\$this->Property_RemovePropertiesValue(\$this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPropertyValue(\$sPropertyId) {
|
|
|
|
|
return \$this->Property_GetEntityPropertyValue(\$this,\$sPropertyId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getProperty(\$sPropertyId) {
|
|
|
|
|
return \$this->Property_GetEntityProperty(\$this,\$sPropertyId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPropertyList() {
|
|
|
|
|
return \$this->Property_GetEntityPropertyList(\$this);
|
|
|
|
|
}
|
|
|
|
|
}";
|
|
|
|
|
eval($sClass);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|