mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-16 23:00:51 +03:00
Доработка категорий
This commit is contained in:
parent
05f8d8905a
commit
507aceb632
|
@ -19,7 +19,7 @@
|
|||
* Обработка блока с редактированием категорий объекта
|
||||
*
|
||||
* @package blocks
|
||||
* @since 1.0
|
||||
* @since 2.0
|
||||
*/
|
||||
class BlockCategoryUpdate extends Block {
|
||||
/**
|
||||
|
@ -41,16 +41,16 @@ class BlockCategoryUpdate extends Block {
|
|||
/**
|
||||
* Нужное нам поведение - получаем список текущих категорий
|
||||
*/
|
||||
$this->Viewer_Assign('aCategoriesCurrent',$oBehavior->getCategories());
|
||||
$this->Viewer_Assign('categoriesSelected', $oBehavior->getCategories(), true);
|
||||
/**
|
||||
* Загружаем параметры
|
||||
*/
|
||||
$aParams=$oBehavior->getParams();
|
||||
$this->Viewer_Assign('aCategoryParams',$aParams);
|
||||
$this->Viewer_Assign('params', $aParams, true);
|
||||
/**
|
||||
* Загружаем список доступных категорий
|
||||
*/
|
||||
$this->Viewer_Assign('aCategories',$this->Category_GetCategoriesTreeByTargetType($aParams['target_type']));
|
||||
$this->Viewer_Assign('categories', $this->Category_GetCategoriesTreeByTargetType($aParams['target_type']), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
{**
|
||||
* Вывод категорий на странице создания нового объекта
|
||||
*}
|
||||
|
||||
{*
|
||||
Вывод категорий на странице создания нового объекта
|
||||
*}
|
||||
{$params = $smarty.local.params}
|
||||
{$categoriesSelected = $smarty.local.categoriesSelected}
|
||||
{$categories = $smarty.local.categories}
|
||||
|
||||
{$aCategoriesCurrentId=[]}
|
||||
{if $aCategoryParams.form_fill_current_from_request && $_aRequest[$aCategoryParams.form_field]}
|
||||
{$aCategoriesCurrentId=$_aRequest[$aCategoryParams.form_field]}
|
||||
{else}
|
||||
{if $aCategoriesCurrent}
|
||||
{foreach $aCategoriesCurrent as $oCategoryCurrent}
|
||||
{$aCategoriesCurrentId[]=$oCategoryCurrent->getId()}
|
||||
{/foreach}
|
||||
{/if}
|
||||
{* Получаем id выделеных категорий *}
|
||||
{if $params.form_fill_current_from_request && $_aRequest[ $params.form_field ]}
|
||||
{$selected = $_aRequest[ $params.form_field ]}
|
||||
{elseif $categoriesSelected}
|
||||
{$selected = []}
|
||||
|
||||
{foreach $categoriesSelected as $category}
|
||||
{$selected[] = $category->getId()}
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
Категория:
|
||||
<select name="{$aCategoryParams.form_field}[]" {if $aCategoryParams.multiple}multiple="multiple" style="height: 200px;"{/if}>
|
||||
{if !$aCategoryParams.validate_require}
|
||||
<option value="">—</option>
|
||||
{/if}
|
||||
{foreach $aCategories as $aCategory}
|
||||
{$oCategory=$aCategory.entity}
|
||||
<option value="{$oCategory->getId()}" {if in_array($oCategory->getId(),$aCategoriesCurrentId)}selected="selected"{/if} style="margin-left: {$oCategory->getLevel()*10}px;">{''|str_pad:(2*$aCategory.level):'-'|cat:$oCategory->getTitle()}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{* Формируем список категорий для select'а *}
|
||||
{$items = []}
|
||||
|
||||
{if ! $params.validate_require}
|
||||
{$items[] = [ 'value' => '', 'text' => '—' ]}
|
||||
{/if}
|
||||
|
||||
{foreach $categories as $category}
|
||||
{$entity = $category.entity}
|
||||
{$items[] = [ 'value' => $entity->getId(), 'text' => $entity->getTitle(), 'level' => $category.level ]}
|
||||
{/foreach}
|
||||
|
||||
{* Селект *}
|
||||
{* TODO: i18n *}
|
||||
{include 'components/field/field.select.tpl' sName="{$params.form_field}[]" aItems=$items sLabel='Категория' sSelectedValue=$selected}
|
Loading…
Reference in a new issue