mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-16 23:00:51 +03:00
Доработка категорий
This commit is contained in:
parent
8421a043f6
commit
129de4a20f
|
@ -180,7 +180,7 @@ class ModuleCategory extends ModuleORM {
|
|||
* @return array
|
||||
*/
|
||||
public function GetCategoriesTreeByType($sId) {
|
||||
$aCategories=$this->Category_LoadTreeOfCategory(array('type_id'=>$sId));
|
||||
$aCategories=$this->LoadTreeOfCategory(array('type_id'=>$sId));
|
||||
return ModuleORM::buildTree($aCategories);
|
||||
}
|
||||
/**
|
||||
|
@ -191,7 +191,7 @@ class ModuleCategory extends ModuleORM {
|
|||
* @return array
|
||||
*/
|
||||
public function GetCategoriesTreeByTargetType($sCode) {
|
||||
if ($oType=$this->Category_GetTypeByTargetType($sCode)) {
|
||||
if ($oType=$this->GetTypeByTargetType($sCode)) {
|
||||
return $this->GetCategoriesTreeByType($oType->getId());
|
||||
}
|
||||
return array();
|
||||
|
@ -342,5 +342,37 @@ class ModuleCategory extends ModuleORM {
|
|||
}
|
||||
return $aCategoryId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Пересобирает полные URL дочерних категорий
|
||||
*
|
||||
* @param $oCategoryStart
|
||||
* @param bool $bStart
|
||||
*/
|
||||
public function RebuildCategoryUrlFull($oCategoryStart,$bStart=true) {
|
||||
static $aRebuildIds;
|
||||
if ($bStart) {
|
||||
$aRebuildIds=array();
|
||||
}
|
||||
|
||||
if (is_null($oCategoryStart->getId())) {
|
||||
$aCategories=$this->GetCategoryItemsByFilter(array('#where'=>array('pid is null'=>array()),'type_id'=>$oCategoryStart->getTypeId()));
|
||||
} else {
|
||||
$aCategories=$this->GetCategoryItemsByFilter(array('pid'=>$oCategoryStart->getId(),'type_id'=>$oCategoryStart->getTypeId()));
|
||||
}
|
||||
|
||||
foreach ($aCategories as $oCategory) {
|
||||
if ($oCategory->getId()==$oCategoryStart->getId()) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($oCategory->getId(),$aRebuildIds)) {
|
||||
continue;
|
||||
}
|
||||
$aRebuildIds[]=$oCategory->getId();
|
||||
$oCategory->setUrlFull($oCategoryStart->getUrlFull().'/'.$oCategory->getUrl());
|
||||
$oCategory->Update();
|
||||
$this->RebuildCategoryUrlFull($oCategory,false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -20,13 +20,95 @@
|
|||
*/
|
||||
class ModuleCategory_EntityCategory extends EntityORM {
|
||||
|
||||
/**
|
||||
* Определяем правила валидации
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aValidateRules=array(
|
||||
array('title','string','max'=>200,'min'=>1,'allowEmpty'=>false),
|
||||
array('url','regexp','pattern'=>'/^[\w\-_]+$/i','allowEmpty'=>false),
|
||||
array('order','number','integerOnly'=>true),
|
||||
array('pid','parent_category'),
|
||||
array('order','order_check'),
|
||||
);
|
||||
|
||||
protected $aRelations=array(
|
||||
'type' => array(self::RELATION_TYPE_BELONGS_TO,'ModuleCategory_EntityType','type_id'),
|
||||
self::RELATION_TYPE_TREE
|
||||
);
|
||||
|
||||
/**
|
||||
* Проверка родительской категории
|
||||
*
|
||||
* @param string $sValue Валидируемое значение
|
||||
* @param array $aParams Параметры
|
||||
* @return bool
|
||||
*/
|
||||
public function ValidateParentCategory($sValue,$aParams) {
|
||||
if ($this->getPid()) {
|
||||
if ($oCategory=$this->Category_GetCategoryById($this->getPid())) {
|
||||
if ($oCategory->getId()==$this->getId()) {
|
||||
return 'Попытка вложить категорию в саму себя';
|
||||
}
|
||||
if ($oCategory->getTypeId()!=$this->getTypeId()) {
|
||||
return 'Неверная родительская категория';
|
||||
}
|
||||
$this->setUrlFull($oCategory->getUrlFull().'/'.$this->getUrl());
|
||||
} else {
|
||||
return 'Неверная категория';
|
||||
}
|
||||
} else {
|
||||
$this->setPid(null);
|
||||
$this->setUrlFull($this->getUrl());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Установка дефолтной сортировки
|
||||
*
|
||||
* @param string $sValue Валидируемое значение
|
||||
* @param array $aParams Параметры
|
||||
* @return bool
|
||||
*/
|
||||
public function ValidateOrderCheck($sValue,$aParams) {
|
||||
if (!$this->getSort()) {
|
||||
$this->setSort(100);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Выполняется перед удалением
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function beforeDelete() {
|
||||
if ($bResult=parent::beforeDelete()) {
|
||||
/**
|
||||
* Запускаем удаление дочерних категорий
|
||||
*/
|
||||
if ($aCildren=$this->getChildren()) {
|
||||
foreach($aCildren as $oChildren) {
|
||||
$oChildren->Delete();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Удаляем связь с таргетом
|
||||
*/
|
||||
if ($aTargets=$this->Category_GetTargetItemsByCategoryId($this->getId())) {
|
||||
foreach($aTargets as $oTarget) {
|
||||
$oTarget->Delete();
|
||||
/**
|
||||
* TODO: Нужно запустить хук, что мы удалили такую-то связь
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return $bResult;
|
||||
}
|
||||
/**
|
||||
* Переопределяем имя поля с родителем
|
||||
* Т.к. по дефолту в деревьях используется поле parent_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
@ -68,4 +150,20 @@ class ModuleCategory_EntityCategory extends EntityORM {
|
|||
}
|
||||
return $oType;
|
||||
}
|
||||
/**
|
||||
* Возвращает URL админки для редактирования
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlAdminUpdate() {
|
||||
return Router::GetPath('admin/categories/'.$this->getTypeByCacheLife()->getTargetType().'/update/'.$this->getId());
|
||||
}
|
||||
/**
|
||||
* Возвращает URL админки для удаления
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlAdminRemove() {
|
||||
return Router::GetPath('admin/categories/'.$this->getTypeByCacheLife()->getTargetType().'/remove/'.$this->getId());
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit 5295efdaea542772a3b79af824b86edb86c0ad14
|
||||
Subproject commit f909f214de3318a4a3037ad5801f277f7b361d15
|
Loading…
Reference in a new issue