Просмотр исходного кода

article信息查询支持redis

visuddhinanda 5 лет назад
Родитель
Сommit
c9f13fb54e
6 измененных файлов с 146 добавлено и 13 удалено
  1. 5 8
      app/article/card.php
  2. 98 0
      app/article/function.php
  3. 16 1
      app/channal/function.php
  4. 4 4
      app/group/group.js
  5. 6 0
      app/redis/redis.json
  6. 17 0
      app/share/function.php

+ 5 - 8
app/article/card.php

@@ -2,21 +2,18 @@
 //
 
 require_once "../path.php";
-require_once "../public/_pdo.php";
+require_once "./function.php";
 require_once '../ucenter/function.php';
-
+require_once '../redis/function.php';
 
 if (isset($_GET["id"])) {
 	$output["id"]=$_GET["id"];
-	PDO_Connect( _FILE_DB_USER_ARTICLE_);
-	$query = "SELECT title,create_time,owner,summary FROM article  WHERE id = ? ";
-	$result = PDO_FetchRow($query, array($_GET["id"]));
-	$strData="";
+	$redis = redis_connect();
+	$article = new Article($redis); 
+	$result = $article->getInfo($_GET["id"]);
 	if ($result) {
-		
 		$_userinfo = new UserInfo();
 		$name = $_userinfo->getName($result["owner"]);
-
 		$strData .= "<div>标题:".$result["title"]."</div>";
 		$strData .=  "<div>创建人:".$name["nickname"]."</div>";
 		$strData .=  "<div>创建时间:".date("Y/m/d",$result["create_time"]/1000)."</div>";

+ 98 - 0
app/article/function.php

@@ -0,0 +1,98 @@
+<?php
+require_once "../path.php";
+require_once "../share/function.php";
+
+class Article
+{
+    private $dbh;
+	private $_redis;
+    public function __construct($redis=false) {
+        $this->dbh = new PDO(_FILE_DB_USER_ARTICLE_, "", "",array(PDO::ATTR_PERSISTENT=>true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+		$this->_redis=$redis;
+    }
+
+    public function getInfo($id){
+		$output = array();
+		if($this->_redis!==false){
+			if($this->_redis->exists("article://info/".$id)===1){
+				$output["title"]=$this->_redis->hGet("article://info/".$id,"title");
+				$output["owner"]=$this->_redis->hGet("article://info/".$id,"owner");
+				$output["summary"]=$this->_redis->hGet("article://info/".$id,"summary");
+				$output["status"]=$this->_redis->hGet("article://info/".$id,"status");
+				$output["create_time"]=$this->_redis->hGet("article://info/".$id,"create_time");
+				$output["modify_time"]=$this->_redis->hGet("article://info/".$id,"modify_time");
+				return $output;
+			}
+		}
+        $query = "SELECT title,owner,summary,status,create_time,modify_time FROM article WHERE id= ? ";
+        $stmt = $this->dbh->prepare($query);
+        $stmt->execute(array($id));
+        $output = $stmt->fetch(PDO::FETCH_ASSOC);
+        if($output){
+			if($this->_redis!==false){
+				$this->_redis->hSet("article://info/".$id,"title",$output["title"]);
+				$this->_redis->hSet("article://info/".$id,"owner",$output["owner"]);
+				$this->_redis->hSet("article://info/".$id,"summary",$output["summary"]);
+				$this->_redis->hSet("article://info/".$id,"status",$output["status"]);
+				$this->_redis->hSet("article://info/".$id,"create_time",$output["create_time"]);
+				$this->_redis->hSet("article://info/".$id,"modify_time",$output["modify_time"]);
+			}
+            return $output;
+        }
+        else{
+            return false;
+        }
+	}
+	public function getTitle($id){
+
+		$query = "SELECT title FROM article  WHERE id = ? ";
+		$stmt = $this->dbh->prepare($query);
+		$stmt->execute(array($id));
+		$channal = $stmt->fetch(PDO::FETCH_ASSOC);
+		if ($channel) {
+			return $channel["name"];
+		} else {
+			return "";
+		}
+	}
+	public function getPower($id){
+		#查询用户对此channel是否有权限		
+
+		$iPower = 0;
+		$query = "SELECT owner,status FROM article WHERE id=? and status>0 ";
+		$stmt = $this->dbh->prepare($query);
+		$stmt->execute(array($id));
+		$channel = $stmt->fetch(PDO::FETCH_ASSOC);
+		if($channel){
+			if(!isset($_COOKIE["userid"])  ){
+				#未登录用户
+				if($channel["status"]==30){
+					#全网公开有建议权限
+					return 10;
+				}
+				else{
+					#其他状态没有任何权限
+					return 0;
+				}
+				
+			}
+			if($channel["owner"]==$_COOKIE["userid"]){
+				return 30;
+			}
+			else if($channel["status"]>=30){
+				#全网公开的 可以提交pr
+				$iPower = 10;
+			}
+		}
+		#查询共享权限,如果共享权限更大,覆盖上面的的
+		$sharePower = share_get_res_power($_COOKIE["userid"],$id);
+		if($sharePower>$iPower){
+			$iPower=$sharePower;
+		}
+		return $iPower;
+	}
+
+}
+
+?>

+ 16 - 1
app/channal/function.php

@@ -38,7 +38,22 @@ class Channal
             return false;
         }
 	}
-	
+	public function getTitle($id)
+	{
+		if (isset($id)) {
+			$query = "SELECT name FROM channal  WHERE id = ? ";
+			$stmt = $this->dbh->prepare($query);
+			$stmt->execute(array($id));
+			$channal = $stmt->fetch(PDO::FETCH_ASSOC);
+			if ($channel) {
+				return $channel["name"];
+			} else {
+				return "";
+			}
+		} else {
+			return "";
+		}
+	}
 	public function getPower($id){
 		#查询用户对此channel是否有权限		
 

+ 4 - 4
app/group/group.js

@@ -190,7 +190,7 @@ function group_list(id, list) {
 								case 1: //pcs
 									html += "<use xlink:href='../studio/svg/icon.svg#article'></use>";
 									cardUrl = "../doc/card.php";
-									html +=
+									doing +=
 										"<a href='../studio/project.php?op=open&doc_id=" +
 										iterator.res_id +
 										"'>打开</a>";
@@ -203,9 +203,9 @@ function group_list(id, list) {
 									html += "<use xlink:href='../studio/svg/icon.svg#article-1'></use>";
 									cardUrl = "../article/card.php";
 									doing +=
-										"<a href='../article/?id=" + iterator.res_id + "' target='_blank'>预览</a>";
+										"<a href='../article/?id=" + iterator.res_id + "' target='_blank'>查看</a>";
 									doing +=
-										"<a href='../article/my_article_edit.php?id=" +
+										"|<a href='../article/my_article_edit.php?id=" +
 										iterator.res_id +
 										"' target='_blank'>编辑</a>";
 									break;
@@ -214,7 +214,7 @@ function group_list(id, list) {
 								case 5: //channel片段
 									break;
 								default:
-									html += "<use xlink:href='../studio/svg/icon.svg#ic_person'></use>";
+									html += "unkow";
 									break;
 							}
 

+ 6 - 0
app/redis/redis.json

@@ -13,5 +13,11 @@
 		"type": "hash",
 		"valid": true,
 		"description": "译文句子列表 key: sent://channel/book-para-start-end "
+	},
+	{
+		"key": "article://info/*",
+		"type": "hash",
+		"valid": true,
+		"description": "article 主要信息 key: article://info/id  字段 title,owner,summary,create_time,modify_time "
 	}
 ]

+ 17 - 0
app/share/function.php

@@ -4,12 +4,15 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
 require_once '../channal/function.php';
+require_once '../article/function.php';
+require_once '../redis/function.php';
 require_once '../doc/function.php';
 /*
 获取某用户的可见的协作资源
 $res_type 见readme.md#资源类型 -1全部类型资源
 */
 function share_res_list_get($userid,$res_type=-1){
+	$redis = redis_connect();
 	# 找我加入的群
 	$dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
     $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
@@ -62,6 +65,7 @@ function share_res_list_get($userid,$res_type=-1){
 		$resList[]=array("res_id"=>$key,"res_type"=>(int)$value["type"],"power"=>(int)$value["power"]);
 	}
 	$channel = new Channal(); 
+	$article = new Article($redis); 
 	foreach ($resList as $key => $res) {
 		# 获取资源标题 和所有者 
 		switch ($res["res_type"]) {
@@ -87,6 +91,19 @@ function share_res_list_get($userid,$res_type=-1){
 				break;
 			case 3:
 				# 3 Article 文章
+				$aInfo = $article->getInfo($res["res_id"]);
+				if($aInfo){
+					$resList[$key]["res_title"]=$aInfo["title"];
+					$resList[$key]["res_owner_id"]=$aInfo["owner"];
+					$resList[$key]["status"]=$aInfo["status"];
+					$resList[$key]["lang"]='';
+				}
+				else{
+					$resList[$key]["res_title"]="_unkown_";
+					$resList[$key]["res_owner_id"]="_unkown_";
+					$resList[$key]["status"]="0";
+					$resList[$key]["lang"]="unkow";
+				}
 				break;
 			case 4:
 				# 4 Collection 文集