예를 들면 

 

추천 받은 댓글이 있는 경우 게시물 목록에 [답변] 표시를 하고 싶습니다.

 

아래 처럼 해도 게시물 목록에서는 에러만 나고 뭘 해도 안되더군요...

 

   <!--@if($comment->get('voted_count')>1)-->
답변
    <!--@end-->    

  • profile

    {@
    $commentList = $document->getComments();
    $commentVote = 0;
    }

    <!--@foreach($commentList as $comment)-->
    {@
    if($comment->get('voted_count') > 0) $commentVote++;
    }
    <!--@end-->

    <!--@if($commentVote > 0 )-->
    답변
    <!--@end-->

  • profile ?
    • skyo
    • 질문기여자
    흠..답변감사드립니다. 이제 에러는 안나는데 아무런 반응이 없습니다. 답변이라는 글자가 게시물 목록에 나오진 않습니다.
  • ? profile

    사용 상 문제는 없을 것 같은데.. 직접 테스트 해본 건 아니라서요..

    일단 설명을 붙이자면,

    $comment는 게시판 list에서 호출할 수 없습니다.

    호출하기 위해서는 getComments()로 코멘트 객체를 불러 올 수 있습니다.

    getComments 함수는 document 모듈에 document.item.php에 정의되어 있습니다.

    // Get a list of comments
    $oCommentModel = getModel('comment');
    $output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin);
    if(!$output->toBool() || !count($output->data)) return;
    // Create commentItem object from a comment list
    // If admin priviledge is granted on parent posts, you can read its child posts.
    $accessible = array();
    $comment_list = array();
    foreach($output->data as $key => $val)
    {
    $oCommentItem = new commentItem();
    $oCommentItem->setAttribute($val);
    // If permission is granted to the post, you can access it temporarily
    if($oCommentItem->isGranted()) $accessible[$val->comment_srl] = true;
    // If the comment is set to private and it belongs child post, it is allowable to read the comment for who has a admin privilege on its parent post
    if($val->parent_srl>0 && $val->is_secret == 'Y' && !$oCommentItem->isAccessible() && $accessible[$val->parent_srl]===true)
    {
    $oCommentItem->setAccessible();
    }
    $comment_list[$val->comment_srl] = $oCommentItem;
    }
    // Variable setting to be displayed on the skin
    Context::set($cpageStr, $output->page_navigation->cur_page);
    Context::set('cpage', $output->page_navigation->cur_page);
    if($output->total_page>1) $this->comment_page_navigation = $output->page_navigation;

     

     

    대략 이부분을 참고하시면 됩니다.

     

     

  • profile

    $commentVote = 0 이랑 ++은 안 돌려도 되지 않나싶은데요.

    {@$commentList = $document->getComments();}
    <!--@foreach($commentList as $comment)-->
    <!--@if($comment->get('voted_count') > 0)-->
    답변
    <!--@end-->
    <!--@end-->

    ... 또는, (저도 잘은 모르겠지만) getComments 함수를 이미 불러들인(?) 게시판 스킨을 사용하시는 경우(저는 스케치북 씁니다)에는

    <!--@foreach($document->getComments() as $comment)-->
    <!--@if($comment->voted_count > 0)-->
    답변
    <!--@end-->
    <!--@end-->

    ... 로 해도 될 것 같습니다. {print_r($comment->voted_count)}로 출력해보니까 추천수가 나오더군요.

  • profile ?
    • skyo
    • 질문기여자

    우오!! 감사합니다. 잘 출력 됩니다!! 다만 댓글 추천이 여러개인경우 

     

    답변 답변 답변 이렇게 출력 되는데.. 1번만 출력 될수 없을까요?

  • ? profile

    글쎄요;;; 거기까지는 저도 잘 모르겠는데요;;;
    혹시 명령문을 삽입한 위치 때문에 '답변'이 반복되는 거 아닐까요?
    제가 실험해봤을 땐 게시판 리스트 각 "게시물 항목 내"에서 foreach 돌렸을 때 순조롭게 성공했었거든요.
    {$comment->voted_count}는 추천수로 잘 나오구요, 추천수가 '2'일 때 <!--@if($comment->voted_count > 0)-->답변<!--@end-->로 했을 때도 '답변'이 한 번만 떠요.

  • profile ?
    • skyo
    • 질문기여자
    아.. 그것 말고 댓글이 2개 있을때 각각 추천을 받으면 두번 뜨더라고요. 한 댓글에 추천갯수 2인 경우 말고요. ^^;
    안되면 그냥 사용해야겠습니다. 다시한번 답변 감사 드립니다.
  • profile
    아, 그렇군요. 댓글을 리스트로 받아오는 명령문이다보니 그렇게 출력 값이 중복됐던 거네요. 도움이 못 돼드려서 죄송합니다;;;
  • profile ?
    • skyo
    • 질문기여자

    네. 그래도 표기가 되므로 도움이 많이 됩니다. 다시한번 감사 드립니다. 제가 이 질문만 1년넘게 해오고 있는데 처음으로

    목록에 댓글 추천이 있는 글이 따로 표기가 되었습니다.

  • ? profile

    1년이라뇨 ㅠㅠ 왠지 그 심정 이해가 됩니다;;;
    이렇게 한 번 해보시는 건 어떨지요. 저는 되는 것 같기도 한데... socialskyo님 경우을 제대로 재연한 것일지는 확신이 잘 없습니다만..
    <!--@foreach($document->getComments() as $comment)--><!--@if($comment->voted_count)-->답변<!--@end-->{@break}<!--@end-->
    {@break} 대신 <!--@break-->도 좋구요.

  • profile ?
    • skyo
    • 질문기여자
    {@break}<!--@end-->

    우오!! 드디어 다 됩니다. 신경써주셔서 너무 감사합니다.
  • ? profile
    이게 어떤 기능인지 궁금하네요 ^^ 캡쳐 라도 해주시면 이해 될텐데요 ^^