displaygradebook.php 31 KB

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