Ver código fonte

新增 下載、瀏覽排序

oransheep 3 anos atrás
pai
commit
b0939e3e62
2 arquivos alterados com 42 adições e 0 exclusões
  1. 28 0
      api-detail.php
  2. 14 0
      script/php/update_popularity.php

+ 28 - 0
api-detail.php

@@ -62,6 +62,18 @@ if (!isset($_SESSION['loggedin'])) {
 			console.log(error);
 		});
 
+		$.ajax({
+			url: "./script/php/update_popularity.php",
+			type: "GET",
+			async: false,
+			data: {
+				api_id: object,
+				update_type: "viewTimes",
+			},
+			contentType: "application/json",
+			dataType: "json"
+		});
+
 		pageHeader = "BIM程式庫";
 	</script>
 </head>
@@ -173,6 +185,22 @@ if (!isset($_SESSION['loggedin'])) {
 		}else if(webLink == null){
 			$("#webLink").append("<span>" + source + "</span>");
 		}
+
+		$(document).ready(function() {
+			$("#apiList a").on("click", function() {
+				$.ajax({
+					url: "./script/php/update_popularity.php",
+					type: "GET",
+					async: false,
+					data: {
+						api_id: object,
+						update_type: "downloadTimes",
+					},
+					contentType: "application/json",
+					dataType: "json"
+				});
+			});
+		});
 		
 	</script>
 	<script src="assets/vendor/jstree/jstree.js"></script>

+ 14 - 0
script/php/update_popularity.php

@@ -0,0 +1,14 @@
+<?php
+if (isset($_GET['api_id'])) {
+include("connectSQL_Component.php");
+
+$api_id = $_GET['api_id'];
+$update_type = $_GET['update_type'];
+
+$sql = "UPDATE [BIMComponents].[dbo].[API_Table] SET $update_type += 1 WHERE [id] = $api_id;";
+
+$fetchResult = sqlsrv_query($conn, $sql);
+
+} else {
+    die("post error!");
+}