/** * Function used by SortableTable to generate the data to display */ public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) { $scoredisplay = ScoreDisplay::instance(); // determine sorting type switch ($this->column) { // Type case 0: $sorting = UserDataGenerator::UDG_SORT_TYPE; break; case 1: $sorting = UserDataGenerator::UDG_SORT_NAME; break; case 2: $sorting = UserDataGenerator::UDG_SORT_COURSE; break; case 3: $sorting = UserDataGenerator::UDG_SORT_CATEGORY; break; case 4: $sorting = UserDataGenerator::UDG_SORT_AVERAGE; break; case 5: $sorting = UserDataGenerator::UDG_SORT_SCORE; break; case 6: $sorting = UserDataGenerator::UDG_SORT_MASK; break; } if ($this->direction == 'DESC') { $sorting |= UserDataGenerator::UDG_SORT_DESC; } else { $sorting |= UserDataGenerator::UDG_SORT_ASC; } $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); // generate the data to display $sortable_data = array(); foreach ($data_array as $data) { if ($data[2] != "") { //filter by course removed $row = array(); $row[] = $this->build_type_column($data[0]); $row[] = $this->build_name_link($data[0]); $row[] = $data[2]; $row[] = $data[3]; $row[] = $data[4]; $row[] = $data[5]; if ($scoredisplay->is_custom()) { $row[] = $data[6]; } $sortable_data[] = $row; } } return $sortable_data; }
public function get_link() { $eval = $this->get_evaluation(); // course/platform admin can go to the view_results page if (api_is_allowed_to_edit()) { return 'gradebook_view_result.php?selecteval=' . $eval->get_id(); } elseif (ScoreDisplay::instance()->is_custom()) { return 'gradebook_statistics.php?selecteval=' . $eval->get_id(); } else { return null; } }
/** * Compare the custom display of 2 scores, can be useful in sorting */ public static function compare_scores_by_custom_display($score1, $score2) { if (!isset($score1)) { return isset($score2) ? 1 : 0; } elseif (!isset($score2)) { return -1; } else { $scoredisplay = ScoreDisplay::instance(); $custom1 = $scoredisplay->display_custom($score1); $custom2 = $scoredisplay->display_custom($score2); if ($custom1 == $custom2) { return 0; } else { return $score1[0] / $score1[1] < $score2[0] / $score2[1] ? -1 : 1; } } }
/** * Display gradebook graphs */ public function display_graph_by_resource() { $headerName = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); if (empty($customdisplays)) { echo get_lang('ToViewGraphScoreRuleMustBeEnabled'); return ''; } $user_results = $this->datagen->get_data_to_graph2(false); //if (empty($this->datagen->get_total_items_count()) || empty($total_users)) { if (empty($user_results) || empty($total_users)) { echo get_lang('NoResults'); return ''; } // Removing first name array_shift($headerName); // Removing last name array_shift($headerName); $pre_result = $new_result = array(); foreach ($user_results as $result) { for ($i = 0; $i < count($headerName); $i++) { if (isset($result[$i + 1])) { $pre_result[$i + 3][] = $result[$i + 1]; } } } $i = 0; $show_draw = false; $resource_list = array(); $pre_result2 = array(); foreach ($pre_result as $key => $res_array) { rsort($res_array); $pre_result2[] = $res_array; } //@todo when a display custom does not exist the order of the color does not match //filling all the answer that are not responded with 0 rsort($customdisplays); if ($total_users > 0) { foreach ($pre_result2 as $key => $res_array) { $key_list = array(); foreach ($res_array as $user_result) { $userResult = isset($user_result[1]) ? $user_result[1] : null; if (!isset($resource_list[$key][$userResult])) { $resource_list[$key][$userResult] = 0; } $resource_list[$key][$userResult] += 1; $key_list[] = $userResult; } foreach ($customdisplays as $display) { if (!in_array($display['display'], $key_list)) { $resource_list[$key][$display['display']] = 0; } } $i++; } } //fixing $resource_list $max = 0; $new_list = array(); foreach ($resource_list as $key => $value) { $new_value = array(); foreach ($customdisplays as $item) { if ($value[$item['display']] > $max) { $max = $value[$item['display']]; } $new_value[$item['display']] = strip_tags($value[$item['display']]); } $new_list[] = $new_value; } $resource_list = $new_list; $i = 1; foreach ($resource_list as $key => $resource) { // Reverse array, otherwise we get highest values first $resource = array_reverse($resource, true); $dataSet = new pData(); $dataSet->addPoints($resource, 'Serie'); $dataSet->addPoints(array_keys($resource), 'Labels'); $dataSet->setSerieDescription('Labels', strip_tags($headerName[$i - 1])); $dataSet->setAbscissa('Labels'); $dataSet->setAbscissaName(get_lang('GradebookSkillsRanking')); $dataSet->setAxisName(0, get_lang('Students')); $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 { /* Create the pChart object */ $widthSize = 480; $heightSize = 250; $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, 30, strip_tags($headerName[$i - 1]), array('FontSize' => 12, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE)); /* Define the chart area */ $myPicture->setGraphArea(50, 40, $widthSize - 20, $heightSize - 50); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_START0); $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); /* Render the picture (choose the best way) */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } echo '<img src="' . $imgPath . '" >'; if ($i % 2 == 0 && $i != 0) { echo '<br /><br />'; } else { echo ' '; } $i++; } }
static function register_user_certificate($category_id, $user_id) { // generating the total score for a course $cats_course = Category::load($category_id, null, null, null, null, null, false); $alleval_course = $cats_course[0]->get_evaluations($user_id, true); $alllink_course = $cats_course[0]->get_links($user_id, true); $evals_links = array_merge($alleval_course, $alllink_course); $item_total = 0; //@todo move these in a function $sum_categories_weight_array = array(); if (isset($cats_course) && !empty($cats_course)) { $categories = Category::load(null, null, null, $category_id); if (!empty($categories)) { foreach ($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); } } else { $sum_categories_weight_array[$category_id] = $cats_course[0]->get_weight(); } } $main_weight = $cats_course[0]->get_weight(); $item_total_value = 0; $item_value = 0; for ($count = 0; $count < count($evals_links); $count++) { $item = $evals_links[$count]; $score = $item->calc_score($user_id); $divide = $score[1] == 0 ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; $item_value = $score[0] / $divide * $item->get_weight() * $sub_cat_percentage / $main_weight; $item_total_value += $item_value; } $item_total_value = (double) $item_total_value; $cattotal = Category::load($category_id); $scoretotal = $cattotal[0]->calc_score($user_id); //Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global $scoredisplay = ScoreDisplay::instance(); $my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); //Show certificate $certificate_min_score = $cats_course[0]->get_certificate_min_score(); $scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition if (isset($certificate_min_score) && $item_total_value >= $certificate_min_score) { $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); if (empty($my_certificate)) { register_user_info_about_certificate($category_id, $user_id, $my_score_in_gradebook, api_get_utc_datetime()); $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); } if (!empty($my_certificate)) { $certificate_obj = new Certificate($my_certificate['id']); $url = Certificate::getCertificatePublicURL($my_certificate['id']); $certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 32), $url, array('target' => '_blank')); $html = '<div class="actions" align="right">'; $html .= Display::url($url, $url, array('target' => '_blank')); $html .= $certificates; $html .= '</div>'; return $html; } } else { return false; } }
/** * @param FlatViewTable $flatviewtable * @param Category $cat * @param $users * @param $alleval * @param $alllinks * @param array $params * @param null $mainCourseCategory */ public static function export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params = array(), $mainCourseCategory = null) { // Getting data $printable_data = self::get_printable_data($cat[0], $users, $alleval, $alllinks, $params, $mainCourseCategory); // HTML report creation first $course_code = trim($cat[0]->get_course_code()); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); $total = array(); if (is_array($customdisplays) && count($customdisplays)) { foreach ($customdisplays as $custom) { $total[$custom['display']] = 0; } $user_results = $flatviewtable->datagen->get_data_to_graph2(false); foreach ($user_results as $user_result) { $total[$user_result[count($user_result) - 1][1]]++; } } $parent_id = $cat[0]->get_parent_id(); if (isset($cat[0]) && isset($parent_id)) { if ($parent_id == 0) { $grade_model_id = $cat[0]->get_grade_model_id(); } else { $parent_cat = Category::load($parent_id); $grade_model_id = $parent_cat[0]->get_grade_model_id(); } } $use_grade_model = true; if (empty($grade_model_id) || $grade_model_id == -1) { $use_grade_model = false; } if ($use_grade_model) { if ($parent_id == 0) { $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed'); } else { $title = api_strtoupper(get_lang('Average')) . '<br />' . $cat[0]->get_description() . ' - (' . $cat[0]->get_name() . ')'; } } else { if ($parent_id == 0) { $title = api_strtoupper(get_lang('Average')) . '<br />' . get_lang('Detailed'); } else { $title = api_strtoupper(get_lang('Average')); } } $columns = count($printable_data[0]); $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0; $table = new HTML_Table(array('class' => 'data_table')); $row = 0; $column = 0; $table->setHeaderContents($row, $column, get_lang('NumberAbbreviation')); $column++; foreach ($printable_data[0] as $printable_data_cell) { if (!is_array($printable_data_cell)) { $printable_data_cell = strip_tags($printable_data_cell); } $table->setHeaderContents($row, $column, $printable_data_cell); $column++; } $row++; if ($has_data) { $counter = 1; foreach ($printable_data[1] as &$printable_data_row) { $column = 0; $table->setCellContents($row, $column, $counter); $table->updateCellAttributes($row, $column, 'align="center"'); $column++; $counter++; foreach ($printable_data_row as $key => &$printable_data_cell) { $attributes = array(); $attributes['align'] = 'center'; $attributes['style'] = null; if ($key === 'name') { $attributes['align'] = 'left'; } if ($key === 'total') { $attributes['style'] = 'font-weight:bold'; } $table->setCellContents($row, $column, $printable_data_cell); $table->updateCellAttributes($row, $column, $attributes); $column++; } $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true); $row++; } } else { $column = 0; $table->setCellContents($row, $column, get_lang('NoResults')); $table->updateCellAttributes($row, $column, 'colspan="' . $columns . '" align="center" class="row_odd"'); } $pdfParams = array('filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(), 'pdf_title' => $title, 'course_code' => $course_code, 'add_signatures' => true); $page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4'; $pdf = new PDF($page_format, $page_format, $pdfParams); $pdf->html_to_pdf_with_template($flatviewtable->return_table()); exit; }
/** * @param $item * @param $ignore_score_color * @return string */ private function build_mask_column($item, $ignore_score_color) { $studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; $scoredisplay = ScoreDisplay::instance(); $displaytype = SCORE_DIV_PERCENT; if ($ignore_score_color) { $displaytype |= SCORE_IGNORE_SPLIT; } return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM); }
/** * @param int $userId * @param GradebookItem $item * @param $ignore_score_color * @return null|string */ private function build_result_column($userId, $item, $ignore_score_color, $forceSimpleResult = false) { $scoredisplay = ScoreDisplay::instance(); $score = $item->calc_score($userId); if (!empty($score)) { switch ($item->get_item_type()) { // category case 'C': if ($score != null) { $displaytype = SCORE_PERCENT; if ($ignore_score_color) { $displaytype |= SCORE_IGNORE_SPLIT; } if ($forceSimpleResult) { return array('display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, 'score_weight' => $score); } return array('display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, 'score_weight' => $score); } else { return array('display' => null, 'score' => $score, 'score_weight' => $score); } break; // evaluation and link // evaluation and link case 'E': case 'L': //if ($parentId == 0) { $scoreWeight = [$score[0] / $score[1] * $item->get_weight(), $item->get_weight()]; //} return array('display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, 'score_weight' => $scoreWeight); } } return array('display' => null, 'score' => null, 'score_weight' => null); }
/** * Function used by SortableTable to generate the data to display */ function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) { $is_western_name_order = api_is_western_name_order(); $scoredisplay = ScoreDisplay::instance(); // determine sorting type $col_adjust = $this->iscourse == '1' ? 1 : 0; switch ($this->column) { // first name or last name case 0 + $col_adjust: if ($is_western_name_order) { $sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME; } else { $sorting = ResultsDataGenerator::RDG_SORT_LASTNAME; } break; // first name or last name // first name or last name case 1 + $col_adjust: if ($is_western_name_order) { $sorting = ResultsDataGenerator::RDG_SORT_LASTNAME; } else { $sorting = ResultsDataGenerator::RDG_SORT_FIRSTNAME; } break; //Score //Score case 2 + $col_adjust: $sorting = ResultsDataGenerator::RDG_SORT_SCORE; break; case 3 + $col_adjust: $sorting = ResultsDataGenerator::RDG_SORT_MASK; break; } if ($this->direction == 'DESC') { $sorting |= ResultsDataGenerator::RDG_SORT_DESC; } else { $sorting |= ResultsDataGenerator::RDG_SORT_ASC; } $data_array = $this->datagen->get_data($sorting, $from, $this->per_page); // generate the data to display $sortable_data = array(); foreach ($data_array as $item) { $row = array(); if ($this->iscourse == '1') { $row[] = $item['result_id']; } if ($is_western_name_order) { $row[] = $item['firstname']; $row[] = $item['lastname']; } else { $row[] = $item['lastname']; $row[] = $item['firstname']; } $row[] = Display::bar_progress($item['percentage_score'], false, $item['score']); //$row[] = Display::bar_progress($item['percentage_score'], true); if ($scoredisplay->is_custom()) { $row[] = $item['display']; } if (!$this->forprint) { $row[] = $this->build_edit_column($item); } $sortable_data[] = $row; } return $sortable_data; }
/** * @param int $category_id * @param int $user_id * @return bool|string */ public static function register_user_certificate($category_id, $user_id) { $courseId = api_get_course_int_id(); $courseCode = api_get_course_id(); $sessionId = api_get_session_id(); // Generating the total score for a course $cats_course = Category::load($category_id, null, null, null, null, $sessionId, false); /** @var Category $category */ $category = $cats_course[0]; //@todo move these in a function $sum_categories_weight_array = array(); if (isset($cats_course) && !empty($cats_course)) { $categories = Category::load(null, null, null, $category_id); if (!empty($categories)) { foreach ($categories as $subCategory) { $sum_categories_weight_array[$subCategory->get_id()] = $subCategory->get_weight(); } } else { $sum_categories_weight_array[$category_id] = $cats_course[0]->get_weight(); } } $main_weight = $cats_course[0]->get_weight(); $cattotal = Category::load($category_id); $scoretotal = $cattotal[0]->calc_score($user_id); // Do not remove this the gradebook/lib/fe/gradebooktable.class.php // file load this variable as a global $scoredisplay = ScoreDisplay::instance(); $my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); // A student always sees only the teacher's repartition $scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT); if (!self::userFinishedCourse($user_id, $cats_course[0], 0, $courseCode, $sessionId, true)) { return false; } $skillToolEnabled = api_get_setting('skill.allow_skills_tool') == 'true'; $userHasSkills = false; if ($skillToolEnabled) { if (!$category->getGenerateCertificates()) { $skill = new Skill(); $skill->add_skill_to_user($user_id, $category_id, $courseId, $sessionId); } $objSkillRelUser = new SkillRelUser(); $userSkills = $objSkillRelUser->get_user_skills($user_id, $courseId, $sessionId); $userHasSkills = !empty($userSkills); if (!$category->getGenerateCertificates() && $userHasSkills) { return ['badge_link' => Display::url(get_lang('DownloadBadges'), api_get_path(WEB_CODE_PATH) . "gradebook/get_badges.php?user={$user_id}", array('target' => '_blank', 'class' => 'btn btn-default'))]; } } $my_certificate = GradebookUtils::get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); if (empty($my_certificate)) { GradebookUtils::register_user_info_about_certificate($category_id, $user_id, $my_score_in_gradebook, api_get_utc_datetime()); $my_certificate = GradebookUtils::get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); } $html = array(); if (!empty($my_certificate)) { $certificate_obj = new Certificate($my_certificate['id']); $fileWasGenerated = $certificate_obj->html_file_is_generated(); if (!empty($fileWasGenerated)) { $url = api_get_path(WEB_PATH) . 'certificates/index.php?id=' . $my_certificate['id']; $certificates = Display::url(Display::returnFontAwesomeIcon('download') . ' ' . get_lang('DownloadCertificate'), $url, array('target' => '_blank', 'class' => 'btn btn-sm btn-primary')); $exportToPDF = Display::url(Display::return_icon('pdf.png', get_lang('ExportToPDF'), array(), ICON_SIZE_MEDIUM), "{$url}&action=export"); $hideExportLink = api_get_setting('hide_certificate_export_link'); $hideExportLinkStudent = api_get_setting('hide_certificate_export_link_students'); if ($hideExportLink === 'true' || api_is_student() && $hideExportLinkStudent === 'true') { $exportToPDF = null; } $html = array('certificate_link' => $certificates, 'pdf_link' => $exportToPDF, 'pdf_url' => "{$url}&action=export"); if ($skillToolEnabled && $userHasSkills) { $html['badge_link'] = Display::url(get_lang('DownloadBadges'), api_get_path(WEB_CODE_PATH) . "gradebook/get_badges.php?user={$user_id}", array('target' => '_blank', 'class' => 'btn btn-default')); } } return $html; } }
/** * Gets the info about a gradebook certificate for a user by course * @param string The course code * @param int The user id * @return array if there is not information return false */ public static function get_info_gradebook_certificate($course_code, $user_id) { $tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $session_id = api_get_session_id(); if (empty($session_id)) { $session_condition = ' AND (session_id = "" OR session_id = 0 OR session_id IS NULL )'; } else { $session_condition = " AND session_id = {$session_id}"; } $sql = 'SELECT * FROM ' . $tbl_grade_certificate . ' WHERE cat_id = (SELECT id FROM ' . $tbl_grade_category . ' WHERE course_code = "' . Database::escape_string($course_code) . '" ' . $session_condition . ' LIMIT 1 ) AND user_id=' . intval($user_id); $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { $row = Database::fetch_array($rs, 'ASSOC'); $score = $row['score_certificate']; $category_id = $row['cat_id']; $cat = Category::load($category_id); $displayscore = ScoreDisplay::instance(); if (isset($cat) && $displayscore->is_custom()) { $grade = $displayscore->display_score(array($score, $cat[0]->get_weight()), SCORE_DIV_PERCENT_WITH_CUSTOM); } else { $grade = $displayscore->display_score(array($score, $cat[0]->get_weight())); } $row['grade'] = $grade; return $row; } return false; }
function sort_by_mask($item1, $item2) { $score1 = isset($item1['score']) ? array($item1['score'], $this->evaluation->get_max()) : null; $score2 = isset($item2['score']) ? array($item2['score'], $this->evaluation->get_max()) : null; return ScoreDisplay::compare_scores_by_custom_display($score1, $score2); }
/** * @param $form_name * @param null $action */ public function __construct($form_name, $action = null) { parent::__construct($form_name, 'post', $action); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); $nr_items = count($customdisplays) != '0' ? count($customdisplays) : '1'; $this->setDefaults(array('scorecolpercent' => $displayscore->get_color_split_value())); $this->addElement('hidden', 'maxvalue', '100'); $this->addElement('hidden', 'minvalue', '0'); $counter = 1; //setting the default values if (is_array($customdisplays)) { foreach ($customdisplays as $customdisplay) { $this->setDefaults(array('endscore[' . $counter . ']' => $customdisplay['score'], 'displaytext[' . $counter . ']' => $customdisplay['display'])); $counter++; } } $scorecol = array(); //settings for the colored score $this->addElement('header', get_lang('ScoreEdit')); if ($displayscore->is_coloring_enabled()) { $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>'); $this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array('size' => 5, 'maxlength' => 5, 'input-size' => 2)); if (api_get_setting('gradebook.teachers_can_change_score_settings') != 'true') { $this->freeze('scorecolpercent'); } $this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('scorecolpercent', 'maxvalue'), get_lang('Over100'), 'compare', '<='); $this->addRule(array('scorecolpercent', 'minvalue'), get_lang('UnderMin'), 'compare', '>'); } //Settings for the scoring system if ($displayscore->is_custom()) { $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>'); $this->addElement('static', null, null, get_lang('ScoreInfo')); $this->setDefaults(array('beginscore' => '0')); $this->addElement('text', 'beginscore', array(get_lang('Between'), null, '%'), array('size' => 5, 'maxlength' => 5, 'disabled' => 'disabled', 'input-size' => 2)); for ($counter = 1; $counter <= 20; $counter++) { $renderer =& $this->defaultRenderer(); $elementTemplateTwoLabel = '<div id=' . $counter . ' style="display: ' . ($counter <= $nr_items ? 'inline' : 'none') . ';"> <!-- BEGIN required --><span class="form_required">*</span> <!-- END required --> <label class="control-label">{label}</label> <div class="form-group"> <label class="col-sm-2 control-label"> </label> <div class="col-sm-1"> <!-- BEGIN error --><span class="form_error">{error}</span><br /> <!-- END error --> <b>' . get_lang('And') . '</b> </div> <div class="col-sm-2"> {element} </div> <div class="col-sm-1"> = </div> '; $elementTemplateTwoLabel2 = ' <div class="col-sm-2"> <!-- BEGIN error --><span class="form_error">{error}</span> <!-- END error --> {element} </div> <div class="col-sm-1"> <a href="javascript:plusItem(' . ($counter + 1) . ')"> <img style="display: ' . ($counter >= $nr_items ? 'inline' : 'none') . ';" id="plus-' . ($counter + 1) . '" src="' . Display::returnIconPath('add.png') . '" alt="' . get_lang('Add') . '" title="' . get_lang('Add') . '"></a> <a href="javascript:minItem(' . $counter . ')"> <img style="display: ' . ($counter >= $nr_items && $counter != 1 ? 'inline' : 'none') . ';" id="min-' . $counter . '" src="' . Display::returnIconPath('delete.png') . '" alt="' . get_lang('Delete') . '" title="' . get_lang('Delete') . '"></a> </div> </div> </div>'; $scorebetw = array(); $this->addElement('text', 'endscore[' . $counter . ']', null, array('size' => 5, 'maxlength' => 5, 'id' => 'txta-' . $counter, 'input-size' => 2)); $this->addElement('text', 'displaytext[' . $counter . ']', null, array('size' => 40, 'maxlength' => 40, 'id' => 'txtb-' . $counter)); $renderer->setElementTemplate($elementTemplateTwoLabel, 'endscore[' . $counter . ']'); $renderer->setElementTemplate($elementTemplateTwoLabel2, 'displaytext[' . $counter . ']'); $this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric'); $this->addRule(array('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<='); $this->addRule(array('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>'); } } if ($displayscore->is_custom()) { $this->addButtonSave(get_lang('Ok')); } }
public function get_data_to_graph2() { // do some checks on users/items counts, redefine if invalid values $usertable = array(); foreach ($this->users as $user) { $usertable[] = $user; } // sort users array usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name')); // generate actual data array $scoredisplay = ScoreDisplay::instance(); $data = array(); $displaytype = SCORE_DIV; $selected_users = $usertable; foreach ($selected_users as $user) { $row = array(); $row[] = $user[0]; // user id $item_value = 0; $item_total = 0; for ($count = 0; $count < count($this->evals_links); $count++) { $item = $this->evals_links[$count]; $score = $item->calc_score($user[0]); $divide = $score[1] == 0 ? 1 : $score[1]; $item_value += $score[0] / $divide * $item->get_weight(); $item_total += $item->get_weight(); $score_denom = $score[1] == 0 ? 1 : $score[1]; $score_final = $score[0] / $score_denom * 100; $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true))); } $total_score = array($item_value, $item_total); $score_final = $item_value / $item_total * 100; $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); $data[] = $row; } return $data; }
/** * Generates an HTML Certificate and fills the path_certificate field in the DB **/ public function generate($params = array()) { //The user directory should be set if (empty($this->certification_user_path) && $this->force_certificate_generation == false) { return false; } require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/gradebook_functions.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/scoredisplay.class.php'; $params['hide_print_button'] = isset($params['hide_print_button']) ? true : false; $my_category = Category::load($this->certificate_data['cat_id']); if (isset($my_category[0]) && $my_category[0]->is_certificate_available($this->user_id)) { $user = api_get_user_info($this->user_id); $scoredisplay = ScoreDisplay::instance(); $scorecourse = $my_category[0]->calc_score($this->user_id); $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'); // Prepare all necessary variables: $organization_name = api_get_setting('Institution'); //$portal_name = api_get_setting('siteName'); $stud_fn = $user['firstname']; $stud_ln = $user['lastname']; //@todo this code is not needed $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn . ' ' . $stud_ln, $my_category[0]->get_name(), $scorecourse_display); $certif_text = str_replace("\\n", "\n", $certif_text); //If the gradebook is related to skills we added the skills to the user $skill = new Skill(); $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id']); if (is_dir($this->certification_user_path)) { if (!empty($this->certificate_data)) { $new_content_html = get_user_certificate_content($this->user_id, $my_category[0]->get_course_code(), false, $params['hide_print_button']); if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) { $name = $this->certificate_data['path_certificate']; $my_path_certificate = $this->certification_user_path . basename($name); if (file_exists($my_path_certificate) && !empty($name) && !is_dir($my_path_certificate) && $this->force_certificate_generation == false) { //Seems that the file was already generated return true; } else { // Creating new name $name = md5($this->user_id . $this->certificate_data['cat_id']) . '.html'; $my_path_certificate = $this->certification_user_path . $name; $path_certificate = '/' . $name; //Getting QR filename $file_info = pathinfo($path_certificate); $qr_code_filename = $this->certification_user_path . $file_info['filename'] . '_qr.png'; $my_new_content_html = str_replace('((certificate_barcode))', Display::img($this->certification_web_user_path . $file_info['filename'] . '_qr.png', 'QR'), $new_content_html['content']); $my_new_content_html = mb_convert_encoding($my_new_content_html, 'UTF-8', api_get_system_encoding()); $result = @file_put_contents($my_path_certificate, $my_new_content_html); if ($result) { //Updating the path self::update_user_info_about_certificate($this->certificate_data['cat_id'], $this->user_id, $path_certificate); $this->certificate_data['path_certificate'] = $path_certificate; if ($this->html_file_is_generated()) { if (!empty($file_info)) { $text = $this->parse_certificate_variables($new_content_html['variables']); $this->generate_qr($text, $qr_code_filename); } } } return $result; } } } } } return false; }
/** * Updates the gradebook score custom values using the scoredisplay class of the * gradebook module * * @param array List of gradebook score custom values * * @author Guillaume Viguier <*****@*****.**> */ function update_gradebook_score_display_custom_values($values) { require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/scoredisplay.class.php'; $scoredisplay = ScoreDisplay::instance(); $scores = $values['gradebook_score_display_custom_values_endscore']; $displays = $values['gradebook_score_display_custom_values_displaytext']; $nr_displays = count($displays); $final = array(); for ($i = 1; $i < $nr_displays; $i++) { if (!empty($scores[$i]) && !empty($displays[$i])) { $final[$i]['score'] = $scores[$i]; $final[$i]['display'] = $displays[$i]; } } $scoredisplay->update_custom_score_display_settings($final); }
$interbreadcrumb[] = array('url' => $_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook')); $category = Category::load($_GET['selectcat']); $my_user_id = Security::remove_XSS($_GET['userid']); $allevals = $category[0]->get_evaluations($my_user_id, true); $alllinks = $category[0]->get_links($my_user_id, true); if ($_GET['selectcat'] != null) { $addparams = array('userid' => $my_user_id, 'selectcat' => Security::remove_XSS($_GET['selectcat'])); } else { $addparams = array('userid' => $my_user_id, 'selecteval' => Security::remove_XSS($_GET['selecteval'])); } $user_table = new UserTable($my_user_id, $allevals, $alllinks, $addparams); if (isset($_GET['exportpdf'])) { $datagen = new UserDataGenerator($my_user_id, $allevals, $alllinks); $data_array = $datagen->get_data(UserDataGenerator::UDG_SORT_NAME, 0, null, true); $newarray = array(); $displayscore = ScoreDisplay::instance(); foreach ($data_array as $data) { $newarray[] = array_slice($data, 1); } $userinfo = api_get_user_info($my_user_id); $html .= get_lang('Results') . ' : ' . api_get_person_name($userinfo['firstname'], $userinfo['lastname']) . ' (' . api_convert_and_format_date(null, DATE_FORMAT_SHORT) . ' ' . api_convert_and_format_date(null, TIME_NO_SEC_FORMAT) . ')'; if ($displayscore->is_custom()) { $header_names = array(get_lang('Evaluation'), get_lang('Course'), get_lang('Category'), get_lang('EvaluationAverage'), get_lang('Result'), get_lang('Display')); } else { $header_names = array(get_lang('Evaluation'), get_lang('Course'), get_lang('Category'), get_lang('EvaluationAverage'), get_lang('Result')); } $table = new HTML_Table(array('class' => 'data_table')); $row = 0; $column = 0; foreach ($header_names as $item) { $table->setHeaderContents($row, $column, $item);
/** * Generate name column * @param unknown_type $item * @return string */ private function build_name_link($item) { $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null; //$session_id = api_get_session_id(); switch ($item->get_item_type()) { // category case 'C': $prms_uri = '?selectcat=' . $item->get_id() . '&view=' . Security::remove_XSS($_GET['view']); if (isset($_GET['isStudentView'])) { if (isset($is_student) || isset($_SESSION['studentview']) && $_SESSION['studentview'] == 'studentview') { $prms_uri = $prms_uri . '&isStudentView=' . Security::remove_XSS($_GET['isStudentView']); } } $cat = new Category(); $show_message = $cat->show_message_resource_delete($item->get_course_code()); return ' <a href="' . Security::remove_XSS($_SESSION['gradebook_dest']) . $prms_uri . '">' . $item->get_name() . '</a>' . ($item->is_course() ? ' [' . $item->get_course_code() . ']' . $show_message : ''); // evaluation // evaluation case 'E': $cat = new Category(); $course_id = CourseManager::get_course_by_category($_GET['selectcat']); $show_message = $cat->show_message_resource_delete($course_id); // course/platform admin can go to the view_results page if (api_is_allowed_to_edit() && $show_message === false) { if ($item->get_type() == 'presence') { return ' ' . '<a href="gradebook_view_result.php?cidReq=' . $course_id . '&selecteval=' . $item->get_id() . '">' . $item->get_name() . '</a>'; } else { return ' ' . '<a href="gradebook_view_result.php?cidReq=' . $course_id . '&selecteval=' . $item->get_id() . '">' . $item->get_name() . '</a> ' . Display::label(get_lang('Evaluation')); } } elseif (ScoreDisplay::instance()->is_custom() && $show_message === false) { // students can go to the statistics page (if custom display enabled) return ' ' . '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">' . $item->get_name() . '</a>'; } elseif ($show_message === false && !api_is_allowed_to_edit() && !ScoreDisplay::instance()->is_custom()) { return ' ' . '<a href="gradebook_statistics.php?selecteval=' . $item->get_id() . '">' . $item->get_name() . '</a>'; } else { return '[' . get_lang('Evaluation') . '] ' . $item->get_name() . $show_message; } // link // link case 'L': $cat = new Category(); $course_id = CourseManager::get_course_by_category($_GET['selectcat']); $show_message = $cat->show_message_resource_delete($course_id); $url = $item->get_link(); if (isset($url) && $show_message === false) { $text = ' <a href="' . $item->get_link() . '">' . $item->get_name() . '</a>'; } else { $text = $item->get_name(); } $text .= " " . Display::label($item->get_type_name(), 'info') . $show_message; $cc = $this->currentcat->get_course_code(); if (empty($cc)) { $text .= ' [<a href="' . api_get_path(REL_COURSE_PATH) . $item->get_course_code() . '/">' . $item->get_course_code() . '</a>]'; } return $text; } }
/** * @param int $userid */ public static function display_header_user($userid) { $select_cat = intval($_GET['selectcat']); $user_id = $userid; $user = api_get_user_info($user_id); $catcourse = Category::load($select_cat); $scoredisplay = ScoreDisplay::instance(); $scorecourse = $catcourse[0]->calc_score($user_id); // generating the total score for a course $allevals = $catcourse[0]->get_evaluations($user_id, true); $alllinks = $catcourse[0]->get_links($user_id, true); $evals_links = array_merge($allevals, $alllinks); $item_value = 0; $item_total = 0; for ($count = 0; $count < count($evals_links); $count++) { $item = $evals_links[$count]; $score = $item->calc_score($user_id); $my_score_denom = $score[1] == 0 ? 1 : $score[1]; $item_value += $score[0] / $my_score_denom * $item->get_weight(); $item_total += $item->get_weight(); //$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT); } $item_value = number_format($item_value, 2, '.', ' '); $total_score = array($item_value, $item_total); $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT); //$scorecourse_display = (isset($scorecourse) ? $scoredisplay->display_score($scorecourse,SCORE_AVERAGE) : get_lang('NoResultsAvailable')); $cattotal = Category::load(0); $scoretotal = $cattotal[0]->calc_score($user_id); $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'); $image_syspath = UserManager::get_user_picture_path_by_id($userid, 'system', false, true); $image_size = getimagesize($image_syspath['dir'] . $image_syspath['file']); //Web path $image_path = UserManager::get_user_picture_path_by_id($userid, 'web', false, true); $image_file = $image_path['dir'] . $image_path['file']; $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . $user['complete_name'] . '" '; if ($image_size[0] > 200) { //limit display width to 200px $img_attributes .= 'width="200" '; } $info = '<div class="row"><div class="span3">'; $info .= '<div class="thumbnail"><img ' . $img_attributes . '/></div>'; $info .= '</div>'; $info .= '<div class="span6">'; $info .= get_lang('Name') . ' : <a target="_blank" href="' . api_get_path(WEB_CODE_PATH) . 'social/profile.php?u=' . $userid . '"> ' . $user['complete_name'] . '</a><br />'; if (api_get_setting('show_email_addresses') == 'true') { $info .= get_lang('Email') . ' : <a href="mailto:' . $user['email'] . '">' . $user['email'] . '</a><br />'; } $info .= get_lang('TotalUser') . ' : <b>' . $scorecourse_display . '</b>'; $info .= '</div>'; $info .= '</div>'; echo $info; }
/** * @param int $userId * @param GradebookItem $item * @param $ignore_score_color * @return null|string */ private function build_result_column($userId, $item, $ignore_score_color, $forceSimpleResult = false) { $scoredisplay = ScoreDisplay::instance(); $score = $item->calc_score($userId); if (!empty($score)) { switch ($item->get_item_type()) { // category case 'C': if ($score != null) { if ($forceSimpleResult) { return array('display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, 'score_weight' => $score); } return array('display' => $scoredisplay->display_score($score, SCORE_DIV), 'score' => $score, 'score_weight' => $score); } else { return array('display' => null, 'score' => $score, 'score_weight' => $score); } break; // evaluation and link // evaluation and link case 'E': case 'L': //if ($parentId == 0) { $scoreWeight = [$score[1] > 0 ? $score[0] / $score[1] * $item->get_weight() : 0, $item->get_weight()]; //} $display = $scoredisplay->display_score($score, SCORE_DIV); $type = $item->get_item_type(); if ($type == 'L' && get_class($item) == 'ExerciseLink') { $display = ExerciseLib::show_score($score[0], $score[1], false); } return array('display' => $display, 'score' => $score, 'score_weight' => $scoreWeight); } } return array('display' => null, 'score' => null, 'score_weight' => null); }
function display_graph_by_resource() { require_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pCache.class.php'; $header_name = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); $img_file = ''; if ($this->datagen->get_total_items_count() > 0 && $total_users > 0) { //Removing first name array_shift($header_name); //Removing last name array_shift($header_name); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); if (is_array($customdisplays) && count($customdisplays)) { $user_results = $this->datagen->get_data_to_graph2(); $pre_result = $new_result = array(); $DataSet = new pData(); //filling the Dataset foreach ($user_results as $result) { //print_r($result); for ($i = 0; $i < count($header_name); $i++) { $pre_result[$i + 3][] = $result[$i + 1]; } } $i = 0; $show_draw = false; $resource_list = array(); $pre_result2 = array(); foreach ($pre_result as $key => $res_array) { rsort($res_array); $pre_result2[] = $res_array; } //@todo when a display custom does not exist the order of the color does not match //filling all the answer that are not responded with 0 rsort($customdisplays); if ($total_users > 0) { foreach ($pre_result2 as $key => $res_array) { $key_list = array(); foreach ($res_array as $user_result) { $resource_list[$key][$user_result[1]] += 1; $key_list[] = $user_result[1]; } foreach ($customdisplays as $display) { if (!in_array($display['display'], $key_list)) { $resource_list[$key][$display['display']] = 0; } } $i++; } } //fixing $resource_list $max = 0; $new_list = array(); foreach ($resource_list as $key => $value) { $new_value = array(); foreach ($customdisplays as $item) { if ($value[$item['display']] > $max) { $max = $value[$item['display']]; } $new_value[$item['display']] = strip_tags($value[$item['display']]); } $new_list[] = $new_value; } $resource_list = $new_list; $i = 1; $j = 0; foreach ($resource_list as $key => $resource) { $new_resource_list = $new_resource_list_name = array(); $DataSet = new pData(); // Reverse array, otherwise we get highest values first $resource = array_reverse($resource, true); foreach ($resource as $name => $cant) { $DataSet->AddPoint($cant, "Serie" . $j); $DataSet->SetSerieName(strip_tags($name), "Serie" . $j); $j++; } //print_r($pre_result); print_r($header_name); // Dataset definition $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie(''); $DataSet->SetXAxisName(get_lang('GradebookSkillsRanking')); $DataSet->SetYAxisName(get_lang('Students')); $show_draw = true; // Cache definition $Cache = new pCache(); // the graph id $gradebook_id = intval($_GET['selectcat']); $graph_id = api_get_user_id() . 'ByResource' . $gradebook_id . api_get_course_id() . api_get_session_id(); if ($show_draw) { //if ($Cache->IsInCache($graph_id, $DataSet->GetData())) { if (0) { //if we already created the img we get the img file id //echo 'in cache'; $img_file = $Cache->GetHash($graph_id, $DataSet->GetData()); } else { // if the image does not exist in the archive/ folder // Initialise the graph $chart_size_w = 480; $chart_size_h = 250; $Test = new pChart($chart_size_w, $chart_size_h); // Adding the color schemma $Test->loadColorPalette(api_get_path(LIBRARY_PATH) . "pchart/palette/pastel.txt"); // set font of the axes $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 8); $area_graph_w = $chart_size_w - 130; $Test->setGraphArea(50, 30, $area_graph_w, $chart_size_h - 50); $Test->drawFilledRoundedRectangle(5, 5, $chart_size_w - 1, $chart_size_h - 20, 5, 240, 240, 240); //$Test->drawRoundedRectangle(5,5,790,330,5,230,230,230); //background color area & stripe or not $Test->drawGraphArea(255, 255, 255, TRUE); //Setting max height by default see #3296 if (!empty($max)) { $Test->setFixedScale(0, $max); } $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150, 150, 150, TRUE, 0, 0, FALSE); //background grid $Test->drawGrid(4, 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->drawBarGraph($DataSet->GetData(), $DataSet->GetDataDescription(), TRUE); //Set legend properties: width, height and text color and font $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 9); $Test->drawLegend($area_graph_w + 10, 50, $DataSet->GetDataDescription(), 255, 255, 255); //Set title properties $Test->setFontProperties(api_get_path(LIBRARY_PATH) . "pchart/fonts/tahoma.ttf", 10); $Test->drawTitle(50, 22, strip_tags($header_name[$i - 1]), 50, 50, 80, $chart_size_w - 50); //------------------ //echo 'not in cache'; $Cache->WriteToCache($graph_id, $DataSet->GetData(), $Test); //ob_start(); //$Test->Stroke(); //ob_end_clean(); $img_file = $Cache->GetHash($graph_id, $DataSet->GetData()); } echo '<img src="' . api_get_path(WEB_ARCHIVE_PATH) . $img_file . '" >'; if ($i % 2 == 0 && $i != 0) { echo '<br />'; } $i++; } } //end foreach } else { echo get_lang('ToViewGraphScoreRuleMustBeEnabled'); } // Pie charts /* $show_draw = false; $resource_list = array(); //print_r($pre_result_pie); if ($total_users>0) { foreach($pre_result_pie as $key=>$res_array) { //$resource_list foreach($res_array as $user_result) { $total+= $user_result / ($total_users*100); } echo $total; //echo $total = $res / ($total_users*100); echo '<br>'; //$DataSet->AddPoint($total,"Serie".$i); //$DataSet->SetSerieName($header_name[$i-1],"Serie".$i); } } //here-------------- foreach($resource_list as $key=>$resource) { $new_resource_list = $new_resource_list_name = array(); foreach($resource as $name=>$cant) { $new_resource_list[]=$cant; $new_resource_list_name[]=$name; } //Pie chart $DataSet = new pData; $DataSet->AddPoint($new_resource_list,"Serie1"); $DataSet->AddPoint($new_resource_list_name,"Serie2"); $DataSet->AddAllSeries(); $DataSet->SetAbsciseLabelSerie("Serie2"); $Test = new pChart(400,300); $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/soft_tones.txt"); // background //$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240); // border color $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230); // This will draw a shadow under the pie chart //$Test->drawFilledCircle(122,102,70,200,200,200); //Draw the pie chart $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8); $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE); $tmp_path = api_get_path(SYS_ARCHIVE_PATH); $Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218); $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250); $user_id = api_get_user_id(); $img_file_generated_name = $key.uniqid('').'gradebook.png'; $Test->Render($tmp_path.$img_file_generated_name); chmod($tmp_path.$img_file_generated_name, api_get_permissions_for_new_files()); if ($i % 2 == 0 && $i!= 0) { echo '<br>'; } echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file_generated_name.'">'; } */ } }
/** * Updates the gradebook score custom values using the scoredisplay class of the * gradebook module * * @param array List of gradebook score custom values * * @author Guillaume Viguier <*****@*****.**> */ function update_gradebook_score_display_custom_values($values) { $scoredisplay = ScoreDisplay::instance(); $scores = $values['gradebook_score_display_custom_values_endscore']; $displays = $values['gradebook_score_display_custom_values_displaytext']; $nr_displays = count($displays); $final = array(); for ($i = 1; $i < $nr_displays; $i++) { if (!empty($scores[$i]) && !empty($displays[$i])) { $final[$i]['score'] = $scores[$i]; $final[$i]['display'] = $displays[$i]; } } $scoredisplay->update_custom_score_display_settings($final); }
/** * This is a function to show the generated data * @param bool $displayWarning * @return array */ public function get_data_to_graph2($displayWarning = true) { // do some checks on users/items counts, redefine if invalid values $usertable = array(); foreach ($this->users as $user) { $usertable[] = $user; } // sort users array usort($usertable, array('FlatViewDataGenerator', 'sort_by_first_name')); // generate actual data array $scoredisplay = ScoreDisplay::instance(); $data = array(); $displaytype = SCORE_DIV; $selected_users = $usertable; foreach ($selected_users as $user) { $row = array(); $row[] = $user[0]; // user id $item_value = 0; $item_total = 0; $final_score = 0; $item_value_total = 0; $convert_using_the_global_weight = true; $course_code = api_get_course_id(); $session_id = api_get_session_id(); $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); if ($parent_id == 0 && !empty($allcat)) { foreach ($allcat as $sub_cat) { $score = $sub_cat->calc_score($user[0]); $real_score = $score; $main_weight = $this->category->get_weight(); $divide = $score[1] == 0 ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; $item_value = $score[0] / $divide * $main_weight; $item_total += $sub_cat->get_weight(); $row[] = array($item_value, trim($scoredisplay->display_score($real_score, SCORE_CUSTOM, null, true))); $item_value_total += $item_value; $final_score += $score[0]; //$final_score = ($final_score / $item_total) * 100; } $total_score = array($final_score, $item_total); $row[] = array($final_score, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); } else { for ($count = 0; $count < count($this->evals_links); $count++) { $item = $this->evals_links[$count]; $score = $item->calc_score($user[0]); $divide = $score[1] == 0 ? 1 : $score[1]; $item_value += $score[0] / $divide * $item->get_weight(); $item_total += $item->get_weight(); $score_denom = $score[1] == 0 ? 1 : $score[1]; $score_final = $score[0] / $score_denom * 100; $row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true))); } $total_score = array($item_value, $item_total); $score_final = $item_value / $item_total * 100; if ($displayWarning) { Display::display_warning_message(Display::display_warning_message($total_score[1])); } $row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); } $data[] = $row; } return $data; }
private function build_result_column($item, $ignore_score_color) { $scoredisplay = ScoreDisplay::instance(); $score = $item->calc_score(api_get_user_id()); if (!empty($score)) { switch ($item->get_item_type()) { // category case 'C': if ($score != null) { $displaytype = SCORE_PERCENT; if ($ignore_score_color) { $displaytype |= SCORE_IGNORE_SPLIT; } return get_lang('Total') . ' : ' . $scoredisplay->display_score($score, $displaytype); } else { return ''; } // evaluation and link // evaluation and link case 'E': case 'L': $displaytype = SCORE_DIV_PERCENT; if ($ignore_score_color) { $displaytype |= SCORE_IGNORE_SPLIT; } return $scoredisplay->display_score($score, SCORE_DIV_PERCENT_WITH_CUSTOM); } } return null; }
$pdf->line(50, 40, 550, 40); $pdf->ezSetY(750); $pdf->ezTable($newarray, $header_names, '', array('showHeadings' => 1, 'shaded' => 1, 'showLines' => 1, 'rowGap' => 3, 'width' => 500)); $pdf->ezStream(); exit; } } elseif (!empty($_GET['export_certificate'])) { //@todo this code seems not to be used $user_id = strval(intval($_GET['user'])); if (!api_is_allowed_to_edit(true, true)) { $user_id = api_get_user_id(); } $category = Category::load($_GET['cat_id']); if ($category[0]->is_certificate_available($user_id)) { $user = api_get_user_info($user_id); $scoredisplay = ScoreDisplay::instance(); $scorecourse = $category[0]->calc_score($user_id); $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable'); $cattotal = Category::load(0); $scoretotal = $cattotal[0]->calc_score($user_id); $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable'); //prepare all necessary variables: $organization_name = api_get_setting('Institution'); $portal_name = api_get_setting('siteName'); $stud_fn = $user['firstname']; $stud_ln = $user['lastname']; $certif_text = sprintf(get_lang('CertificateWCertifiesStudentXFinishedCourseYWithGradeZ'), $organization_name, $stud_fn . ' ' . $stud_ln, $category[0]->get_name(), $scorecourse_display); $certif_text = str_replace("\\n", "\n", $certif_text); $date = api_convert_and_format_date(null, DATE_FORMAT_SHORT); $pdf = new Cezpdf('a4', 'landscape'); $pdf->selectFont(api_get_path(LIBRARY_PATH) . 'ezpdf/fonts/Courier.afm');
/** * @param int $category_id * @param int $user_id * @return bool|string */ public static function register_user_certificate($category_id, $user_id) { // Generating the total score for a course $cats_course = Category::load($category_id, null, null, null, null, api_get_session_id(), false); /** @var Category $category */ $category = $cats_course[0]; $alleval_course = $category->get_evaluations($user_id, true); $alllink_course = $category->get_links($user_id, true); $evals_links = array_merge($alleval_course, $alllink_course); //@todo move these in a function $sum_categories_weight_array = array(); if (isset($cats_course) && !empty($cats_course)) { $categories = Category::load(null, null, null, $category_id); if (!empty($categories)) { foreach ($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); } } else { $sum_categories_weight_array[$category_id] = $cats_course[0]->get_weight(); } } $main_weight = $cats_course[0]->get_weight(); $item_total_value = 0; for ($count = 0; $count < count($evals_links); $count++) { /** @var AbstractLink $item */ $item = $evals_links[$count]; $score = $item->calc_score($user_id); $item_value = 0; if (!empty($score)) { $divide = $score[1] == 0 ? 1 : $score[1]; $item_value = $score[0] / $divide * $item->get_weight(); } $item_total_value += $item_value; } $item_total_value = (double) $item_total_value; $cattotal = Category::load($category_id); $scoretotal = $cattotal[0]->calc_score($user_id); //Do not remove this the gradebook/lib/fe/gradebooktable.class.php file load this variable as a global $scoredisplay = ScoreDisplay::instance(); $my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE); // Show certificate $certificate_min_score = $cats_course[0]->get_certificate_min_score(); // A student always sees only the teacher's repartition $scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT); if (isset($certificate_min_score) && $item_total_value >= $certificate_min_score) { $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); if (empty($my_certificate)) { register_user_info_about_certificate($category_id, $user_id, $my_score_in_gradebook, api_get_utc_datetime()); $my_certificate = get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); } $html = array(); if (!empty($my_certificate)) { $certificate_obj = new Certificate($my_certificate['id']); $fileWasGenerated = $certificate_obj->html_file_is_generated(); if (!empty($fileWasGenerated)) { $url = api_get_path(WEB_PATH) . 'certificates/index.php?id=' . $my_certificate['id']; $certificates = Display::url(' ' . get_lang('DownloadCertificate'), $url, array('target' => '_blank', 'class' => 'btn')); $exportToPDF = Display::url(Display::return_icon('pdf.png', get_lang('ExportToPDF'), array(), ICON_SIZE_MEDIUM), "{$url}&action=export"); $html = array('certificate_link' => $certificates, 'pdf_link' => $exportToPDF); } return $html; } } else { return false; } }