베스트 댓글을 확인하기 위해 문서에 달린 댓글들의 각 추천수 중 제일 높은 값을 확인해야 하는 쿼리가 필요합니다.

 

 

추천 액션 직후 확인하는 작업을 수행하도록 해보려고 합니다.

 

$comment_srl = Context::get('target_srl');
$oCommentModel = getModel('comment');
$oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE);
$args->document_srl = $oComment->get('document_srl');
$cvotecount = ?????? ; // 쿼리 파일을 애드온에 업로드 하려 합니다.

 

 

쿼리파일 xml 이 필요합니다.

여러 댓글 중 추천수가 가장 높은 숫자를 $cvotecount 에담아야 합니다.  여러댓글 중 추천이 하나도 없다면 0이 담기구요.

 

 

 

  • profile

    문서의 댓글을 불러오는 쿼리는

    <query id="getComment" action="select">
    <tables>
    <table name="comments" />
    </tables>
    <columns>
    <column name="*" />
    </columns>
    <conditions>
    <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
    </conditions>
    </query>

    이렇게 하는게 아닐까 하는 생각이 듭니다.

    아마도 이렇게 쿼리하면 해당 문서의 댓글이 배열에 모두 담길 것 같은데요. 여기서 추천수 중에 제일 큰 값을 쏙 빼내야 할 것 같습니다.

     

    <column name="*" />

    <column name="comments.voted_count" />

    여기를 고치면 추천수 컬럼만 가지고 오겠군요.....

  • profile
    $cvotecount = executeQueryArray('addons.cvotecounter.getComment', $args);

    이렇게까지 하면 댓글들의 각 추천 수가 배열로 담길 것 같은데. 맞나 모르겠습니다.

    맏다면

    이 배열 값 중 가장 큰값만 다시 담으려면 어째야 할까요 ?
  • profile
    쿼리문으로 적으면

    SELECT * FROM xe_comments WHERE document_srl = 'srl번호' ORDER BY voted_count DESC LIMIT 1

    이건데....
    xe에서 사용하는 xml문법은 모르겠어요. -0-;;;;
    <navigation>
    <index var="voted_count" default="voted_count" order="desc" />
    <list_count var="list_count" default="1" />
    </navigation>

    요런거 컨디션 아래 추가하면 될거라고 추측만 해봐요.
  • profile profile

    <query id="getComment" action="select">
        <tables>
            <table name="comments" />
        </tables>
        <columns>
            <column name="comments.voted_count" />
        </columns>
        <conditions>
            <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
        </conditions>
    </query>

     


    <navigation>
    <index var="voted_count" default="voted_count" order="desc" />
    <list_count var="list_count" default="1" />
    </navigation>
    현재 갯수 제한 없이 모두 가져오는 것에서 말씀 하신 정렬로 1개를 조건으로 걸면 아예 1개만 가져오겠네요.

     

    요렇게 하면 되는건가요??

  • profile profile
    <query id="getComment" action="select">
    <tables>
    <table name="comments" />
    </tables>
    <columns>
    <column name="comments.voted_count" />
    </columns>
    <conditions>
    <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
    </conditions>
    <navigation>
    <index var="voted_count" default="voted_count" order="desc" />
    <list_count var="comment_max_vote_count" default="1" />
    </navigation>
    </query>

    쿼리안에 들어가야해요~
    제가 xml쿼리문을 몰라서 매뉴얼 잠깐 보고 예상하는 것이라 잘 몰라요...-0-;;;
    list_count 에 var값 바꿨어요.
    list_count는 게시판 목록의 갯수가 들어가 있는 변수라서요.
    $comment_max_vote_count 요 값에 숫자를 넣어주면 해당 갯수만큼 가져올것 같네요.
    없으면 디폴트값인 1개 가져오구요.
  • profile profile

    답변 감사합니다.

    그럼 1개만 가져왔을때는..
    $cvotecount 값을 즉시 사용할 수 있나요 ?

    $cvotecount = executeQueryArray('addons.cvotecounter.getComment', $args);
    array 형태가 아닐것 같아서요. 1개이면....

     

    위 쿼리문을 고쳐야 할까욧 ??

  • profile profile
    (제가 xe문법은 잘 몰라요... -0-;;;)
    배열이 아니고 1개만 가져오는 것이니 어레이를 빼고 executeQuery 요걸 쓰면되지 않을까요?
  • profile

    <columns>
        <column name="MAX(comments.voted_count)" alias="cvotecount" />
    </columns>

     

    <query id="getComment" 여기에서 query ID를 파일명에 맞게 변경

    <navigation> 부분은 제거 (MAX 함수를 사용하면 0~1개만 가져오므로 갯수 제한할 필요 없음)

    executeQuery로 실행

     

    $cvotecount = $output->data->cvotecount ?: 0;

  • profile profile
    역시 xe는 xe전문가가 답변을 달아야 제대로 된 답변이 나오죠! 크하하
  • profile profile
    답변 감사합니다.

    베스트 댓글을 추천 시마다 확인해서 이 값을 문서의 추가설명 공간에 넣으려고 합니다.

    이 값을 게시판 목록에서 매번 사용하려고 하는데요.

    목록에서 매번 해달 게시글의 추천수를 확인하는 것 보다는 조금은 효율이 높아질까요 ?
  • profile profile
    검색 조건으로 사용하거나 목록에서 수십 개의 글에 한꺼번에 적용하지 않는다면 특별히 무거운 쿼리는 아닙니다.
  • profile profile

    그럼 그냥 저장하지 말고 목록에서 모든 게시글을 출력할때 각 게시글의 댓글 중 가장 최대 추천수를 쿼리하는게 나은가요 ?? 물론 저희는 묻고답하기에 사용하려고 하는데 한페이지에 50개 정도 목록을 사용합니다.

     

    그리고 저 마지막 담은 값을 게시글의 extra_vars 에 넣어봤는데

    O:8:"stdClass":2:{s:12:"document_srl";i:2271529;s:10:"cvotecount";i:0;}

     

    이렇게 db에서 보이는 것으로 보아 뭔가 이상하게 들어가는 듯 하네요.

    추천수는 1이  되어야 하는데 0 으로 들어갔네요.

     

    그리고  document_srl  값은 왜 들어가는지.. 이상하네요...

     

    // extra_vars 필드 정의
    $exvars->document_srl = $args->document_srl;
    $exvars->cvotecount = $cvotecount;
    $args->extra_vars = serialize($exvars);


    // extra_vars 필드 값 업데이트
            $tmpout = executeQuery('addons.cvotecounter.updateDocumentExtra', $args)

     

     

     

    <query id="updateDocumentExtra" action="update">
        <tables>
            <table name="documents" />
        </tables>
        <columns>
            <column name="extra_vars" var="extra_vars" notnull="notnull" />
        </columns>
        <conditions>
            <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
        </conditions>
    </query>

  • profile profile
    목록에서 모든 게시글을 출력할때 쿼리하시면 곤란하죠. 글 숫자만큼 쿼리가 발생하잖아요. 어딘가 저장해놓을 수 있다면 가장 좋습니다.

    어디에서 어떤 변수를 넣어 어떻게 쿼리하셨는지에 따라 잘못된 값이 들어갈 수도 있습니다. 저장하기 전에 값을 제대로 찍어보세요.
  • profile profile

    그래서 추천할때 쿼리서 문서의 extra_vars 에 저장하는 것을 구현하고 있습니다.
    그 값을 불러오는 건 조금 부하가 덜할 것 같아서요.
    그런데 지금 제일 높은 추천수가 들어가지 않고 0으로 쿼리가 되네요.

    문서번호도 담기는 것 같고 뭔가 숫자 하나만 담기지 않는 듯 하네요.

     

     

     

    if($act == 'procCommentVoteUp' && $called_position == 'after_module_proc') {
    //문서의 댓글 중 추천수 중 가장 높은 수 쿼리 후 아래 변수에 담기
    $comment_srl = Context::get('target_srl');
    $oCommentModel = getModel('comment');
    $oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE);
    $args->document_srl = $oComment->get('document_srl');
    $cvotecount = $output->data->cvotecount ?: 0;

    // extra_vars 필드 정의
    $exvars->document_srl = $args->document_srl;
    $tmpout = executeQuery('addons.cvotecounter.getDocument', $args);
    $exvars=unserialize($tmpout->data->extra_vars);
    $exvars->document_srl = $args->document_srl;
    $exvars->cvotecount = $cvotecount;
    $args->extra_vars = serialize($exvars);


    // extra_vars 필드 값 업데이트
            $tmpout = executeQuery('addons.cvotecounter.updateDocumentExtra', $args);

  • profile profile

    $cvotecount를 불러오는 데 사용하시는 $output 변수는 어디서 갑툭튀한 건가요?
    없는 변수를 참조하니까 0으로 들어가지요.

    위에서 더블유님이 알려주시고 제가 다듬은 쿼리를 실행한 후에
    그 결과를 $output에 담으셔야 하는데... 뭔가 한줄 빠진 것 같습니다.

  • profile profile
    방금 발견했습니다. 애드온 쿼파일을 이용하는 쿼리 코드가 빠졌네요.
  • profile profile

    자꾸 질문 드려 죄송합니다.

    if($act == 'procCommentVoteUp' && $called_position == 'after_module_proc') {
    //문서의 댓글 중 추천수 중 가장 높은 수 쿼리 후 아래 변수에 담기
    $comment_srl = Context::get('target_srl');
    $oCommentModel = getModel('comment');
    $oComment = $oCommentModel->getComment($comment_srl, FALSE, FALSE);
    $args->document_srl = $oComment->get('document_srl');
    $koutput = executeQuery('addons.cvotecounter.getComment', $args);
    $cvotecount = $koutput->data->cvotecount ?: 0;

    // extra_vars 필드 정의
    $exvars->document_srl = $args->document_srl;
    $tmpout = executeQuery('addons.cvotecounter.getDocument', $args);
    $exvars=unserialize($tmpout->data->extra_vars);
    $exvars->document_srl = $args->document_srl;
    $exvars->cvotecount = $cvotecount;
    $args->extra_vars = serialize($exvars);


    // extra_vars 필드 값 업데이트
    $tmpout = executeQuery('addons.cvotecounter.updateDocumentExtra', $args);

    }



    최종 이렇게 했는데오 여전히
    $exvars->document_srl = $args->document_srl;

    위 부분 삭제하고 문서번호는 저장되지 않게 되었습니다.


    중요한

     

    추천수 값이 0으로 들어가네요.... 어디가 잘못 된 것일까요....

     

    <query id="getComment" action="select">
        <tables>
            <table name="comments" />
        </tables>
        <columns>
            <column name="MAX(comments.voted_count)" alias="cvotecount" />
        </columns>
        <conditions>
            <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
        </conditions>
        <navigation>    
    </query>

  • profile profile
    닫히지 않은 <navigation> 태그가 있네요. 지워보세요.
  • profile profile
    아. 저거 때문이면.... 부들부들.... 식사 하고 올라가서 실제 저렇게 업로드 했는지 확인해볼게요..
  • profile profile
    마지막 실수는 이거였네요. 도움 감사했습니다. 원하는 대로 구현이 완료 되었습니다.

    이제 이 값을 스킨에서 가져가 좋은댓글이 있는 게시글인지 목록에서 표현해 보도록 하겠습니다. 매번 모든 댓글에서 가지는 추천수를 쿼리하는게 부담스러워 해당 기능을 제거했는데 이 지표로 다시 구현해봐야겠네요.