Exemple #1
0
 public function generatemenucontrol()
 {
     $menu = Menu::find(Input::get("idmenu"));
     $menu->name = Input::get("menuname");
     $menu->save();
     foreach (Input::get("arraydata") as $value) {
         $menuitem = MenuItem::find($value["id"]);
         $menuitem->parent = $value["parent"];
         $menuitem->sort = $value["sort"];
         $menuitem->depth = $value["depth"];
         $menuitem->save();
     }
     echo json_encode(array("resp" => 1));
 }
 /**
  * Создает новую модель пунта меню.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new MenuItem();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $model->menu_id = Yii::app()->getRequest()->getQuery('mid', null);
     if (($data = Yii::app()->getRequest()->getPost('MenuItem')) !== null) {
         $model->setAttributes($data);
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('MenuModule.menu', 'New item was added to menu!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
         }
     }
     $criteria = new CDbCriteria();
     $criteria->select = new CDbExpression('MAX(sort) as sort');
     $max = $model->find($criteria);
     $model->sort = $max->sort + 1;
     // Set sort in Adding Form as ma x+ 1
     $this->render('create', array('model' => $model));
 }
Exemple #3
0
 public function deleteItemInfo($slug)
 {
     $results = \MenuItem::where('menu_item_slug', '=', $slug)->get();
     foreach ($results as $result) {
         $id = $result->menu_item_id;
     }
     if (\Auth::check()) {
         \DB::beginTransaction();
         try {
             $statement = \MenuItem::find($id);
             $statement->delete();
         } catch (ValidationException $e) {
             DB::rollback();
             throw $e;
         }
         \DB::commit();
         return \Redirect::to('admin')->withMessage('<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Item has been deleted</div>');
     }
     return \Redirect::to('admin');
 }
 /**
  * Update the specified resource in storage.
  * PUT /menus/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // dd(Input::all());
     // 1. Reset all visibilities
     $menu = Menu::findOrFail($id);
     $menuitems_original = $menu->items;
     foreach ($menuitems_original as $item) {
         $item->visible = '0';
         $item->save();
     }
     // 2. Save the new visibility state from user inputs
     if (Input::get('menu')) {
         $menuitems = Input::get('menu');
         foreach ($menuitems as $item) {
             $menuitem_object = MenuItem::find($item);
             $menuitem_object->visible = '1';
             $menuitem_object->save();
         }
     }
     return Redirect::route('admin.menus.index')->with("message", "Data berhasil disimpan");
 }
 public function menudeletepost()
 {
     $menumodel = new MenuItem();
     $sons = $menumodel->getsons(Input::get("id"));
     if (count($sons) == 0) {
         $menub = MenuItem::find(Input::get("id"));
         $menub->delete();
         echo json_encode(array("resp" => "This item has been deleted successfully", "error" => 2));
     } else {
         echo json_encode(array("resp" => "This menu item has children, delete them first.", "error" => 1));
     }
 }
Exemple #6
0
 public function updateMenuItem($slug)
 {
     $validate = new Validate();
     $validator = $validate->Validate();
     if (\Auth::check()) {
         $check = new CheckEditedItem();
         $slugcheck = $check->checkSlugMatch($slug);
         $namecheck = $check->checkNameMatch($slug);
         $idcheck = $check->checkIdMatch($slug);
         $results = \MenuItem::where('menu_item_slug', '=', $slug)->get(array('menu_item_description', 'menu_item_picture_uri', 'menu_item_name', 'menu_item_slug', 'menu_item_id', 'menu_item_short', 'menu_item_category_fk', 'menu_item_price'));
         foreach ($results as $result) {
             $menu_item_description = $result->menu_item_description;
             $menu_item_name = $result->menu_item_name;
             $menu_item_picture_uri = $result->menu_item_picture_uri;
             $slug = $result->menu_item_slug;
             $id = $result->menu_item_id;
             $menu_item_short = $result->menu_item_short;
             $menu_item_category_fk = $result->menu_item_category_fk;
             $menu_item_price = $result->menu_item_price;
         }
         if ($validator->fails()) {
             return \Redirect::back()->withErrors($validator);
         }
         if ($idcheck === true) {
             \DB::beginTransaction();
             try {
                 $slug = strtolower($slug);
                 $statement = \MenuItem::find($id);
                 $statement->menu_item_description = \Input::get('description');
                 if (\Input::hasFile('Upload')) {
                     $name = \Input::file('Upload')->getClientOriginalName();
                     \Input::file('Upload')->move('uploads', $name);
                     $statement->menu_item_picture_uri = '/uploads/' . $name;
                 }
                 $statement->menu_item_short = \Input::get('desc');
                 $statement->menu_item_price = \Input::get('price');
                 $statement->menu_item_category_fk = \Input::get('category');
                 $statement->save();
             } catch (ValidationException $e) {
                 DB::rollback();
                 throw $e;
             }
             \DB::commit();
             return \Redirect::to('admin/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved at: ' . link_to('/menu/' . $slug) . '</p></div>');
         }
         if ($slugcheck === false || $namecheck === false) {
             $slug = \Input::get('name');
             $slug = preg_replace('#[ -]+#', '-', $slug);
             $slug = strtolower($slug);
             $results = \MenuItem::where('menu_item_slug', '=', $slug)->get(array('menu_item_id'));
             foreach ($results as $result) {
                 $check_id = $result->menu_item_id;
             }
             if (isset($check_id)) {
                 return \Redirect::back()->withErrors($validator)->withInput(array('name', 'description', 'category', 'desc', 'price'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">An item with the same name already exists');
             }
             \DB::beginTransaction();
             try {
                 $statement = \MenuItem::find($id);
                 $statement->menu_item_name = \Input::get('name');
                 $statement->menu_item_description = \Input::get('description');
                 if (\Input::hasFile('Upload')) {
                     $name = \Input::file('Upload')->getClientOriginalName();
                     \Input::file('Upload')->move('uploads', $name);
                     $statement->menu_item_picture_uri = '/uploads/' . $name;
                 }
                 $statement->menu_item_slug = $slug;
                 $statement->menu_item_price = \Input::get('price');
                 $statement->menu_item_short = \Input::get('desc');
                 $statement->menu_item_category_fk = \Input::get('category');
                 $statement->save();
             } catch (ValidationException $e) {
                 DB::rollback();
                 throw $e;
             }
             \DB::commit();
             return \Redirect::to('admin/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved at: ' . link_to('/menu/' . $slug) . '</p></div>');
         }
         return \Redirect::to('admin/edit/' . $slug)->withErrors($validator)->withInput(array('name', 'description', 'category', 'desc', 'price'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">An item with the same name already exists');
     }
 }
Exemple #7
0
 protected function assertOtherScopeNotAffected()
 {
     $node = MenuItem::find(3);
     $this->assertEquals(1, $node->getLft());
 }
<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
include 'includes/layout.php';
require 'models/menu-item.class.php';
$menuItem = new MenuItem();
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $item = $menuItem->find($id);
}
?>

<?php 
if (!empty($item)) {
    ?>
  <section id="menuItemForm" class="col-sm-10">
    <form id="addForm">
      <div class="form-group">
        <input class="form-control" id="nameField" value="<?php 
    echo $item->name;
    ?>
" placeholder="Name">
      </div>
      <div class="form-group">
        <div class="input-group">
          <div class="input-group-addon">$</div>
          <input type="number" min="0" step="0.01" data-number-to-fixed="2" data-number-stepfactor="100" class="form-control currency" id="priceField" placeholder="Price" value="<?php 
    echo $item->price;
    ?>
">
 /**
  * Show the form for editing the specified resource.
  * GET /menuitems/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $menus = Menu::lists('name', 'id');
     $menuitem = MenuItem::find($id);
     $menuitems = MenuItem::parent()->get()->lists('name', 'id');
     $menuitems[0] = '---- Top Level -----';
     ksort($menuitems);
     unset($menuitems[$id]);
     return View::make('menu_items.edit', compact('menus', 'menuitem', 'menuitems'));
 }