Пример #1
0
\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">
\t\t<div class="pvs">{$score}</div>
\t\t{$score_text}
\t</div>
\t<div class="answers">
\t\t{$answers_link}
\t</div>
Пример #2
0
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;
}