@extends('layouts.master')

@section('navigation')
    @if ($role == 1)
        @include('local.managers.admins._new_navigation')
    @elseif($role == 2)
        @include('local.managers.sCoords._new_navigation')
    @elseif($role == 3)
        @include('local.managers.pCoords._new_navigation')
    @else
        @include('local.professors._navigation')
    @endif
@stop

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

            <h3 id="{{ $outcome->id }}" class="outcome">{{ $outcome->name }}</h3>
            <table class="table table-condensed table-bordered datatable">
                <thead>
                    <tr>
                        <th>Course</th>
                        <th>Program</th>
                        <th>Findings</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr class="column-search">
                        <th><input class="column-search-bar form-control" type="text" placeholder="Buscar" /></th>
                        <th><select class="column-search-select form-control">
                                <option value=""></option>
                            </select></th>
                        <th><input class="column-search-bar form-control" type="text" placeholder="Buscar" /></th>
                    </tr>
                </tfoot>
                <tbody>
                    <!-- For each grouped course -->
                    @foreach ($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)
                            ->whereIn('semester_id', Session::get('semesters_ids'))
                            ->get();
                        
                        $semester_code = DB::table('semesters')
                            ->where('id', '=', $course->semester_id)
                            ->first();
                        $program = DB::table('programs')
                            ->where('id', $course->program_id)
                            ->first();
                        
                        ?>

                        @if (count($sections_evaluating))
                            <tr>
                                <td>
                                    {{ $course->code }}-{{ $course->number }} ({{ $semester_code->code }})
                                </td>
                                <td>{{ $program->name }}</td>
                                <td>
                                    <!-- For each section -->
                                    @foreach ($sections_evaluating as $index3 => $section)
                                        <h5><u>Instance {{ $section->section }}</u></h5>

                                        <!-- For each activity in the section -->
                                        @foreach ($section->activities as $index4 => $activity)
                                            <?php Log::info($section);
                                            Log::info($section->activities);
                                            Log::info($activity->o_att_array);
                                            Log::info('this is the cap_array for ' . $activity->name);
                                            Log::info($activity->cap_array);
                                            Log::info('aqui papi'); ?>

                                            <!-- If activity is not draft, has a rubric and the rubric has the outcome being evaluated -->
                                            @if ($activity->draft == 0 && $activity->diagnostic == 0 && array_key_exists($outcome->id, (array) $activity->o_att_array))
                                                <h5>Measure {{ $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:
                                                    "<strong>{{ $activity->name }}</strong>". At the time of assessment
                                                    there were {{ $activity->amount_of_assessed_students() }} students in
                                                    the section.</p>
                                                <p>The expected performance level was that
                                                    <strong>{{ $activity->rubric[0]->expected_percentage }}%</strong> of
                                                    students participating in the activity would score
                                                    <strong>{{ $activity->rubric[0]->expected_points }} points</strong>
                                                    or more in the 1-{{ $activity->rubric[0]->max_score }} point scale
                                                    used.</p>
                                                <p>The results for each criterion were as follows:</p>

                                                <table class="table table-condensed table-bordered datatable">

                                                    @foreach ($activity->cap_array as $criterion_id => $criterion)
                                                        @if (in_array($outcome->id, json_decode($criterion->outcome_id)) /*== $outcome->id*/ && $criterion->score_percentage >= $activity->rubric[0]->expected_percentage)
                                                            <tr>
                                                                <td>{{ $criterion->name }}</td>
                                                                <td class="col-md-1 success">
                                                                    {{ $criterion->score_percentage }}%</td>
                                                            </tr>
                                                        @elseif(in_array($outcome->id, json_decode($criterion->outcome_id)) && $criterion->score_percentage < $activity->rubric[0]->expected_percentage)
                                                            <tr>
                                                                <td>{{ $criterion->name }}</td>
                                                                <td class="col-md-1 danger">
                                                                    {{ $criterion->score_percentage }}%</td>
                                                            </tr>
                                                        @endif
                                                    @endforeach
                                                </table>

                                                <ul>

                                                </ul>
                                                <p>

                                                    <?php
                                                    $o_att_array = $activity->o_att_array;
                                                    $o_ach_array = $activity->o_ach_array;
                                                    Log::info($o_att_array);
                                                    Log::info($o_ach_array);
                                                    Log::info('los outcomes');
                                                    $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><strong>Transforming Actions</strong></h5>
                                                @if ($activity->transforming_actions)
                                                    {{ $activity->transforming_actions }}
                                                @else
                                                    None
                                                @endif
                                            @elseif ($activity->draft == 0)
                                                <h5>Measure {{ $index4 + 1 }}</h5>
                                                <em>Outcome not measured.</em>
                                            @else
                                            @endif
                                        @endforeach
                                    @endforeach
                                </td>
                            </tr>
                        @else
                            <tr>
                                <td>
                                    <h4>{{ $course->code }}-{{ $course->number }}</h4>
                                </td>
                                <td>
                                    <p>No assessment.</p>
                                </td>
                            </tr>
                        @endif
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
@stop

@section('included-js')
    @include('global._datatables_js')
@stop

@section('javascript')

    // Hide tables that have no courses
    $('.no-courses').each(function() {

    //$(this).closest('tr').hide();

    });

    // Hide tables with empty bodies
    $('tbody').each(function() {
    if($(this).children(':visible').length==0)
    {
    //$(this).closest('table').hide();
    }
    });




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

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

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

@stop
