function award_badge($object_id, $user_id, $badge_slug, $badge_badge = false)
 {
     if (!$user_id) {
         return;
     }
     // add badge to userbadges
     qa_db_query_sub('INSERT INTO ^userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) ' . 'VALUES (NOW(), 1, #, #, $, 0)', $object_id, $user_id, $badge_slug);
     if (qa_opt('event_logger_to_database')) {
         // add event
         $handle = qa_getHandleFromId($user_id);
         qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $user_id, $handle, qa_cookie_get_create(), 'badge_awarded', 'badge_slug=' . $badge_slug . ($object_id ? "\t" . 'postid=' . $object_id : ''));
     }
     if (qa_opt('badge_email_notify')) {
         qa_badge_notification($user_id, $object_id, $badge_slug);
     }
     // check for sheer number of badges, unless this badge was for number of badges (avoid recursion!)
     if (!$badge_badge) {
         $this->check_badges($user_id);
     }
 }
Ejemplo n.º 2
0
function qa_badge_award_check($badges, $var, $uid, $oid = NULL, $notify = 1)
{
    // oid is the postid (if), notify = 1 for email and popup, 2 for just popup.
    if (!$uid) {
        return;
    }
    $awarded = array();
    foreach ($badges as $badge_slug) {
        if (($var === false || (int) $var >= (int) qa_opt('badge_' . $badge_slug . '_var')) && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') {
            if ($oid) {
                $result = @qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND badge_slug=$ AND object_id=#', $uid, $badge_slug, $oid), true);
            } else {
                $result = @qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND badge_slug=$', $uid, $badge_slug), true);
            }
            if ($result == null) {
                // not already awarded this badge
                qa_db_query_sub('INSERT INTO ^userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) ' . 'VALUES (NOW(), #, #, #, #, 0)', $notify, $oid, $uid, $badge_slug);
                if ($notify > 0) {
                    //qa_db_usernotice_create($uid, $content, 'html');
                    if (qa_opt('badge_email_notify') && $notify == 1) {
                        qa_badge_notification($uid, $oid, $badge_slug);
                    }
                    if (qa_opt('event_logger_to_database')) {
                        // add event
                        $handle = qa_getHandleFromId($uid);
                        qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $uid, $handle, qa_cookie_get_create(), 'badge_awarded', 'badge_slug=' . $badge_slug . ($oid ? "\t" . 'postid=' . $oid : ''));
                    }
                }
                array_push($awarded, $badge_slug);
            }
        }
    }
    return $awarded;
}