d75f5c4b by sayhoChun

comment save api

1 parent 00f7359b
......@@ -233,21 +233,96 @@ if (! class_exists("ApiBoard"))
$targetFk=$this->req["targetFk"];
$userFk=$this->req["userFk"];
$content=$this->req["content"];
$parentGroup=$this->req["parentGroup"]; //부모 댓글의 기본키
$commentNo=$this->
$sql="
INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType)
VALUES
(
'{$userFk}',
$parentNo=$this->req["parentNo"]; //부모 댓글의 기본키
if(empty($parentNo)){ //부모가 없을 때
$sql="
INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType, status, regDate)
VALUES
(
'{$userFk}',
'{$targetFk}',
'{$this->mysql_insert_id()}',
1,
1,
'{$content}',
'{$commentType}',
1,
NOW()
)
";
$this->update($sql);
return $this->makeResultJson("1", "저장되었습니다");
}
else{ //부모 있을 때
$sql="
SELECT *
FROM tblComment
WHERE commentType='{$commentType}'
AND commentGroup=(SELECT commentGroup FROM tblComment WHERE commentType='{$commentType}' AND commentNo='{$parentNo}' AND status=1)
AND depth=(SELECT depth+1 FROM tblComment WHERE commentType='{$commentType}' AND commentNo='{$parentNo}' AND status=1)
LIMIT 0, 1
";
$child=$this->getRow($sql);
$childNo=$child["commentNo"];
$childGroup=$child["commentGroup"];
$childOrder=$child["gOrder"];
$childDepth=$child["depth"];
if(!empty(childNo)){ //부모에게 자식이 있을 때
$sql="
INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType, status, regDate)
VALUES
(
'{$userFk}',
'{$targetFk}',
'{$childGroup}',
'{$childOrder}' + 1,
'{$childDepth}',
'{$content}',
'{$commentType}',
1,
NOW()
)
";
$this->update($sql);
$sql="
UPDATE tblComment
SET gOrder=gOrder+1
WHERE commentGroup='{$childGroup}' AND gOrder > '{$childOrder}' + 1 AND status=1
";
$this->update($sql);
}
else{ //부모에게 자식이 없을 때
$sql="
INSERT INTO tblComment(userFk, targetFk, commentGroup, gOrder, depth, content, commentType)
VALUES
(
'{$userFk}',
'{$targetFk}',
IFNULL(SELECT commentGroup FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}' AND depth=0, '{$this->mysql_insert_id()}'),
IFNULL(SELECT gOrder FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1,
IFNULL(SELECT depth FROM tblComment WHERE commentType='{$commentType}' AND commentGroup='{$parentGroup}', -1)+1,
(SELECT commentGroup FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모의 그룹
(SELECT gOrder + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 순서+1
(SELECT depth + 1 FROM tblComment WHERE commentNo='{$parentNo}' AND status=1), //부모 깊이+1
'{$content}',
'{$commentType}'
)
";
'{$commentType}',
1,
NOW()
)
";
$this->update($sql);
$sql="
UPDATE tblComment
SET gOrder=gOrder+1
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
";
$this->update($sql);
}
}
}
......
......@@ -69,6 +69,23 @@ $(document).ready(function(){
}
});
}) ;
$(".saveComment").click2(function(){
$.ajax({
url : "/action_front.php?cmd=ApiBoard.saveComment",
async : false,
cache : false,
dataType: 'json',
success : function(data){
alert(data["certNo"]+" || "+data["name"]+data["imgPathCert"]+" || "+data["regDate"]);
},
error : function(req, res, error){
alert(req+res+error);
}
});
}) ;
}) ;
</script>
......