Exemplo n.º 1
0
 /**
  * @covers badgeos_get_users_points()
  */
 public function test_badgeos_get_users_points()
 {
     $actual_points = 250;
     $user_id = $this->factory->user->create();
     update_user_meta($user_id, '_badgeos_points', $actual_points);
     $earned_points = badgeos_get_users_points($user_id);
     $this->assertSame($earned_points, $actual_points);
 }
/**
 * Posts a log entry when a user earns points
 *
 * @since  1.0.0
 * @param  integer $user_id        The given user's ID
 * @param  integer $new_points     The new points the user is being awarded
 * @param  integer $admin_id       If being awarded by an admin, the admin's user ID
 * @param  integer $achievement_id The achievement that generated the points, if applicable
 * @return integer                 The user's updated point total
 */
function badgeos_update_users_points($user_id = 0, $new_points = 0, $admin_id = 0, $achievement_id = null)
{
    // Use current user's ID if none specified
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    // Grab the user's current points
    $current_points = badgeos_get_users_points($user_id);
    // If we're getting an admin ID, $new_points is actually the final total, so subtract the current points
    if ($admin_id) {
        $new_points = $new_points - $current_points;
    }
    // Update our user's total
    $total_points = max($current_points + $new_points, 0);
    update_user_meta($user_id, '_badgeos_points', $total_points);
    // Available action for triggering other processes
    do_action('badgeos_update_users_points', $user_id, $new_points, $total_points, $admin_id, $achievement_id);
    // Maybe award some points-based badges
    foreach (badgeos_get_points_based_achievements() as $achievement) {
        badgeos_maybe_award_achievement_to_user($achievement->ID, $user_id);
    }
    return $total_points;
}
 function widget($args, $instance)
 {
     global $user_ID;
     extract($args);
     echo $before_widget;
     $title = apply_filters('widget_title', $instance['title']);
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     //user must be logged in to view earned badges and points
     if (is_user_logged_in()) {
         //display user's points if widget option is enabled
         if ($instance['point_total'] == 'on') {
             echo '<p class="badgeos-total-points">' . sprintf(__('My Total Points: %s', 'badgeos'), '<strong>' . number_format(badgeos_get_users_points()) . '</strong>') . '</p>';
         }
         $achievements = badgeos_get_user_achievements();
         if (is_array($achievements) && !empty($achievements)) {
             $number_to_show = absint($instance['number']);
             $thecount = 0;
             wp_enqueue_script('badgeos-achievements');
             wp_enqueue_style('badgeos-widget');
             //load widget setting for achievement types to display
             $set_achievements = isset($instance['set_achievements']) ? $instance['set_achievements'] : '';
             //show most recently earned achievement first
             $achievements = array_reverse($achievements);
             echo '<ul class="widget-achievements-listing">';
             foreach ($achievements as $achievement) {
                 //verify achievement type is set to display in the widget settings
                 //if $set_achievements is not an array it means nothing is set so show all achievements
                 if (!is_array($set_achievements) || in_array($achievement->post_type, $set_achievements)) {
                     //exclude step CPT entries from displaying in the widget
                     if (get_post_type($achievement->ID) != 'step') {
                         $permalink = get_permalink($achievement->ID);
                         $title = get_the_title($achievement->ID);
                         $img = badgeos_get_achievement_post_thumbnail($achievement->ID, array(50, 50), 'wp-post-image');
                         $thumb = $img ? '<a style="margin-top: -25px;" class="badgeos-item-thumb" href="' . esc_url($permalink) . '">' . $img . '</a>' : '';
                         $class = 'widget-badgeos-item-title';
                         $item_class = $thumb ? ' has-thumb' : '';
                         // Setup credly data if giveable
                         $giveable = credly_is_achievement_giveable($achievement->ID, $user_ID);
                         $item_class .= $giveable ? ' share-credly addCredly' : '';
                         $credly_ID = $giveable ? 'data-credlyid="' . absint($achievement->ID) . '"' : '';
                         echo '<li id="widget-achievements-listing-item-' . absint($achievement->ID) . '" ' . $credly_ID . ' class="widget-achievements-listing-item' . esc_attr($item_class) . '">';
                         echo $thumb;
                         echo '<a class="widget-badgeos-item-title ' . esc_attr($class) . '" href="' . esc_url($permalink) . '">' . esc_html($title) . '</a>';
                         echo '</li>';
                         $thecount++;
                         if ($thecount == $number_to_show && $number_to_show != 0) {
                             break;
                         }
                     }
                 }
             }
             echo '</ul><!-- widget-achievements-listing -->';
         }
     } else {
         //user is not logged in so display a message
         _e('You must be logged in to view earned achievements', 'badgeos');
     }
     echo $after_widget;
 }
Exemplo n.º 4
0
/**
 * Save extra user meta fields to the Edit Profile screen
 *
 * @since  1.0.0
 * @param  int  $user_id      User ID being saved
 * @return mixed			  false if current user can not edit users, void if can
 */
function badgeos_save_user_profile_fields($user_id = 0)
{
    if (!current_user_can('edit_user', $user_id)) {
        return false;
    }
    $can_notify = isset($_POST['_badgeos_can_notify_user']) ? 'true' : 'false';
    update_user_meta($user_id, '_badgeos_can_notify_user', $can_notify);
    // Update our user's points total, but only if edited
    if (isset($_POST['user_points']) && $_POST['user_points'] != badgeos_get_users_points($user_id)) {
        badgeos_update_users_points($user_id, absint($_POST['user_points']), get_current_user_id());
    }
}
/**
 * Check if user meets the points requirement for a given achievement
 *
 * @since  1.0.0
 * @param  bool    $return         The current status of whether or not the user deserves this achievement
 * @param  integer $user_id        The given user's ID
 * @param  integer $achievement_id The given achievement's post ID
 * @return bool                    Our possibly updated earning status
 */
function badgeos_user_meets_points_requirement($return = false, $user_id = 0, $achievement_id = 0)
{
    // First, see if the achievement requires a minimum amount of points
    if ('points' == get_post_meta($achievement_id, '_badgeos_earned_by', true)) {
        // Grab our user's points and see if they at least as many as required
        $user_points = absint(badgeos_get_users_points($user_id));
        $points_required = absint(get_post_meta($achievement_id, '_badgeos_points_required', true));
        $last_activity = badgeos_achievement_last_user_activity($achievement_id);
        if ($user_points >= $points_required) {
            $return = true;
        } else {
            $return = false;
        }
        // If the user just earned the badge, though, don't let them earn it again
        // This prevents an infinite loop if the badge has no maximum earnings limit
        if ($last_activity >= time('-2 seconds')) {
            $return = false;
        }
    }
    // Return our eligibility status
    return $return;
}
 public function shortcode($atts)
 {
     $atts = shortcode_atts(array('type' => 'all', 'format' => 'simple', 'user_id' => 0, 'link_to' => false), $atts);
     if ($atts['type'] == 'all') {
         $atts['type'] = badgeos_get_achievement_types_slugs();
     }
     $points = absint(badgeos_get_users_points($atts['user_id']));
     $level = $this->get_level_info($points, $atts['type']);
     // no progress bar
     if (!$level['next_points']) {
         return '';
     }
     $progress = $points / $level['next_points'] * 100 . "%";
     $output = '';
     if ($atts['link_to']) {
         $output .= '<a href="' . $atts['link_to'] . '">';
     }
     $title = "";
     if ($level['current_achievement']) {
         $title = get_the_title($level['current_achievement']) . ": ";
     }
     $output .= $this->wppb_get_progress_bar(false, false, $progress, false, $progress, true, sprintf(__("%s%d/%d Points", 'badgeos-activity-progress'), $title, $points, $level['next_points']));
     if ($atts['link_to']) {
         $output .= '</a>';
     }
     if ($atts['format'] == 'extended') {
         $progress = $output;
         $output = __('Current activity level:', 'badgeos-activity-progress');
         if ($level['current_achievement']) {
             $output .= '<div class="badgeos-badge-wrap">';
             $output .= badgeos_get_achievement_post_thumbnail($level['current_achievement']);
             $output .= '<span class="badgeos-title-wrap"><a href="' . get_permalink($level['current_achievement']) . '">' . get_the_title($level['current_achievement']) . '</a></span>';
             $output .= '</div>';
         } else {
             $output .= ' ' . __('No activity level reached.', 'badgeos-activity-progress') . '<br>';
         }
         $output .= '<p>' . sprintf(__("Activity points needed for next level: %d", 'badgeos-activity-progress'), $level['next_points']) . '</p>';
         $output .= $progress;
     }
     wp_enqueue_style('activity-progress-shortcode');
     return $output;
 }
    $showing = "follows";
    $followers = bp_follow_total_follow_counts(array("user_id" => bp_displayed_user_id()));
} elseif (function_exists("bp_add_friend_button")) {
    $showing = "friends";
}
?>
		
                <div id="item-statistics">
                    <div class="numbers">
                    
                         <?php 
if ($GLOBALS['badgeos']) {
    ?>
                         <span>
                            <p><?php 
    $points = badgeos_get_users_points(bp_displayed_user_id());
    echo number_format($points);
    ?>
</p>
                            <p><?php 
    printf(_n('Point', 'Points', $points, 'social-learner'));
    ?>
</p>
                         </span>
                         <?php 
}
?>

                        <?php 
if ($showing == "follows") {
    ?>