Skip to content

Commit

Permalink
Merge branch 'menu'
Browse files Browse the repository at this point in the history
  • Loading branch information
olezhikz committed Nov 4, 2018
2 parents 512f039 + 78a3f75 commit ee7814b
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 2 deletions.
15 changes: 13 additions & 2 deletions classes/actions/ActionAdmin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ protected function RegisterEvent()
* Утилиты
*/
$this->RegisterEventExternal('Utils', 'PluginAdmin_ActionAdmin_EventUtils');

/*
* Меню
*/
$this->RegisterEventExternal('Menu', 'PluginAdmin_ActionAdmin_EventMenu');

/*
*
Expand Down Expand Up @@ -392,6 +395,7 @@ protected function RegisterEvent()
*/
$this->AddEventPreg('#^comments$#iu', '#^delete$#iu', 'Comments::EventFullCommentDelete');


/*
*
* --- Плагины ---
Expand Down Expand Up @@ -450,7 +454,14 @@ protected function RegisterEvent()
'Settings::EventTopicTypeRemove');
$this->AddEventPreg('#^settings$#iu', '#^topic-type$#iu', '#^ajax-sort$#iu',
'Settings::EventTopicTypeAjaxSort');

/*
* Меню
*/

$this->AddEventPreg('#^menu$#i', '#^[\w-]+$#i', '#^remove$#i', '#^\d{1,5}$#i', 'Menu::EventCategoryRemove');
$this->AddEventPreg('#^menu$#i', '#^[\w-]+$#i', '#^update$#i', '#^\d{1,5}$#i', 'Menu::EventCategoryUpdate');
$this->AddEventPreg('#^menu$#i', '#^[\w-]+$#i', '#^create$#i', '#^$#i', 'Menu::EventItemCreate');
$this->AddEventPreg('#^menu$#i', '#^[\w-]+$#i', 'Menu::EventList');
/*
*
* --- Шаблоны ---
Expand Down
167 changes: 167 additions & 0 deletions classes/actions/admin/EventMenu.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php

/*
* LiveStreet CMS
* Copyright © 2018 OOO "ЛС-СОФТ"
*
* ------------------------------------------------------
*
* Official site: www.livestreetcms.com
* Contact e-mail: [email protected]
*
* 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 Oleg Demodov <[email protected]>
*
*/

/**
* Редактирование меню
*
* @author oleg
*/
class PluginAdmin_ActionAdmin_EventMenu extends Event{

public function EventList() {
$oMenu = $this->Menu_GetMenuByFilter(['name' => $this->GetParam(0)]);
if(!$oMenu){
return $this->EventNotFound();
}

$aItems = $this->Menu_LoadTreeOfItem([
'menu_id' => $oMenu->getId(),
'#order' => array('priority' => 'desc')
]);

$aItems = ModuleORM::buildTree($aItems);

$this->Viewer_Assign('aItems', $aItems);
$this->Viewer_Assign('oMenu', $oMenu);

$this->SetTemplateAction('menu/list');
}

public function EventItemCreate()
{
$oMenu = $this->Menu_GetMenuByFilter(['name' => $this->GetParam(0)]);
if(!$oMenu){
return $this->EventNotFound();
}

if (getRequest('item_submit')) {
$this->Security_ValidateSendForm();

$oItem = Engine::GetEntity('ModuleMenu_EntityItem');
$oItem->_setDataSafe(getRequest('item'));

$oItem->setMenuId($oMenu->getId());

if ($oItem->_Validate()) {
$oItem->setTitle(htmlspecialchars($oItem->getTitle()));

if ($oItem->Add()) {
$this->Message_AddNotice('Добавление прошло успешно', $this->Lang_Get('common.attention'), true);
Router::LocationAction("admin/menu/" . $oMenu->getName());
} else {
$this->Message_AddError('Возникла ошибка при добавлении', $this->Lang_Get('common.error.error'));
}
} else {
$this->Message_AddError($oItem->_getValidateError(), $this->Lang_Get('common.error.error'));
}
}
/**
* Получаем список пупнктов для данного меню
*/
$aItems = $this->Menu_LoadTreeOfItem([
'menu_id' => $oMenu->getId(),
'#order' => array('priority' => 'desc')
]);

$aItems = ModuleORM::buildTree($aItems);

$this->Viewer_Assign('aItems', $aItems);
$this->Viewer_Assign('oMenu', $oMenu);
$this->SetTemplateAction('menu/create');
}

public function EventCategoryUpdate()
{
$oMenu = $this->Menu_GetMenuByFilter(['name' => $this->GetParam(0)]);
if(!$oMenu){
return $this->EventNotFound();
}
if (!($oItem = $this->Menu_GetItemById($this->GetParam(2)))) {
return $this->EventNotFound();
}

/**
* Получаем список пупнктов для данного меню
*/
$aItems = $this->Menu_LoadTreeOfItem([
'menu_id' => $oMenu->getId(),
'#order' => array('priority' => 'desc')
]);

$aItems = ModuleORM::buildTree($aItems);

if (getRequest('item_submit')) {
$this->Security_ValidateSendForm();
$oItem->_setDataSafe(getRequest('item'));

if ($oItem->_Validate()) {
$oItem->setTitle(htmlspecialchars($oItem->getTitle()));

if ($oItem->Save()) {
$this->Message_AddNotice('Сохранение прошло успешно', $this->Lang_Get('common.attention'), true);
Router::LocationAction("admin/menu/" . $oMenu->getName());
} else {
$this->Message_AddError('Возникла ошибка при сохранении', $this->Lang_Get('common.error.error'));
}
} else {
$this->Message_AddError($oItem->_getValidateError(), $this->Lang_Get('common.error.error'));
}
} else {
$_REQUEST['item'] = array(
'pid' => $oItem->getPid(),
'title' => htmlspecialchars_decode($oItem->getTitle()),
'name' => $oItem->getName(),
'url' => $oItem->getUrl(),
'priority' => $oItem->getPriority(),
'enable' => $oItem->getEnable(),
'active' => $oItem->getActive(),
);
}

$this->Viewer_Assign('oItem', $oItem);
$this->Viewer_Assign('aItems', $aItems);
$this->Viewer_Assign('oMenu', $oMenu);
$this->SetTemplateAction('menu/create');
}

public function EventCategoryRemove()
{
$oMenu = $this->Menu_GetMenuByFilter(['name' => $this->GetParam(0)]);
if(!$oMenu){
return $this->EventNotFound();
}
if (!($oItem = $this->Menu_GetItemById($this->GetParam(2)))) {
return $this->EventNotFound();
}

/**
* Удаляем
*/
if ($oItem->Delete()) {
$this->Message_AddNotice('Удаление прошло успешно', null, true);
} else {
$this->Message_AddError('Возникла ошибка при удалении', null, true);
}

Router::LocationAction("admin/menu/{$oMenu->getName()}");
}
}
45 changes: 45 additions & 0 deletions classes/hooks/HookMenu.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* LiveStreet CMS
* Copyright © 2018 OOO "ЛС-СОФТ"
*
* ------------------------------------------------------
*
* Official site: www.livestreetcms.com
* Contact e-mail: [email protected]
*
* 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 Oleg Demodov <[email protected]>
*
*/

/**
* Description of HookMenu
*
* @author oleg
*/
class PluginAdmin_HookMenu extends Hook {

public function RegisterHook() {
$this->AddHook('init_admin_menu', 'InitActionAdmin');
}

public function InitActionAdmin() {

$aMenus = $this->Menu_GetMenuItemsAll();
$oSection = Engine::GetEntity('PluginAdmin_Ui_MenuSection')->SetCaption('Меню')->SetName('menu')->SetUrl('menu')->setIcon('bars');
foreach ($aMenus as $oMenu) {
$oSection->AddItem(Engine::GetEntity('PluginAdmin_Ui_MenuItem')->SetCaption(htmlspecialchars($oMenu->getTitle()))->SetUrl($oMenu->getName()));
}

$oMenu = $this->PluginAdmin_Ui_GetMenuMain();
$oMenu->AddSection($oSection);
}
}
8 changes: 8 additions & 0 deletions frontend/components/p-menus/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "p-menus",
"version": "1.0.0",
"templates": {
"form": "form.tpl",
"list": "list.tpl"
}
}
45 changes: 45 additions & 0 deletions frontend/components/p-menus/form.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{**
* Форма добавления/редактирования категории
*}

{$component = 'p-cron-form'}
{component_define_params params=[ 'menuItems' ]}

<form method="post">
{component 'admin:field' template='hidden.security-key'}

{$items = [[
'value' => '',
'text' => ''
]]}

{foreach $menuItems as $menuItem}
{$items[] = [
'text' => ''|str_pad:(2 * $menuItem.level):'-'|cat:{lang name=$menuItem['entity']->getTitle()},
'value' => $menuItem['entity']->getId()
]}
{/foreach}

{component 'admin:field' template='select' name='item[pid]' label='Вложить в' items=$items}

{* Код *}
{component 'admin:field' template='text' name='item[name]' label='Код'}

{* Название *}
{component 'admin:field' template='text' name='item[title]' label='Название'}

{* URL *}
{component 'admin:field' template='text' name='item[url]' label='Url'}

{* Сортировка *}
{component 'admin:field' template='text' name='item[priority]' label='Приоритет'}

{* Статус *}
{component 'admin:field' template='checkbox' name='item[enable]' label='Включен'}

{* Активный *}
{component 'admin:field' template='checkbox' name='item[active]' label='Активный'}

{* Кнопки *}
{component 'admin:button' name='item_submit' text="{($_aRequest) ? $aLang.plugin.admin.save : $aLang.plugin.admin.add}" value=1 mods='primary'}
</form>
49 changes: 49 additions & 0 deletions frontend/components/p-menus/list.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{**
* Список категорий
*}

{$component = 'p-menu-list'}
{component_define_params params=[ 'items' ]}

{if $items}
<table class="ls-table">
<thead>
<tr>
<th>Название</th>
<th>URL</th>
<th>Элементов</th>
<th>Включен</th>
<th>Активный</th>
<th class="ls-table-cell-actions">Действие</th>
</tr>
</thead>
<tbody>
{foreach $items as $itemWrapper}
{$item = $itemWrapper['entity']}
{$level = $itemWrapper['level']}

<tr data-id="{$item->getId()}">
<td>
<i class="fa fa-file" style="margin-left: {$level * 20}px;"></i>

{if $item->getUrl()}
<a href="{$item->getUrl()}" border="0">{lang name=$item->getTitle()} ({$item->getTitle()})</a>
{else}
{lang name=$item->getTitle()} ({$item->getTitle()})
{/if}
</td>
<td>{$item->getUrl()}</td>
<td>{$item->getCountTargetOfDescendants()}</td>
<td>{$item->getEnable()}</td>
<td>{$item->getActive()}</td>
<td class="ls-table-cell-actions">
<a href="{router page="admin/menu/{$oMenu->getName()}/update/{$item->getId()}"}" class="fa fa-edit" title="{$aLang.plugin.admin.edit}"></a>
<a href="{router page="admin/menu/{$oMenu->getName()}/remove/{$item->getId()}"}?security_ls_key={$LIVESTREET_SECURITY_KEY}" class="fa fa-trash-o js-confirm-remove" title="{$aLang.plugin.admin.delete}"></a>
</td>
</tr>
{/foreach}
</tbody>
</table>
{else}
{component 'admin:blankslate' text='Нет пунктов. Вы можете добавить.'}
{/if}
22 changes: 22 additions & 0 deletions frontend/skin/default/actions/ActionAdmin/menu/create.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{**
* Добавление категории
*
*}

{extends "{$aTemplatePathPlugin.admin}layouts/layout.base.tpl"}

{block 'layout_options' append}
{$layoutBackUrl = {router page="admin/menu/{$oMenu->getName()}"}}
{/block}

{block 'layout_page_title'}
{if $_aRequest}
Редактирование пункта для меню &laquo;{$oMenu->getTitle()|escape}&raquo;
{else}
Добавление пункта для меню &laquo;{$oMenu->getTitle()|escape}&raquo;
{/if}
{/block}

{block 'layout_content'}
{component 'admin:p-menus' template='form' menuItems=$aItems}
{/block}
Loading

0 comments on commit ee7814b

Please sign in to comment.