- 취지 : 댓글들 중에서 문서 작성자가 추천한 댓글을 특별하게 표시해줄 수 있습니다.

- 용례 : 질문글에 달린 댓글을 작성자가 채택했는지 표시해줄 수 있습니다. 예. 질문자 채택 답변

 

우선, 게시판 스킨에서 댓글 목록 반복문 시작 전에 다음과 같은 구문을 삽입해줍니다.

가령 <block cond="$oDocument->getCommentCount()"> 또는 <!--@if($oDocument->getCommentCount())-->처럼 댓글이 있는 경우를 뜻하는 조건문 코드 바로 아래에 넣어주면 좋습니다.

 

{@
$query = 'SELECT comment_voted_log.comment_srl FROM comments_list, comment_voted_log WHERE comments_list.document_srl = ? AND comments_list.comment_srl = comment_voted_log.comment_srl AND comment_voted_log.member_srl = ? AND comment_voted_log.point >= 1';
$cond_args = [$oDocument->document_srl, $oDocument->getMemberSrl()];

$oDB = DB::getInstance();
$stmt = $oDB->query($query, $cond_args);
$comment_srls_voted_by_author = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
}

 

이렇게 하면

$comment_srls_voted_by_author라는 배열 변수에 문서 작성자가 추천한 댓글들의 번호 목록이 담기게 됩니다.

 

그리고, 댓글들이 반복되는 코드 즈음, 예컨대 <block loop="$oDocument->getComments()=>$key,$comment"> 같은 코드 아래쯤에 다음과 같은 코드를 넣어보세요.

 

<!--@if(in_array($comment->comment_srl, $comment_srls_voted_by_author))-->
<span style="background: #2DB074; color: #fff; padding: 4px 12px; border-radius: 8px;">작성자 추천 댓글</span>
<!--@endif-->

 

이런 식으로 in_array($comment->comment_srl, $comment_srls_voted_by_author) 라는 조건을 활용해서 적당한 위치를 잡아 작성자 추천 댓글에 다양한 스타일링(굵은 글씨 강조, 테두리 효과, 배경색 표시 등)을 해볼 수 있을 겁니다.

 

+ 그리고 $comment_srls_voted_by_author의 댓글번호 목록을 통해 작성자 추천 댓글들만 목록 상단에 뿌려준다든가 하는 것도 가능할 것 같아요. (부모-자식 댓글의 보기 권한 상속 문제 등은 숙제로 남겨두고ㅎ) 대강 다음과 같이 리스트($comment_list_voted_by_author) 생성을 해볼 수 있습니다. 활용은 각자 알아서!

{@
$comment_list_voted_by_author = [];
if ( !empty($comment_srls_voted_by_author) ):
    foreach($comment_srls_voted_by_author as $key => $val):
        $args = new stdClass();
        $args->comment_srl = $val;
        $output = executeQuery('comment.getComment', $args);

        $oCommentItem = new commentItem();
        $oCommentItem->setAttribute($output->data);
        $comment_list_voted_by_author[$val] = $oCommentItem;
    endforeach;
endif;
}

 

윤삼

profile
아무래도 중급 초반 수준의 코딩 오타쿠인 것 같습니다.
  • profile
    유용한 팁 항상 감사합니다. ^^*
  • profile profile

    타운에서 질문글 검색하다가 갑자기 아이디어가 떠올랐습니다ㅎㅎ

  • profile
    응원합니다! 여러가지 재밌는 응용이 가능할것 같습니다.
  • profile profile
    지식인이나 스택오버플로우 같은 효과를 낼 수 있겠더라구요.
  • ?
    생각을 끌어낼 수 있도록 도와주시니 항상 감사할 따름입니다~
  • ? profile
    바로 활용하셔도 좋고 어떻게든 유익하다면 저는 좋습니다 😀