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;">
  362. <a href="'.api_get_self().'?'.api_get_cidreq().'&studentoverview=&exportpdf=&selectcat='.$catobj->get_id().'" target="_blank">
  363. '.Display::return_icon('pdf.png', get_lang('ExportPDF'), [], ICON_SIZE_MEDIUM).'
  364. '.get_lang('ExportPDF').'</a>';
  365. }
  366. $header .= '</td></tr>';
  367. $header .= '</table></div>';
  368. }
  369. // for course admin & platform admin add item buttons are added to the header
  370. $actionsLeft = '';
  371. $actionsRight = '';
  372. $my_api_cidreq = api_get_cidreq();
  373. $isCoach = api_is_coach(api_get_session_id(), api_get_course_int_id());
  374. $accessToRead = api_is_allowed_to_edit(null, true) || $isCoach;
  375. $accessToEdit = api_is_allowed_to_edit(null, true);
  376. $courseCode = api_get_course_id();
  377. if ($accessToRead) {
  378. $my_category = $catobj->showAllCategoryInfo($catobj->get_id());
  379. if ($selectcat != '0' && $accessToEdit) {
  380. if ($my_api_cidreq == '') {
  381. $my_api_cidreq = 'cidReq='.$my_category['course_code'];
  382. }
  383. if ($show_add_link && !$message_resource) {
  384. $actionsLeft .= '<a href="gradebook_add_eval.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'" >'.
  385. Display::return_icon('new_evaluation.png', get_lang('NewEvaluation'), '',
  386. ICON_SIZE_MEDIUM).'</a>';
  387. $cats = Category::load($selectcat);
  388. if ($cats[0]->get_course_code() != null && !$message_resource) {
  389. $actionsLeft .= '<a href="gradebook_add_link.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  390. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '',
  391. ICON_SIZE_MEDIUM).'</a>';
  392. } else {
  393. $actionsLeft .= '<a href="gradebook_add_link_select_course.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  394. Display::return_icon('new_online_evaluation.png', get_lang('MakeLink'), '',
  395. ICON_SIZE_MEDIUM).'</a>';
  396. }
  397. }
  398. }
  399. if ((empty($grade_model_id) || $grade_model_id == -1) && $accessToEdit) {
  400. $actionsLeft .= '<a href="gradebook_add_cat.php?'.api_get_cidreq().'&selectcat='.$catobj->get_id().'">'.
  401. Display::return_icon(
  402. 'new_folder.png',
  403. get_lang('AddGradebook'),
  404. [],
  405. ICON_SIZE_MEDIUM
  406. ).'</a></td>';
  407. }
  408. if ($selectcat != '0' && $accessToRead) {
  409. if (!$message_resource) {
  410. $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  411. Display::return_icon('statistics.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM).'</a>';
  412. if ($my_category['generate_certificates'] == 1) {
  413. $actionsLeft .= Display::url(
  414. Display::return_icon(
  415. 'certificate_list.png',
  416. get_lang('GradebookSeeListOfStudentsCertificates'),
  417. '',
  418. ICON_SIZE_MEDIUM
  419. ),
  420. "gradebook_display_certificate.php?$my_api_cidreq&cat_id=".$selectcat
  421. );
  422. }
  423. $actionsLeft .= Display::url(
  424. Display::return_icon(
  425. 'user.png',
  426. get_lang('GradebookListOfStudentsReports'),
  427. '',
  428. ICON_SIZE_MEDIUM
  429. ),
  430. "gradebook_display_summary.php?$my_api_cidreq&selectcat=".$selectcat
  431. );
  432. $allow = api_get_configuration_value('gradebook_custom_student_report');
  433. if ($allow) {
  434. $actionsLeft .= Display::url(
  435. get_lang('GenerateCustomReport'),
  436. api_get_path(WEB_AJAX_PATH)."gradebook.ajax.php?$my_api_cidreq&a=generate_custom_report",
  437. ['class' => 'btn btn-default ajax']
  438. );
  439. }
  440. // Right icons
  441. if ($accessToEdit) {
  442. $actionsRight = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id(
  443. ).'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  444. Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM).'</a>';
  445. if (api_get_plugin_setting('customcertificate', 'enable_plugin_customcertificate') == 'true' &&
  446. api_get_course_setting('customcertificate_course_enable', $courseCode) == 1
  447. ) {
  448. $actionsRight .= '<a href="'.api_get_path(
  449. WEB_PLUGIN_PATH
  450. ).'customcertificate/src/index.php?'.
  451. $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
  452. Display::return_icon(
  453. 'certificate.png',
  454. get_lang('AttachCertificate'),
  455. '',
  456. ICON_SIZE_MEDIUM
  457. ).'</a>';
  458. } else {
  459. $actionsRight .= '<a href="'.api_get_path(WEB_CODE_PATH).
  460. 'document/document.php?curdirpath=/certificates&'.
  461. $my_api_cidreq.'&origin=gradebook&selectcat='.$catobj->get_id().'">'.
  462. Display::return_icon(
  463. 'certificate.png',
  464. get_lang('AttachCertificate'),
  465. '',
  466. ICON_SIZE_MEDIUM
  467. ).'</a>';
  468. }
  469. if (empty($categories)) {
  470. $actionsRight .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id(
  471. ).'&'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  472. Display::return_icon(
  473. 'percentage.png',
  474. get_lang('EditAllWeights'),
  475. '',
  476. ICON_SIZE_MEDIUM
  477. ).'</a>';
  478. }
  479. $score_display_custom = api_get_setting('gradebook_score_display_custom');
  480. if (api_get_setting('teachers_can_change_score_settings') == 'true' &&
  481. $score_display_custom['my_display_custom'] == 'true'
  482. ) {
  483. $actionsRight .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  484. Display::return_icon('ranking.png', get_lang('ScoreEdit'), '', ICON_SIZE_MEDIUM).'</a>';
  485. }
  486. }
  487. }
  488. }
  489. } elseif (isset($_GET['search'])) {
  490. echo $header = '<b>'.get_lang('SearchResults').' :</b>';
  491. }
  492. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  493. api_get_user_id(),
  494. api_get_course_info()
  495. );
  496. if ($isDrhOfCourse) {
  497. $actionsLeft .= '<a href="gradebook_flatview.php?'.$my_api_cidreq.'&selectcat='.$catobj->get_id().'">'.
  498. Display::return_icon(
  499. 'statistics.png',
  500. get_lang('FlatView'),
  501. '',
  502. ICON_SIZE_MEDIUM
  503. ).
  504. '</a>';
  505. }
  506. if ($isCoach || api_is_allowed_to_edit(null, true)) {
  507. echo $toolbar = Display::toolbarAction(
  508. 'gradebook-actions',
  509. [$actionsLeft, $actionsRight]
  510. );
  511. }
  512. if ($accessToEdit || api_is_allowed_to_edit(null, true)) {
  513. $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0;
  514. $weight = '<strong>'.get_lang('TotalWeight').' : </strong>'.$weight;
  515. $min_certification = intval($catobj->getCertificateMinScore() > 0) ? $catobj->getCertificateMinScore() : 0;
  516. if (!empty($min_certification)) {
  517. $model = ExerciseLib::getCourseScoreModel();
  518. if (!empty($model)) {
  519. $defaultCertification = api_number_format($min_certification, 2);
  520. $questionWeighting = $catobj->get_weight();
  521. foreach ($model['score_list'] as $item) {
  522. $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
  523. $model = ExerciseLib::getModelStyle($item, $i);
  524. if ($defaultCertification == $i) {
  525. $min_certification = $model;
  526. break;
  527. }
  528. }
  529. }
  530. }
  531. $min_certification = get_lang('CertificateMinScore').' : '.$min_certification;
  532. $edit_icon = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'&id_session='.$catobj->get_session_id().'">'.
  533. Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL).'</a>';
  534. $msg = $weight.' - '.$min_certification.$edit_icon;
  535. //@todo show description
  536. $description = (($catobj->get_description() == '' || is_null($catobj->get_description())) ? '' : '<strong>'.get_lang('GradebookDescriptionLog').'</strong>'.': '.$catobj->get_description());
  537. echo Display::return_message($msg, 'normal', false);
  538. if (!empty($description)) {
  539. echo Display::div($description, []);
  540. }
  541. }
  542. }
  543. /**
  544. * @param Category $catobj
  545. * @param $is_course_admin
  546. * @param $is_platform_admin
  547. * @param $simple_search_form
  548. * @param bool $show_add_qualification
  549. * @param bool $show_add_link
  550. */
  551. public function display_reduce_header_gradebook(
  552. $catobj,
  553. $is_course_admin,
  554. $is_platform_admin,
  555. $simple_search_form,
  556. $show_add_qualification = true,
  557. $show_add_link = true
  558. ) {
  559. //student
  560. if (!$is_course_admin) {
  561. $user = api_get_user_info(api_get_user_id());
  562. $catcourse = Category::load($catobj->get_id());
  563. $scoredisplay = ScoreDisplay::instance();
  564. $scorecourse = $catcourse[0]->calc_score(api_get_user_id());
  565. $scorecourse_display = isset($scorecourse) ? $scoredisplay->display_score($scorecourse, SCORE_AVERAGE) : get_lang('NoResultsAvailable');
  566. $cattotal = Category::load(0);
  567. $scoretotal = $cattotal[0]->calc_score(api_get_user_id());
  568. $scoretotal_display = isset($scoretotal) ? $scoredisplay->display_score($scoretotal, SCORE_PERCENT) : get_lang('NoResultsAvailable');
  569. $scoreinfo = get_lang('StatsStudent').' :<b> '.$user['complete_name'].'</b><br />';
  570. if ((!$catobj->get_id() == '0') && (!isset($_GET['studentoverview'])) && (!isset($_GET['search']))) {
  571. $scoreinfo .= '<br />'.get_lang('TotalForThisCategory').' : <b>'.$scorecourse_display.'</b>';
  572. }
  573. $scoreinfo .= '<br />'.get_lang('Total').' : <b>'.$scoretotal_display.'</b>';
  574. Display::addFlash(
  575. Display::return_message($scoreinfo, 'normal', false)
  576. );
  577. }
  578. // show navigation tree and buttons?
  579. $header = '<div class="actions">';
  580. if ($is_course_admin) {
  581. $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>';
  582. $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>';
  583. } elseif (!(isset($_GET['studentoverview']))) {
  584. $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>';
  585. } else {
  586. $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>';
  587. }
  588. $header .= '</div>';
  589. echo $header;
  590. }
  591. /**
  592. * @param int $userId
  593. * @param int $categoryId
  594. *
  595. * @return string
  596. */
  597. public static function display_header_user($userId, $categoryId)
  598. {
  599. $user = api_get_user_info($userId);
  600. if (empty($user)) {
  601. return '';
  602. }
  603. $catcourse = Category::load($categoryId);
  604. $scoredisplay = ScoreDisplay::instance();
  605. // generating the total score for a course
  606. $allevals = $catcourse[0]->get_evaluations(
  607. $userId,
  608. true,
  609. api_get_course_id()
  610. );
  611. $alllinks = $catcourse[0]->get_links(
  612. $userId,
  613. true,
  614. api_get_course_id()
  615. );
  616. $evals_links = array_merge($allevals, $alllinks);
  617. $item_value = 0;
  618. $item_total = 0;
  619. for ($count = 0; $count < count($evals_links); $count++) {
  620. $item = $evals_links[$count];
  621. $score = $item->calc_score($userId);
  622. $my_score_denom = ($score[1] == 0) ? 1 : $score[1];
  623. $item_value += $score[0] / $my_score_denom * $item->get_weight();
  624. $item_total += $item->get_weight();
  625. }
  626. $item_value = api_number_format($item_value, 2);
  627. $total_score = [$item_value, $item_total];
  628. $scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
  629. $info = '<div class="row"><div class="col-md-3">';
  630. $info .= '<div class="thumbnail"><img src="'.$user['avatar'].'" /></div>';
  631. $info .= '</div>';
  632. $info .= '<div class="col-md-6">';
  633. $info .= get_lang('Name').' : '.$user['complete_name_with_message_link'].'<br />';
  634. if (api_get_setting('show_email_addresses') == 'true') {
  635. $info .= get_lang('Email').' : <a href="mailto:'.$user['email'].'">'.$user['email'].'</a><br />';
  636. }
  637. $info .= get_lang('TotalUser').' : <b>'.$scorecourse_display.'</b>';
  638. $info .= '</div>';
  639. $info .= '</div>';
  640. echo $info;
  641. }
  642. }