UserTestStatsStorageAcl.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. Lib::loadClass('Core_AclSimpleSchemaBase');
  3. Lib::loadClass('Schema_UserProcessStorageAcl');
  4. Lib::loadClass('ParseOgcFilter');
  5. Lib::loadClass('ProcesTestyHelper');
  6. class Schema_UserTestStatsStorageAcl extends Core_AclSimpleSchemaBase {
  7. public $_simpleSchema = [
  8. 'root' => [
  9. '@namespace' => 'default_objects/UserTestStats',
  10. 'ID' => [ '@type' => 'xsd:integer' ],
  11. 'PARENT_ID' => [ '@type' => 'xsd:integer' ],
  12. 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
  13. 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
  14. 'link_uruchom_filtr_procesu' => [ '@type' => 'p5:www_link' ],
  15. 'link_uruchom_test_teoretyczny' => [ '@type' => 'p5:www_link', '@label' => "Wykonaj test teoretyczny"],
  16. 'wynik_teoretyczny' => [ '@type' => 'xsd:string', '@label' => "Wynik teoretyczny" ],
  17. 'wynik_teoretyczny_value' => [ '@type' => 'xsd:string', '@label' => "Wynik teoretyczny" ],
  18. 'wynik_praktyczny' => [ '@type' => 'xsd:string', '@label' => "Wynik praktyczny" ],
  19. 'wynik_unactual' => [ '@type' => 'xsd:string', '@label' => "Test nieaktualny?" ],
  20. 'wynik_unactual_id' => [ '@type' => 'xsd:integer', '@label' => "Nr nieaktualnego testu" ],
  21. 'link_popraw_test' => [ '@type' => 'xsd:integer', '@label' => "Popraw test" ],
  22. 'last_update_date' => [ '@type' => 'xsd:date' , '@label' => 'Ostatnia zmiana w procesie' ],
  23. // 'autor' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_CREATE_AUTHOR' ],
  24. // 'utworzono' => [ '@type' => 'xsd:date' , '@alias' => 'A_RECORD_CREATE_DATE' ],
  25. // 'zaktualizował' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_UPDATE_AUTHOR' ],
  26. // 'zaktualizowano' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_UPDATE_DATE' ]
  27. ]
  28. ];
  29. public $_rootTableName = 'CRM_PROCES';
  30. public $idUser = null;
  31. public $_userProcessAcl = null;// Schema_UserProcessStorageAcl
  32. public function __construct($simpleSchema = null) {
  33. parent::__construct($simpleSchema);
  34. $this->idUser = User::getID();// default - current user
  35. $this->_userProcessAcl = new Schema_UserProcessStorageAcl();// Core_AclHelper::getAclByNamespace('default_objects/UserProcess')
  36. $this->_userProcessAcl->setIdUser($this->idUser);
  37. }
  38. public function setIdUser($idUser) { $this->idUser = intval($idUser); $this->_userProcessAcl->setIdUser($this->idUser); }
  39. public function getIdUser() { return $this->idUser; }
  40. public function getTotal($params = []) { return $this->_userProcessAcl->getTotal(); }
  41. public function _parseSqlWhere($params = []) { return $this->_userProcessAcl->_parseSqlWhere($params); }
  42. public function getItems($params = []) {
  43. $bupLimit = V::get('limit', 0, $params);
  44. $params['limit'] = 0;
  45. $items = $this->_userProcessAcl->getItems($params);
  46. if (empty($items)) return $items;
  47. $params['limit'] = $bupLimit;
  48. $sqlWhereAnd[] = "t.ID_PROCES_INIT in (" . implode(",", array_keys($items)) . ")";
  49. // if ($max_age > 0) {
  50. // $sqlWhereAnd[] = "COALESCE(UNIX_TIMESTAMP(t.`TEST_END`), 0) > (UNIX_TIMESTAMP(NOW()) - {$max_age})";
  51. // }
  52. $sqlWhereAnd = (!empty($sqlWhereAnd)) ? "and " . implode("\n and ", $sqlWhereAnd) : '';
  53. $idUser = $this->idUser;
  54. $wynikiTeoret = DB::getPDO()->fetchAllByKey("
  55. select test.ID
  56. , test.ID_PROCES_INIT
  57. , test.OCENA
  58. , test.A_STATUS
  59. , test.TEST_TYPE
  60. , test.TEST_END
  61. from CRM_TESTY test
  62. where test.ID in(
  63. select MAX(t.ID) as ID
  64. from CRM_TESTY t
  65. where t.`ID_TESTER`='{$idUser}'
  66. and t.TEST_TYPE = 'TEORETYCZNY'
  67. {$sqlWhereAnd}
  68. group by t.ID_PROCES_INIT
  69. )
  70. ", 'ID_PROCES_INIT');
  71. DBG::log($wynikiTeoret, 'array', "\$wynikiTeoret");
  72. $wynikiPraktyczne = DB::getPDO()->fetchAllByKey("
  73. select test.ID
  74. , test.ID_PROCES_INIT
  75. , test.OCENA
  76. , test.A_STATUS
  77. , test.TEST_TYPE
  78. , test.TEST_END
  79. from CRM_TESTY test
  80. where test.ID in(
  81. select MAX(t.ID) as ID
  82. from CRM_TESTY t
  83. where t.`ID_TESTER`='{$idUser}'
  84. and t.TEST_TYPE = 'PRAKTYCZNY'
  85. {$sqlWhereAnd}
  86. group by t.ID_PROCES_INIT
  87. )
  88. ", 'ID_PROCES_INIT');
  89. DBG::log($wynikiPraktyczne, 'array', "\$wynikiPraktyczne");
  90. $limit = V::get('limit', 0, $params);
  91. $limit = ($limit < 0) ? 0 : $limit;
  92. $offset = V::get('limitstart', 0, $params);
  93. $offset = ($offset < 0) ? 0 : $offset;
  94. $items = array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
  95. if (empty($items)) return $items;
  96. $testyLastUpdate = DB::getPDO()->fetchAllByKey("
  97. select i.idx_PROCES_INIT_ID as ID, max(p.`A_RECORD_UPDATE_DATE`) as max_update_date
  98. from CRM_PROCES p
  99. join CRM_PROCES_idx i on(i.ID_PROCES = p.ID)
  100. where i.idx_PROCES_INIT_ID in (" . implode(",", array_keys($items)) . ")
  101. group by i.idx_PROCES_INIT_ID
  102. ", 'ID');
  103. DBG::log($testyLastUpdate, 'array', "\$testyLastUpdate");
  104. DBG::log($items, 'array', "\$items...");
  105. array_walk($items, function(&$item, $key) use ($wynikiTeoret, $wynikiPraktyczne, $testyLastUpdate) {
  106. $item['link_uruchom_test_teoretyczny'] = Request::getPathUri() . "procesy5.php?task=CRM_TESTY__ADD_TEST&test_type=TEORETYCZNY&proces_id={$item['ID']}";
  107. $item['wynik_teoretyczny_value'] = (array_key_exists($item['ID'], $wynikiTeoret)) ? $wynikiTeoret[ $item['ID'] ][ 'OCENA' ] : 0;
  108. $item['wynik_teoretyczny'] = ProcesTestyHelper::getOcenaLabel($item['wynik_teoretyczny_value']);
  109. $wynik_praktyczny_value = (array_key_exists($item['ID'], $wynikiPraktyczne)) ? $wynikiPraktyczne[ $item['ID'] ][ 'OCENA' ] : 0;
  110. $item['wynik_praktyczny'] = ProcesTestyHelper::getOcenaLabel($wynik_praktyczny_value);
  111. $item['wynik_unactual'] = '';
  112. $item['wynik_unactual_id'] = '';
  113. $item['link_popraw_test'] = '';
  114. $item['last_test_end'] = '';
  115. $item['last_update_date'] = (array_key_exists($item['ID'], $testyLastUpdate)) ? $testyLastUpdate[ $item['ID'] ][ 'max_update_date' ] : null;
  116. if (array_key_exists($item['ID'], $wynikiTeoret)) {
  117. $test = $wynikiTeoret[ $item['ID'] ];
  118. $item['last_test_end'] = $test['TEST_END'];
  119. $max_update_date = DB::getPDO()->fetchValue("
  120. select max(p.`A_RECORD_UPDATE_DATE`) as max_update_date
  121. from `CRM_PROCES` as p
  122. where p.`ID` in(
  123. select i.`ID_PROCES`
  124. from `CRM_PROCES_idx` i
  125. where i.`idx_PROCES_INIT_ID`='{$item['ID']}'
  126. )
  127. ");
  128. if ($item['last_update_date']) {
  129. $max_update_date = substr($item['last_update_date'], 0, 10);
  130. $test_end = substr($item['last_test_end'], 0, 10);
  131. if ($max_update_date > $test_end) {
  132. $item['wynik_unactual'] = $max_update_date;
  133. $item['wynik_unactual_id'] = $test['ID'];
  134. $item['link_popraw_test'] = "procesy5.php?task=CRM_TESTY__ADD_TEST&function_init=fun_CRM_TESTY__ADD_FIX&test_id={$test['ID']}";
  135. }
  136. }
  137. }
  138. });
  139. return $items;
  140. }
  141. }