mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-16 23:00:51 +03:00
Доработка универсальных категорий
This commit is contained in:
parent
b7c8fa699e
commit
8421a043f6
|
@ -30,15 +30,6 @@ class ModuleCategory extends ModuleORM {
|
|||
const TARGET_STATE_NOT_ACTIVE=2;
|
||||
const TARGET_STATE_REMOVE=3;
|
||||
|
||||
protected $oMapper=null;
|
||||
|
||||
/**
|
||||
* Инициализация
|
||||
*/
|
||||
public function Init() {
|
||||
parent::Init();
|
||||
$this->oMapper=Engine::GetMapper(__CLASS__);
|
||||
}
|
||||
/**
|
||||
* Возвращает список категорий сущности
|
||||
*
|
||||
|
@ -189,18 +180,8 @@ class ModuleCategory extends ModuleORM {
|
|||
* @return array
|
||||
*/
|
||||
public function GetCategoriesTreeByType($sId) {
|
||||
$aRow=$this->oMapper->GetCategoriesByType($sId);
|
||||
if (count($aRow)) {
|
||||
$aRec=$this->Tools_BuildEntityRecursive($aRow);
|
||||
}
|
||||
if (!isset($aRec['collection'])) {
|
||||
return array();
|
||||
}
|
||||
$aResult=$this->Category_GetCategoryItemsByFilter(array('id in'=>array_keys($aRec['collection']),'#index-from-primary','#order'=>array('FIELD:id'=>array_keys($aRec['collection']))));
|
||||
foreach ($aResult as $oCategory) {
|
||||
$oCategory->setLevel($aRec['collection'][$oCategory->getId()]);
|
||||
}
|
||||
return $aResult;
|
||||
$aCategories=$this->Category_LoadTreeOfCategory(array('type_id'=>$sId));
|
||||
return ModuleORM::buildTree($aCategories);
|
||||
}
|
||||
/**
|
||||
* Возвращает дерево категорий
|
||||
|
@ -343,6 +324,7 @@ class ModuleCategory extends ModuleORM {
|
|||
} else {
|
||||
$iCategoryId=$oCategory;
|
||||
}
|
||||
$aCategoryId=array($iCategoryId);
|
||||
if ($bIncludeChild) {
|
||||
/**
|
||||
* Сначала получаем полный список категорий текущего типа
|
||||
|
@ -351,45 +333,14 @@ class ModuleCategory extends ModuleORM {
|
|||
$oCategory=$this->GetCategoryById($iCategoryId);
|
||||
}
|
||||
if ($oCategory) {
|
||||
$aCategories=$this->oMapper->GetCategoriesByType($oCategory->getTypeId());
|
||||
$aCategoriesChild=$this->GetChildItemsFromCategories($aCategories,$iCategoryId);
|
||||
$aCategoryId=array_merge(array((int)$iCategoryId),array_keys($aCategoriesChild));
|
||||
} else {
|
||||
return null;
|
||||
if ($aChildren=$oCategory->getDescendants()) {
|
||||
foreach($aChildren as $oCategoryChild) {
|
||||
$aCategoryId[]=$oCategoryChild->getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aCategoryId=array($iCategoryId);
|
||||
}
|
||||
return $aCategoryId;
|
||||
}
|
||||
/**
|
||||
* Обрабатывает дочерние категории
|
||||
*
|
||||
* @param $aCategories
|
||||
* @param null $iCategoryId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function GetChildItemsFromCategories($aCategories,$iCategoryId=null) {
|
||||
static $aResult;
|
||||
static $bIsChild;
|
||||
|
||||
foreach($aCategories as $aCategory) {
|
||||
if ($aCategory['id']==$iCategoryId) {
|
||||
$bIsChild=true;
|
||||
$this->GetChildItemsFromCategories($aCategory['childNodes'],$iCategoryId);
|
||||
return $aResult ? $aResult : array();
|
||||
}
|
||||
if ($bIsChild) {
|
||||
$aCat=$aCategory;
|
||||
unset($aCat['childNodes']);
|
||||
$aResult[$aCat['id']]=$aCat;
|
||||
}
|
||||
if ($aCategory['childNodes']) {
|
||||
$this->GetChildItemsFromCategories($aCategory['childNodes'],$iCategoryId);
|
||||
}
|
||||
}
|
||||
return $aResult ? $aResult : array();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -23,6 +23,14 @@
|
|||
* Поведение, которое необходимо добавлять к ORM модулю сущности у которой добавляются категории
|
||||
*/
|
||||
class ModuleCategory_BehaviorModule extends Behavior {
|
||||
/**
|
||||
* Дефолтные параметры
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aParams=array(
|
||||
'target_type'=>'',
|
||||
);
|
||||
/**
|
||||
* Список хуков
|
||||
*
|
||||
|
@ -48,7 +56,7 @@ class ModuleCategory_BehaviorModule extends Behavior {
|
|||
public function CallbackGetItemsByFilterAfter($aParams) {
|
||||
$aEntities=$aParams['aEntities'];
|
||||
$aFilter=$aParams['aFilter'];
|
||||
$this->Category_RewriteGetItemsByFilter($aEntities,$aFilter,'test');
|
||||
$this->Category_RewriteGetItemsByFilter($aEntities,$aFilter,$this->getParam('target_type'));
|
||||
}
|
||||
/**
|
||||
* Модифицирует результат ORM запроса
|
||||
|
@ -56,7 +64,7 @@ class ModuleCategory_BehaviorModule extends Behavior {
|
|||
* @param $aParams
|
||||
*/
|
||||
public function CallbackGetItemsByFilterBefore($aParams) {
|
||||
$aFilter=$this->Category_RewriteFilter($aParams['aFilter'],$aParams['sEntityFull'],'test');
|
||||
$aFilter=$this->Category_RewriteFilter($aParams['aFilter'],$aParams['sEntityFull'],$this->getParam('target_type'));
|
||||
$aParams['aFilter']=$aFilter;
|
||||
}
|
||||
}
|
|
@ -22,8 +22,17 @@ class ModuleCategory_EntityCategory extends EntityORM {
|
|||
|
||||
protected $aRelations=array(
|
||||
'type' => array(self::RELATION_TYPE_BELONGS_TO,'ModuleCategory_EntityType','type_id'),
|
||||
self::RELATION_TYPE_TREE
|
||||
);
|
||||
|
||||
/**
|
||||
* Переопределяем имя поля с родителем
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getTreeParentKey() {
|
||||
return 'pid';
|
||||
}
|
||||
/**
|
||||
* Выполняется перед сохранением
|
||||
*
|
||||
|
|
|
@ -1,46 +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>
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Маппер для работы с БД
|
||||
*
|
||||
* @package modules.category
|
||||
* @since 1.0
|
||||
*/
|
||||
class ModuleCategory_MapperCategory extends Mapper {
|
||||
|
||||
public function GetCategoriesByType($sId) {
|
||||
$sql = "SELECT
|
||||
id,
|
||||
id as ARRAY_KEY,
|
||||
pid as PARENT_KEY
|
||||
FROM
|
||||
".Config::Get('db.table.category')."
|
||||
WHERE
|
||||
type_id = ?d
|
||||
ORDER by `order` desc;
|
||||
";
|
||||
if ($aRows=$this->oDb->select($sql,$sId)) {
|
||||
return $aRows;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
Subproject commit fcf92c128844ed9d9c2e5fb5f5877b1f0c1592ed
|
||||
Subproject commit 5295efdaea542772a3b79af824b86edb86c0ad14
|
Loading…
Reference in a new issue