/**
  * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  * @return string  content html
  */
 public function get_teachers_information_graph()
 {
     $teachers = $this->teachers;
     $graph = '';
     $user_ids = array_keys($teachers);
     $a_last_week = get_last_week();
     if (is_array($user_ids) && count($user_ids) > 0) {
         $data_set = new pData();
         foreach ($user_ids as $user_id) {
             $teacher_info = api_get_user_info($user_id);
             $username = $teacher_info['username'];
             $time_by_days = array();
             foreach ($a_last_week as $day) {
                 // day is received as y-m-d 12:00:00
                 $start_date = api_get_utc_datetime($day);
                 $end_date = api_get_utc_datetime($day + (3600 * 24 - 1));
                 $time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date);
                 $hours = floor($time_on_platform_by_day / 3600);
                 $min = floor(($time_on_platform_by_day - $hours * 3600) / 60);
                 $time_by_days[] = $min;
             }
             $data_set->AddPoint($time_by_days, $username);
             $data_set->AddSerie($username);
         }
         $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]);
         $days_on_week = array();
         foreach ($a_last_week as $weekday) {
             $days_on_week[] = date('d/m', $weekday);
         }
         $data_set->AddPoint($days_on_week, "Days");
         $data_set->SetXAxisName($last_week);
         $data_set->SetYAxisName(get_lang('Minutes'));
         $data_set->SetAbsciseLabelSerie("Days");
         $graph_id = $this->user_id . 'TeacherConnectionsGraph';
         $cache = new pCache();
         // the graph id
         $data = $data_set->GetData();
         if ($cache->IsInCache($graph_id, $data_set->GetData())) {
             //if we already created the img
             $img_file = $cache->GetHash($graph_id, $data_set->GetData());
         } else {
             // Initializing the graph
             $bg_width = 440;
             $bg_height = 350;
             $test = new pChart($bg_width + 10, $bg_height + 20);
             $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
             $test->setGraphArea(65, 30, $bg_width - 70, $bg_height - 50);
             $test->drawFilledRoundedRectangle(7, 7, $bg_width, $bg_height, 5, 240, 240, 240);
             $test->drawRoundedRectangle(5, 5, $bg_width + 2, $bg_height + 2, 5, 230, 230, 230);
             $test->drawGraphArea(255, 255, 255, TRUE);
             $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE);
             $test->drawGrid(4, TRUE, 230, 230, 230, 50);
             // Drawing lines
             //$test->drawLineGraph($data_set->GetData(),$data_set->GetDataDescription());
             $test->drawFilledCubicCurve($data_set->GetData(), $data_set->GetDataDescription(), 0.1, 30);
             //$test->drawPlotGraph($data_set->GetData(),$data_set->GetDataDescription(),3,2,255,255,255);
             // Drawing Legend
             $test->setFontProperties(api_get_path(LIBRARY_PATH) . 'pchart/fonts/tahoma.ttf', 8);
             $test->drawLegend($bg_width - 80, 20, $data_set->GetDataDescription(), 204, 204, 255);
             $test->writeValues($data_set->GetData(), $data_set->GetDataDescription(), array("Days"));
             $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;
 }
Exemplo n.º 2
0
    public function get_teachers_content_html_for_drh()
    {
        $teachers = $this->teachers;
        //$content = '<div style="margin:10px;">';
        $content = '<h4>' . get_lang('YourTeachers') . '</h4>';
        $teachers_table = null;
        if (count($teachers) > 0) {
            $a_last_week = get_last_week();
            $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]);
            $teachers_table .= '<table class="data_table" width:"95%">';
            $teachers_table .= '
								<tr>
									<th>' . get_lang('User') . '</th>
									<th>' . get_lang('TimeSpentLastWeek') . '<br />' . $last_week . '</th>
								</tr>
							';
            $i = 1;
            foreach ($teachers as $teacher) {
                $teacher_id = $teacher['user_id'];
                $firstname = $teacher['firstname'];
                $lastname = $teacher['lastname'];
                $username = $teacher['username'];
                $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($teacher_id, true));
                if ($i % 2 == 0) {
                    $class_tr = 'row_odd';
                } else {
                    $class_tr = 'row_even';
                }
                $teachers_table .= '<tr class="' . $class_tr . '">
										<td>' . api_get_person_name($firstname, $lastname) . ' (' . $username . ')</td>
										<td align="right">' . $time_on_platform . '</td>
									</tr>';
                $i++;
            }
            $teachers_table .= '</table>';
        } else {
            $teachers_table .= get_lang('ThereIsNoInformationAboutYourTeachers');
        }
        $content .= $teachers_table;
        if (count($teachers) > 0) {
            $content .= '<div style="text-align:right;margin-top:10px;"><a href="' . api_get_path(WEB_CODE_PATH) . 'mySpace/teachers.php">' . get_lang('SeeMore') . '</a></div>';
        }
        //$content .= '</div>';
        return $content;
    }
 /**
  * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  * @return string  content html
  */
 public function get_teachers_information_graph()
 {
     $teachers = $this->teachers;
     $graph = '';
     $user_ids = array_keys($teachers);
     $a_last_week = get_last_week();
     if (is_array($user_ids) && count($user_ids) > 0) {
         $dataSet = new pData();
         foreach ($user_ids as $user_id) {
             $teacher_info = api_get_user_info($user_id);
             $username = $teacher_info['username'];
             $time_by_days = array();
             foreach ($a_last_week as $day) {
                 // day is received as y-m-d 12:00:00
                 $start_date = api_get_utc_datetime($day);
                 $end_date = api_get_utc_datetime($day + (3600 * 24 - 1));
                 $time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date);
                 $hours = floor($time_on_platform_by_day / 3600);
                 $min = floor(($time_on_platform_by_day - $hours * 3600) / 60);
                 $time_by_days[] = $min;
             }
             $dataSet->addPoints($time_by_days, $username);
         }
         $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]);
         $days_on_week = array();
         foreach ($a_last_week as $weekday) {
             $days_on_week[] = date('d/m', $weekday);
         }
         $dataSet->addPoints($days_on_week, 'Days');
         $dataSet->setAbscissaName($last_week);
         $dataSet->setAxisName(0, get_lang('Minutes'));
         $dataSet->setAbscissa('Days');
         $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 = 440;
             $heightSize = 350;
             $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(40, 40, $widthSize - 20, $heightSize - 80);
             /* Draw the scale */
             $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_ADDALL_START0, '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, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0);
             $myPicture->drawFilledSplineChart($settings);
             $myPicture->drawLegend(40, 20, array('Mode' => LEGEND_HORIZONTAL));
             /* 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;
 }