Browse Source

mv to PDO in TableMsgs route

Piotr Labudda 6 năm trước cách đây
mục cha
commit
9332327130
1 tập tin đã thay đổi với 29 bổ sung42 xóa
  1. 29 42
      SE/se-lib/Route/TableMsgs.php

+ 29 - 42
SE/se-lib/Route/TableMsgs.php

@@ -427,29 +427,18 @@ function tblMsgsLoadMoreRows(n) {
 		$toType = V::get('to_type', '', $args);
 		$to = V::get('to', '', $args);
 		$msg = V::get('msg', '', $args);
-		$usrLogin = User::getLogin();
 
-		$db = DB::getDB();
-		if (!$db) throw new Exception("Brak dazy danych!");
-		if ($db->has_errors()) throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
-		$item = array();
-		$item['`uiTargetType`'] = "'default_db_table_record'";
-		$item['`uiTargetName`'] = "'{$tableName}.{$idRow}'";
-		$item['`userTargetType`'] = "'{$toType}'";
-		$item['`userTargetName`'] = "'{$to}'";
-		$item['`msg`'] = "'" . $db->_($msg) . "'";
-		$item['`A_RECORD_CREATE_DATE`'] = "NOW()";
-		$item['`A_RECORD_CREATE_AUTHOR`'] = "'{$usrLogin}'";
-		$item['`A_STATUS`'] = "'WAITING'";
-		$item['`app_className`'] = "'TableMsgs'";
-		$sql = "insert into `CRM_UI_MSGS` (" . implode(",", array_keys($item)) . ")
-			values (" . implode(",", array_values($item)) . ")
-		";
-		$res = $db->query($sql);
-		if (!$res || $db->has_errors()) throw new Exception("Wystąpiły błędy podczas próby zapisu wiadomości: " . implode("\n<br>", $db->get_errors()));
-		$createdId = $db->insert_id();
-		if ($createdId <= 0) throw new Exception("Nie udało się zapisać wiadomości.");
-		return $createdId;
+		return DB::getPDO()->insert('CRM_UI_MSGS', [
+			'uiTargetType' => 'default_db_table_record',
+			'uiTargetName' => "{$tableName}.{$idRow}",
+			'userTargetType' => $toType,
+			'userTargetName' => $to,
+			'msg' => $msg,
+			'A_RECORD_CREATE_DATE' => "NOW()",
+			'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
+			'A_STATUS' => 'WAITING',
+			'app_className' => 'TableMsgs',
+		]);
 	}
 
 	function _printMsgForm($args) {
@@ -670,29 +659,27 @@ function tblMsgsLoadMoreRows(n) {
 	function _markAsRead($msg) {
 		if ($msg['_read']) return;
 
-		$usrLogin = User::getLogin();
-		$db = DB::getDB();
-		if (!$db) throw new Exception("Brak dazy danych!");
-		if ($db->has_errors()) throw new Exception("DB Errors: " . implode("\n<br>", $db->get_errors()));
-		$sql = "update `CRM_UI_MSGS`
-			set `A_STATUS`='NORMAL'
-				, `A_RECORD_UPDATE_AUTHOR`='{$usrLogin}'
-				, `A_RECORD_UPDATE_DATE`=NOW()
-				, `actionExecutedTime`=NOW()
-			where `ID`='{$msg['_raw']->ID}'
-				and `A_STATUS`='WAITING'
-				and `A_RECORD_UPDATE_AUTHOR`=''
-				and `A_RECORD_UPDATE_DATE` is null
+		DB::getPDO()->execSql("
+			update CRM_UI_MSGS
+			set A_STATUS = 'NORMAL'
+				, A_RECORD_UPDATE_AUTHOR = :login
+				, A_RECORD_UPDATE_DATE = NOW()
+				, actionExecutedTime = NOW()
+			where ID = :id
+				and A_STATUS = 'WAITING'
+				and A_RECORD_UPDATE_AUTHOR = ''
+				and A_RECORD_UPDATE_DATE is null
 				and (
-					('{$usrLogin}'!=`A_RECORD_CREATE_AUTHOR`)
-					or ('{$usrLogin}'=`A_RECORD_CREATE_AUTHOR`
-						and 'user'=`userTargetType`
-						and '{$usrLogin}'=`userTargetName`
+					( :login != A_RECORD_CREATE_AUTHOR )
+					or ( :login = A_RECORD_CREATE_AUTHOR
+						and 'user' = userTargetType
+						and :login = userTargetName
 					)
 				)
-		";
-		$res = $db->query($sql);
-		if (!$res || $db->has_errors()) throw new Exception("Wystąpiły błędy podczas próby zapisu wiadomości: " . implode("\n<br>", $db->get_errors()));
+		", [
+			':id' => $msg['_raw']->ID,
+			':login' => User::getLogin(),
+		]);
 	}
 
 	function viewMsg($msg) {