ApiBoard.php 7.67 KB
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/ApiBase.php" ;?>
<?

if (! class_exists("ApiBoard"))
{

	class ApiBoard extends ApiBase
	{

		function __construct($req)
		{
			parent::__construct($req);
		}

		//공지사항 리스트
		function getListOfNotice(){
			$sql="
				SELECT *
				FROM tblNotice
				ORDER BY noticeNo DESC
			";
			return json_encode($this->getArray($sql));
			
			return makeResultJson(1, "aa");
		}
		
		//공지사항 정보
		function getInfoOfNotice(){
			$noticeNo=$this->req["no"];
			
			$sql="
				SELECT *
				FROM tblNotice
				WHERE noticeNo='{$noticeNo}'
			";
			return json_encode($this->getArray($sql));
				
		}
		
		//이벤트 리스트
		function getListOfEvent(){
			$sql="
				SELECT *
				FROM tblEvent
				ORDER BY eventNo DESC
			";
			return json_encode($this->getArray($sql));
		}
		
		//이벤트 정보
		function getInfoOfEvent(){
			$eventNo=$this->req["no"];
			$sql="
				SELECT *
				FROM tblEvent
				WHERE eventNo='{$eventNo}'
			";
			return json_encode($this->getArray($sql));
		}
		
		//자유게시판 리스트
		function getListOfBoard(){
			$sql="
				SELECT COUNT(*) 
				FROM tblBoard
				WHERE status='Y'
				ORDER BY boardNo DESC
			";
			$this->rownum = $this->getValue($sql, "rn");
			$this->setPageForDevice($this->rownum);
			
			$sql="
				SELECT *
				FROM tblBoard
				WHERE status='Y'
				ORDER BY boardNo DESC
				LIMIT {$this->startNum}, {$this->endNum}
			";
			$list=$this->getArray($sql);
			
			if (sizeof($list) > 0)
				return $this->makeResultJson("1", "", $list);
			else
				return $this->makeResultJson("-1000", "내역이 없습니다.");
		}
		
		//게시물 정보
		function getInfoOfBoard(){
			$boardNo = $this->req["no"];
			$sql="
				SELECT *
				FROM tblBoard
				WHERE boardNo='{$boardNo}' AND status='Y'
				LIMIT 1
			";
			$result=$this->getRow($sql);
			
			if($result != null){
				$sql="
					SELECT C.*, U.userID
					FROM tblComment C
					JOIN tblUser U ON C.userFk=U.userNo
					WHERE targetFk='{$boardNo}' AND commentType='FB'
					ORDER BY C.commentGroup ASC, C.gOrder ASC
				";
				$commentList=$this->getArray($sql);
				
				return $this->makeResultJson("1", "", $result, Array(
						"commentList" => $commentList
						));
			}
			else{
				return $this->makeResultJson("-1000", "내역이 없습니다.");
			}		
		}

		//고객센터 게시물 리스트
		function getListOfCS(){
			$sql="
				SELECT COUNT(*)
				FROM tblCustomerService
				WHERE status='Y'
				ORDER BY csNo DESC
			";
			$this->rownum = $this->getValue($sql, "rn");
			$this->setPageForDevice($this->rownum);
			
			$sql="
				SELECT *
				FORM tblCustomerService
				WHERE status='Y'
				ORDER BY csNo DESC
				LIMIT {$this->startNum}, {$this->endNum}
			";
			$list=$this->getArray($sql);
			
			if(sizeof($list)>0)
				return $this->makeResultJson("1", "", $list);
			else 
				return $this->makeResultJson("1000", "내역이 없습니다.");
		}
		
		//고객센터 게시물 내용
		function getInfoOfCS(){
			$csNo=$this->req["no"];
			$sql="
				SELECT *
				FROM tblCustomerService
				WHERE csNo='{$csNo}' AND status='Y'
				LIMIT 1
			";
			$result=$this->getRow($sql);
			
			if($result != null){
				$sql="
				SELECT
				FROM tblComment C
				JOIN tblUser U ON C.userFk=U.userNo
				WHERE targetFk='{$csNo}' AND commentType='CS'
				ORDER BY C.commentGroup ASC, C.gOrder ASC
				";
					
				$commentList=$this->getArray($sql);
				
				return $this->makeResultJson("1", "", $result, Array(
						"commentList" => $commentList
				));
			}
			else{
				return $this->makeResultJson("-1000", "내역이 없습니다.");
			}
		}
		
		//AS 엄체 리스트
		function getListOfCompany(){
			$sql="
				SELECT COUNT(*)
				FROM tblCompany
				WHERE status='Y'
				ORDER BY companyNo DESC
			";
			$this->rownum=$this->getValue($sql, "rn");
			$this->setPageForDevice($this->rownum);
			
			$sql="
				SELECT *
				FROM tblCompany
				WHERE status='Y'
				ORDER BY companyNo DESC
				LIMIT {$this->startNum}, {$this->endNum}
			";
			$list=$this->getArray($sql);
			
			if(sizeof($list)>0)
				return $this->makeResultJson("1", "", $list);
			else 
				return $this->makeResultJson("-1000", "내역이 없습니다.");
		}
		
		function getInfoOfCompany(){
			$companyNo=$this->req["no"];
			
			$sql="
				SELECT *
				FROM tblCompany
				WHERE companyNo='{$companyNo}' AND status='Y'
				LIMIT 1
			";
			$result=$this->getRow($sql);
			
			if($result != null){
				$sql="
					SELECT 
					FROM tblComment C
					JOIN tblUser U ON C.userFk=U.userNo
					WHERE targetFk='{$companyNo}' AND commentType='CP'
					ORDER BY commentNo DESC
				";
				$commentList=$this->getArray($sql);
				
				return $this->makeResultJson("1", "", $result, Array(
						"commentList" => $commentList
				));
			}
			else{
				return $this->makeResultJson("-1000", "내역이 없습니다.");
			}
		}
		
		//댓글 저장
		function saveComment(){								
			$commentType=$this->req["commentType"];
			$targetFk=$this->req["targetFk"];
			$userFk=$this->req["userFk"];
			$content=$this->req["content"];
			$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}',
					(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}',
					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);
				}
				
			}

			
		}
		
		
		
		
		
	} // 클래스 종료
}
?>