Skip to content

Commit cb3566f

Browse files
committed
use db expresionn
1 parent dd73fd2 commit cb3566f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/Menu.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use luya\cms\menu\Item;
1313
use luya\cms\menu\InjectItemInterface;
1414
use luya\cms\menu\QueryOperatorFieldInterface;
15+
use yii\db\Expression;
1516

1617
/**
1718
* Menu container component by language.
@@ -565,16 +566,17 @@ public function getModulesMap()
565566
*/
566567
private function getNavData($langId)
567568
{
568-
return (new DbQuery())->from(['cms_nav_item item'])
569-
->select(['item.id', 'item.nav_id', 'item.title', 'item.description', 'item.keywords', 'item.alias', 'item.title_tag', 'item.timestamp_create', 'item.timestamp_update', 'item.create_user_id', 'item.update_user_id', 'nav.is_home', 'nav.parent_nav_id', 'nav.sort_index', 'nav.is_hidden', 'item.nav_item_type', 'item.nav_item_type_id', 'nav_container.alias AS container'])
570-
->leftJoin('cms_nav nav', 'nav.id=item.nav_id')
571-
->leftJoin('cms_nav_container nav_container', 'nav_container.id=nav.nav_container_id')
572-
->where(['nav.is_deleted' => false, 'item.lang_id' => $langId, 'nav.is_offline' => false, 'nav.is_draft' => false])
573-
->andWhere(['or', ['publish_from' => null], ['<=', 'publish_from', time()]])
574-
->andWhere(['or', ['publish_till' => null], ['>=', 'publish_till', time()]])
575-
->orderBy(['container' => 'ASC', 'parent_nav_id' => 'ASC', 'nav.sort_index' => 'ASC'])
576-
->indexBy('id')
577-
->all();
569+
return (new DbQuery())
570+
->from(['cms_nav_item item'])
571+
->select(['item.id', 'item.nav_id', 'item.title', 'item.description', 'item.keywords', 'item.alias', 'item.title_tag', 'item.timestamp_create', 'item.timestamp_update', 'item.create_user_id', 'item.update_user_id', 'nav.is_home', 'nav.parent_nav_id', 'nav.sort_index', 'nav.is_hidden', 'item.nav_item_type', 'item.nav_item_type_id', 'nav_container.alias AS container'])
572+
->leftJoin('cms_nav nav', 'nav.id=item.nav_id')
573+
->leftJoin('cms_nav_container nav_container', 'nav_container.id=nav.nav_container_id')
574+
->where(['nav.is_deleted' => false, 'item.lang_id' => $langId, 'nav.is_offline' => false, 'nav.is_draft' => false])
575+
->andWhere(['or', ['publish_from' => null], ['<=', 'publish_from', new Expression('UNIX_TIMESTAMP()')]])
576+
->andWhere(['or', ['publish_till' => null], ['>=', 'publish_till', new Expression('UNIX_TIMESTAMP()')]])
577+
->orderBy(['container' => 'ASC', 'parent_nav_id' => 'ASC', 'nav.sort_index' => 'ASC'])
578+
->indexBy('id')
579+
->all();
578580
}
579581

580582
private $_paths = [];
@@ -597,19 +599,19 @@ private function buildIndexForContainer($data)
597599
}
598600

599601
foreach ($this->_nodes as $node) {
600-
$this->_paths[$node['nav_id']] = $this->processParant($node['nav_id'], null);
602+
$this->_paths[$node['nav_id']] = $this->processParent($node['nav_id'], null);
601603
}
602604

603605
return $this->_paths;
604606
}
605607

606-
private function processParant($nodeId, $path)
608+
private function processParent($nodeId, $path)
607609
{
608610
$parentId = $this->_nodes[$nodeId]['parent_nav_id'];
609611
$alias = $this->_nodes[$nodeId]['alias'];
610612

611613
if ($parentId > 0 && array_key_exists($parentId, $this->_nodes)) {
612-
return $this->processParant($parentId, $path) . '/' . $alias;
614+
return $this->processParent($parentId, $path) . '/' . $alias;
613615
}
614616

615617
return $alias;

0 commit comments

Comments
 (0)