UserTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. class Route_UserTest extends RouteBase {
  4. public function handleAuth() {
  5. if (!User::logged()) User::authByRequest();
  6. }
  7. public function defaultAction() {
  8. UI::gora();
  9. UI::menu();
  10. session_write_close();
  11. try {
  12. $procesMenu = ProcesMenu::getInstance();
  13. // $procesMenu->menuAction();// like UI::menu() ?
  14. $acl = Core_AclHelper::getAclByNamespace('default_objects/UserTestStats');// default_objects/UserProcess
  15. $userTestStatsList = $acl->getItems();
  16. UI::setTitle("Testy - Moje");
  17. $this->userTestsView($userTestStatsList);
  18. } catch (Exception $e) {
  19. UI::alert('danger', $e->getMessage());
  20. }
  21. UI::dol();
  22. }
  23. public function adminUserTestAction() {// TODO: replace POST from admin menu to view another user tests
  24. UI::gora();
  25. UI::menu();
  26. session_write_close();
  27. try {
  28. $idUser = V::get('_user_id', 0, $_REQUEST, 'int');
  29. $user = [];// $user = Core_AclHelper::getAclByNamespace('default_db/ADMIN_USERS')->getItem($idUser);
  30. $user['name'] = "TODO: user name({$idUser})";
  31. $acl = Core_AclHelper::getAclByNamespace('default_objects/UserTestStats');// default_objects/UserProcess
  32. $acl->setIdUser($idUser);
  33. $userTestStatsList = $acl->getItems();
  34. UI::setTitle("Testy - pracownika {$user['name']}");
  35. $this->userTestsView($userTestStatsList);
  36. } catch (Exception $e) {
  37. UI::alert('danger', $e->getMessage());
  38. }
  39. UI::dol();
  40. }
  41. public function userTestsView($userTestStatsList) {
  42. $activeFiltrProcessId = User::getAcl()->getPermsFiltrProcesId();
  43. echo UI::h('style', [ 'type' => "text/css" ], "
  44. .tbl-wyniki-testow {}
  45. .tbl-wyniki-testow td {vertical-align:top;font-size:small;}
  46. .tbl-wyniki-testow .proces-box {padding:0 6px;background:#f00;color:#fff;font-weight:bold;font-family:arial;text-decoration:none}
  47. .tbl-wyniki-testow .proces-title {padding:0 3px;}
  48. .tbl-wyniki-testow .wynik-cell .wyniki-cell-header {height:56px;overflow:hidden;}
  49. .tbl-wyniki-testow .wynik-cell {padding:0 3px;}
  50. .tbl-wyniki-testow .wynik-BRAK_TESTU .proces-box {background-color:silver;}
  51. .tbl-wyniki-testow .wynik-BRAK_PYTAN .proces-box {background-color:#51B7D5;}
  52. .tbl-wyniki-testow .wynik-DOBRY .proces-box {background-color:lightgreen;}
  53. .tbl-wyniki-testow .wynik-DOSTATECZNY .proces-box {background-color:#FFFFB1; color:#777;}
  54. .tbl-wyniki-testow .wynik-NIEDOSTATECZNY .proces-box {background-color:#FC5151;}
  55. .tbl-wyniki-testow .wynik-IDEALNY .proces-box {background-color:gold;}
  56. .tbl-wyniki-testow .wynik-NIEAKTUALNY .proces-box {background-color:silver;}
  57. ");
  58. $procesyInitList = [];
  59. foreach ($userTestStatsList as $row) {
  60. $procesyInitList[ $row['ID'] ] = $row['nazwa'];
  61. }
  62. $parentIdList = array_filter(
  63. array_map(function ($row) {
  64. return (int)$row['PARENT_ID'];
  65. }, $userTestStatsList),
  66. function ($id) { return $id > 0; }
  67. );
  68. $sqlProcesyInitIds = (!empty($parentIdList)) ? implode(",", $parentIdList) : '';
  69. $parentProcessList = DB::getPDO()->fetchAll("
  70. select p.ID, p.PARENT_ID, p.DESC as nazwa
  71. from CRM_PROCES as p
  72. where p.ID in({$sqlProcesyInitIds})
  73. ");
  74. foreach ($parentProcessList as $parentProcess) {
  75. echo UI::h('div', ['class'=>"container tbl-wyniki-testow page-header"], [
  76. UI::h('h3', [], [
  77. "{$parentProcess['nazwa']} ",
  78. UI::h('small', [], [
  79. UI::h('a', [ 'href' => "procesy5.php?task=CRM_PROCES&amp;filtr_id={$parentProcess['ID']}" ], "{{$parentProcess['ID']}}"),
  80. ]),
  81. ]),
  82. ]);
  83. UI::startContainer(['class'=>"tbl-wyniki-testow"]);
  84. UI::startTag('div', ['class'=>"row"]);
  85. $i = 0;
  86. foreach ($userTestStatsList as $testStats) {
  87. if ($testStats['PARENT_ID'] != $parentProcess['ID']) continue;
  88. echo UI::h('div', ['class'=>"col-md-3 wynik-cell wynik-{$testStats['wynik_teoretyczny']}"], [
  89. UI::h('div', ['class'=>"panel panel-default"], [
  90. UI::h('div', ['class'=>"panel-heading"], [
  91. UI::h('span', ['title'=>htmlspecialchars($testStats['nazwa']), 'data-toggle'=>"tooltip"], V::strShortUtf8($testStats['nazwa'], 80)),
  92. UI::h('a', ['href'=>"procesy5.php?task=PROCES_VIEW&id_proces={$testStats['ID']}", 'title'=>"zobacz instrukcję do procesu {$testStats['ID']}", 'target'=>"_blank"], "{{$testStats['ID']}}"),
  93. ]), // .panel-heading
  94. UI::h('div', ['class'=>"panel-body"], [
  95. UI::h('ul', ['style' => "padding-left:20px"], [
  96. UI::h('li', [], [
  97. ($activeFiltrProcessId == $testStats['ID'])
  98. ? UI::h('a', ['href'=>"index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsAll", 'style'=>"font-weight:bold"], "Wyłącz filtr uprawnien dla")
  99. : UI::h('a', ['href'=>"index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces={$testStats['ID']}"], "Uruchom filtr uprawnien dla"),
  100. " {$testStats['ID']}"
  101. ]),
  102. UI::h('li', [], [
  103. UI::h('a', ['href'=>"procesy5.php?task=CRM_TESTY__ADD_TEST&test_type=TEORETYCZNY&proces_id={$testStats['ID']}"], "Wykonaj test teoretyczny dla"),
  104. " {$testStats['ID']}",
  105. ]),
  106. UI::h('li', [], [
  107. "Test teoretyczny: ",
  108. UI::h('span', ['class'=>"proces-box"], [
  109. " {$testStats['wynik_teoretyczny']} ",
  110. ($testStats['wynik_teoretyczny_value'])
  111. ? UI::h('em', null, $testStats['wynik_teoretyczny_value'])
  112. : '',
  113. ]),
  114. ]),
  115. UI::h('li', ['class'=>"wynik-{$testStats['wynik_praktyczny']}"], "Test praktyczny: {$testStats['wynik_praktyczny']}"),
  116. ]),
  117. ($testStats['wynik_unactual'])
  118. ? UI::h('div', [ 'class' => "alert alert-danger" ], [
  119. "<b>Uwaga! Test nieaktualny: </b> ",
  120. ($testStats['link_popraw_test'])
  121. ? " <a class=\"btn btn-xs btn-primary\" href=\"{$testStats['link_popraw_test']}\">popraw</a>"
  122. : '',
  123. "<br>" . substr($testStats['last_test_end'], 0, 10) . " - zakończenie testu",
  124. "<br>" . substr($testStats['last_update_date'], 0, 10) . " - ostatnia zmiana w procesie",
  125. ])
  126. : '',
  127. ]), // .panel-body
  128. ]), // .panel
  129. ]); // .wynik-cell
  130. if (++$i >= 4) {
  131. $i = 0;
  132. UI::endTag('div');// .row
  133. UI::startTag('div', ['class'=>"row"]);
  134. }
  135. }
  136. UI::endTag('div');// .row
  137. UI::endContainer();
  138. }
  139. }
  140. }