displaygradebook.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class DisplayGradebook.
  5. *
  6. * @package chamilo.gradebook
  7. */
  8. class DisplayGradebook
  9. {
  10. /**
  11. * Displays the header for the result page containing the navigation tree and links.
  12. *
  13. * @param Evaluation $evalobj
  14. * @param $selectcat
  15. * @param $shownavbar 1=show navigation bar
  16. * @param $forpdf only output for pdf file
  17. */
  18. public static function display_header_result($evalobj, $selectcat, $page)
  19. {
  20. $header = null;
  21. if (api_is_allowed_to_edit(null, true)) {
  22. $header = '<div class="actions">';
  23. if ($page != 'statistics') {
  24. $header .= '<a href="'.Category::getUrl().'selectcat='.$selectcat.'">'.
  25. Display::return_icon(('back.png'), get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
  26. if (($evalobj->get_course_code() != null) && !$evalobj->has_results()) {
  27. $header .= '<a href="gradebook_add_result.php?'.api_get_cidreq().'&selectcat='.$selectcat.'&selecteval='.$evalobj->get_id().'">
  28. '.Display::return_icon('evaluation_rate.png', get_lang('AddResult'), '', ICON_SIZE_MEDIUM).'</a>';
  29. }
  30. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  31. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&import=">'.
  32. Display::return_icon('import_evaluation.png', get_lang('ImportResult'), '', ICON_SIZE_MEDIUM).'</a>';
  33. }
  34. if ($evalobj->has_results()) {
  35. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&export=">'.
  36. Display::return_icon('export_evaluation.png', get_lang('ExportResult'), '', ICON_SIZE_MEDIUM).'</a>';
  37. if (api_is_platform_admin() || $evalobj->is_locked() == false) {
  38. $header .= '<a href="gradebook_edit_result.php?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'">'.
  39. Display::return_icon('edit.png', get_lang('EditResult'), '', ICON_SIZE_MEDIUM).'</a>';
  40. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&selecteval='.$evalobj->get_id().'&deleteall=" onclick="return confirmationall();">'.
  41. Display::return_icon('delete.png', get_lang('DeleteResult'), '', ICON_SIZE_MEDIUM).'</a>';
  42. }
  43. }
  44. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&print=&selecteval='.$evalobj->get_id().'" target="_blank">'.
  45. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  46. } else {
  47. $header .= '<a href="gradebook_view_result.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
  48. Display::return_icon(('back.png'), get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
  49. }
  50. $header .= '</div>';
  51. }
  52. if ($evalobj->is_visible() == '1') {
  53. $visible = get_lang('Yes');
  54. } else {
  55. $visible = get_lang('No');
  56. }
  57. $scoredisplay = ScoreDisplay::instance();
  58. $student_score = '';
  59. $average = '';
  60. if ($evalobj->has_results()) {
  61. // TODO this check needed ?
  62. $score = $evalobj->calc_score();
  63. if ($score != null) {
  64. $average = get_lang('Average').' :<b> '.$scoredisplay->display_score($score, SCORE_AVERAGE).'</b>';
  65. $student_score = $evalobj->calc_score(api_get_user_id());
  66. $student_score = Display::tag(
  67. 'h3',
  68. get_lang('Score').': '.$scoredisplay->display_score($student_score, SCORE_DIV_PERCENT)
  69. );
  70. $allowMultipleAttempts = api_get_configuration_value('gradebook_multiple_evaluation_attempts');
  71. if ($allowMultipleAttempts) {
  72. $results = Result::load(null, api_get_user_id(), $evalobj->get_id());
  73. if (!empty($results)) {
  74. /** @var Result $resultData */
  75. foreach ($results as $resultData) {
  76. $student_score .= ResultTable::getResultAttemptTable($resultData);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. $description = '';
  83. if (!$evalobj->get_description() == '') {
  84. $description = get_lang('Description').' :<b> '.$evalobj->get_description().'</b><br>';
  85. }
  86. if ($evalobj->get_course_code() == null) {
  87. $course = get_lang('CourseIndependent');
  88. } else {
  89. $course = CourseManager::getCourseNameFromCode($evalobj->get_course_code());
  90. }
  91. $evalinfo = '<table width="100%" border="0"><tr><td>';
  92. $evalinfo .= '<h2>'.$evalobj->get_name().'</h2><hr>';
  93. $evalinfo .= $description;
  94. $evalinfo .= get_lang('Course').' :<b> '.$course.'</b><br />';
  95. $evalinfo .= get_lang('QualificationNumeric').' :<b> '.$evalobj->get_max().'</b><br>'.$average;
  96. if (!api_is_allowed_to_edit()) {
  97. $evalinfo .= $student_score;
  98. }
  99. if (!$evalobj->has_results()) {
  100. $evalinfo .= '<br /><i>'.get_lang('NoResultsInEvaluation').'</i>';
  101. }
  102. if ($page != 'statistics') {
  103. if (api_is_allowed_to_edit(null, true)) {
  104. $evalinfo .= '<br /><a href="gradebook_statistics.php?'.api_get_cidreq().'&selecteval='.Security::remove_XSS($_GET['selecteval']).'"> '.
  105. Display::return_icon(
  106. 'statistics.png',
  107. get_lang('ViewStatistics'),
  108. '',
  109. ICON_SIZE_MEDIUM
  110. ).'</a>';
  111. }
  112. }
  113. $evalinfo .= '</td><td>'.
  114. Display::return_icon(
  115. 'tutorial.gif',
  116. '',
  117. ['style' => 'float:right; position:relative;']
  118. )
  119. .'</td></table>';
  120. echo $evalinfo;
  121. echo $header;
  122. }
  123. /**
  124. * Displays the header for the flatview page containing filters.
  125. *
  126. * @param $catobj
  127. * @param $showeval
  128. * @param $showlink
  129. */
  130. public static function display_header_reduce_flatview($catobj, $showeval, $showlink, $simple_search_form)
  131. {
  132. $header = '<div class="actions">';
  133. if ($catobj->get_parent_id() == 0) {
  134. $select_cat = $catobj->get_id();
  135. $url = Category::getUrl();
  136. } else {
  137. $select_cat = $catobj->get_parent_id();
  138. $url = 'gradebook_flatview.php';
  139. }
  140. $header .= '<a href="'.$url.'?'.api_get_cidreq().'&selectcat='.$select_cat.'">'.
  141. Display::return_icon('back.png', get_lang('FolderView'), '', ICON_SIZE_MEDIUM).'</a>';
  142. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  143. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  144. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  145. $exportCsvUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  146. 'export_format' => 'csv',
  147. 'export_report' => 'export_report',
  148. 'selectcat' => $catobj->get_id(),
  149. ]);
  150. $header .= Display::url(
  151. Display::return_icon(
  152. 'export_csv.png',
  153. get_lang('ExportAsCSV'),
  154. '',
  155. ICON_SIZE_MEDIUM
  156. ),
  157. $exportCsvUrl
  158. );
  159. $exportXlsUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  160. 'export_format' => 'xls',
  161. 'export_report' => 'export_report',
  162. 'selectcat' => $catobj->get_id(),
  163. ]);
  164. $header .= Display::url(
  165. Display::return_icon(
  166. 'export_excel.png',
  167. get_lang('ExportAsXLS'),
  168. '',
  169. ICON_SIZE_MEDIUM
  170. ),
  171. $exportXlsUrl
  172. );
  173. $exportDocUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  174. 'export_format' => 'doc',
  175. 'export_report' => 'export_report',
  176. 'selectcat' => $catobj->get_id(),
  177. ]);
  178. $header .= Display::url(
  179. Display::return_icon(
  180. 'export_doc.png',
  181. get_lang('ExportAsDOC'),
  182. '',
  183. ICON_SIZE_MEDIUM
  184. ),
  185. $exportDocUrl
  186. );
  187. $exportPrintUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  188. 'print' => '',
  189. 'selectcat' => $catobj->get_id(),
  190. ]);
  191. $header .= Display::url(
  192. Display::return_icon(
  193. 'printer.png',
  194. get_lang('Print'),
  195. '',
  196. ICON_SIZE_MEDIUM
  197. ),
  198. $exportPrintUrl,
  199. ['target' => '_blank']
  200. );
  201. $exportPdfUrl = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  202. 'exportpdf' => '',
  203. 'selectcat' => $catobj->get_id(),
  204. 'offset' => $offset,
  205. 'flatviewlist_page_nr' => $pageNum,
  206. 'flatviewlist_per_page' => $perPage,
  207. ]);
  208. $header .= Display::url(
  209. Display::return_icon(
  210. 'pdf.png',
  211. get_lang('ExportToPDF'),
  212. '',
  213. ICON_SIZE_MEDIUM
  214. ),
  215. $exportPdfUrl
  216. );
  217. $header .= '</div>';
  218. echo $header;
  219. }
  220. /**
  221. * Displays the header for the gradebook containing the navigation tree and links.
  222. *
  223. * @param Category $catobj
  224. * @param int $showtree '1' will show the browse tree and naviation buttons
  225. * @param $selectcat
  226. * @param bool $is_course_admin
  227. * @param bool $is_platform_admin
  228. * @param bool $simple_search_form
  229. * @param bool $show_add_qualification Whether to show or not the link to add a new qualification
  230. * (we hide it in case of the course-embedded tool where we have only one
  231. * per course or session)
  232. * @param bool $show_add_link Whether to show or not the link to add a new item inside
  233. * the qualification (we hide it in case of the course-embedded tool
  234. * where we have only one qualification per course or session)
  235. * @param array $certificateLinkInfo
  236. */
  237. public static function header(
  238. $catobj,
  239. $showtree,
  240. $selectcat,
  241. $is_course_admin,
  242. $is_platform_admin,
  243. $simple_search_form,
  244. $show_add_qualification = true,
  245. $show_add_link = true,
  246. $certificateLinkInfo = []
  247. ) {
  248. $userId = api_get_user_id();
  249. $courseId = api_get_course_int_id();
  250. $sessionId = api_get_session_id();
  251. // Student.
  252. $status = CourseManager::getUserInCourseStatus($userId, $courseId);
  253. $sessionStatus = 0;
  254. if (!empty($sessionId)) {
  255. $sessionStatus = SessionManager::get_user_status_in_course_session(
  256. $userId,
  257. $courseId,
  258. $sessionId
  259. );
  260. }
  261. $objcat = new Category();
  262. $course_id = CourseManager::get_course_by_category($selectcat);
  263. $message_resource = $objcat->show_message_resource_delete($course_id);
  264. $grade_model_id = $catobj->get_grade_model_id();
  265. $header = null;
  266. if (isset($catobj) && !empty($catobj)) {
  267. $categories = Category::load(
  268. null,
  269. null,
  270. null,
  271. $catobj->get_id(),
  272. null,
  273. $sessionId
  274. );
  275. }
  276. if (!$is_course_admin && ($status != 1 || $sessionStatus == 0) && $selectcat != 0) {
  277. $catcourse = Category::load($catobj->get_id());
  278. /** @var Category $category */
  279. $category = $catcourse[0];
  280. $main_weight = $category->get_weight();
  281. $scoredisplay = ScoreDisplay::instance();
  282. $allevals = $category->get_evaluations($userId, true);
  283. $alllinks = $category->get_links($userId, true);
  284. $allEvalsLinks = array_merge($allevals, $alllinks);
  285. $item_value_total = 0;
  286. $scoreinfo = null;
  287. for ($count = 0; $count < count($allEvalsLinks); $count++) {
  288. $item = $allEvalsLinks[$count];
  289. $score = $item->calc_score($userId);
  290. if (!empty($score)) {
  291. $divide = $score[1] == 0 ? 1 : $score[1];
  292. $item_value = $score[0] / $divide * $item->get_weight();
  293. $item_value_total += $scoredisplay->format_score($item_value);
  294. }
  295. }
  296. $item_total = $main_weight;
  297. $total_score = [$item_value_total, $item_total];
  298. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  299. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  300. $additionalButtons = null;
  301. if (!empty($certificateLinkInfo)) {
  302. $additionalButtons .= '<div class="btn-group pull-right">';
  303. $additionalButtons .= isset($certificateLinkInfo['certificate_link']) ? $certificateLinkInfo['certificate_link'] : '';
  304. $additionalButtons .= isset($certificateLinkInfo['badge_link']) ? $certificateLinkInfo['badge_link'] : '';
  305. $additionalButtons .= '</div>';
  306. }
  307. $scoreinfo .= '<strong>'.sprintf(get_lang('TotalX'), $scorecourse_display.$additionalButtons).'</strong>';
  308. }
  309. echo Display::return_message($scoreinfo, 'normal', false);
  310. }
  311. // show navigation tree and buttons?
  312. if ($showtree == '1' || isset($_GET['studentoverview'])) {
  313. $header = '<div class="actions"><table>';
  314. $header .= '<tr>';
  315. if (!$selectcat == '0') {
  316. $header .= '<td><a href="'.api_get_self().'?selectcat='.$catobj->get_parent_id().'">'.
  317. Display::return_icon(
  318. 'back.png',
  319. get_lang('BackTo').' '.get_lang('RootCat'),
  320. '',
  321. ICON_SIZE_MEDIUM
  322. ).
  323. '</a></td>';
  324. }
  325. $header .= '<td>'.get_lang('CurrentCategory').'</td>'.
  326. '<td><form name="selector"><select name="selectcat" onchange="document.selector.submit()">';
  327. $cats = Category::load();
  328. $tree = $cats[0]->get_tree();
  329. unset($cats);
  330. $line = null;
  331. foreach ($tree as $cat) {
  332. for ($i = 0; $i < $cat[2]; $i++) {
  333. $line .= '&mdash;';
  334. }
  335. $line = isset($line) ? $line : '';
  336. if (isset($_GET['selectcat']) && $_GET['selectcat'] == $cat[0]) {
  337. $header .= '<option selected value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
  338. } else {
  339. $header .= '<option value='.$cat[0].'>'.$line.' '.$cat[1].'</option>';
  340. }
  341. $line = '';
  342. }
  343. $header .= '</select></form></td>';
  344. if (!empty($simple_search_form) && $message_resource === false) {
  345. $header .= '<td style="vertical-align: top;">'.$simple_search_form->toHtml().'</td>';
  346. } else {
  347. $header .= '<td></td>';
  348. }
  349. if (!($is_course_admin &&
  350. $message_resource === false &&
  351. isset($_GET['selectcat']) && $_GET['selectcat'] != 0) &&
  352. isset($_GET['studentoverview'])
  353. ) {
  354. $header .= '<td style="vertical-align: top;"><a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
  355. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  356. '.get_lang('ExportPDF').'</a>';
  357. }
  358. $header .= '</td></tr>';
  359. $header .= '</table></div>';
  360. }
  361. // for course admin & platform admin add item buttons are added to the header
  362. $actionsLeft = '';
  363. $actionsRight = '';
  364. $my_api_cidreq = api_get_cidreq();
  365. if (api_is_allowed_to_edit(null, true)) {
  366. if (empty($grade_model_id) || $grade_model_id == -1) {
  367. $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
  368. Display::return_icon(
  369. 'new_folder.png',
  370. get_lang('AddGradebook'),
  371. [],
  372. ICON_SIZE_MEDIUM
  373. ).'</a></td>';
  374. }
  375. if ($selectcat != '0') {
  376. $my_category = $catobj->showAllCategoryInfo($catobj->get_id());
  377. if ($my_api_cidreq == '') {
  378. $my_api_cidreq = 'cidReq='.$my_category['course_code'];
  379. }
  380. if ($show_add_link && !$message_resource) {
  381. $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'.
  382. Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), '', ICON_SIZE_MEDIUM).'</a>';
  383. $cats = Category::load($selectcat);
  384. if ($cats[0]->get_course_code() != null && !$message_resource) {
  385. $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  386. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM).'</a>';
  387. } else {
  388. $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  389. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '', ICON_SIZE_MEDIUM).'</a>';
  390. }
  391. }
  392. if (!$message_resource) {
  393. $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  394. Display::return_icon('statistics.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
  395. if ($my_category['generate_certificates'] == 1) {
  396. $actionsLeft .= Display::url(
  397. Display::return_icon(
  398. 'certificate_list.png',
  399. get_lang('GradebookSeeListOfStudentsCertificates'),
  400. '',
  401. ICON_SIZE_MEDIUM
  402. ),
  403. "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat
  404. );
  405. }
  406. $actionsLeft .= Display::url(
  407. Display::return_icon(
  408. 'user.png',
  409. get_lang('GradebookListOfStudentsReports'),
  410. '',
  411. ICON_SIZE_MEDIUM
  412. ),
  413. "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
  414. );
  415. $allow = api_get_configuration_value('gradebook_custom_student_report');
  416. if ($allow) {
  417. $actionsLeft .= Display::url(
  418. get_lang('GenerateCustomReport'),
  419. api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report",
  420. ['class' => 'btn btn-default ajax']
  421. );
  422. }
  423. // Right icons
  424. $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  425. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
  426. $courseCode = api_get_course_id();
  427. if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' &&
  428. api_get_course_setting('customcertificate_course_enable', $courseCode) == 1
  429. ) {
  430. $actionsRight .= '<a href="'.api_get_path(WEB_PLUGIN_PATH).'customcertificate/src/index.php?'.
  431. $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
  432. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).'</a>';
  433. } else {
  434. $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).
  435. 'document/document.php?curdirpath=/certificates&'.
  436. $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
  437. Display::return_icon('certificate.png', get_lang('AttachCertificate'), '', ICON_SIZE_MEDIUM).'</a>';
  438. }
  439. if (empty($categories)) {
  440. $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id().'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  441. Display::return_icon('percentage.png', get_lang('EditAllWeights'), '', ICON_SIZE_MEDIUM).'</a>';
  442. }
  443. $score_display_custom = api_get_setting('gradebook_score_display_custom');
  444. if (api_get_setting('teachers_can_change_score_settings') == 'true' && $score_display_custom['my_display_custom'] == 'true') {
  445. $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  446. Display::return_icon('ranking.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
  447. }
  448. }
  449. }
  450. } elseif (isset($_GET['search'])) {
  451. echo $header = '<b>'.get_lang('SearchResults').' :</b>';
  452. }
  453. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  454. api_get_user_id(),
  455. api_get_course_info()
  456. );
  457. if ($isDrhOfCourse) {
  458. $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  459. Display::return_icon(
  460. 'statistics.png',
  461. get_lang('FlatView'),
  462. '',
  463. ICON_SIZE_MEDIUM
  464. ).
  465. '</a>';
  466. }
  467. if (api_is_allowed_to_edit(null, true)) {
  468. echo $toolbar = Display::toolbarAction(
  469. 'gradebook-actions',
  470. [$actionsLeft, $actionsRight]
  471. );
  472. }
  473. if (api_is_allowed_to_edit(null, true)) {
  474. $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
  475. $weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
  476. $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0;
  477. $min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
  478. $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  479. Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
  480. $msg = $weight.' - '.$min_certification.$edit_icon;
  481. //@todo show description
  482. $description = (($catobj->get_description() == '' || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.$catobj->get_description());
  483. echo Display::return_message($msg, 'normal', false);
  484. if (!empty($description)) {
  485. echo Display::div($description, []);
  486. }
  487. }
  488. }
  489. /**
  490. * @param Category $catobj
  491. * @param $is_course_admin
  492. * @param $is_platform_admin
  493. * @param $simple_search_form
  494. * @param bool $show_add_qualification
  495. * @param bool $show_add_link
  496. */
  497. public function display_reduce_header_gradebook(
  498. $catobj,
  499. $is_course_admin,
  500. $is_platform_admin,
  501. $simple_search_form,
  502. $show_add_qualification = true,
  503. $show_add_link = true
  504. ) {
  505. //student
  506. if (!$is_course_admin) {
  507. $user = api_get_user_info(api_get_user_id());
  508. $catcourse = Category::load($catobj->get_id());
  509. $scoredisplay = ScoreDisplay::instance();
  510. $scorecourse = $catcourse[0]->calc_score(api_get_user_id());
  511. $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable');
  512. $cattotal = Category::load(0);
  513. $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
  514. $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable');
  515. $scoreinfo = get_lang('StatsStudent').' :<b> '.$user['complete_name'].'</b><br />';
  516. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  517. $scoreinfo .= '<br />'.get_lang('TotalForThisCategory').' : <b>'.$scorecourse_display.'</b>';
  518. }
  519. $scoreinfo .= '<br />'.get_lang('Total').' : <b>'.$scoretotal_display.'</b>';
  520. Display::addFlash(
  521. Display::return_message($scoreinfo, 'normal', false)
  522. );
  523. }
  524. // show navigation tree and buttons?
  525. $header = '<div class="actions">';
  526. if ($is_course_admin) {
  527. $header .= '<a href="gradebook_flatview.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.Display::return_icon('statistics.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
  528. $header .= '<a href="gradebook_scoring_system.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.Display::return_icon('settings.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
  529. } elseif (!(isset($_GET['studentoverview']))) {
  530. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&selectcat='.$catobj->get_id().'">'.Display::return_icon('view_list.gif', get_lang('FlatView')).' '.get_lang('FlatView').'</a>';
  531. } else {
  532. $header .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">'.Display::return_icon('pdf.png', get_lang('ExportPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  533. }
  534. $header .= '</div>';
  535. echo $header;
  536. }
  537. /**
  538. * @param int $userId
  539. * @param int $categoryId
  540. *
  541. * @return string
  542. */
  543. public static function display_header_user($userId, $categoryId)
  544. {
  545. $user = api_get_user_info($userId);
  546. if (empty($user)) {
  547. return '';
  548. }
  549. $catcourse = Category::load($categoryId);
  550. $scoredisplay = ScoreDisplay::instance();
  551. // generating the total score for a course
  552. $allevals = $catcourse[0]->get_evaluations(
  553. $userId,
  554. true,
  555. api_get_course_id()
  556. );
  557. $alllinks = $catcourse[0]->get_links(
  558. $userId,
  559. true,
  560. api_get_course_id()
  561. );
  562. $evals_links = array_merge($allevals, $alllinks);
  563. $item_value = 0;
  564. $item_total = 0;
  565. for ($count = 0; $count < count($evals_links); $count++) {
  566. $item = $evals_links[$count];
  567. $score = $item->calc_score($userId);
  568. $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
  569. $item_value += $score[0] / $my_score_denom * $item->get_weight();
  570. $item_total += $item->get_weight();
  571. }
  572. $item_value = api_number_format($item_value, 2);
  573. $total_score = [$item_value, $item_total];
  574. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  575. $info = '<div class="row"><div class="col-md-3">';
  576. $info .= '<div class="thumbnail"><img src="'.$user['avatar'].'" /></div>';
  577. $info .= '</div>';
  578. $info .= '<div class="col-md-6">';
  579. $info .= get_lang('Name').' : '.$user['complete_name_with_message_link'].'<br />';
  580. if (api_get_setting('show_email_addresses') == 'true') {
  581. $info .= get_lang('Email').' : <a href="mailto:'.$user['email'].'">'.$user['email'].'</a><br />';
  582. }
  583. $info .= get_lang('TotalUser').' : <b>'.$scorecourse_display.'</b>';
  584. $info .= '</div>';
  585. $info .= '</div>';
  586. echo $info;
  587. }
  588. }