mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-26 03:30:48 +03:00
Доработка дополнительных полей
This commit is contained in:
parent
fa437004f2
commit
181f463e47
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
<?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 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()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?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_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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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` ;
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue