| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- Lib::loadClass('Core_AclSimpleSchemaBase');
- Lib::loadClass('Schema_UserProcessStorageAcl');
- Lib::loadClass('ParseOgcFilter');
- Lib::loadClass('ProcesTestyHelper');
- class Schema_UserTestStatsStorageAcl extends Core_AclSimpleSchemaBase {
- public $_simpleSchema = [
- 'root' => [
- '@namespace' => 'default_objects/UserTestStats',
- 'ID' => [ '@type' => 'xsd:integer' ],
- 'PARENT_ID' => [ '@type' => 'xsd:integer' ],
- 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
- 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
- 'link_uruchom_filtr_procesu' => [ '@type' => 'p5:www_link' ],
- 'link_uruchom_test_teoretyczny' => [ '@type' => 'p5:www_link', '@label' => "Wykonaj test teoretyczny"],
- 'wynik_teoretyczny' => [ '@type' => 'xsd:string', '@label' => "Wynik teoretyczny" ],
- 'wynik_teoretyczny_value' => [ '@type' => 'xsd:string', '@label' => "Wynik teoretyczny" ],
- 'wynik_praktyczny' => [ '@type' => 'xsd:string', '@label' => "Wynik praktyczny" ],
- 'wynik_unactual' => [ '@type' => 'xsd:string', '@label' => "Test nieaktualny?" ],
- 'wynik_unactual_id' => [ '@type' => 'xsd:integer', '@label' => "Nr nieaktualnego testu" ],
- 'link_popraw_test' => [ '@type' => 'xsd:integer', '@label' => "Popraw test" ],
- 'last_update_date' => [ '@type' => 'xsd:date' , '@label' => 'Ostatnia zmiana w procesie' ],
- // 'autor' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_CREATE_AUTHOR' ],
- // 'utworzono' => [ '@type' => 'xsd:date' , '@alias' => 'A_RECORD_CREATE_DATE' ],
- // 'zaktualizował' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_UPDATE_AUTHOR' ],
- // 'zaktualizowano' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_UPDATE_DATE' ]
- ]
- ];
- public $_rootTableName = 'CRM_PROCES';
- public $idUser = null;
- public $_userProcessAcl = null;// Schema_UserProcessStorageAcl
- public function __construct($simpleSchema = null) {
- parent::__construct($simpleSchema);
- $this->idUser = User::getID();// default - current user
- $this->_userProcessAcl = new Schema_UserProcessStorageAcl();// Core_AclHelper::getAclByNamespace('default_objects/UserProcess')
- $this->_userProcessAcl->setIdUser($this->idUser);
- }
- public function setIdUser($idUser) { $this->idUser = intval($idUser); $this->_userProcessAcl->setIdUser($this->idUser); }
- public function getIdUser() { return $this->idUser; }
- public function getTotal($params = []) { return $this->_userProcessAcl->getTotal(); }
- public function _parseSqlWhere($params = []) { return $this->_userProcessAcl->_parseSqlWhere($params); }
- public function getItems($params = []) {
- $bupLimit = V::get('limit', 0, $params);
- $params['limit'] = 0;
- $items = $this->_userProcessAcl->getItems($params);
- if (empty($items)) return $items;
- $params['limit'] = $bupLimit;
- $sqlWhereAnd[] = "t.ID_PROCES_INIT in (" . implode(",", array_keys($items)) . ")";
- // if ($max_age > 0) {
- // $sqlWhereAnd[] = "COALESCE(UNIX_TIMESTAMP(t.`TEST_END`), 0) > (UNIX_TIMESTAMP(NOW()) - {$max_age})";
- // }
- $sqlWhereAnd = (!empty($sqlWhereAnd)) ? "and " . implode("\n and ", $sqlWhereAnd) : '';
- $idUser = $this->idUser;
- $wynikiTeoret = DB::getPDO()->fetchAllByKey("
- select test.ID
- , test.ID_PROCES_INIT
- , test.OCENA
- , test.A_STATUS
- , test.TEST_TYPE
- , test.TEST_END
- from CRM_TESTY test
- where test.ID in(
- select MAX(t.ID) as ID
- from CRM_TESTY t
- where t.`ID_TESTER`='{$idUser}'
- and t.TEST_TYPE = 'TEORETYCZNY'
- {$sqlWhereAnd}
- group by t.ID_PROCES_INIT
- )
- ", 'ID_PROCES_INIT');
- DBG::log($wynikiTeoret, 'array', "\$wynikiTeoret");
- $wynikiPraktyczne = DB::getPDO()->fetchAllByKey("
- select test.ID
- , test.ID_PROCES_INIT
- , test.OCENA
- , test.A_STATUS
- , test.TEST_TYPE
- , test.TEST_END
- from CRM_TESTY test
- where test.ID in(
- select MAX(t.ID) as ID
- from CRM_TESTY t
- where t.`ID_TESTER`='{$idUser}'
- and t.TEST_TYPE = 'PRAKTYCZNY'
- {$sqlWhereAnd}
- group by t.ID_PROCES_INIT
- )
- ", 'ID_PROCES_INIT');
- DBG::log($wynikiPraktyczne, 'array', "\$wynikiPraktyczne");
- $limit = V::get('limit', 0, $params);
- $limit = ($limit < 0) ? 0 : $limit;
- $offset = V::get('limitstart', 0, $params);
- $offset = ($offset < 0) ? 0 : $offset;
- $items = array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
- if (empty($items)) return $items;
- $testyLastUpdate = DB::getPDO()->fetchAllByKey("
- select i.idx_PROCES_INIT_ID as ID, max(p.`A_RECORD_UPDATE_DATE`) as max_update_date
- from CRM_PROCES p
- join CRM_PROCES_idx i on(i.ID_PROCES = p.ID)
- where i.idx_PROCES_INIT_ID in (" . implode(",", array_keys($items)) . ")
- group by i.idx_PROCES_INIT_ID
- ", 'ID');
- DBG::log($testyLastUpdate, 'array', "\$testyLastUpdate");
- DBG::log($items, 'array', "\$items...");
- array_walk($items, function(&$item, $key) use ($wynikiTeoret, $wynikiPraktyczne, $testyLastUpdate) {
- $item['link_uruchom_test_teoretyczny'] = Request::getPathUri() . "procesy5.php?task=CRM_TESTY__ADD_TEST&test_type=TEORETYCZNY&proces_id={$item['ID']}";
- $item['wynik_teoretyczny_value'] = (array_key_exists($item['ID'], $wynikiTeoret)) ? $wynikiTeoret[ $item['ID'] ][ 'OCENA' ] : 0;
- $item['wynik_teoretyczny'] = ProcesTestyHelper::getOcenaLabel($item['wynik_teoretyczny_value']);
- $wynik_praktyczny_value = (array_key_exists($item['ID'], $wynikiPraktyczne)) ? $wynikiPraktyczne[ $item['ID'] ][ 'OCENA' ] : 0;
- $item['wynik_praktyczny'] = ProcesTestyHelper::getOcenaLabel($wynik_praktyczny_value);
- $item['wynik_unactual'] = '';
- $item['wynik_unactual_id'] = '';
- $item['link_popraw_test'] = '';
- $item['last_test_end'] = '';
- $item['last_update_date'] = (array_key_exists($item['ID'], $testyLastUpdate)) ? $testyLastUpdate[ $item['ID'] ][ 'max_update_date' ] : null;
- if (array_key_exists($item['ID'], $wynikiTeoret)) {
- $test = $wynikiTeoret[ $item['ID'] ];
- $item['last_test_end'] = $test['TEST_END'];
- $max_update_date = DB::getPDO()->fetchValue("
- select max(p.`A_RECORD_UPDATE_DATE`) as max_update_date
- from `CRM_PROCES` as p
- where p.`ID` in(
- select i.`ID_PROCES`
- from `CRM_PROCES_idx` i
- where i.`idx_PROCES_INIT_ID`='{$item['ID']}'
- )
- ");
- if ($item['last_update_date']) {
- $max_update_date = substr($item['last_update_date'], 0, 10);
- $test_end = substr($item['last_test_end'], 0, 10);
- if ($max_update_date > $test_end) {
- $item['wynik_unactual'] = $max_update_date;
- $item['wynik_unactual_id'] = $test['ID'];
- $item['link_popraw_test'] = "procesy5.php?task=CRM_TESTY__ADD_TEST&function_init=fun_CRM_TESTY__ADD_FIX&test_id={$test['ID']}";
- }
- }
- }
- });
- return $items;
- }
- }
|