From 181f463e47f78fb85726a825ae14c859f58d0215 Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Thu, 23 Jan 2014 16:14:15 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blocks/BlockPropertyUpdate.class.php | 3 +- .../classes/hooks/HookTopicType.class.php | 43 ---------- .../classes/modules/media/Media.class.php | 2 +- .../modules/property/Property.class.php | 85 +++++++++++++++++++ .../property/entity/Target.entity.class.php | 72 ++++++++++++++++ .../classes/modules/topic/Topic.class.php | 5 ++ application/config/config.php | 1 + install/patch.sql | 21 ++++- 8 files changed, 185 insertions(+), 47 deletions(-) delete mode 100644 application/classes/hooks/HookTopicType.class.php create mode 100644 application/classes/modules/property/entity/Target.entity.class.php diff --git a/application/classes/blocks/BlockPropertyUpdate.class.php b/application/classes/blocks/BlockPropertyUpdate.class.php index 8b36e7df..100871e8 100644 --- a/application/classes/blocks/BlockPropertyUpdate.class.php +++ b/application/classes/blocks/BlockPropertyUpdate.class.php @@ -31,8 +31,7 @@ class BlockPropertyUpdate extends Block { /** * Получаем набор свойств */ - $aProperties=$this->Property_GetPropertyItemsByFilter(array('target_type'=>$sTargetType,'#order'=>array('sort'=>'desc'))); - $this->Property_AttachValueForProperties($aProperties,$sTargetType,$iTargetId); + $aProperties=$this->Property_GetPropertiesForUpdate($sTargetType,$iTargetId); $this->Viewer_Assign('aProperties',$aProperties); } } \ No newline at end of file diff --git a/application/classes/hooks/HookTopicType.class.php b/application/classes/hooks/HookTopicType.class.php deleted file mode 100644 index b797228c..00000000 --- a/application/classes/hooks/HookTopicType.class.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - */ - -/** - * Хук для интеграции типов топиков с дополнительными полями - */ -class HookTopicType extends Hook { - - public function RegisterHook() { - $this->AddHook('lang_init_start','InitStart'); - } - - public function InitStart() { - /** - * Получаем список типов топиков - */ - $aTopicTypeItems=$this->Topic_GetTopicTypeItems(); - foreach($aTopicTypeItems as $oType) { - /** - * Запускаем механизм свойств(дополнительныз полей) для каждого вида топика - */ - $this->Property_AddTargetType('topic_'.$oType->getCode(),array('entity'=>'ModuleTopic_EntityTopic','name'=>'Топик - '.$oType->getName())); - } - } -} \ No newline at end of file diff --git a/application/classes/modules/media/Media.class.php b/application/classes/modules/media/Media.class.php index 32a3eb60..796ba800 100644 --- a/application/classes/modules/media/Media.class.php +++ b/application/classes/modules/media/Media.class.php @@ -545,7 +545,7 @@ class ModuleMedia extends ModuleORM { public function CheckTargetComment($iTargetId) { if ($oComment=$this->Comment_GetCommentById($iTargetId)) { /** - * Проверяем права на редактирование топика + * Проверяем права на редактирование комментария */ if ($this->ACL_IsAllowEditComment($oComment,$this->oUserCurrent)) { return true; diff --git a/application/classes/modules/property/Property.class.php b/application/classes/modules/property/Property.class.php index 2d438a8b..0013d21a 100644 --- a/application/classes/modules/property/Property.class.php +++ b/application/classes/modules/property/Property.class.php @@ -30,6 +30,12 @@ class ModuleProperty extends ModuleORM { const PROPERTY_TYPE_TAGS='tags'; const PROPERTY_TYPE_VIDEO_LINK='video_link'; const PROPERTY_TYPE_SELECT='select'; + /** + * Список состояний типов объектов + */ + const TARGET_STATE_ACTIVE=1; + const TARGET_STATE_NOT_ACTIVE=2; + const TARGET_STATE_REMOVE=3; protected $oMapper=null; /** @@ -54,6 +60,15 @@ class ModuleProperty extends ModuleORM { public function Init() { parent::Init(); $this->oMapper=Engine::GetMapper(__CLASS__); + + /** + * Получаем типы из БД и активируем их + */ + if ($aTargetItems=$this->GetTargetItemsByFilter(array('state'=>self::TARGET_STATE_ACTIVE))) { + foreach($aTargetItems as $oTarget) { + $this->Property_AddTargetType($oTarget->getType(),$oTarget->getParams()); + } + } } /** * Возвращает список типов объектов @@ -259,6 +274,13 @@ class ModuleProperty extends ModuleORM { * @return array */ public function GetEntityPropertyList($oTarget) { + $sTargetType=$oTarget->getPropertyTargetType(); + /** + * Проверяем зарегистрирован ли такой тип + */ + if (!$this->IsAllowTargetType($sTargetType)) { + return array(); + } if (!$oTarget->getPropertyIsLoadAll()) { $aProperties=$this->oMapper->GetPropertiesValueByTarget($oTarget->getPropertyTargetType(),$oTarget->getId()); $this->AttachPropertiesForTarget($oTarget,$aProperties); @@ -607,4 +629,67 @@ class ModuleProperty extends ModuleORM { 'ModuleProperty_EntityValueTag_save', )); } + /** + * Создает новый тип объекта в БД для дополнительных полей + * + * @param string $sType + * @param array $aParams + * @param bool $bRewrite + * + * @return bool|ModuleProperty_EntityTarget + */ + public function CreateTargetType($sType,$aParams,$bRewrite=false) { + /** + * Проверяем есть ли уже такой тип + */ + if ($oTarget=$this->GetTargetByType($sType)) { + if (!$bRewrite) { + return false; + } + } else { + $oTarget=Engine::GetEntity('ModuleProperty_EntityTarget'); + $oTarget->setType($sType); + } + $oTarget->setState(self::TARGET_STATE_ACTIVE); + $oTarget->setParams($aParams); + if ($oTarget->Save()) { + return $oTarget; + } + return false; + } + /** + * Отключает тип объекта для дополнительных полей + * + * @param string $sType + * @param int $iState self::TARGET_STATE_NOT_ACTIVE или self::TARGET_STATE_REMOVE + */ + public function RemoveTargetType($sType,$iState=self::TARGET_STATE_NOT_ACTIVE) { + if ($oTarget=$this->GetTargetByType($sType)) { + $oTarget->setState($iState); + $oTarget->Save(); + } + } + + /** + * Возвращает набор полей/свойств для показа их на форме редактирования + * + * @param $sTargetType + * @param $iTargetId + * + * @return mixed + */ + public function GetPropertiesForUpdate($sTargetType,$iTargetId) { + /** + * Проверяем зарегистрирован ли такой тип + */ + if (!$this->IsAllowTargetType($sTargetType)) { + return array(); + } + /** + * Получаем набор свойств + */ + $aProperties=$this->Property_GetPropertyItemsByFilter(array('target_type'=>$sTargetType,'#order'=>array('sort'=>'desc'))); + $this->Property_AttachValueForProperties($aProperties,$sTargetType,$iTargetId); + return $aProperties; + } } \ No newline at end of file diff --git a/application/classes/modules/property/entity/Target.entity.class.php b/application/classes/modules/property/entity/Target.entity.class.php new file mode 100644 index 00000000..08ee5458 --- /dev/null +++ b/application/classes/modules/property/entity/Target.entity.class.php @@ -0,0 +1,72 @@ + + * + */ + +class ModuleProperty_EntityTarget extends EntityORM { + + protected $aValidateRules=array( + + ); + + protected $aRelations=array( + + ); + + protected function beforeSave() { + if ($this->_isNew()) { + $this->setDateCreate(date("Y-m-d H:i:s")); + } else { + $this->setDateUpdate(date("Y-m-d H:i:s")); + } + return true; + } + + /** + * Возвращает список дополнительных параметров + * + * @return array|mixed + */ + public function getParams() { + $aData=@unserialize($this->_getDataOne('params')); + if (!$aData) { + $aData=array(); + } + return $aData; + } + /** + * Устанавливает список дополнительных параметров + * + * @param $aParams + */ + public function setParams($aParams) { + $this->_aData['params']=@serialize($aParams); + } + /** + * Возвращает конкретный параметр + * + * @param $sName + * + * @return null + */ + public function getParam($sName) { + $aParams=$this->getParams(); + return isset($aParams[$sName]) ? $aParams[$sName] : null; + } +} \ No newline at end of file diff --git a/application/classes/modules/topic/Topic.class.php b/application/classes/modules/topic/Topic.class.php index 02122520..1974c9fa 100644 --- a/application/classes/modules/topic/Topic.class.php +++ b/application/classes/modules/topic/Topic.class.php @@ -1631,6 +1631,11 @@ class ModuleTopic extends Module { $oType->setId($sId); //чистим зависимые кеши $this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('topic_type_new')); + /** + * Регистрируем новый тип в дополнительных полях + * todo: fix lang text + */ + $this->Property_CreateTargetType('topic_'.$oType->getCode(),array('entity'=>'ModuleTopic_EntityTopic','name'=>'Топик - '.$oType->getName()),true); return $oType; } return false; diff --git a/application/config/config.php b/application/config/config.php index c1370c2d..5e2fb77c 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -281,6 +281,7 @@ $config['db']['table']['geo_city'] = '___db.table.prefix___geo_city'; $config['db']['table']['geo_target'] = '___db.table.prefix___geo_target'; $config['db']['table']['user_changemail'] = '___db.table.prefix___user_changemail'; $config['db']['table']['property'] = '___db.table.prefix___property'; +$config['db']['table']['property_target'] = '___db.table.prefix___property_target'; $config['db']['table']['property_select'] = '___db.table.prefix___property_select'; $config['db']['table']['property_value'] = '___db.table.prefix___property_value'; $config['db']['table']['property_value_tag'] = '___db.table.prefix___property_value_tag'; diff --git a/install/patch.sql b/install/patch.sql index c9ca5000..ce53150d 100644 --- a/install/patch.sql +++ b/install/patch.sql @@ -224,4 +224,23 @@ ALTER TABLE `prefix_topic_type` ADD `sort` INT NOT NULL DEFAULT '0' AFTER `state ADD INDEX ( `sort` ) ; -- 12.01.2014 -ALTER TABLE `prefix_property` ADD `description` VARCHAR( 500 ) NOT NULL AFTER `title` ; \ No newline at end of file +ALTER TABLE `prefix_property` ADD `description` VARCHAR( 500 ) NOT NULL AFTER `title` ; + +--23.01.2014 +-- +-- Структура таблицы `prefix_property_target` +-- + +CREATE TABLE IF NOT EXISTS `prefix_property_target` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `type` varchar(50) NOT NULL, + `date_create` datetime NOT NULL, + `date_update` datetime DEFAULT NULL, + `state` tinyint(4) NOT NULL DEFAULT '1', + `params` text NOT NULL, + PRIMARY KEY (`id`), + KEY `type` (`type`), + KEY `date_create` (`date_create`), + KEY `date_update` (`date_update`), + KEY `state` (`state`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;