d75f5c4b by sayhoChun

comment save api

1 parent 00f7359b
...@@ -233,21 +233,96 @@ if (! class_exists("ApiBoard")) ...@@ -233,21 +233,96 @@ if (! class_exists("ApiBoard"))
233 $targetFk=$this->req["targetFk"]; 233 $targetFk=$this->req["targetFk"];
234 $userFk=$this->req["userFk"]; 234 $userFk=$this->req["userFk"];
235 $content=$this->req["content"]; 235 $content=$this->req["content"];
236 $parentGroup=$this->req["parentGroup"]; //부모 댓글의 기본키 236 $parentNo=$this->req["parentNo"]; //부모 댓글의 기본키
237 $commentNo=$this-> 237
238
239 if(empty($parentNo)){ //부모가 없을 때
240 $sql="
241 INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType, status, regDate)
242 VALUES
243 (
244 '{$userFk}',
245 '{$targetFk}',
246 '{$this->mysql_insert_id()}',
247 1,
248 1,
249 '{$content}',
250 '{$commentType}',
251 1,
252 NOW()
253 )
254 ";
255 $this->update($sql);
256 return $this->makeResultJson("1", "저장되었습니다");
257 }
258 else{ //부모 있을 때
259 $sql="
260 SELECT *
261 FROM tblComment
262 WHERE commentType='{$commentType}'
263 AND commentGroup=(SELECT commentGroup FROM tblComment WHERE commentType='{$commentType}' AND commentNo='{$parentNo}' AND status=1)
264 AND depth=(SELECT depth+1 FROM tblComment WHERE commentType='{$commentType}' AND commentNo='{$parentNo}' AND status=1)
265 LIMIT 0, 1
266 ";
267 $child=$this->getRow($sql);
268 $childNo=$child["commentNo"];
269 $childGroup=$child["commentGroup"];
270 $childOrder=$child["gOrder"];
271 $childDepth=$child["depth"];
272
273 if(!empty(childNo)){ //부모에게 자식이 있을 때
274 $sql="
275 INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType, status, regDate)
276 VALUES
277 (
278 '{$userFk}',
279 '{$targetFk}',
280 '{$childGroup}',
281 '{$childOrder}' + 1,
282 '{$childDepth}',
283 '{$content}',
284 '{$commentType}',
285 1,
286 NOW()
287 )
288 ";
289 $this->update($sql);
290
291 $sql="
292 UPDATE tblComment
293 SET gOrder=gOrder+1
294 WHERE commentGroup='{$childGroup}' AND gOrder > '{$childOrder}' + 1 AND status=1
295 ";
296 $this->update($sql);
297 }
298 else{ //부모에게 자식이 없을 때
238 $sql=" 299 $sql="
239 INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType) 300 INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType)
240 VALUES 301 VALUES
241 ( 302 (
242 '{$userFk}', 303 '{$userFk}',
243 '{$targetFk}', 304 '{$targetFk}',
244 IFNULL(SELECT commentGroup FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}' AND depth=0, '{$this->mysql_insert_id()}'), 305 (SELECT commentGroup FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모의 그룹
245 IFNULL(SELECT gOrder FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1, 306 (SELECT gOrder + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 순서+1
246 IFNULL(SELECT depth FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1, 307 (SELECT depth + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 깊이+1
247 '{$content}', 308 '{$content}',
248 '{$commentType}' 309 '{$commentType}',
310 1,
311 NOW()
249 ) 312 )
250 "; 313 ";
314 $this->update($sql);
315
316 $sql="
317 UPDATE tblComment
318 SET gOrder=gOrder+1
319 WHERE commentGroup=(SELECT commentGroup FROM tblComment WHERE commentNo='{$parentNo}' AND status=1) AND gOrder > (SELECT gOrder + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1) AND status=1
320 ";
321 $this->update($sql);
322 }
323
324 }
325
251 326
252 } 327 }
253 328
......
...@@ -70,6 +70,23 @@ $(document).ready(function(){ ...@@ -70,6 +70,23 @@ $(document).ready(function(){
70 }); 70 });
71 }) ; 71 }) ;
72 72
73 $(".saveComment").click2(function(){
74 $.ajax({
75 url : "/action_front.php?cmd=ApiBoard.saveComment",
76 async : false,
77 cache : false,
78 dataType: 'json',
79 success : function(data){
80 alert(data["certNo"]+" || "+data["name"]+data["imgPathCert"]+" || "+data["regDate"]);
81 },
82 error : function(req, res, error){
83 alert(req+res+error);
84 }
85 });
86 }) ;
87
88
89
73 }) ; 90 }) ;
74 </script> 91 </script>
75 92
......