public function store()
 {
     $input = Input::all();
     $last_category = VideoCategory::orderBy('order', 'DESC')->first();
     if (isset($last_category->order)) {
         $new_category_order = intval($last_category->order) + 1;
     } else {
         $new_category_order = 1;
     }
     $input['order'] = $new_category_order;
     $video_category = VideoCategory::create($input);
     if (isset($video_category->id)) {
         return Redirect::to('admin/videos/categories')->with(array('note' => 'Successfully Added Your New Video Category', 'note_type' => 'success'));
     }
 }
Пример #2
0
 function generate_menu($menu)
 {
     $previous_item = array();
     $first_parent_id = 0;
     $depth = 0;
     $output = '';
     foreach ($menu as $menu_item) {
         $hasChildren = $menu_item->hasChildren();
         if (isset($previous_item->id) && $menu_item->parent_id == $previous_item->parent_id || $menu_item->parent_id == NULL) {
             $output .= '</li>';
         }
         if (isset($previous_item->parent_id) && $previous_item->parent_id !== $menu_item->parent_id && $previous_item->id != $menu_item->parent_id) {
             if ($depth == 2) {
                 $output .= '</li></ul>';
                 $depth -= 1;
             }
             if ($depth == 1 && $menu_item->parent_id == $first_parent_id) {
                 $output .= '</li></ul>';
                 $depth -= 1;
             }
         }
         if ($menu_item->type == 'videos') {
             $active = '';
             if (Request::is('videos')) {
                 $active = ' active';
             }
             $output .= '<li class="dropdown' . $active . '">';
             $output .= '<a href="/videos" class="dropdown-toggle">' . $menu_item->name . ' <span class="caret"></span></a>';
             $output .= '<ul class="dropdown-menu multi-level" role="menu">';
             $output .= generate_video_post_menu(VideoCategory::orderBy('order', 'ASC')->get(), '/videos/category/');
             $output .= '</li></ul>';
             $output .= '</li>';
             continue;
         }
         if ($menu_item->type == 'posts') {
             $active = '';
             if (Request::is('posts')) {
                 $active = ' active';
             }
             $output .= '<li class="dropdown' . $active . '">';
             $output .= '<a href="/posts" class="dropdown-toggle">' . $menu_item->name . ' <span class="caret"></span></a>';
             $output .= '<ul class="dropdown-menu multi-level" role="menu">';
             $output .= generate_video_post_menu(PostCategory::orderBy('order', 'ASC')->get(), '/posts/category/');
             $output .= '</li></ul>';
             $output .= '</li>';
             continue;
         }
         $li_class = '';
         $caret = '';
         $dropdown_toggle = '';
         if ($hasChildren) {
             $dropdown_toggle = ' class="dropdown-toggle"';
         }
         if ($hasChildren && $depth == 0) {
             if (Request::is(str_replace('/', '', $menu_item->url))) {
                 $li_class .= ' class="active dropdown"';
             } else {
                 $li_class .= ' class="dropdown"';
             }
             $caret = ' <span class="caret"></span>';
         } elseif ($hasChildren && $depth > 0) {
             $li_class .= ' class="dropdown-submenu"';
         }
         if (!$hasChildren && $depth == 0 && Request::is(str_replace('/', '', $menu_item->url)) || $menu_item->url == '/' && Request::is('/')) {
             $li_class .= ' class="active"';
         }
         $output .= '<li' . $li_class . '>';
         $output .= '<a href="' . $menu_item->url . '"' . $dropdown_toggle . '>' . $menu_item->name . $caret . '</a>';
         if ($hasChildren) {
             $output .= '<ul class="dropdown-menu multi-level" role="menu">';
             $depth += 1;
         }
         $previous_item = $menu_item;
     }
     $output .= '</li></ul>';
     return $output;
 }