Example #1
0
 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $session->set('web_id', $request->post('web_id'));
         $id = MenuRecord::getMainMenuId();
         $session->set('menu_id', $id);
     } else {
         if ($request->post('menu_id')) {
             $id = $request->post('menu_id');
             $session->set('menu_id', $id);
         } elseif ($session->get('menu_id')) {
             $menu = MenuRecord::findOne($session->get('menu_id'));
             if ($menu) {
                 $id = $session->get('menu_id');
             } else {
                 $id = MenuRecord::getMainMenuId();
                 $session->set('menu_id', $id);
             }
         } else {
             $id = MenuRecord::getMainMenuId();
             $session->set('menu_id', $id);
         }
     }
     $session->close();
     /* @var $controller \backend\controllers\MenuItemController */
     $controller = $this->owner;
     $controller->setMenu($id);
     return parent::beforeAction($action);
 }
Example #2
0
 public function search($web_id)
 {
     /** @var ActiveQuery $query */
     $query = MenuRecord::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]);
     $query->andWhere(['web_id' => $web_id]);
     $query->orderBy(['main' => SORT_DESC]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Returns main menu item id for given web and language
  * @param $webId
  * @param $languageId
  * @return bool|string
  */
 public static function getMainMenuItemId($webId, $languageId)
 {
     $mainMenuId = MenuRecord::find()->select('id')->where(['web_id' => $webId, 'main' => 1])->scalar();
     if ($mainMenuId) {
         $mainMenuItemId = MenuItemRecord::find()->select('id')->where(['menu_id' => $mainMenuId, 'language_id' => $languageId, 'main' => 1])->scalar();
         if ($mainMenuItemId) {
             return $mainMenuItemId;
         }
     }
     return false;
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMenu()
 {
     return $this->hasOne(MenuRecord::className(), ['id' => 'menu_id']);
 }
Example #5
0
 /**
  * Finds the Menu model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MenuRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MenuRecord::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('back', 'The requested page does not exist.'));
 }
Example #6
0
 /**
  * Initializes boxes property
  * @param bool $insert
  */
 public function initBoxes($insert = true)
 {
     if ($insert) {
         if (MenuRecord::existsMoreMenuRecords() === false) {
             $this->boxes[] = self::PROPERTY_MAIN;
         }
         $this->boxes[] = self::PROPERTY_ACTIVE;
         $this->boxes[] = self::PROPERTY_PUBLIC;
     } else {
         if ($this->main) {
             $this->boxes[] = self::PROPERTY_MAIN;
         }
         if ($this->active) {
             $this->boxes[] = self::PROPERTY_ACTIVE;
         }
         if ($this->public) {
             $this->boxes[] = self::PROPERTY_PUBLIC;
         }
     }
 }
Example #7
0
 /**
  * Checks if menu is mainmenu
  *
  * @param $menu_id
  *
  * @return bool
  */
 private static function isMainMenu($menu_id)
 {
     $menuMain = MenuRecord::find()->select('main')->where(['id' => $menu_id])->scalar();
     return $menuMain ? true : false;
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMenus()
 {
     return $this->hasMany(MenuRecord::className(), ['web_id' => 'id']);
 }
Example #9
0
echo Html::dropDownList('web_id', $web_id, WebRecord::getWebOptions(), ['onchange' => 'this.form.submit()', 'class' => 'form-control']);
?>
		    </div>
		    <?php 
echo Html::endForm();
?>

		    <?php 
echo Html::beginForm(['menu-item/index']);
?>
		    <div class="form-group col-md-6">
			    <?php 
echo Html::label(Yii::t('back', 'Menu'), 'menu_id');
?>
			    <?php 
echo Html::dropDownList('menu_id', $menu_id, MenuRecord::getMenuOptions(), ['onchange' => 'this.form.submit()', 'class' => 'form-control']);
?>
		    </div>
		    <?php 
echo Html::endForm();
?>
	    </div>

		<?php 
if ($model->parent_id) {
    ?>
			<div class="panel panel-default parent-menu-tree">
				<div class="panel-heading"><?php 
    echo Yii::t('back', 'Parent levels');
    ?>
</div>
Example #10
0
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'text_id')->textInput(['maxlength' => 255]);
?>

    <?php 
echo $form->field($model, 'web_id')->dropDownList($model->getWebOptions());
?>

	<?php 
echo $form->field($model, 'boxes')->inline()->checkboxList([MenuRecord::PROPERTY_MAIN => Yii::t('back', 'Main'), MenuRecord::PROPERTY_ACTIVE => Yii::t('back', 'Active'), MenuRecord::PROPERTY_PUBLIC => Yii::t('back', 'Public')], ['id' => 'modal-boxes', 'data-main' => (MenuRecord::existsMoreMenuRecords($model->isNewRecord ? true : false) && !$model->main) == true ? 0 : 1]);
?>


	<div class="form-group modal-footer">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('back', 'Create') : Yii::t('back', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
	    <button type="button" class="btn btn-default" data-dismiss="modal"><?php 
echo Yii::t('back', 'Close');
?>
</button>
    </div>

    <?php 
ActiveForm::end();
Example #11
0
 /**
  * @return MenuRecord object
  */
 public function getMenu()
 {
     return MenuRecord::findOne($this->menu_id);
 }
Example #12
0
 /**
  * Gets menu options for dropdown
  * @param $wid integer ID of web
  * @return string
  */
 public function actionMenuListOptions($wid)
 {
     $items = MenuRecord::find()->where(['web_id' => $wid])->activeStatus()->orderBy('title')->all();
     $itemsOptions = ['arr' => false, 'prompt' => "-- " . Yii::t('back', 'Not selected') . " --"];
     return $this->renderPartial('_listOptions', compact('items', 'itemsOptions'));
 }