Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
olezhikz
committed
Oct 31, 2018
1 parent
ac88f2d
commit 59097f6
Showing
8 changed files
with
504 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* LiveStreet CMS | ||
* Copyright © 2018 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 Oleg Demodov <boxmilo@gmail.com> | ||
* | ||
*/ | ||
|
||
/** | ||
* Description of Menu | ||
* | ||
* @author oleg | ||
*/ | ||
class ModuleMenu extends ModuleORM { | ||
|
||
const STATE_ITEM_ENABLE = 1; | ||
const STATE_ITEM_DISABLE = 0; | ||
const STATE_ITEM_ACTIVE = 2; | ||
|
||
private $aMenus = []; | ||
|
||
public function Init() { | ||
parent::Init(); | ||
} | ||
|
||
/** | ||
* Возвращает дерево пунктов | ||
* | ||
* @param int $sId MenuId | ||
* | ||
* @return array | ||
*/ | ||
public function GetItemsTreeByMenuId($sId) | ||
{ | ||
$aItems = $this->LoadTreeOfItem(array('menu_id' => $sId)); | ||
return ModuleORM::buildTree($aItems); | ||
} | ||
|
||
public function Get($sName) { | ||
if( !isset($this->aMenus[$sName]) ){ | ||
$this->aMenus[$sName] = $this->GetMenuByName($sName); | ||
} | ||
|
||
return $this->aMenus[$sName]; | ||
} | ||
|
||
public function GetMenuByName($sName) { | ||
if(!$oMenu = $this->GetMenuByFilter(['name' => $sName])){ | ||
return null; | ||
} | ||
$aItemsTree = $this->LoadTreeOfItem([ | ||
'menu_id' => $oMenu->getId(), | ||
'#order' => ['priority' => 'asc'], | ||
'#where' => ["t.state > ?d" => [0]] | ||
]); | ||
|
||
foreach ($aItemsTree as $oItem) { | ||
$oItem->setParent($oMenu); | ||
} | ||
|
||
$oMenu->setChildren($aItemsTree); | ||
return $oMenu; | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
application/classes/modules/menu/entity/AbstractItem.entity.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
|
||
/* | ||
* LiveStreet CMS | ||
* Copyright © 2018 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 Oleg Demodov <boxmilo@gmail.com> | ||
* | ||
*/ | ||
|
||
/** | ||
* Description of Item | ||
* | ||
* @author oleg | ||
*/ | ||
class ModuleMenu_EntityAbstractItem extends EntityORM{ | ||
|
||
|
||
public function find($sName) { | ||
return $this->recursiveSearch($sName, $this->getChildren()); | ||
} | ||
|
||
public function recursiveSearch($sName, $aItems) { | ||
if(!is_array($aItems)){ | ||
return null; | ||
} | ||
foreach ($aItems as $oItem) { | ||
if($oItem->getName() == $sName){ | ||
return $oItem; | ||
} | ||
if($mResult = $this->recursiveSearch($sName, $oItem->getChildren())){ | ||
return $mResult; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private function findIndex($aItems, $sName){ | ||
if(!is_array($aItems)){ | ||
return false; | ||
} | ||
|
||
foreach ($aItems as $key => $oItem) { | ||
if($oItem->getName() == $sName){ | ||
return $key; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public function after($oItem) { | ||
if(!is_array($oItem)){ | ||
$oItem = [$oItem]; | ||
} | ||
|
||
if(get_class($this) == "ModuleMenu_EntityMenu"){ | ||
return $this; | ||
} | ||
|
||
if(!$oParent = $this->getParent()){ | ||
return $this; | ||
} | ||
|
||
$oParent->spliceChild($this->getName(), 1, $oItem); | ||
|
||
return $this; | ||
} | ||
|
||
public function before($oItem) { | ||
if(get_class($this) == "ModuleMenu_EntityMenu"){ | ||
return $this; | ||
} | ||
|
||
if(!is_array($oItem)){ | ||
$oItem = [$oItem]; | ||
} | ||
|
||
if(!$oParent = $this->getParent()){ | ||
return $this; | ||
} | ||
|
||
$oParent->spliceChild($this->getName(), 0, $oItem); | ||
|
||
return $this; | ||
} | ||
|
||
public function remove() { | ||
if(get_class($this) == "ModuleMenu_EntityMenu"){ | ||
return $this; | ||
} | ||
|
||
if(!$oParent = $this->getParent()){ | ||
return $this; | ||
} | ||
|
||
$oParent->spliceChild($this->getName(), 0, [], 1); | ||
} | ||
|
||
public function spliceChild($sName, $iOffset, $aItems, $iRemove=0){ | ||
|
||
$aChildrens = $this->getChildren(); | ||
|
||
if(!is_array($aChildrens)){ | ||
return $this; | ||
} | ||
|
||
if(($iKey = $this->findIndex($aChildrens, $sName)) === false){ | ||
return $this; | ||
} | ||
|
||
array_splice($aChildrens, $iKey?($iKey+$iOffset):$iKey, $iRemove, $aItems); | ||
|
||
$this->setChildren($aChildrens); | ||
|
||
return $this; | ||
} | ||
|
||
|
||
public function appendChild($oItem) { | ||
$aItems = $this->getChildren(); | ||
|
||
if(!is_array($aItems)){ | ||
$aItems= []; | ||
} | ||
|
||
$aItems[] = $oItem; | ||
$this->setChildren($aItems); | ||
return $this; | ||
} | ||
|
||
public function prependChild($oItem) { | ||
$aItems = $this->getChildren(); | ||
|
||
if(!is_array($aItems)){ | ||
$aItems= []; | ||
} | ||
|
||
array_unshift($aItems, $oItem); | ||
$this->setChildren($aItems); | ||
return $this; | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
application/classes/modules/menu/entity/Item.entity.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
/* | ||
* LiveStreet CMS | ||
* Copyright © 2018 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 Oleg Demodov <boxmilo@gmail.com> | ||
* | ||
*/ | ||
|
||
/** | ||
* Description of Item | ||
* | ||
* @author oleg | ||
*/ | ||
class ModuleMenu_EntityItem extends ModuleMenu_EntityAbstractItem{ | ||
|
||
protected $aRelations = [ | ||
'menu' => [self::RELATION_TYPE_BELONGS_TO, "ModuleMenu_EntityMenu", 'menu_id'], | ||
self::RELATION_TYPE_TREE | ||
]; | ||
|
||
/** | ||
* Определяем правила валидации | ||
* | ||
* @var array | ||
*/ | ||
public $aValidateRules = array( | ||
array('title', 'string', 'max' => 250, 'min' => 1, 'allowEmpty' => false), | ||
array('name', 'string', 'max' => 30, 'min' => 1, 'allowEmpty' => true), | ||
array('url', 'string', 'max' => 1000, 'min' => 1, 'allowEmpty' => false), | ||
array('enable', 'number'), | ||
array('active', 'number'), | ||
array('pid', 'parent_item'), | ||
array('priority', 'number'), | ||
array('menu_id', 'menu_id'), | ||
); | ||
|
||
public function _getTreeParentKey() | ||
{ | ||
return 'pid'; | ||
} | ||
|
||
public function beforeSave() | ||
{ | ||
if(!parent::beforeSave()){ | ||
return false; | ||
} print_r($this->_getData()); | ||
|
||
if(!$this->_getDataOne('enable')){ | ||
$this->setState(ModuleMenu::STATE_ITEM_DISABLE); | ||
return true; | ||
} | ||
$this->setState(ModuleMenu::STATE_ITEM_ENABLE); | ||
|
||
if($this->_getDataOne('active')){ | ||
$this->setState(ModuleMenu::STATE_ITEM_ACTIVE); | ||
} | ||
return true; | ||
} | ||
|
||
public function afterDelete() { | ||
parent::afterDelete(); | ||
|
||
$aChildrenItems = $this->getChildren(); | ||
foreach ($aChildrenItems as $oItem) { | ||
$oItem->setState(ModuleMenu::STATE_ITEM_DISABLE); | ||
$oItem->setPid(null); | ||
$oItem->Save(); | ||
} | ||
} | ||
|
||
public function ValidateParentItem($sValue, $aParams) | ||
{ | ||
if(!$sValue){ | ||
return true; | ||
} | ||
if (!$oItem = $this->Menu_GetItemById($this->getPid())) { | ||
return $this->Lang_Get('menu.message.no_find_parent_item'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
public function ValidateMenuId($sValue, $aParams) | ||
{ | ||
|
||
if (!$oMenu = $this->Menu_GetMenuById($this->getMenuId())) { | ||
return $this->Lang_Get('menu.message.no_find_menu'); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function getEnable() { | ||
if($this->getState()){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
public function getActive() { | ||
if($this->getState() == ModuleMenu::STATE_ITEM_ACTIVE){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
application/classes/modules/menu/entity/Menu.entity.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* LiveStreet CMS | ||
* Copyright © 2018 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 Oleg Demodov <boxmilo@gmail.com> | ||
* | ||
*/ | ||
|
||
/** | ||
* Description of Menu | ||
* | ||
* @author oleg | ||
*/ | ||
class ModuleMenu_EntityMenu extends ModuleMenu_EntityAbstractItem { | ||
|
||
public function getItems() { | ||
return $this->getChildren(); | ||
} | ||
|
||
} |
Oops, something went wrong.