コード例 #1
0
ファイル: dislike.php プロジェクト: hejosadi/PiGo-LMS
 */
// Get input
$entity_guid = (int) get_input('answer_guid');
$user_guid = elgg_get_logged_in_user_guid();
if ($entity = get_entity($entity_guid)) {
    $container = get_entity($entity->container_guid);
    // check if the user voted to an owned entity
    if ($entity->getOwnerGUID() == $user_guid) {
        register_error(elgg_echo('answers:vote:failure:owner'));
        return true;
    }
    // check if user can vote on this group
    if (!$container->canWriteToContainer()) {
        register_error(elgg_echo('answers:vote:failure:notmember'));
        return true;
    }
    elgg_load_library('answers:utilities');
    // check the actual user opinion
    if (answers_does_user_dislike_answer($entity, $user_guid)) {
        $action_result = answers_unlike($entity, $user_guid);
    } else {
        $action_result = answers_dislike($entity, $user_guid);
    }
    if ($action_result) {
        echo json_encode(array('score' => answers_overall_rating($entity), 'like_dislike' => answers_get_like_dislike($entity, $user_guid)));
    } else {
        register_error(elgg_echo('answers:vote:failure'));
    }
} else {
    register_error(elgg_echo('answers:notfound'));
}
コード例 #2
0
ファイル: question.php プロジェクト: hejosadi/PiGo-LMS
\t{$rating_block}
\t<div class="question-content mbl">
\t\t{$question_info}
\t\t{$body}
\t\t<div id="comments" class="elgg-comments">
\t\t\t{$question_comments}
\t\t\t{$question_add_comment}
\t\t</div>
\t</div>
</div>
HTML;
} else {
    // brief view
    elgg_load_library('answers:utilities');
    // need it for brief view in group module
    $score = answers_overall_rating($question);
    if ($score > 1) {
        $score_text = elgg_echo('answers:score:more');
    } else {
        $score_text = elgg_echo('answers:score:one');
    }
    $num_answers = answers_count_question_answers($question);
    if ($num_answers > 1) {
        $answers_text = elgg_echo('answers:answers');
    } else {
        $answers_text = elgg_echo('answers:answer');
    }
    $answers_link = elgg_view('output/url', array('text' => "<div>{$num_answers}</div>{$answers_text}", 'href' => $question->getURL() . '#question-answers'));
    $rating_block = <<<HTML
<div class="rating-block float center">
\t<div class="briefscore">
コード例 #3
0
ファイル: answers.php プロジェクト: hejosadi/PiGo-LMS
function answers_get_sorted_questions($owner_guid, $sort = 'newest')
{
    $owner = get_entity($owner_guid);
    $params = array('type' => 'object', 'subtype' => 'question');
    $container_or_owner = elgg_instanceof($owner, 'group') ? 'container_guid' : 'owner_guid';
    $params[$container_or_owner] = $owner_guid;
    $unsorted_questions = elgg_get_entities($params);
    if ($sort != 'newest') {
        // elgg_get_entities already filter by dates. Doesn't need array_multisort.
        $unsorted_ratings = array();
        $unsorted_actions = array();
        $unsorted_answers = array();
        foreach ($unsorted_questions as $question) {
            $unsorted_ratings[] = answers_overall_rating($question);
            $unsorted_dates[] = $question->time_created;
            $unsorted_actions[] = $question->last_action;
            // @todo: answer question or vote answer update question last_action ?
            $unsorted_answers[] = answers_count_question_answers($question);
        }
        if ($sort == 'votes') {
            array_multisort($unsorted_ratings, SORT_DESC, $unsorted_dates, SORT_ASC, $unsorted_questions);
        } else {
            if ($sort == 'activity') {
                array_multisort($unsorted_actions, SORT_DESC, $unsorted_ratings, SORT_DESC, $unsorted_questions);
            } else {
                if ($sort == 'unanswered') {
                    // @todo change to less answered ?
                    array_multisort($unsorted_answers, SORT_ASC, $unsorted_ratings, SORT_DESC, $unsorted_dates, SORT_ASC, $unsorted_questions);
                }
            }
        }
    }
    return $unsorted_questions;
}
コード例 #4
0
ファイル: rating_block.php プロジェクト: hejosadi/PiGo-LMS
<?php

/**
 * Voting area view
 * Used for question and answer object full view
 */
$entity = $vars['entity'];
$user_guid = elgg_get_logged_in_user_guid();
$container_guid = elgg_get_page_owner_entity();
$score = answers_overall_rating($entity);
if ($entity->getOwnerGUID() != $user_guid && $container_guid->canWriteToContainer()) {
    $liked = answers_does_user_like_answer($entity, $user_guid) == 'like' ? ' liked' : '';
    $up = elgg_view('output/url', array('text' => '<div class="gwf">↑</div>', 'href' => '#', 'is_trusted' => true, 'class' => "t tooltip w answer_like{$liked}", 'title' => elgg_echo('answers:vote:tooltip:like')));
    $disliked = answers_does_user_dislike_answer($entity, $user_guid) == 'dislike' ? ' disliked' : '';
    $down = elgg_view('output/url', array('text' => '<div class="gwf mbm">↓</div>', 'href' => '#', 'is_trusted' => true, 'class' => "t tooltip w answer_dislike{$disliked}", 'title' => elgg_echo('answers:vote:tooltip:dislike')));
}
$subtype = $entity->getSubtype();
if ($subtype == 'question') {
    // here code to favorite question. Usefull ? Todo ?
} else {
    if ($subtype == 'answer') {
        $question = answers_get_question_for_answer($entity);
        if ($question->chosen_answer == $entity->getGUID()) {
            $chosen = true;
            $chosen_view = '<div class="choose chosen tooltip w t" title="' . elgg_echo('answers:answer:tooltip:bestanswer') . '"><div class="gwf mtm">œ</div></div>';
        }
        if ($question->getOwnerGUID() == $user_guid) {
            if ($chosen) {
                $class = ' chosen';
            }
            $chosen_view = elgg_view('output/url', array('text' => '<div class="gwf">&#10004;</div>', 'href' => elgg_get_site_url() . 'action/answers/choose?answer_id=' . $entity->getGUID(), 'class' => "choose tooltip w t{$class}", 'is_action' => true, 'is_trusted' => true, 'title' => $chosen ? elgg_echo('answers:answer:tooltip:bestanswer') : elgg_echo('answers:answer:tooltip:choose')));
コード例 #5
0
ファイル: start.php プロジェクト: amcfarlane1251/ongarde
function get_sorted_question_answers($question)
{
    $unsorted_answers = get_question_answers($question);
    $unsorted_ratings = array();
    $unsorted_dates = array();
    foreach ($unsorted_answers as $answer) {
        $unsorted_ratings[] = answers_overall_rating($answer);
        $unsorted_dates[] = $answer->time_created;
    }
    array_multisort($unsorted_ratings, SORT_DESC, $unsorted_dates, SORT_ASC, $unsorted_answers);
    return $unsorted_answers;
}