@extends('layouts.master')

@section('navigation')
    @if(Auth::user()->role==1)
        @include('local.managers.admins._navigation')
    @elseif(Auth::user()->role==2)
        @include('local.managers.sCoords._navigation')
    @elseif(Auth::user()->role==3)
        @include('local.managers.pCoords._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>
         

                                <!-- For each grouped course -->
                                <ul id = "levelTabs" class="nav nav-tabs" role="tablist">
                                        
                                   
                                @foreach($courses as $index2=>$course)
                              
                            
                          
                                   <li role= "presentation">
                                        <a data-toggle = "tab" href ="#{{ $course->code}}-{{ $course->number }}"
                                            role ="tab">{{ $course->code}}-{{ $course->number }}</a>
                                        </li>
                            @endforeach
                                </ul>
                                <div id="allLists" class="tab-content">
                                   
                                


                           @foreach($courses as $index2=>$course)

                           <?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();*/


                           $sections_evaluating = Course::has('activities')
               
               //->whereNotNull('outcomes_attempted')
               //->whereRaw('outcomes_attempted not like \'%"'.$outcome->id.'":0%\'')
               ->with(array('activities'=>function($query) use(&$course){
                   $activities = DB::table('activities')
                   ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
                   ->join('assessments', 'assessments.activity_criterion_id', '=','activity_criterion.id')
                   //->join('criterion_objective_outcome', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
                   ->join('courses','courses.id','=','activities.course_id')
                   ->where('courses.code',$course->code)
                   ->where('courses.number',$course->number)
                   ->where('activities.draft',0)
                   ->where('activities.diagnostic',0)
                   //->where('criterion_objective_outcome.outcome_id', $outcome->id)
                   ->select('activity_id')
                   ->lists('activity_id');

                   //$query->whereNotNull('outcomes_attempted');
                   //$query->whereRaw('outcomes_attempted not like \'%"'.$outcome->id.'":0%\'');
               $query->whereIn('activities.id', $activities);
           } ))
                   

               ->where('code', $course->code)->where('number',$course->number)
               ->where('user_id',Auth::user()->id)
               ->whereIn('semester_id', Session::get('semesters_ids'))
               ->orderBy('semester_id')
               ->get();
               
              
                       ?>

                            
                            <div role = "tabpanel" class = 'tab-pane' id = "{{$course->code}}-{{$course->number}}">
                                @foreach($sections_evaluating as $index3 => $section)
                                <h3 style="text-align: center"> Course: {{$course->code}} {{$course->number}}-{{$section->section}}</h3> 
                                <?php
                                Log::info($section->publishedActivities);
                                ?>
                                @foreach($section->publishedActivities as $index4 => $activity)

                                <h5 style="display: inline;">Activity {{$index4+1}}: </h5>
                                <p style="display: inline;">{{$activity->name}} <strong>({{$activity->date}})</strong></p>
                                <br>
                                <br>
                                <h5 style="display: inline;">Performance Indicators: </h5>
                                    <?php
                                    Log::info($activity->rubric[0]);
                                    ?>
                                <p style="display: inline;"><i>{{$activity->rubric[0]->num_scales}} (
                                <?php
                                    $titles = $activity->rubric[0]->getTitles();
                                    ?>
                                @if(sizeof($titles) != 1)
                                    @foreach ($titles as $index5=>$rubric_title)
                                        @if($index5!= ($activity->rubric[0]->num_scales)-1 )
                                            {{$rubric_title->text}},
                                        @else
                                            and {{$rubric_title->text}}
                                        @endif
                                            
                                    @endforeach
                                )
                                @else
                                    {{$titles[0]->text}} )
                                @endif
                                </i></p>
                                <br>
                                <h5 style="display: inline;">Scale: </h5>
                                @if($activity->rubric[0]->max_score == 1)

                               <p style="display: inline;">1 point scale</p>
                                @else
                                <p style="display: inline;">1-{{$activity->rubric[0]->max_score}} point scale</p>

                                @endif
                                <br>
                                <br>
                                <h4>Perfomance by Learning Outcome Criteria</h4>
                                <h5 style = "display: inline; margin:30px;">Target by criterion: </h5>
                                <p  style = "display: inline;"> <i>{{$activity->rubric[0]->expected_points}} or more</i>
                                </p>
                                <br>
                                <h5 style = "display: inline; margin:30px;">Expected percent of students achieving the target by criterion: </h5>
                                <p  style = "display: inline;"> <i>{{$activity->rubric[0]->expected_percentage}} %</i>
                                </p>
                                <br>

                                <table class='table table-striped table-condensed datatable'>
                                <thead>
                                    <tr>
                                        <th>
                                            Criterion
                                        </th>
                                        <th>
                                            Number of Students Assessed
                                        </th>
                                        <th>
                                            Number of students that achieved the target
                                        </th>
                                        <th>
                                            %
                                        </th>
                                        <th>
                                            Outcomes
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($activity->allActivityCriterionInfo() as $index5=>$ac_criterion)
                                    <tr>
                                        <td> {{$ac_criterion->name}}</td>
                                        <td>{{Criterion::students_attempted($ac_criterion->criterion_id, $activity->id)}}
                                        </td>
                                        <td>
                                        {{Criterion::students_achieved($ac_criterion->criterion_id, $activity->id)}}

                                        </td>
                                        <?php

                                        $out_att = Criterion::students_attempted($ac_criterion->criterion_id, $activity->id);
                                        $out_ach = Criterion::students_achieved($ac_criterion->criterion_id, $activity->id);
                                        
                                        $percentage = "N/A";
                                        $activity->getOutcomeReport();
                                        

                                        ?>
                                        
                                            @if($out_att==0)
                                            <td class="col-md-1 danger">{{ $percentage }}</td>

                                            @else
                                            <?php
                                            $percentage = round(($out_ach/$out_att)*100, 2)
                                            ?>
                                                @if ($percentage>=$activity->rubric[0]->expected_percentage)
                                                <td class="col-md-1 success">{{ $percentage }}%</td>
                                                                 
                                                @else
                                                <td class="col-md-1 danger">{{ $percentage }}%</td>
                                                      
                                                @endif



                                           @endif


                                        
                                        <td>
                                            
                                            
                                            @foreach(Criterion::outcomes($ac_criterion->criterion_id) as $index6=>$outcome)
                                            
                                             {{$index6 + 1}}.   <?php echo $outcome->name."\n\n\n <br>" ?>
                                             
                                            

                                            @endforeach
                                            
                                            
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            
                                </table>
                                <hr>
                                <br>

                                <h4>Perfomance by Learning Outcome Student</h4>
                                <h5 style = "display: inline; margin:30px;">Target by outcome: </h5>
                                <p  style = "display: inline;"> <i>>= 66.67% of the attempts</i>
                                </p>
                                <br>
                                <h5 style = "display: inline; margin:30px;">Expected percent of students achieving the target by outcome: </h5>
                                <p  style = "display: inline;"> <i> 
                                    <?php
                                     $expected = DB::table('target_outcomes_program')
        ->where('program_id', $course->program_id)
        ->where('semester_id', $course->semester_id)
        ->first()->expected_target;

        
                                    ?>
                                    {{$expected}}
                                </i>
                                </p>
                                <br>
                                <table class='table table-striped table-condensed datatable'>
                                    <thead>
                                        <tr>
                                            <th>
                                                Outcome
                                            </th>
                                            <th>
                                                Number of Students Assessed
                                            </th>
                                            <th>
                                                Number of students that achieved the target
                                            </th>
                                            <th>
                                                %
                                            </th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($activity->getOutcomeReport() as $outcome)
                                        <tr>
                                            <td>
                                                {{$outcome->name}}
                                            </td>
                                            <td>
                                                {{$outcome->attempted}}
                                            </td>
                                            <td>
                                                {{$outcome->achieved}}
                                            </td>
                                            @if($outcome->percentage>= $expected)
                                                <td class="col-md-1 success">{{ $outcome->percentage }}%</td>
                                                                 
                                                @else
                                                <td class="col-md-1 danger">{{ $outcome->percentage }}%</td>
                                                      
                                                @endif



                                           

                                        </tr>

                                        @endforeach
                                    </tbody>
                                </table>

                                <br>
                                <hr>





                                
                                @endforeach
                            
                                @endforeach
                            </div>

                            

                                        @endforeach
                            

            


                                        
        </div>
    </div>

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

@section('javascript')



@stop