@extends('layouts.master')

@section('navigation')
        @include('local.managers.admins._navigation')
@stop

@section('main')
    <div class="row">
        <div class="col-md-12">
            <p>This report contains performance information for all Schools and Programs with assessed courses during the following semester(s):</p>
            <ul>
                @foreach (Session::get('semesters_info') as $semester_info)
                    <li>{{ $semester_info }}</li>
                @endforeach
            </ul>

            <p>Unlinked programs did not assess this outcome.</p>

            
            <h3>Table of Contents</h3>
            <ol id="table-of-contents" class="upper-roman">
                
            </ol>

            <h3 id="{{ $outcome->id }}" class="outcome">{{ $outcome->name }}</h3>
            @foreach ($schools as $school)
            <table class="table table-condensed table-bordered">
                <thead>
                    <tr>
                        <th colspan="12">
                            <h4 id="{{ $outcome->id }}-{{ $school->id }}" class="school table-header" >{{ $school->name }}
                                </h4>
                            <a class="to-top" href="">
                                <span class="glyphicon glyphicon-arrow-up hidden-print"></span>
                                To Top
                            </a>

                        </th>
                    </tr>
                    <tr class="center-text">
                        <th>Academic Program</th>
                        <th>Findings</th>
                    </tr
                </thead>
                <tbody>
                @foreach ($school->programs as $program)
                    @if($program->assessesOutcome($outcome->id))
                        <tr>
                            <td id="{{ $outcome->id }}-{{ $school->id }}-{{ $program->id }}" class="program col-md-3" >{{ $program->name }}</td>
                            <td class="col-md-9">

                            <!-- For each grouped course -->
                            @foreach($program->courses as $index2=>$course)
                                <!-- If grouped course has activities that evaluate the outcome -->

                                <?php

                                    $sections_evaluating = Course::has('activities')
                                    ->whereNotNull('outcomes_attempted')
                                    ->whereRaw('outcomes_attempted not like \'%"'.$outcome->id.'":0%\'')
                                    ->with(array('activities'=>function($query) use(&$outcome){
                                        $query->whereNotNull('outcomes_attempted');
                                        $query->whereRaw('outcomes_attempted not like \'%"'.$outcome->id.'":0%\'');} ))
                                    ->where('code', $course->code)->where('number',$course->number)
                                    ->get();
                                ?>

                                @if(count($sections_evaluating))
                                    <h4>Instance {{ $index2 +1 }}: {{ $course->code}}-{{ $course->number }}</h4>

                                    <!-- For each section -->
                                    @foreach($sections_evaluating as $index3 => $section)
                                        <h5><u>Section {{ $index3 + 1}}</u></h5>

                                        <!-- For each activity in the section -->
                                        @foreach($section->activities as $index4 => $activity)

                                            <!-- If activity has a rubric and the rubric has the outcome being evaluated -->
                                            @if($activity->rubric_id != NULL && array_key_exists($outcome->id, (array)$activity->o_att_array) && $activity->o_att_array[$outcome->id] >=1)
                                                <h5>Activity {{ $index4 + 1 }}</h5>
                                                <p>A rubric was used in the {{ $section->code }}-{{ $section->number }} ({{ $section->name }}) course ({{ date('M Y', strtotime($course->updated_at))}}) to assess students’ <u>{{ strtolower($outcome->name) }}</u> in the activity: "{{ $activity->name }}". N= {{ count($section->students) }}. </p>  
                                                <p>The expected performance level was that {{ $activity->rubric->expected_percentage }}% of students participating in the activity would score {{ $activity->rubric->expected_points }} points or more in the 1-8 point scale used.</p>
                                                <p>The results for each criterion were as follows:</p>
                                                
                                                <table class="table table-condensed table-bordered">
                                                    <tbody>
                                                        @foreach((array)$activity->cap_array as $index5 => $cap)
                                                            <tr>
                                                            @if(Criterion::find($index5)['outcome_id'] == $outcome->id && $cap >= $activity->rubric->expected_percentage )
                                                                <td>{{ Criterion::find($index5)['name'] }}</td>
                                                                <td class="col-md-1 success">{{ $cap }}%</td>
                                                            @elseif(Criterion::find($index5)['outcome_id'] == $outcome->id && $cap < $activity->rubric->expected_percentage )
                                                                <td>{{ Criterion::find($index5)['name'] }}</td>
                                                                <td class="col-md-1 danger">{{ $cap }}%</td>
                                                            @endif
                                                            </tr>
                                                        @endforeach
                                                    </tbody>
                                                </table>

                                                <ul>
                                                        
                                                </ul>
                                                <p>

                                                <?php 
                                                    $o_att_array = $activity->o_att_array;
                                                    $o_ach_array = $activity->o_ach_array;
                                                    $percentage = ($o_ach_array[$outcome->id]/$o_att_array[$outcome->id])*100;
                                                ?>
                                                @if($percentage >= 100)
                                                    The expected goal was reached in <strong>all</strong> (100%) of the criteria assessed. Therefore, the goal for this outcome ({{ $outcome->expected_outcome }}%) was <strong>met</strong>.
                                                @elseif ($percentage < 1)
                                                    The expected goal was reached in <strong>none</strong> (0%) of the criteria assessed. Therefore, the goal for this outcome ({{ $outcome->expected_outcome }}%) was <strong>not met</strong>.
                                                @elseif ($percentage >= $outcome->expected_outcome)
                                                    The expected goal was reached in <strong>{{ $o_ach_array[$outcome->id] }}</strong> out of the <strong>{{ $o_att_array[$outcome->id] }}</strong> ({{ round($percentage, 2) }}%) criteria assessed. Therefore, the goal for this outcome ({{ $outcome->expected_outcome }}%) was <strong>met</strong>.
                                                @elseif ($percentage < $outcome->expected_outcome)
                                                    The expected goal was reached in <strong>{{ $o_ach_array[$outcome->id] }}</strong> out of the <strong>{{ $o_att_array[$outcome->id] }}</strong> ({{ round($percentage, 2) }}%) criteria assessed. Therefore, the goal for this outcome ({{ $outcome->expected_outcome }}%) was <strong> not met</strong>.
                                                @endif
                                                </p>

                                                <h5>Transformative Actions</h5>
                                                @if($activity->transforming_actions)
                                                    {{ $activity->transforming_actions }}
                                                @else
                                                    None
                                                @endif
                                                <br><br>

                                            @else
                                                <h5>Activity {{ $index4 + 1 }}</h5>
                                                <em>Outcome not measured.</em>
                                            @endif
                                        @endforeach
                                    @endforeach
                                <hr>    
                                @endif                            
                            @endforeach
                            </td>
                        </tr>
                    @else
                        <tr>
                            <td id="{{ $outcome->id }}-{{ $school->id }}-{{ $program->id }}" class="program no-courses col-md-3" >{{ $program->name }}</td>
                            <td class="col-md-9">
                                This program does not assess {{ $outcome->name }}.
                            </td>
                        </tr>
                    @endif
                @endforeach
                </tbody>
            </table>
            @endforeach
        </div>
    </div>
@stop

@section('javascript')

// Build table of contents
var outcome = $('.outcome');
var str ='';
str+='<li><a href="#'+outcome.attr('id')+'">'+outcome.text()+'</a><ol class="schools upper-alpha">';

$('[id^='+outcome.attr('id')+'-].school').each(function(e){
    var school = $(this);
    str+='<li><a href="#'+school.attr('id')+'">'+school.text()+'</a><ol class="programs">';
    
    $('[id^='+school.attr('id')+'-].program').each(function(e){

        var program = $(this);
        if(!program.hasClass('no-courses'))
            str+='<li><a href="#'+program.attr('id')+'">'+program.text()+'</a></li>';
        else
            str+='<li>'+program.text()+'</li>';

    });
    
    str+='</ol></li>';
});

str+='</ol></li>';
console.log(str);
$('#table-of-contents').append(str);


// ----------------------------------------------------------------------------
// Events
//

$('.to-top').on('click', function(e) {
    e.preventDefault();

     $(this).scrollTop(0);
    $('html').animate({scrollTop:0}, 1);
    $('body').animate({scrollTop:0}, 1);
})

@stop