示例#1
0
namespace hypeJunction\GameMechanics;

$user = elgg_get_logged_in_user_entity();
$entity = elgg_extract('entity', $vars, false);
$full = elgg_extract('full_view', $vars, false);
$icon_size = elgg_extract('icon_size', $vars, 'medium');
$icon_user_status = elgg_extract('icon_user_status', $vars, true);
$sortable = elgg_extract('sortable', $vars, false);
if (!elgg_in_context('widgets') && !elgg_in_context('activity')) {
    $metadata = elgg_view_menu('entity', array('entity' => $entity, 'handler' => PAGEHANDLER, 'sort_by' => 'priority', 'class' => 'elgg-menu-hz'));
}
$title = elgg_view('output/url', array('text' => $entity->title, 'href' => $entity->getURL(), 'class' => 'elgg-lightbox'));
$icon = elgg_view_entity_icon($entity, $icon_size, array('link_class' => !$sortable ? 'elgg-lightbox' : '', 'icon_user_status' => $icon_user_status));
if ($full) {
    $content = elgg_view('output/longtext', array('value' => $entity->description));
    if (gmReward::isClaimed($entity->guid, $user->guid)) {
        $content .= '<div class="gm-badge-claimed-notice">' . elgg_echo('mechanics:alreadyclaimed') . '</div>';
    }
    $summary = elgg_view('object/elements/summary', array('entity' => $entity, 'title' => false, 'metadata' => $metadata, 'subtitle' => false, 'content' => $content));
    if (elgg_is_xhr()) {
        echo elgg_view_title($entity->title);
    }
    echo elgg_view_image_block($icon, $summary, array('class' => 'gm-badge-full'));
    echo elgg_view('framework/mechanics/rules', $vars);
} else {
    if (get_input('list_type', 'gallery') == 'gallery') {
        if ($icon_size == 'tiny' || $icon_size == 'small') {
            echo $icon;
        } else {
            echo elgg_view_module('aside', $title, $icon, array('class' => 'gm-badge-module', 'footer' => $metadata));
        }
示例#2
0
<?php

namespace hypeJunction\GameMechanics;

$badge_guid = get_input('guid');
$badge = get_entity($badge_guid);
if (!elgg_instanceof($badge, 'object', HYPEGAMEMECHANICS_BADGE_SUBTYPE)) {
    register_error(elgg_echo('mechanics:badge:claim:failure'));
    forward(REFERER);
}
$user = elgg_get_logged_in_user_entity();
if (gmReward::claimBadge($badge->guid, $user->guid)) {
    system_message(elgg_echo('mechanics:badge:claim:success', array($badge->title)));
    add_to_river('framework/mechanics/river/claim', 'claim', $user->guid, $badge->guid);
} else {
    register_error(elgg_echo('mechanics:badge:claim:failure'));
}
forward(REFERER);
示例#3
0
 * @uses $vars['img_class']  Optional CSS class added to img
 * @uses $vars['link_class'] Optional CSS class for the link
 */
namespace hypeJunction\GameMechanics;

$entity = $vars['entity'];
$user = elgg_get_logged_in_user_entity();
$sizes = array('small', 'medium', 'large', 'tiny', 'master', 'topbar');
// Get size
if (!in_array($vars['size'], $sizes)) {
    $vars['size'] = "medium";
}
if (elgg_extract('icon_user_status', $vars, false)) {
    if (gmReward::isClaimed($entity->guid, $user->guid)) {
        $class = "gm-badge gm-badge-claimed";
    } elseif (gmReward::isEligible($entity->guid, $user->guid)) {
        $class = "gm-badge gm-badge-eligible";
    } else {
        $class = "gm-badge gm-badge-unclaimed";
    }
} else {
    $class = "gm-badge";
}
$class .= " gm-badge-{$vars['size']}";
$extra_class = elgg_extract('img_class', $vars, '');
if ($extra_class) {
    $class .= " {$extra_class}";
}
$title = $entity->title . ': ' . $entity->description;
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
$url = isset($vars['href']) ? $vars['href'] : $entity->getURL();
示例#4
0
namespace hypeJunction\GameMechanics;

elgg_make_sticky_form('points/award');
$guid = get_input('guid');
$entity = get_entity($guid);
if (!elgg_instanceof($entity, 'user') || !$entity->canAnnotate(0, 'gm_score_award')) {
    register_error(elgg_echo('mechanics:admin:award:error_permissions'));
    forward(REFERER);
}
$amount = (int) get_input('amount', 0);
$note = get_input('note', '');
if (!$amount) {
    register_error(elgg_echo('mechanics:admin:award:error_amount'));
    forward(REFERER);
}
if (gmReward::awardPoints($amount, $note, $entity->guid)) {
    if ($amount > 0) {
        system_message(elgg_echo('mechanics:admin:award:success'));
    } else {
        system_message(elgg_echo('mechanics:admin:penalty:success'));
    }
    $admin = elgg_get_logged_in_user_entity();
    $admin_link = elgg_view('output/url', array('text' => $admin->name, 'href' => $admin->getURL()));
    if (!$note) {
        $note = elgg_echo('mechanics:no_note');
    }
    $balance = elgg_view('output/url', array('href' => PAGEHANDLER . '/history/' . $user->username));
    if ($amount > 0) {
        $subject = elgg_echo('mechanics:create:award');
        $message = elgg_echo('mechanics:create:award:message', array($admin_link, $amount, $note, $balance));
    } else {
示例#5
0
/**
 * Reward user with applicable badges
 *
 * @param ElggUser $user
 * @return boolean
 */
function reward_user($user = null)
{
    if (!$user) {
        $user = elgg_get_logged_in_user_entity();
    }
    $gmReward = gmReward::rewardUser($user);
    $errors = $gmReward->getErrors();
    if ($errors) {
        foreach ($errors as $error) {
            register_error($error);
        }
    }
    $messages = $gmReward->getMessages();
    if ($messages) {
        foreach ($messages as $message) {
            system_message($message);
        }
    }
    //check again for badges that needed dependcies badges to be claimed
    $gmReward->rewardUser($user);
    $badges = $gmReward->getNewUserBadges();
    $_SESSION['badges'] = $badges;
    if (count($badges)) {
        foreach ($badges as $badge) {
            //system_message(elgg_echo('mechanics:badge:claim:success', array($badge->title)));
            add_to_river('framework/mechanics/river/claim', 'claim', $user->guid, $badge->guid);
        }
    }
    //error_log(print_r($gmReward->getLog(), true));
    return true;
}