Skip to content

Instantly share code, notes, and snippets.

@adamgoose
Created August 6, 2014 23:09
Show Gist options
  • Select an option

  • Save adamgoose/1dd4b29e4db16cf5c9b9 to your computer and use it in GitHub Desktop.

Select an option

Save adamgoose/1dd4b29e4db16cf5c9b9 to your computer and use it in GitHub Desktop.
@section('content')
<section id="main_content">
<div class="container">
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="{{route('mentor-center')}}">Mentor Center</a></li>
<li><a href="{{route('mentor-center')}}">Audit Report</a></li>
<li class="active">{{$user->name}}</li>
</ol>
<div class="row">
<div class="col-md-7">
<table class="table table-striped table-hover table-header-rotated">
<thead>
<tr>
<th>Course</th>
@foreach($audit->getColumns() as $column)
<th class="rotate-45">
<div>
<span>{{$column->name}}</span>
</div>
</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach($user->courseProgress->unique() as $course)
<tr>
<th>
<a href="{{route('courses.show', $course->slug)}}">
<i class="icon-link-ext"></i>
{{$course->title}}
</a>
</th>
@foreach($audit->getColumns() as $column)
<td>
@if($audit->completedFor($course, $column))
<i class="icon-check"></i>
@else
<i class="icon-check-empty"></i>
@endif
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="col-md-4 col-md-offset-1">
<div class="box_style_1">
<h4>{{$user->name}}</h4>
<h5>Teams</h5>
<ul class="list_1">
@foreach($user->teams as $team)
<li>
<a href="{{route('teams.show', $team->slug)}}">
{{$team->name}}
<small>({{$team->sport.' '.$team->pivot->role}})</small>
</a>
</li>
@endforeach
</ul>
<h5>Mentors</h5>
<ul class="list_1">
@foreach($user->mentors as $mentor)
<li>
<a href="#">
{{$mentor->name}}
<small>({{$mentor->pivot->type}})</small>
</a>
</li>
@endforeach
</ul>
</div>
</div>
</div>
</div>
</section>
@stop
<?php namespace TAA\Entities\User;
use Course;
use Illuminate\Database\Eloquent\Collection;
use User;
class AuditHelper {
/**
* @var User
*/
public $user;
/**
* @var Collection
*/
protected $completedScopes;
/**
* @param User $user
*/
function __construct(User $user)
{
$this->user = $user;
$this->eagerLoad();
}
private function eagerLoad()
{
$this->user->load('courseProgress', 'teams.collections', 'mentors');
$load = [];
foreach($this->user->courseProgress as $course)
{
$load[$course->pivot->scope_type][] = $course->pivot->scope_id;
}
$User = User::whereIn('id', $load['User'])->get();
$Collection = \Collection::whereIn('id', $load['Collection']);
foreach($this->user->courseProgress as $course)
{
$scope = ${$course->pivot->scope_type}->find($course->pivot->scope_id);
$course->pivot->setRelation('scope', $scope);
}
}
/**
* @return Collection
*/
public function getColumns()
{
$collection = new Collection($this->user->teams->all());
foreach($this->user->mentors as $mentor)
$collection->push($mentor);
return $collection;
}
/**
* @param Course $course
* @param $scope
*
* @return bool
*/
public function completedFor(Course $course, $scope)
{
switch(get_class($scope))
{
case 'Team':
$collections = $scope->collections;
foreach($collections as $collection)
if($this->scopesFor($course)->contains($collection))
return true;
break;
case 'User':
if($this->scopesFor($course)->contains($scope))
return true;
break;
}
return false;
}
/**
* @param Course $course
*
* @return mixed
*/
protected function scopesFor(Course $course)
{
return $this->user->courseProgress->filter(function($c) use ($course)
{
return $course->id == $c->id;
})->map(function($course)
{
return $course->pivot->scope;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment