Пример #1
0
<?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')));
Пример #2
0
 */
// 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'));
}
Пример #3
0
/**
 * Get whether a user likes/dislikes/ or is neutral about an answer
 *
 * @param <type> $answer
 * @param <type> $user_guid
 * @return <type>
 */
function answers_get_like_dislike($answer, $user_guid)
{
    if (answers_does_user_like_answer($answer, $user_guid)) {
        return 'like';
    }
    if (answers_does_user_dislike_answer($answer, $user_guid)) {
        return 'dislike';
    }
    return false;
}