[ '@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::_('DBG', '>0', "\$wynikiTeoret", $wynikiTeoret, __CLASS__, __FUNCTION__, __LINE__); $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::_('DBG', '>0', "\$wynikiPraktyczne", $wynikiPraktyczne, __CLASS__, __FUNCTION__, __LINE__); $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::_('DBG', '>0', "\$testyLastUpdate", $testyLastUpdate, __CLASS__, __FUNCTION__, __LINE__); 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['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; } }