Exemplo n.º 1
0
 /**
  * Returns menu id of given page id
  * @param $pageId
  * @return bool|integer
  */
 public static function getMenuItemIdFromPageId($pageId)
 {
     $menuId = MenuItemRecord::find()->select('menu_item.id')->joinWith(['menu.web', 'menuItemContent'])->where(['menu_item.content_type' => MenuItemRecord::CONTENT_PAGE, 'web.weburl' => \Yii::$app->request->get('web', \Yii::$app->params['defaultWeb']), 'menu_item_content.content_id' => $pageId])->scalar();
     return $menuId;
 }
Exemplo n.º 2
0
 /**
  * Gets parent items tree for dropdown
  * @param integer $pid
  * @param integer $i
  *
  * @return array
  */
 public function getParentItems($pid = null, $i = 0)
 {
     $listItems = [];
     $query = MenuItemRecord::find()->where('main = 0 AND menu_id = :mid AND language_id = :lid', [':mid' => $this->menu_id, ':lid' => $this->language_id]);
     if ($pid === null) {
         $query->andWhere('ISNULL(parent_id)');
     } else {
         $query->andWhere('parent_id = :pid', [':pid' => $pid]);
     }
     if ($this->scenario == 'update') {
         $query->andWhere('id != :id', [':id' => $this->item_id]);
     }
     $items = $query->all();
     foreach ($items as $item) {
         /** @var $item \common\models\MenuItemRecord */
         $listItems[$item->id] = str_repeat('=', $i) . ($i > 0 ? ' ' : '') . $item->title;
         if ($item->hasItems()) {
             $listItems = ArrayHelper::merge($listItems, $this->getParentItems($item->id, ++$i));
             --$i;
         }
     }
     return $listItems;
 }