コード例 #1
0
 /**
  * Generates a big graph with the number of best results
  * @param	array
  */
 static function generate_exercise_result_graph($attempts)
 {
     $exercise_title = strip_tags($attempts['title']);
     $attempts = $attempts['data'];
     $my_exercise_result_array = $exercise_result = array();
     if (empty($attempts)) {
         return null;
     }
     foreach ($attempts as $attempt) {
         if (api_get_user_id() == $attempt['exe_user_id']) {
             if ($attempt['exe_weighting'] != 0) {
                 $my_exercise_result_array[] = $attempt['exe_result'] / $attempt['exe_weighting'];
             }
         } else {
             if ($attempt['exe_weighting'] != 0) {
                 $exercise_result[] = $attempt['exe_result'] / $attempt['exe_weighting'];
             }
         }
     }
     //Getting best result
     rsort($my_exercise_result_array);
     $my_exercise_result = 0;
     if (isset($my_exercise_result_array[0])) {
         $my_exercise_result = $my_exercise_result_array[0] * 100;
     }
     $max = 100;
     $pieces = 5;
     $part = round($max / $pieces);
     $x_axis = array();
     $final_array = array();
     $my_final_array = array();
     for ($i = 1; $i <= $pieces; $i++) {
         $sum = 1;
         if ($i == 1) {
             $sum = 0;
         }
         $min = ($i - 1) * $part + $sum;
         $max = $i * $part;
         $x_axis[] = $min . " - " . $max;
         $count = 0;
         foreach ($exercise_result as $result) {
             $percentage = $result * 100;
             if ($percentage >= $min && $percentage <= $max) {
                 $count++;
             }
         }
         $final_array[] = $count;
         if ($my_exercise_result >= $min && $my_exercise_result <= $max) {
             $my_final_array[] = 1;
         } else {
             $my_final_array[] = 0;
         }
     }
     //Fix to remove the data of the user with my data
     for ($i = 0; $i <= count($my_final_array); $i++) {
         if (!empty($my_final_array[$i])) {
             $my_final_array[$i] = $final_array[$i] + 1;
             //Add my result
             $final_array[$i] = 0;
         }
     }
     // Dataset definition
     $dataSet = new pData();
     $dataSet->addPoints($final_array, 'Serie1');
     $dataSet->addPoints($my_final_array, 'Serie2');
     $dataSet->addPoints($x_axis, 'Serie3');
     $dataSet->setSerieDescription('Serie1', get_lang('Score'));
     $dataSet->setSerieDescription('Serie2', get_lang('MyResults'));
     $dataSet->setAbscissa('Serie3');
     $dataSet->setXAxisName(get_lang('Score'));
     $dataSet->normalize(100, "%");
     $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true);
     // 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 {
         /* Create the pChart object */
         $widthSize = 480;
         $heightSize = 250;
         $fontSize = 8;
         $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));
         /* Write the chart title */
         $myPicture->drawText(250, 20, $exercise_title, array('FontSize' => 12, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE));
         /* Define the chart area */
         $myPicture->setGraphArea(50, 50, $widthSize - 20, $heightSize - 30);
         /* Draw the scale */
         $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_MANUAL, 'ManualScale' => array('0' => array('Min' => 0, 'Max' => 100)));
         $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('DisplayValues' => true, 'DisplaySize' => $fontSize, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayOrientation' => ORIENTATION_HORIZONTAL, 'Gradient' => false, 'Surrounding' => 30, 'InnerSurrounding' => 25);
         $myPicture->drawStackedBarChart($settings);
         $legendSettings = array('Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER);
         $myPicture->drawLegend($widthSize / 2, 30, $legendSettings);
         /* 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;
     }
     return $imgPath;
 }
コード例 #2
0
 /**
  * This method return a graph containing information about evaluations
  * inside courses in sessions, it's used inside get_block method for
  * showing it inside dashboard interface
  * @return string  img html
  */
 public function get_evaluations_courses_in_sessions_graph()
 {
     $graphs = array();
     if (!empty($this->sessions)) {
         $session_ids = array_keys($this->sessions);
         foreach ($session_ids as $session_id) {
             $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id));
             $courses_graph = array();
             foreach ($courses_code as $course_code) {
                 $cats = Category::load(null, null, $course_code, null, null, $session_id);
                 if (isset($cats) && isset($cats[0])) {
                     $alleval = $cats[0]->get_evaluations(null, true, $course_code);
                     $alllinks = $cats[0]->get_links(null, true);
                     $users = GradebookUtils::get_all_users($alleval, $alllinks);
                     $datagen = new FlatViewDataGenerator($users, $alleval, $alllinks);
                     $evaluation_sumary = $datagen->get_evaluation_sumary_results();
                     if (!empty($evaluation_sumary)) {
                         $items = array_keys($evaluation_sumary);
                         $max = $min = $avg = array();
                         foreach ($evaluation_sumary as $evaluation) {
                             $max[] = $evaluation['max'];
                             $min[] = $evaluation['min'];
                             $avg[] = $evaluation['avg'];
                         }
                         // Dataset definition
                         $dataSet = new pData();
                         $dataSet->addPoints($min, 'Serie3');
                         $dataSet->addPoints($avg, 'Serie2');
                         $dataSet->addPoints($max, 'Serie1');
                         $dataSet->addPoints($items, 'Labels');
                         $dataSet->setSerieDescription('Serie1', get_lang('Max'));
                         $dataSet->setSerieDescription('Serie2', get_lang('Avg'));
                         $dataSet->setSerieDescription('Serie3', get_lang('Min'));
                         $dataSet->setAbscissa('Labels');
                         $dataSet->setAbscissaName(get_lang('EvaluationName'));
                         $dataSet->normalize(100, '%');
                         $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true);
                         // 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 {
                             /* Create the pChart object */
                             $widthSize = $this->bg_width;
                             $heightSize = $this->bg_height;
                             $fontSize = 8;
                             $angle = 50;
                             $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(50, 30, $widthSize - 20, $heightSize - 100);
                             /* Draw the scale */
                             $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_MANUAL, 'ManualScale' => array('0' => array('Min' => 0, 'Max' => 100)), '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('DisplayValues' => true, 'DisplaySize' => $fontSize, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayOrientation' => ORIENTATION_HORIZONTAL, 'Gradient' => false, 'Surrounding' => 30, 'InnerSurrounding' => 25);
                             $myPicture->drawStackedBarChart($settings);
                             $legendSettings = array('Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER);
                             $myPicture->drawLegend($widthSize / 2, 15, $legendSettings);
                             /* 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;
                         }
                         if (!empty($imgPath)) {
                             $courses_graph[$course_code] = '<img src="' . $imgPath . '">';
                         }
                     }
                 }
             }
             if (!empty($courses_graph)) {
                 $graphs[$session_id] = $courses_graph;
             }
         }
     }
     return $graphs;
 }