Kaynağa Gözat

fixed bug in user tests - wrong group by in test stats sql

Piotr Labudda 9 yıl önce
ebeveyn
işleme
261c648b89

+ 2 - 3
SE/se-lib/ProcesMenu.php

@@ -24,7 +24,7 @@ class ProcesMenu {
 	function __construct() {
 		$this->_user_id = User::getID();
 		if (User::isAdmin()) {
-			$this->_user_id = V::get('_user_id', 0, $_POST, 'int');
+			$this->_user_id = V::get('_user_id', 0, $_REQUEST, 'int');
 			if (!$this->_user_id) {
 				$this->_user_id = User::getID();
 			}
@@ -35,8 +35,7 @@ class ProcesMenu {
 			die('Error Acl');
 		}
 
-		// TODO: run only if needed
-		if ('1' == V::get('_CLEAN_CACHE', '', $_POST)) {
+		if ('1' == V::get('_CLEAN_CACHE', '', $_REQUEST)) {
 			$this->_cleanTestsCache();
 		}
 		$this->_generateTestResults();

+ 22 - 19
SE/se-lib/ProcesTestyHelper.php

@@ -327,36 +327,39 @@ class ProcesTestyHelper {
 	/**
 	 * Get Testy stats by user.
 	 *
-	 * @param int $user_id
+	 * @param int $idUser
 	 * @param int $max_age
 	 * @param array $proces_ids
 	 *
-	 * @usage $testy = ProcesTestyHelper::get_tetsy_stats($user_id, 30000000, $proces_ids);
+	 * @usage $testy = ProcesTestyHelper::get_tetsy_stats($idUser, 30000000, $proces_ids);
 	 */
-	public static function get_tetsy_stats($user_id, $max_age = 0, $proces_ids = array()) {
+	public static function get_tetsy_stats($idUser, $max_age = 0, $proces_ids = array()) {
 		$testy_stats = array();
 		Lib::loadClass('DB');
 		$db = DB::getDB();
-		$sql_where_arr = array();
-		$sql_where_arr[] = "t.`ID_TESTER`='{$user_id}'";
+		$sqlWhereAnd = array();
 		if (!empty($proces_ids)) {
-			$sql_where_arr[] = "t.`ID_PROCES_INIT` in (" . implode(",", $proces_ids) . ")";
+			$sqlWhereAnd[] = "t.`ID_PROCES_INIT` in (" . implode(",", $proces_ids) . ")";
 		}
 		if ($max_age > 0) {
-			$sql_where_arr[] = "COALESCE(UNIX_TIMESTAMP(t.`TEST_END`), 0) > (UNIX_TIMESTAMP(NOW()) - {$max_age})";
+			$sqlWhereAnd[] = "COALESCE(UNIX_TIMESTAMP(t.`TEST_END`), 0) > (UNIX_TIMESTAMP(NOW()) - {$max_age})";
 		}
-		$sql = "select MAX(tbl.`ID`) as `ID`
-				, tbl.`ID_PROCES_INIT`
-				, tbl.`OCENA`
-				, tbl.`A_STATUS`
-				, tbl.`TEST_TYPE`
-				, tbl.`TEST_END`
-			from ( select t.`ID`, t.`ID_PROCES_INIT`, t.`OCENA`, t.`A_STATUS`, t.`TEST_TYPE`, t.`TEST_END`
-				from `CRM_TESTY` as t
-				where " . implode("\n and ", $sql_where_arr) . "
-				order by t.`ID` DESC
-			) AS tbl
-			group by tbl.`TEST_TYPE`, tbl.`ID_PROCES_INIT`
+		$sqlWhereAnd = (!empty($sqlWhereAnd)) ? "and " . implode("\n and ", $sqlWhereAnd) : '';
+		$sql = "
+			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}'
+					{$sqlWhereAnd}
+				group by t.TEST_TYPE, t.ID_PROCES_INIT
+			)
 		";
 		$res = $db->query($sql);
 		while ($r = $db->fetch($res)) {

+ 28 - 8
SE/se-lib/Route/UserTest.php

@@ -16,23 +16,43 @@ class Route_UserTest extends RouteBase {
     try {
       $procesMenu = ProcesMenu::getInstance();
       // $procesMenu->menuAction();// like UI::menu() ?
-      $userAcl = User::getAcl();
       $acl = Core_AclHelper::getAclByNamespace('default_objects/UserProcess');
       $userProcessList = $acl->getItems();
-      DBG::nicePrint($userProcessList, '$userProcessList');
-      $procesyInitGroup = $this->getUsedProcesInitGroupedList($userAcl);
-      DBG::nicePrint($procesyInitGroup, '$procesyInitGroup');
-  		if (empty($procesyInitGroup)) {
-  			echo '<p>' . "Brak przypisanych procesów." . '</p>';
-  			return;
-  		}
+      $this->userTestsView($userProcessList);
+    } catch (Exception $e) {
+      UI::alert('danger', $e->getMessage());
+    }
+    UI::dol();
+  }
 
+  public function adminUserTestAction() {// TODO: replace POST from admin menu to view another user tests
+    UI::gora();
+    UI::menu();
+    try {
+      $idUser = V::get('_user_id', 0, $_REQUEST, 'int');
+      $acl = Core_AclHelper::getAclByNamespace('default_objects/UserProcess');
+      $acl->setIdUser($idUser);
+      $userProcessList = $acl->getItems();
+      $this->userTestsView($userProcessList);
     } catch (Exception $e) {
       UI::alert('danger', $e->getMessage());
     }
     UI::dol();
   }
 
+  public function userTestsView($userProcessList) {
+    DBG::nicePrint($userProcessList, '$userProcessList');
+
+    // old way
+    $userAcl = User::getAcl();
+    $procesyInitGroup = $this->getUsedProcesInitGroupedList($userAcl);
+    DBG::nicePrint($procesyInitGroup, '$procesyInitGroup');
+    if (empty($procesyInitGroup)) {
+      echo '<p>' . "Brak przypisanych procesów." . '</p>';
+      return;
+    }
+  }
+
   public function getUsedProcesInitGroupedList($userAcl) {
 		$procesyInitGroup = array();
 		$procesyInitList = $this->getUserProcesInitList($userAcl);

+ 12 - 2
SE/se-lib/Schema/UserProcessStorageAcl.php

@@ -9,6 +9,7 @@ class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
     'root' => [
       '@namespace' => 'default_objects/UserProcess',
       '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' ],
@@ -19,6 +20,15 @@ class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
     ]
   ];
   public $_rootTableName = 'CRM_PROCES';
+  public $idUser = null;
+
+  public function __construct($simpleSchema = null) {
+    parent::__construct($simpleSchema);
+    $this->idUser = User::getID();// default - current user
+  }
+
+  public function setIdUser($idUser) { $this->idUser = intval($idUser); }
+  public function getIdUser() { return $this->idUser; }
 
   public function getTotal($params = []) {
     $sqlWhereAnd = $this->_parseSqlWhere($params);
@@ -81,6 +91,7 @@ class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
 
     $items = DB::getPDO()->fetchAllByKey("
       select p.ID
+        , p.PARENT_ID
         , p.`DESC` as nazwa
         , p.`OPIS` as opis
         , p.A_RECORD_CREATE_AUTHOR as `autor`
@@ -107,7 +118,6 @@ class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
   }
 
   public function _getUserIdGroupList() {
-    $idUser = User::getID();
     return array_map(
       function ($row) {
         return $row['ID'];
@@ -117,7 +127,7 @@ class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
         from `CRM_AUTH_PROFILE` as up
           left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
         where
-          up.`REMOTE_ID`='{$idUser}'
+          up.`REMOTE_ID`='{$this->idUser}'
           and up.`A_STATUS` in('WAITING', 'NORMAL')
           and up.`REMOTE_TABLE`='ADMIN_USERS'
           and z.`ID` is not null