How Jump to with collections of data in laravel -
i'm implementing jump to...
functionality in project. want is:
- if user in first item left button not included.
- if user in last item right button not included.
- the left button should have link same link before current/selected item.
- the right button should have link same link after current/selected item.
please see code below:
controller
$course = course::with([ 'assignments' => $undeleted, 'quizzes' => $undeleted, 'add_links' => $undeleted ])->findorfail($id); $course_items = collect($course->assignments); $course_items = $course_items->merge(collect($course->quizzes)); $course_items = $course_items->merge(collect($course->add_links)); $course_items = $course_items->sortby('item_number');
view
<div class="jump-to"> <div class="pull-right"> <div class="btn-group" role="group"> @foreach($course->topics $topic) @foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortby('item_number') $first_item) @if($first_item->id != $assignment->id) <a href="#" class="btn btn-primary"> <i class="fa fa-angle-left"></i> </a> @endif <?php break 2; ?> @endforeach @endforeach <div class="btn-group" role="group"> <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> jump <div class="caret"></div> </button> <ul class="dropdown-menu" role="menu"> @foreach($course->topics $topic) <li class="jdivider"> topic {{ $topic->topic_number }} </li> @foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortby('item_number') $topic_item) <li> @if($topic_item->item_type() == 'assignment') <a title="assignment: {{ $topic_item->name }}" class="regular-link" href="{{ route('assignment.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}"> <i class="fa fa-tasks"></i> {{ str_limit($topic_item->name, 15) }} </a> @elseif($topic_item->item_type() == 'quiz') <a title="quiz: {{ $topic_item->name }}" class="regular-link" href="{{ route('quiz.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}"> <i class="fa fa-file-text"></i> {{ str_limit($topic_item->name, 15) }} </a> @elseif($topic_item->item_type() == 'add_link') <a href="#"> @if(!empty($topic_item->file_location) && in_array(strtolower(last(explode('.', $topic_item->file_location))), ['pdf', 'docx', 'doc'])) <i class="fa fa-file-pdf-o"></i> @elseif(empty($topic_item->file_location)) <i class="fa fa-globe"></i> @else <i class="fa fa-file-text-o"></i> @endif {{ str_limit($topic_item->name, 15) }} </a> @endif </li> @endforeach @endforeach </ul> </div> <a href="#" class="btn btn-primary"> <i class="fa fa-angle-right"></i> </a> </div> </div> </div>
example dropdown links
:
assignment1
assignment2
quiz1
quiz2
reviewer1
if clicked assignment2, left button, has id
or link
assignment1
. if clicked reviewer1, right button disappears , left button has id
or link quiz2 , same other links.
Comments
Post a Comment