displaygradebook.php 29 KB

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