/**
  * @return \Illuminate\View\View
  */
 public function index()
 {
     // Log action by user.
     Audit::log(Auth::user()->id, trans('admin/menu-builder/menu-builder.audit-log.category'), trans('admin/menu-builder/menu-builder.audit-log.msg-index'));
     // Set page title and description.
     $page_title = trans('admin/menu-builder/menu-builder.page.index.title');
     $page_description = trans('admin/menu-builder/menu-builder.page.index.description');
     // Load all menus ordered by Parent (asc), Position (asc), Label (asc) and finally ID (asc).
     $menus = Menu::orderBy('parent_id', 'ASC')->orderBy('position', 'ASC')->orderBy('label', 'ASC')->orderBy('id', 'ASC')->get();
     // Convert menu query result to JSON for JSTree
     $menusJson = $this->menusOrmToJsTreeJson($menus);
     // List label and id of all menus ordered by Label (asc).
     $parents = Menu::where('separator', '0')->orderBy('label', 'ASC')->orderBy('id', 'ASC')->get()->lists('label', 'id');
     // Convert to array.
     $parents = $parents->toArray();
     // List name and id of all routes ordered by Name (asc).
     $routes = Route::whereNotNull('name')->orderBy('name', 'ASC')->get()->lists('name', 'id');
     // Convert to array.
     $routes = $routes->toArray();
     // Add a blank option at the top.
     $routes = array('blank' => '') + $routes;
     // List display name and id of all permissions ordered by Name (asc).
     $permissions = Permission::orderBy('name', 'ASC')->get()->lists('display_name', 'id');
     // Convert to array.
     $permissions = $permissions->toArray();
     // Add a blank option at the top.
     $permissions = array('blank' => '') + $permissions;
     // Return view
     return view('admin.menus.index', compact('menus', 'menusJson', 'parents', 'routes', 'permissions', 'page_title', 'page_description'));
 }
Example #2
0
 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function __construct(LaravelFacebookSdk $fb, Menu $menu, ProjectRepository $project_repo)
 {
     $this->middleware('auth');
     $this->menuItems = $menu->where('active', '1')->orderBy('weight', 'asc')->get();
     $this->login_url = $fb->getLoginUrl(['email']);
     $this->project_repo = $project_repo;
 }
Example #3
0
 /**
  * Create a new authentication controller instance.
  *
  * @param  \Illuminate\Contracts\Auth\Guard  $auth
  * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
  * @return void
  */
 public function __construct(Guard $auth, Registrar $registrar, Menu $menu)
 {
     $this->auth = $auth;
     $this->registrar = $registrar;
     $this->menuItems = $menu->where('active', '1')->orderBy('weight', 'asc')->get();
     $this->middleware('guest', ['except' => 'getLogout']);
 }
Example #4
0
 public function content($slug)
 {
     $menu_item = Menu::where('url', $slug);
     if ($menu_item->count()) {
         return view('home.content', ['menu_item' => $menu_item->first()]);
     }
     return view('errors.404');
 }
Example #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $eventId)
 {
     $menu = Menu::where('event_id', '=', $eventId)->get()->first();
     if (!$menu) {
         return $this->respondNotFound('Menu does not exist');
     }
     $menu_name = $menu->menu_name;
     $menu->delete();
     return $this->respondDeleteSuccess($menu_name . ' deleted');
 }
Example #6
0
 public function generateMenu()
 {
     $menu = Menu::where('pid', '=', 0)->orderBy('id', 'asc')->get();
     foreach ($menu as $k => $item) {
         $menu[$k]['sub'] = Menu::where('pid', '=', $item->id)->orderBy('id', 'asc')->get();
         if (count($menu[$k]['sub']) < 1) {
             unset($menu[$k]['sub']);
         }
     }
     return $menu;
 }
Example #7
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     //if(!parent::authorize()) return false;
     if ($this->menu) {
         if ($this->user()->isAdmin()) {
             return true;
         }
         return Menu::where('id', $this->menu)->where('user_id', $this->user()->id)->exists();
     }
     return true;
 }
Example #8
0
 /**
  * A basic test example.
  *
  * @return void
  */
 public function testExample()
 {
     //$this->assertTrue(true);
     //Unauthorized access
     $this->visit('/admin')->seePageIs('login');
     //Logging as Admin
     $admin = User::where('is_admin', '1')->first();
     $this->actingAs($admin)->visit('/admin')->seePageIs('admin');
     $this->actingAs($admin)->visit('/admin/pages/main')->see('Главная страница');
     $this->actingAs($admin)->visit('/admin/pages/main/edit')->see('Редактирование главной страницы');
     $this->actingAs($admin)->visit('/admin/pages/static')->see('Статические страницы');
     try {
         //Opening static page editor
         $static_page = Page::where('id', '>', 1)->firstOrFail();
     } catch (ModelNotFoundException $e) {
     } finally {
         $this->actingAs($admin)->visit('/admin/pages/static/' . $static_page->id . '/edit')->see('Редактирование страницы');
         unset($static_page);
     }
     $this->actingAs($admin)->visit('/admin/pages/static')->click('Создать')->see('Создание страницы');
     $this->actingAs($admin)->visit('/admin/menu')->see('Редактор меню');
     //Create new menu item
     $this->actingAs($admin)->visit('/admin/menu')->click('Создать')->see('Новый пункт меню')->select(0, 'pid')->type('Тест', 'name')->type('test357', 'url')->press('Создать')->seePageIs('/admin/menu');
     try {
         //Delete created item
         $menu = Menu::where('url', 'test357')->firstOrFail();
     } catch (ModelNotFoundException $e) {
     } finally {
         $this->actingAs($admin)->delete('/admin/menu/' . $menu->id);
         $this->assertResponseStatus(302);
         $this->assertRedirectedToRoute('admin.menu');
         $this->followRedirects()->see('Редактор меню');
         unset($menu);
     }
     //File manager
     $this->actingAs($admin)->visit('/admin/files')->see('Файловый менеджер');
     //Users
     $this->actingAs($admin)->visit('/admin/users')->see('Пользователи');
     try {
         //Editing myself
         $user = User::where('id', $admin->id)->firstOrFail();
     } catch (ModelNotFoundException $e) {
     } finally {
         $this->actingAs($admin)->visit('/admin/users/' . $admin->id . '/edit')->see('Редактирование пользователя')->press('Обновить')->seePageIs('/admin/users');
         unset($user);
     }
     //Logout
     $this->actingAs($admin)->visit('/logout')->seePageIs('/');
     //Logging as User
     $user = User::where('is_admin', '0')->first();
     $this->actingAs($user)->get('/admin')->seeStatusCode('403');
     $this->actingAs($user)->visit('/logout')->seePageIs('/');
 }
Example #9
0
 private function _moveMenuItem($menu_id, $operator)
 {
     $menu = Menu::find($menu_id);
     $order = $operator == '>' ? 'asc' : 'desc';
     $neighbour = Menu::where('sort', $operator, $menu->sort)->orderBy('sort', $order)->first();
     if (empty($neighbour)) {
         return false;
     }
     $old_sort = $menu->sort;
     $menu->sort = $neighbour->sort;
     $neighbour->sort = $old_sort;
     $menu->save();
     $neighbour->save();
     return true;
 }
Example #10
0
 /**
  * Create a new controller instance.
  *
  * @return void
  */
 public function __construct(LaravelFacebookSdk $fb, Menu $menu, UserRepository $userrepo, ProjectRepository $project_repo)
 {
     $this->middleware('auth');
     $this->menuItems = $menu->where('active', '1')->orderBy('weight', 'asc')->get();
     $this->login_url = $fb->getLoginUrl(['email']);
     $this->userrepo = $userrepo;
     $this->project_repo = $project_repo;
     $id = Auth::user()->id;
     $userProfile = Profile::where('user_id', $id)->first();
     $errorNotification = '0';
     if ($userProfile->f_name == '' || $userProfile->l_name == '' || $userProfile->dob == '0000-00-00' || $userProfile->about_me == '' || $userProfile->first_address == '' || $userProfile->alternate_address == '' || $userProfile->state == '' || $userProfile->zipcode == '' || $userProfile->user_avtar == '') {
         $errorNotification = '1';
     }
     $this->errorNotification = $errorNotification;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request, $eventId)
 {
     $input = Input::except('token');
     $menu = Menu::where('event_id', '=', $eventId)->first();
     $menuItem = new MenuItem();
     if (!$menu->id) {
         return $this->respondNotFound('Menu Not Found');
     }
     $validator = $menuItem->getValidator($input);
     if ($validator->fails()) {
         return $this->respondInvalidData($validator->errors());
     }
     $menuItem->fill($input);
     $menuItem->menu_id = $menu->id;
     $menuItem->save();
     return $this->respondCreateSuccess($menuItem->name . ' created');
 }
Example #12
0
 public function detail($id)
 {
     $page = 'catalog';
     $title = Menu::where('key', $page)->value('name');
     $menuHtml = $this->menuHtml($page);
     $menuItems = Menu::all();
     $bottomMenuHtml = view('bottom', ['menuItems' => $menuItems])->render();
     $pageInfo = Page::where('key', $page)->first();
     $categories = Category::orderBy('sort', 'asc')->get();
     $product = Product::with(['category', 'color'])->find($id);
     $product->increment('views');
     $recommended = Product::with('category')->take(4)->get();
     $smallCart = $this->smallCart();
     $cartItem = $this->cartItem($product->id);
     $page = $product;
     $page->title = $product->name;
     return view('site.product', ['menuHtml' => $menuHtml, 'menuBottomHtml' => $bottomMenuHtml, 'title' => $title, 'page' => $page, 'product' => $product, 'categories' => $categories, 'recommended' => $recommended, 'count' => $smallCart['count'], 'sum' => $smallCart['sum'], 'currentItem' => $cartItem, 'currentProductCategory' => $product->category]);
 }
Example #13
0
 protected function _record($model, $action)
 {
     parent::_record($model, $action);
     $module = $this->modelName;
     if (Input::get('inmenu') && is_array(Input::get('menu'))) {
         $menuSite = \App\Models\Menu::where('element_id', $this->result['model']['id'])->where('module', $module)->get();
         $inMenu = array();
         $isMenu = array();
         foreach ($menuSite as $m) {
             $inMenu[$m->id] = $m->rootNode();
             if (in_array($inMenu[$m->id], Input::get('menu'))) {
                 $isMenu[] = $inMenu[$m->id];
                 $menu = $m;
                 $menu->module = $module;
                 $menu->name = $this->result['model']['name'];
                 $menu->path = $this->result['model']['path'];
                 $model->menu()->save($menu);
             } else {
                 $m->forceDelete();
             }
         }
         $newMenu = array_diff(Input::get('menu'), $isMenu);
         foreach ($newMenu as $mn) {
             $menu = new \App\Models\Menu();
             $menu->module = $module;
             $menu->name = $this->result['model']['name'];
             $menu->path = $this->result['model']['path'];
             $menu->parent = $mn;
             if ($this->result['model']['parent']) {
                 $parent = \App\Models\Menu::where('element_id', $this->result['model']['parent'])->where('module', $module)->get();
                 foreach ($parent as $m) {
                     $node = $m->rootNode();
                     if ($node == $mn) {
                         $menu->parent = $m->id;
                     }
                 }
             }
             $model->menu()->save($menu);
         }
     }
     return $this->result();
 }
Example #14
0
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function getIndex()
 {
     $menuItems = Menu::where('active', '1')->orderBy('weight', 'asc')->get();
     return view('welcome', ['_featuredProducts' => count($this->Projectlist(Null, 'popular')) > 0 ? (object) $this->Projectlist(Null, 'popular') : $this->Projectlist(Null, 'popular'), '_recently_added' => count($this->Projectlist(Null, 'latest')) > 0 ? (object) $this->Projectlist(Null, 'latest') : $this->Projectlist(Null, 'latest'), '_menus' => $menuItems, 'login_url' => $this->login_url, '_categoryLists' => Category::where('active', '1')->orderBy('id', 'asc')->get(), '_genreLists' => Genre::where('active', '1')->orderBy('id', 'asc')->get(), '_projectLists' => count($this->Projectlist()) > 0 ? (object) $this->Projectlist() : $this->Projectlist(), '_sliders' => Banner::where('active', '1')->orderBy('weight', 'asc')->get()]);
 }
Example #15
0
 public function menuDelete($id)
 {
     try {
         $menu = Menu::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return response('Page not found.', 404);
     }
     if ($menu->pid == 0) {
         Menu::where('pid', '=', $menu->id)->delete();
     }
     $menu->delete();
     return redirect()->route('admin.menu');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // TODO: Remove this before release...
     // Look for and delete route named 'do-not-pre-load' if it exist.
     // That route is used to test a failure with the Authorization middleware and should not be loaded automatically.
     $routeToDelete = Route::where('name', 'test-acl.do-not-pre-load')->get()->first();
     if ($routeToDelete) {
         Route::destroy($routeToDelete->id);
     }
     $testUserOne = User::create(['username' => 'user1', 'first_name' => 'User', 'last_name' => 'One', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserTwo = User::create(['username' => 'user2', 'first_name' => 'User', 'last_name' => 'Two', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserThree = User::create(['username' => 'user3', 'first_name' => 'User', 'last_name' => 'Three', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserFour = User::create(['username' => 'user4', 'first_name' => 'User', 'last_name' => 'Four', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserFive = User::create(['username' => 'user5', 'first_name' => 'User', 'last_name' => 'Five', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserSix = User::create(['username' => 'user6', 'first_name' => 'User', 'last_name' => 'Six', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserSeven = User::create(['username' => 'user7', 'first_name' => 'User', 'last_name' => 'Seven', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserEight = User::create(['username' => 'user8', 'first_name' => 'User', 'last_name' => 'Eight', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserNine = User::create(['username' => 'user9', 'first_name' => 'User', 'last_name' => 'Nine', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserTen = User::create(['username' => 'user10', 'first_name' => 'User', 'last_name' => 'Ten', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserEleven = User::create(['username' => 'user11', 'first_name' => 'User', 'last_name' => 'Eleven', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserTwelve = User::create(['username' => 'user12', 'first_name' => 'User', 'last_name' => 'Twelve', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserThirteen = User::create(['username' => 'user13', 'first_name' => 'User', 'last_name' => 'Thirteen', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserFourteen = User::create(['username' => 'user14', 'first_name' => 'User', 'last_name' => 'Fourteen', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     $testUserFifteen = User::create(['username' => 'user15', 'first_name' => 'User', 'last_name' => 'Fifteen', 'email' => '*****@*****.**', "password" => "Password1", "auth_type" => "internal", "enabled" => true]);
     /////////
     // Create a few test permissions for the flash-test pages.
     $permTestLevelSuccess = Permission::create(['name' => 'test-level-success', 'display_name' => 'Test level success', 'description' => 'Testing level success', 'enabled' => true]);
     $permTestLevelInfo = Permission::create(['name' => 'test-level-info', 'display_name' => 'Test level info', 'description' => 'Testing level info', 'enabled' => true]);
     $permTestLevelWarning = Permission::create(['name' => 'test-level-warning', 'display_name' => 'Test level warning', 'description' => 'Testing level warning', 'enabled' => true]);
     $permTestLevelError = Permission::create(['name' => 'test-level-error', 'display_name' => 'Test level error', 'description' => 'Testing level error', 'enabled' => true]);
     ////////////////////////////////////
     // Create some roles for the flash test pages.
     ////////////////////////////////////
     // Success
     $roleFlashSuccessViewer = Role::create(["name" => "flash-success-viewer", "display_name" => "Flash success viewer", "description" => "Can see the success flash test page.", "enabled" => true]);
     // Assign permission TestLevelSuccess
     $roleFlashSuccessViewer->perms()->attach($permTestLevelSuccess->id);
     // Assign user membership to role
     $roleFlashSuccessViewer->users()->attach($testUserTwo->id);
     // Info
     $roleFlashInfoViewer = Role::create(["name" => "flash-info-viewer", "display_name" => "Flash info viewer", "description" => "Can see the info flash test page.", "enabled" => true]);
     // Assign permission Info and Success to the InfoViewer role.
     $roleFlashInfoViewer->perms()->attach($permTestLevelInfo->id);
     $roleFlashInfoViewer->perms()->attach($permTestLevelSuccess->id);
     // Assign user membership to role
     $roleFlashInfoViewer->users()->attach($testUserThree->id);
     // Warning
     $roleFlashWarningViewer = Role::create(["name" => "flash-warning-viewer", "display_name" => "Flash warning viewer", "description" => "Can see the warning flash test page.", "enabled" => true]);
     // Assign permission Warning, Info and Success to the WarningViewer role.
     $roleFlashWarningViewer->perms()->attach($permTestLevelWarning->id);
     $roleFlashWarningViewer->perms()->attach($permTestLevelInfo->id);
     $roleFlashWarningViewer->perms()->attach($permTestLevelSuccess->id);
     // Assign user membership to role
     $roleFlashWarningViewer->users()->attach($testUserFour->id);
     // Error
     $roleFlashErrorViewer = Role::create(["name" => "flash-error-viewer", "display_name" => "Flash error viewer", "description" => "Can see the error flash test page.", "enabled" => true]);
     // Assign permission Error, Warning, Info and Success to the ErrorViewer role.
     $roleFlashErrorViewer->perms()->attach($permTestLevelError->id);
     $roleFlashErrorViewer->perms()->attach($permTestLevelWarning->id);
     $roleFlashErrorViewer->perms()->attach($permTestLevelInfo->id);
     $roleFlashErrorViewer->perms()->attach($permTestLevelSuccess->id);
     // Assign user membership to role
     $roleFlashErrorViewer->users()->attach($testUserFive->id);
     /////////
     // Find basic-authenticated permission.
     $permBasicAuthenticated = Permission::where('name', 'basic-authenticated')->first();
     // Find guest-only permission.
     $permGuestOnly = Permission::where('name', 'guest-only')->first();
     // Find open-to-all permission.
     $permOpenToAll = Permission::where('name', 'open-to-all')->first();
     // Find admin-settings permission.
     $permAdminSettings = Permission::where('name', 'admin-settings')->first();
     ////////////////////////////////////
     // Associate some permission to acl test routes
     $routeTestACLHome = Route::where('name', 'test-acl.home')->get()->first();
     $routeTestACLHome->permission()->associate($permOpenToAll);
     $routeTestACLHome->save();
     //
     $routeTestACLAdmins = Route::where('name', 'test-acl.admins')->get()->first();
     $routeTestACLAdmins->permission()->associate($permAdminSettings);
     $routeTestACLAdmins->save();
     //
     $routeTestACLBasicAuthenticated = Route::where('name', 'test-acl.basic-authenticated')->get()->first();
     $routeTestACLBasicAuthenticated->permission()->associate($permBasicAuthenticated);
     $routeTestACLBasicAuthenticated->save();
     //
     $routeTestACLGuestOnly = Route::where('name', 'test-acl.guest-only')->get()->first();
     $routeTestACLGuestOnly->permission()->associate($permGuestOnly);
     $routeTestACLGuestOnly->save();
     //
     $routeTestACLOpenToAll = Route::where('name', 'test-acl.open-to-all')->get()->first();
     $routeTestACLOpenToAll->permission()->associate($permOpenToAll);
     $routeTestACLOpenToAll->save();
     ////////////////////////////////////
     // Associate some permission to flash test routes
     $routeFlashHome = Route::where('name', 'test-flash.home')->get()->first();
     $routeFlashHome->permission()->associate($permOpenToAll);
     $routeFlashHome->save();
     //
     $routeFlashSuccess = Route::where('name', 'test-flash.success')->get()->first();
     $routeFlashSuccess->permission()->associate($permTestLevelSuccess);
     $routeFlashSuccess->save();
     //
     $routeFlashInfo = Route::where('name', 'test-flash.info')->get()->first();
     $routeFlashInfo->permission()->associate($permTestLevelInfo);
     $routeFlashInfo->save();
     //
     $routeFlashWarning = Route::where('name', 'test-flash.warning')->get()->first();
     $routeFlashWarning->permission()->associate($permTestLevelWarning);
     $routeFlashWarning->save();
     //
     $routeFlashError = Route::where('name', 'test-flash.error')->get()->first();
     $routeFlashError->permission()->associate($permTestLevelError);
     $routeFlashError->save();
     ////////////////////////////////////
     // Associate some permission to menu test routes
     $routeTestMenusHome = Route::where('name', 'test-menus.home')->get()->first();
     $routeTestMenusHome->permission()->associate($permOpenToAll);
     $routeTestMenusHome->save();
     //
     $routeTestMenusOne = Route::where('name', 'test-menus.one')->get()->first();
     $routeTestMenusOne->permission()->associate($permOpenToAll);
     $routeTestMenusOne->save();
     //
     $routeTestMenusTwo = Route::where('name', 'test-menus.two')->get()->first();
     $routeTestMenusTwo->permission()->associate($permBasicAuthenticated);
     $routeTestMenusTwo->save();
     //
     $routeTestMenusTwoA = Route::where('name', 'test-menus.two-a')->get()->first();
     $routeTestMenusTwoA->permission()->associate($permTestLevelSuccess);
     $routeTestMenusTwoA->save();
     //
     $routeTestMenusTwoB = Route::where('name', 'test-menus.two-b')->get()->first();
     $routeTestMenusTwoB->permission()->associate($permTestLevelInfo);
     $routeTestMenusTwoB->save();
     //
     $routeTestMenusThree = Route::where('name', 'test-menus.three')->get()->first();
     $routeTestMenusThree->permission()->associate($permTestLevelWarning);
     $routeTestMenusThree->save();
     /////////
     // Find home menu.
     $menuHome = Menu::where('name', 'home')->first();
     /////////
     // Create Test ACL menu folder
     $menuTestACL = Menu::create(['name' => 'test-acl.home', 'label' => 'Test ACL', 'position' => 20, 'icon' => 'fa fa-bolt', 'separator' => false, 'url' => '/test-acl/home', 'enabled' => true, 'parent_id' => $menuHome->id, 'route_id' => null, 'permission_id' => $permOpenToAll->id]);
     // Create DoNotPreLoad menu
     $menuDoNotPreLoad = Menu::create(['name' => 'test-acl.do-not-pre-load', 'label' => 'Do not pre-load', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => '/test-acl/do-not-pre-load', 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => null, 'permission_id' => null]);
     // Create NoPerm menu
     $menuNoPerm = Menu::create(['name' => 'test-acl.no-perm', 'label' => 'No perm', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => '/test-acl/no-perm', 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => null, 'permission_id' => null]);
     // Create GuestOnly menu
     $menuGuestOnly = Menu::create(['name' => 'test-acl.guest-only', 'label' => 'Guest Only', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => $routeTestACLGuestOnly->id, 'permission_id' => null]);
     // Create OpenToAll menu
     $menuOpenToAll = Menu::create(['name' => 'test-acl.open-to-all', 'label' => 'Open to all', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => $routeTestACLOpenToAll->id, 'permission_id' => null]);
     // Create BasicAuthenticated menu
     $menuBasicAuthenticated = Menu::create(['name' => 'test-acl.basic-authenticated', 'label' => 'Basic authenticated', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => $routeTestACLBasicAuthenticated->id, 'permission_id' => null]);
     // Create Admins menu
     $menuAdmins = Menu::create(['name' => 'test-acl.admins', 'label' => 'Admins', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => $routeTestACLAdmins->id, 'permission_id' => null]);
     // Create PowerUsers menu
     $menuPowerUsers = Menu::create(['name' => 'test-acl.power-users', 'label' => 'Power users', 'position' => 0, 'icon' => 'fa fa-file', 'separator' => false, 'url' => '/test-acl/power-users', 'enabled' => true, 'parent_id' => $menuTestACL->id, 'route_id' => null, 'permission_id' => null]);
     /////////
     // Create Test flash menu folder
     $menuTestFlashHome = Menu::create(['name' => 'test-flash.home', 'label' => 'Test Flash', 'position' => 20, 'icon' => 'fa fa-bolt', 'separator' => false, 'url' => '/test-flash/home', 'enabled' => true, 'parent_id' => $menuHome->id, 'route_id' => null, 'permission_id' => $permBasicAuthenticated->id]);
     // Create Flash success menu
     $menuFlashSuccess = Menu::create(['name' => 'test-flash.success', 'label' => 'Flash success', 'position' => 0, 'icon' => 'fa fa-check fa-colour-green', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestFlashHome->id, 'route_id' => $routeFlashSuccess->id, 'permission_id' => null]);
     // Create Flash info menu
     $menuFlashInfo = Menu::create(['name' => 'test-flash.info', 'label' => 'Flash info', 'position' => 10, 'icon' => 'fa fa-info fa-colour-blue', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestFlashHome->id, 'route_id' => $routeFlashInfo->id, 'permission_id' => null]);
     // Create Flash warning menu
     $menuFlashWarning = Menu::create(['name' => 'test-flash.warning', 'label' => 'Flash warning', 'position' => 20, 'icon' => 'fa fa-warning fa-colour-orange', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestFlashHome->id, 'route_id' => $routeFlashWarning->id, 'permission_id' => null]);
     // Create Flash error menu
     $menuFlashError = Menu::create(['name' => 'test-flash.error', 'label' => 'Flash error', 'position' => 30, 'icon' => 'fa fa-ban fa-colour-red', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestFlashHome->id, 'route_id' => $routeFlashError->id, 'permission_id' => null]);
     /////////
     // Create Test menu folder
     $menuTestMenusHome = Menu::create(['name' => 'test-menus.home', 'label' => 'Test Menus', 'position' => 30, 'icon' => 'fa fa-bolt', 'separator' => false, 'url' => '/test-menus/home', 'enabled' => true, 'parent_id' => $menuHome->id, 'route_id' => null, 'permission_id' => $permOpenToAll->id]);
     // Create Menu 1 menu
     $menuTestMenusOne = Menu::create(['name' => 'test-menus.one', 'label' => 'Menu One', 'position' => 0, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusHome->id, 'route_id' => $routeTestMenusOne->id, 'permission_id' => null]);
     // Create Menu 2 menu
     $menuTestMenusTwo = Menu::create(['name' => 'test-menus.two', 'label' => 'Menu Two', 'position' => 10, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusHome->id, 'route_id' => $routeTestMenusTwo->id, 'permission_id' => null]);
     // Create Menu 2a menu
     $menuTestMenusTwo2a = Menu::create(['name' => 'test-menus.two-a', 'label' => 'Menu Two A', 'position' => 0, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusTwo->id, 'route_id' => $routeTestMenusTwoA->id, 'permission_id' => null]);
     // Create Menu 2b menu
     $menuTestMenusTwo2b = Menu::create(['name' => 'test-menus.two-b', 'label' => 'Menu Two B', 'position' => 10, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusTwo->id, 'route_id' => $routeTestMenusTwoB->id, 'permission_id' => null]);
     // Create Menu 2a alias by URL
     $menuTestMenusTwo2a = Menu::create(['name' => 'test-menus.two-a-alias-url', 'label' => 'Menu Two A alias by URL', 'position' => 0, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => '/test-menus/two-a', 'enabled' => true, 'parent_id' => $menuTestMenusTwo->id, 'route_id' => null, 'permission_id' => $permBasicAuthenticated->id]);
     // Create Menu 2a alias by ROUTE
     $menuTestMenusTwo2a = Menu::create(['name' => 'test-menus.two-a-alias-route', 'label' => 'Menu Two A alias by route', 'position' => 0, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusTwo->id, 'route_id' => Route::where('name', 'like', "test-menus.two_a")->get()->first()->id, 'permission_id' => null]);
     // Create Menu 3 menu
     $menuTestMenusTwo3 = Menu::create(['name' => 'test-menus.three', 'label' => 'Menu Three', 'position' => 20, 'icon' => 'fa fa-bars', 'separator' => false, 'url' => null, 'enabled' => true, 'parent_id' => $menuTestMenusHome->id, 'route_id' => $routeTestMenusThree->id, 'permission_id' => null]);
 }
Example #17
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $last_period = Helper::defaultPeriodId();
     $current_period = Helper::periodAfterId($last_period);
     $item_purchases = [];
     $last_stock = [];
     $current_stock = [];
     $item_sales = [];
     $item_wastes = [];
     $items = [];
     $wastage = [];
     $sales_chart = [];
     $items_without_price = 0;
     $period = null;
     if ($last_period) {
         $purchases = Purchases::orderBy('date_created', 'ASC')->where(['stock_period_id' => $last_period])->get();
         foreach ($purchases as $purchase) {
             foreach ($purchase->purchases()->get() as $itemPurchase) {
                 if (array_key_exists($itemPurchase->item_id, $item_purchases)) {
                     $item_purchases[$itemPurchase->item_id]['value'] += $itemPurchase->value;
                     $item_purchases[$itemPurchase->item_id]['occurrences']++;
                     $item_purchases[$itemPurchase->item_id]['price'] += $itemPurchase->value == 0 ? 0 : $itemPurchase->price / $itemPurchase->value;
                 } else {
                     $item_purchases[$itemPurchase->item_id]['value'] = $itemPurchase->value;
                     $item_purchases[$itemPurchase->item_id]['price'] = $itemPurchase->value == 0 ? 0 : $itemPurchase->price / $itemPurchase->value;
                     $item_purchases[$itemPurchase->item_id]['occurrences'] = 1;
                 }
             }
         }
         foreach ($item_purchases as $key => $purchase) {
             $item_purchases[$key]['price'] = $purchase['price'] / $purchase['occurrences'];
         }
         $last_stock_items = StockItem::where(['stock_period_id' => $last_period])->get();
         foreach ($last_stock_items as $si) {
             if (array_key_exists($si->item_id, $last_stock)) {
                 $last_stock[$si->item_id] += $si->stock;
             } else {
                 $last_stock[$si->item_id] = $si->stock;
             }
         }
         $current_stock_items = StockItem::where(['stock_period_id' => $current_period])->get();
         foreach ($current_stock_items as $si) {
             if (array_key_exists($si->item_id, $current_stock)) {
                 $current_stock[$si->item_id] += $si->stock;
             } else {
                 $current_stock[$si->item_id] = $si->stock;
             }
         }
         $sales = Sales::where(['stock_period_id' => $last_period])->get();
         foreach ($sales as $sale) {
             foreach ($sale->sales()->orderBy('quantity', 'DESC')->get() as $sale_item) {
                 $menu = $sale_item->menu()->first();
                 if ($menu) {
                     $color = $this->rand_color();
                     $sales_chart[$menu->id] = ['value' => $sale_item->quantity, 'color' => $color, 'highlight' => $this->alter_brightness($color, 20), 'label' => $menu->title];
                     if ($menu->type == 'item') {
                         if (array_key_exists($menu->item_id, $item_sales)) {
                             $item_sales[$menu->item_id] += $menu->value * $sale_item->quantity;
                         } else {
                             $item_sales[$menu->item_id] = $menu->value * $sale_item->quantity;
                         }
                     } elseif ($menu->type == 'recipe') {
                         $recipe = $menu->recipe()->first();
                         if ($recipe) {
                             $usage = $this->countUsageFromRecipe($recipe);
                             foreach ($usage as $key => $use) {
                                 if (array_key_exists($key, $item_sales)) {
                                     $item_sales[$key] += $sale_item->quantity * $use;
                                 } else {
                                     $item_sales[$key] = $sale_item->quantity * $use;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $wastes = Wastes::where(['stock_period_id' => $last_period])->get();
         foreach ($wastes as $waste) {
             if (array_key_exists($waste->reason()->first()->id, $wastage)) {
                 $wastage[$waste->reason()->first()->id]['value'] = $wastage[$waste->reason()->first()->id]['value'] + 1;
             } else {
                 $color = $this->rand_color();
                 $wastage[$waste->reason()->first()->id] = ['value' => 1, 'color' => $color, 'highlight' => $this->alter_brightness($color, 20), 'label' => $waste->reason()->first()->reason];
             }
             if ($waste->type == 'item') {
                 if (array_key_exists($waste->item_id, $item_wastes)) {
                     $item_wastes[$waste->item_id] += $waste->value;
                 } else {
                     $item_wastes[$waste->item_id] = $waste->value;
                 }
             } elseif ($waste->type == 'recipe') {
                 $recipe = $waste->recipe()->first();
                 if ($recipe) {
                     $usage = $this->countUsageFromRecipe($recipe);
                     foreach ($usage as $key => $use) {
                         if (array_key_exists($key, $item_wastes)) {
                             $item_wastes[$key] += $waste->recipe_count * $use;
                         } else {
                             $item_wastes[$key] = $waste->recipe_count * $use;
                         }
                     }
                 }
             } elseif ($waste->type == 'menu') {
                 $menu = $waste->menu()->first();
                 if ($menu) {
                     if ($menu->type == 'item') {
                         if (array_key_exists($menu->item_id, $item_wastes)) {
                             $item_wastes[$menu->item_id] += $waste->menu_count * $menu->value;
                         } else {
                             $item_wastes[$menu->item_id] = $waste->menu_count * $menu->value;
                         }
                     } elseif ($menu->type == 'recipe') {
                         $recipe = $menu->recipe()->first();
                         if ($recipe) {
                             $usage = $this->countUsageFromRecipe($recipe);
                             foreach ($usage as $key => $use) {
                                 if (array_key_exists($key, $item_wastes)) {
                                     $item_wastes[$key] += $waste->menu_count * $use;
                                 } else {
                                     $item_wastes[$key] = $waste->menu_count * $use;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $period = StockPeriods::findOrFail($last_period);
     }
     $all_items = Items::all();
     $variance = 0;
     $count = 0;
     foreach ($all_items as $item) {
         if (!array_key_exists($item->category()->first()->id, $items)) {
             $items[$item->category()->first()->id]['category'] = $item->category()->first()->title;
             $items[$item->category()->first()->id]['variance'] = 0;
             $items[$item->category()->first()->id]['items'] = [];
         }
         $current_item = [];
         //$items[$item->id]['object'] = $item;
         $current_item['title'] = $item->title;
         $current_item['units'] = $item->units()->where(['default' => 1])->first()->unit()->first()->title;
         $current_item['wastage'] = array_key_exists($item->id, $item_wastes) ? $item_wastes[$item->id] : 0;
         $current_item['last_stock'] = array_key_exists($item->id, $last_stock) ? $last_stock[$item->id] : 0;
         $current_item['current_stock'] = array_key_exists($item->id, $current_stock) ? $current_stock[$item->id] : 0;
         if (array_key_exists($item->id, $item_purchases)) {
             $current_item['purchases'] = $item_purchases[$item->id];
         } else {
             $price = 0;
             $item_price = ItemPurchases::where(['item_id' => $item->id])->orderBy('created_at', 'DESC')->first();
             if ($item_price) {
                 $value = $item_price->value;
                 if ($value == 0) {
                     $value = 1;
                 }
                 $price = $item_price->price / $value;
             } else {
                 if ($item->price) {
                     $price = $item->price;
                 } else {
                     $items_without_price++;
                 }
             }
             $current_item['purchases'] = ['value' => 0, 'price' => $price, 'occurrences' => 0];
         }
         $current_item['sales'] = array_key_exists($item->id, $item_sales) ? $item_sales[$item->id] : 0;
         $current_item['must_stock'] = $current_item['last_stock'] + $current_item['purchases']['value'] - $current_item['sales'] - $current_item['wastage'];
         $current_item['stock_difference'] = $current_item['current_stock'] - $current_item['must_stock'];
         $current_item['variance'] = round($current_item['stock_difference'] * $current_item['purchases']['price'], 2);
         $variance += $current_item['variance'];
         $items[$item->category()->first()->id]['variance'] += $current_item['variance'];
         $items[$item->category()->first()->id]['items'][$item->id] = $current_item;
         $count++;
     }
     $summary_stock = Items::select('count(*)')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $current_period . ' and stock_items.item_id = items.id)')->count();
     $summary_invoices = Purchases::where(['stock_period_id' => $last_period])->count();
     $summary_sales = Sales::where(['stock_period_id' => $last_period])->count();
     $summary_menu = Menu::where(['checked' => 0])->count();
     $summary_wastes = Wastes::where(['stock_period_id' => $last_period])->count();
     return view('Client.index')->with(array('last_period' => $last_period, 'date_from' => $period ? date('Y-m-d', strtotime($period->date_from)) : date('Y-m-d', strtotime('-30 days')), 'date_to' => $period ? date('Y-m-d', strtotime($period->date_to)) : date('Y-m-d', time()), 'last_stock_summary_items' => $items, 'variance' => $variance, 'items' => $items, 'count' => $count, 'sales' => count($sales_chart) > 10 ? array_slice($sales_chart, 0, 10) : $sales_chart, 'wastage' => $wastage, 'summary' => ['stock' => $summary_stock, 'invoices' => $summary_invoices, 'sales' => $summary_sales, 'menu' => $summary_menu, 'no_price' => $items_without_price, 'wastes' => $summary_wastes]));
 }
 /**
  * Resolve the parent menu item and return it's ID.
  * Default to the 'root' menu item if no match can be found.
  *
  * @param $parent
  * @return mixed
  */
 protected static function getParentMenuID($parent)
 {
     // Set the parent id to be root by default.
     $parent_id = Menu::where('name', 'root')->first()->id;
     //        // If a string was provided, find the Menu based on that name.
     //        if (is_string($parent)) {
     //            $parent = Menu::where('name', $parent)->first();
     //        }
     $parent = Menu::resolve($parent);
     // If a Menu object was provided or found in the previous block,
     // return the ID of that object.
     if ($parent instanceof Menu) {
         $parent_id = $parent->id;
     }
     return $parent_id;
 }
 public function setDefault($id)
 {
     $itemUnit = ItemUnits::findOrFail($id);
     Helper::add($id, 'changed item ' . $itemUnit->item()->first()->title . '(ID ' . $itemUnit->item()->first()->id . ') default unit to ' . $itemUnit->unit()->first()->title);
     ItemUnits::where('item_id', $itemUnit->item_id)->update(['default' => 0]);
     ItemUnits::where('id', $id)->update(['default' => 1]);
     ItemUnits::where(['item_id' => $itemUnit->item_id])->update(['factor' => DB::raw('factor/' . $itemUnit->factor)]);
     StockItem::where(['item_id' => $itemUnit->item_id])->update(['stock' => DB::raw('stock/' . $itemUnit->factor)]);
     RecipeItems::where(['item_id' => $itemUnit->item_id])->update(['value' => DB::raw('value/' . $itemUnit->factor)]);
     Menu::where(['item_id' => $itemUnit->item_id])->update(['value' => DB::raw('value/' . $itemUnit->factor)]);
     ItemPurchases::where(['item_id' => $itemUnit->item_id])->update(['value' => DB::raw('value/' . $itemUnit->factor)]);
     StockCheck::where(['item_id' => $itemUnit->item_id])->update(['before' => DB::raw('`before` / ' . $itemUnit->factor), 'after' => DB::raw('`after` / ' . $itemUnit->factor)]);
     return Redirect::action('ItemUnitsController@index', array('item_id' => $itemUnit->item_id));
 }
Example #20
0
 /**
  * Update/Store admin menu settings
  * POST /admin/settings
  *
  * @return Response
  */
 public function storeSettings()
 {
     $data = Input::all();
     Log::info($data);
     $allMenus = Menu::lists('name', 'id');
     $allItems = MenuItem::lists('title', 'id');
     //existing menus
     foreach ($data['menus'] as $i => $menu) {
         $m = Menu::updateOrCreate(['id' => $i], array('name' => $menu, 'link' => $data['mlinks'][$i], 'sort_id' => $data['msorts'][$i]));
         if (isset($data['imenus'][$i])) {
             foreach ($data['imenus'][$i] as $k => $im) {
                 $sm = MenuItem::updateOrCreate(['id' => $k], array('title' => $im, 'link' => $data['ilinks'][$i][$k], 'sort_id' => $data['isorts'][$i][$k]));
                 unset($allItems[$k]);
             }
         }
         if (isset($data['submenus'][$i])) {
             foreach ($data['submenus'][$i] as $k => $sb) {
                 MenuItem::create(array('menu_id' => $i, 'title' => $sb, 'link' => $data['sublinks'][$i][$k], 'sort_id' => $data['subsorts'][$i][$k]));
             }
         }
         unset($allMenus[$i]);
     }
     //new menus
     if (isset($data['newmenus'])) {
         foreach ($data['newmenus'] as $i => $nmenu) {
             $m = Menu::create(array('name' => $nmenu, 'link' => $data['newlinks'][$i], 'sort_id' => $data['newsorts'][$i]));
             if (isset($data['submenus'][$i])) {
                 foreach ($data['submenus'][$i] as $k => $im) {
                     $sm = MenuItem::create(array('menu_id' => $m->id, 'title' => $im, 'link' => $data['sublinks'][$i][$k], 'sort_id' => $data['subsorts'][$i][$k]));
                 }
                 unset($data['submenus'][$i]);
                 unset($allItems[$i]);
             }
         }
         //new submenus of exising menus
         foreach ($data['submenus'] as $k => $im) {
             foreach ($data['submenus'][$k] as $i => $sb) {
                 MenuItem::create(array('menu_id' => $k, 'title' => $sb, 'link' => $data['sublinks'][$k][$i], 'sort_id' => $data['subsorts'][$k][$i]));
             }
         }
     }
     foreach ($allItems as $i => $title) {
         MenuItem::where('id', '=', $i)->delete();
     }
     foreach ($allMenus as $m => $name) {
         Menu::where('id', '=', $m)->delete();
     }
     if (Request::ajax()) {
         return Response::json('success');
     }
     return View::make('admin.settings');
 }
Example #21
0
 public function compose(View $view)
 {
     $items = \App\Models\Menu::where('position', 'bottom')->orderBy('sort', 'asc')->get();
     $view->with('items', $items);
 }
 public function BloggView()
 {
     $getBloggs = Menu::where('menu_name', '=', 'Blogg')->select('info')->get();
     return View('Runningshoes.pages.blogg.BloggView')->with(array('getBloggs' => $getBloggs));
 }
Example #23
0
 public function __construct(Menu $menu, LaravelFacebookSdk $fb)
 {
     $this->menuItems = $menu->where('active', '1')->orderBy('weight', 'asc')->get();
     $this->login_url = $fb->getLoginUrl(['email']);
 }