/**
  * This method return a graph containing information about students evaluation,
  * it's used inside get_block method for showing it inside dashboard interface
  * @return string  img html
  */
 public function get_students_attendance_graph()
 {
     $students = $this->students;
     $attendance = new Attendance();
     // get data
     $attendances_faults_avg = array();
     if (is_array($students) && count($students) > 0) {
         foreach ($students as $student) {
             $student_id = $student['user_id'];
             //$student_info = api_get_user_info($student_id);
             // get average of faults in attendances by student
             $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
             if (!empty($results_faults_avg)) {
                 $attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent'];
             } else {
                 $attendances_faults_avg[$student['lastname']] = 0;
             }
         }
     }
     arsort($attendances_faults_avg);
     $usernames = array_keys($attendances_faults_avg);
     $faults = array();
     foreach ($usernames as $username) {
         $faults[] = $attendances_faults_avg[$username];
     }
     $graph = '';
     $img_file = '';
     if (is_array($usernames) && count($usernames) > 0) {
         // Defining data
         $dataSet = new pData();
         $dataSet->addPoints($faults, 'Serie1');
         $dataSet->addPoints($usernames, 'Labels');
         $dataSet->setSerieDescription('Series1', get_lang('Average'));
         $dataSet->setSerieDescription('Labels', get_lang('User'));
         $dataSet->setAbscissa('Labels');
         $dataSet->setAbscissaName(get_lang('User'));
         $dataSet->setAxisName(0, get_lang('Attendance'));
         $palette = array('0' => array('R' => 186, 'G' => 206, 'B' => 151, 'Alpha' => 100), '1' => array('R' => 210, 'G' => 148, 'B' => 147, 'Alpha' => 100), '2' => array('R' => 148, 'G' => 170, 'B' => 208, 'Alpha' => 100), '3' => array('R' => 221, 'G' => 133, 'B' => 61, 'Alpha' => 100), '4' => array('R' => 65, 'G' => 153, 'B' => 176, 'Alpha' => 100), '5' => array('R' => 114, 'G' => 88, 'B' => 144, 'Alpha' => 100), '6' => array('R' => 138, 'G' => 166, 'B' => 78, 'Alpha' => 100), '7' => array('R' => 171, 'G' => 70, 'B' => 67, 'Alpha' => 100), '8' => array('R' => 69, 'G' => 115, 'B' => 168, 'Alpha' => 100));
         // Cache definition
         $cachePath = api_get_path(SYS_ARCHIVE_PATH);
         $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
         $chartHash = $myCache->getHash($dataSet);
         if ($myCache->isInCache($chartHash)) {
             $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
             $myCache->saveFromCache($chartHash, $imgPath);
             $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
         } else {
             $maxCounts = max(count($usernames), count($faults));
             if ($maxCounts < 5) {
                 $heightSize = 200;
             } else {
                 $heightSize = $maxCounts * 40;
             }
             /* Create the pChart object */
             $widthSize = 480;
             $angle = 40;
             $myPicture = new pImage($widthSize, $heightSize, $dataSet);
             /* Turn of Antialiasing */
             $myPicture->Antialias = false;
             /* Add a border to the picture */
             $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0));
             /* Set the default font */
             $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10));
             /* Do NOT Write the chart title */
             /* Define the chart area */
             $myPicture->setGraphArea(80, 40, $widthSize - 20, $heightSize - 40);
             /* Draw the scale */
             $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_ADDALL_START0, 'Pos' => SCALE_POS_TOPBOTTOM, 'DrawXLines' => false, 'LabelRotation' => $angle);
             $myPicture->drawScale($scaleSettings);
             /* Turn on shadow computing */
             $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
             /* Draw the chart */
             $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10));
             $settings = array('OverrideColors' => $palette, 'Gradient' => false, 'GradientMode' => GRADIENT_SIMPLE, 'DisplayPos' => LABEL_POS_TOP, 'DisplayValues' => true, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayShadow' => true, 'Surrounding' => 10);
             $myPicture->drawBarChart($settings);
             /* Write and save into cache */
             $myCache->writeToCache($chartHash, $myPicture);
             $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
             $myCache->saveFromCache($chartHash, $imgPath);
             $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
         }
         $graph = '<img src="' . $imgPath . '" >';
     } else {
         $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>';
     }
     return $graph;
 }
    public function get_students_content_html_for_drh()
    {
        $attendance = new Attendance();
        $students = $this->students;
        $content = '<div style="margin:5px;">';
        $content .= '<h3><font color="#000">' . get_lang('YourStudents') . '</font></h3>';
        $students_table = null;
        if (count($students) > 0) {
            $students_table .= '<table class="data_table">';
            $students_table .= '<tr>
									<th>' . get_lang('User') . '</th>
									<th>' . get_lang('AttendancesFaults') . '</th>
									<th>' . get_lang('Evaluations') . '</th>
								</tr>';
            $i = 1;
            foreach ($students as $student) {
                $student_id = $student['user_id'];
                $firstname = $student['firstname'];
                $lastname = $student['lastname'];
                $username = $student['username'];
                // get average of faults in attendances by student
                $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
                if (!empty($results_faults_avg)) {
                    $attendances_faults_avg = '<a title="' . get_lang('GoToStudentDetails') . '" href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $student_id . '">' . $results_faults_avg['faults'] . '/' . $results_faults_avg['total'] . ' (' . $results_faults_avg['porcent'] . '%)</a>';
                } else {
                    $attendances_faults_avg = '0%';
                }
                $courses_by_user = CourseManager::get_courses_list_by_user_id($student_id, true);
                $evaluations_avg = 0;
                $score = $weight = 0;
                foreach ($courses_by_user as $course) {
                    $course_code = $course['code'];
                    $cats = Category::load(null, null, $course_code, null, null, null, false);
                    $scoretotal = array();
                    if (isset($cats) && isset($cats[0])) {
                        $scoretotal = $cats[0]->calc_score($student_id, $course_code);
                    }
                    if (!empty($scoretotal)) {
                        $score += $scoretotal[0];
                        $weight += $scoretotal[1];
                    }
                }
                if (!empty($weight)) {
                    $evaluations_avg = '<a title="' . get_lang('GoToStudentDetails') . '" href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/myStudents.php?student=' . $student_id . '">' . round($score, 2) . '/' . round($weight, 2) . '(' . round($score / $weight * 100, 2) . ' %)</a>';
                }
                if ($i % 2 == 0) {
                    $class_tr = 'row_odd';
                } else {
                    $class_tr = 'row_even';
                }
                $students_table .= '<tr class="' . $class_tr . '">
										<td>' . api_get_person_name($firstname, $lastname) . ' (' . $username . ')</td>
										<td>' . $attendances_faults_avg . '</td>
										<td>' . $evaluations_avg . '</td>
									</tr>';
                $i++;
            }
            $students_table .= '</table>';
        } else {
            $students_table .= get_lang('ThereIsNoInformationAboutYourStudents');
        }
        $content .= $students_table;
        if (count($students) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;">
                            <a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/index.php?view=admin&display=yourstudents">' . get_lang('SeeMore') . '</a>
                         </div>';
        }
        $content .= '</div>';
        return $content;
    }
 /**
  * This method return a graph containing informations about students evaluation, it's used inside get_block method for showing it inside dashboard interface
  * @return string  img html
  */
 public function get_students_attendance_graph()
 {
     $students = $this->students;
     $attendance = new Attendance();
     // get data
     $attendances_faults_avg = array();
     if (is_array($students) && count($students) > 0) {
         foreach ($students as $student) {
             $student_id = $student['user_id'];
             //$student_info = api_get_user_info($student_id);
             // get average of faults in attendances by student
             $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id);
             if (!empty($results_faults_avg)) {
                 $attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent'];
             } else {
                 $attendances_faults_avg[$student['lastname']] = 0;
             }
         }
     }
     arsort($attendances_faults_avg);
     $usernames = array_keys($attendances_faults_avg);
     $faults = array();
     foreach ($usernames as $username) {
         $faults[] = $attendances_faults_avg[$username];
     }
     $graph = '';
     $img_file = '';
     if (is_array($usernames) && count($usernames) > 0) {
         // Defining data
         $data_set = new pData();
         $data_set->AddPoint($faults, "Promedio");
         $data_set->AddPoint($usernames, "Usuario");
         $data_set->AddAllSeries();
         $data_set->SetAbsciseLabelSerie("Usuario");
         // prepare cache for saving image
         $graph_id = $this->user_id . 'StudentEvaluationGraph';
         // the graph id
         $cache = new pCache(api_get_path(SYS_ARCHIVE_PATH));
         $data = $data_set->GetData();
         // return $this->DataDescription
         if ($cache->IsInCache($graph_id, $data_set->GetData())) {
             //if (0) {
             //if we already created the img
             $img_file = $cache->GetHash($graph_id, $data_set->GetData());
             // image file with hash
         } else {
             if (count($usernames) < 5) {
                 $height = 200;
             } else {
                 $height = count($usernames) * 40;
             }
             // Initialise the graph
             $test = new MyHorBar(400, $height + 30);
             $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
             $test->setGraphArea(100, 30, 370, $height);
             $test->drawFilledRoundedRectangle(7, 7, 393, $height, 5, 240, 240, 240);
             $test->drawRoundedRectangle(5, 5, 395, $height, 5, 230, 230, 230);
             $test->drawGraphArea(255, 255, 255, TRUE);
             //X axis
             $test->setFixedScale(0, 100, 10);
             //var_dump($data_set->GetDataDescription());
             $test->drawHorScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_ADDALL, 150, 150, 150, TRUE, 0, 0, TRUE);
             $test->setColorPalette(0, 255, 0, 0);
             $test->drawHorGrid(10, TRUE, 230, 230, 230, 50);
             // Draw the 0 line
             $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 6);
             $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
             // Draw the bar graph
             $test->drawHorBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE, 50);
             $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
             ob_start();
             $test->Stroke();
             ob_end_clean();
             $img_file = $cache->GetHash($graph_id, $data_set->GetData());
         }
         if (!empty($img_file)) {
             $graph = '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '">';
         }
     } else {
         $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>';
     }
     return $graph;
 }