コード例 #1
0
ファイル: get-love.php プロジェクト: highfidelity/love
// AJAX request to get love sent to an user
include "../config.php";
include "../class.session_handler.php";
include "helper/check_session.php";
include "../functions.php";
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $con);
if (empty($_REQUEST['id'])) {
    echo 'error: args';
    return;
}
if (empty($_REQUEST['period_id'])) {
    echo 'error: args';
    return;
}
// From user
$fromUser = new User();
$fromUser->findUserById($_SESSION['userid']);
$fromUsername = mysql_real_escape_string($fromUser->getUsername());
// Sent to user
$user = new User();
$user->findUserById($_REQUEST['id']);
$username = mysql_real_escape_string($user->getUsername());
//Get review period start date and end date
$rewarder = new Rewarder();
$period = $rewarder->getPeriod($_REQUEST['period_id']);
$start_date = $period['start_date'];
$end_date = $period['end_date'];
$love = getUserLove($username, $fromUsername, $start_date, $end_date);
$total_love = getUserLove($username, "", $start_date, $end_date);
echo json_encode(array($love, $total_love));
コード例 #2
0
ファイル: functions.php プロジェクト: highfidelity/love
function endReviewPeriod($reset, $conversion_rate, $signature)
{
    $email_template = $conversion_rate ? 'end-period-conversion' : 'end-period';
    $template_data = array('date' => date("F j, Y"), 'signature' => $signature);
    foreach (Rewarder::getCurrentReceivers() as $receiver) {
        $user_template_data = $template_data;
        $user_template_data['points'] = $receiver['received_points'];
        $user_template_data['people'] = $receiver['givers'];
        if ($conversion_rate) {
            $user_template_data['worth'] = $conversion_rate;
            $user_template_data['total_earnings'] = $receiver['received_points'] * $conversion_rate;
        }
        sendTemplateEmail($receiver['username'], $email_template, $user_template_data);
    }
    // makes changes to the database finishing the rewarder
    Rewarder::markPaidAll();
    // reseting all rewarder balances to 0
    if ($reset) {
        $sql = "UPDATE " . REVIEW_USERS . " SET `rewarder_points` = 0";
        mysql_unbuffered_query($sql);
    }
}
コード例 #3
0
ファイル: api.php プロジェクト: highfidelity/love
function populatePeers()
{
    $user_id = intval($_REQUEST['user_id']);
    $peers = $_REQUEST['peers'];
    $rewarder = new Rewarder($user_id);
    foreach ($peers as $peer) {
        $peer_id = intval($peer);
        // if user is not on our list - add him
        if ($rewarder->getGivenPoints($peer_id) === null) {
            $rewarder->setGivenPoints($peer_id, 0);
        }
    }
    $rsp['status'] = SL_OK;
    respond($rsp);
}
コード例 #4
0
ファイル: rewarder-json.php プロジェクト: highfidelity/love
        $json = json_encode(array(0, $rewarderList));
        echo $json;
        break;
    case 'end-period':
        $reset = (bool) $_REQUEST['reset'];
        $conversion_rate = floatval($_REQUEST['conversion_rate']);
        $signature = $_REQUEST['signature'];
        endReviewPeriod($reset, $conversion_rate, $signature);
        break;
    case 'populate-rewarder-list':
        $period = $rewarder->getPeriod($_REQUEST['period_id']);
        $normalized = $_REQUEST['normalized'];
        echo json_encode($rewarder->populateRewarderUserList($period, $normalized));
        break;
    case 'update-user-admin':
        $user_list = $_REQUEST['users'];
        // Update database with the new users
        $rewarder->setUsersAndPerms($user_list);
        break;
    case 'reset_user_review':
        $user_id = $_REQUEST['user_id'];
        $review_id = $_REQUEST['review_id'];
        $period_id = $_REQUEST['period_id'];
        $rewarderTo = new Rewarder($user_id);
        $result = $rewarderTo->resetCurrentReview($review_id, $period_id);
        echo json_encode($result);
        break;
    default:
        echo json_encode(array('error' => 'wrong action'));
        break;
}
コード例 #5
0
    echo json_encode($periods);
    return;
} else {
    $period = "";
    // Check that a specified period is passed
    if (empty($_REQUEST['period'])) {
        if (empty($_REQUEST['period_id'])) {
            echo 'error: args';
            return;
        } else {
            $period_id = mysql_real_escape_string($_REQUEST['period_id']);
        }
    } else {
        $period = mysql_real_escape_string($_REQUEST['period']);
    }
    $results = Rewarder::getResultsForPeriod($period, $period_id);
    // Create an array to hold the point values
    $points = array();
    $percentage = array();
    // Create an array to hold the users
    $users = array();
    // Create an array to hold the givers
    $givers = array();
    $team_givers = array();
    // Relation array
    $relation = array();
    foreach ($results as $result) {
        $points[] = $result['received_points'];
        $percentage[] = $result['received_percentage'];
        $users[] = $result['nickname'];
        $givers[] = $result['givers'];
コード例 #6
0
ファイル: Rewarder.class.php プロジェクト: highfidelity/love
 public static function getResultsForPeriodForCampaign($paid_date, $period_id = -1)
 {
     $period = Rewarder::getPeriod($period_id);
     $date_filter = "  `period_id` = '{$period_id}' ";
     // get the users list of the team members
     $query = "CREATE TEMPORARY TABLE teamLoves\n            SELECT DISTINCT " . LOVE_USERS . ".username, " . LOVE_USERS . ".nickname AS nickname, " . LOVE_USERS . ".id AS id \n            FROM " . LOVE_USERS . " \n            INNER JOIN " . REVIEW_REWARDER . " ON " . LOVE_USERS . ".id =" . REVIEW_REWARDER . ".receiver_id  \n            WHERE  " . LOVE_USERS . ".username IS NOT NULL  \n             AND " . REVIEW_REWARDER . ".period_id = {$period['id']};\n        ";
     $rt = mysql_query($query) or die("Couldn't execute query." . mysql_error());
     $subQuery = "SELECT " . REVIEW_REWARDER . ".receiver_id AS receiver_id, IFNULL(COUNT(DISTINCT " . LOVE_LOVE . ".giver),0) AS givers " . " FROM " . LOVE_USERS . " INNER JOIN " . REVIEW_REWARDER . " ON " . LOVE_USERS . ".id =" . REVIEW_REWARDER . ".receiver_id " . " LEFT JOIN " . LOVE_LOVE . " ON username="******".receiver " . " AND " . LOVE_LOVE . ".at > '{$period['start_date']}' " . " AND " . LOVE_LOVE . ".at < '{$period['end_date']}' " . " WHERE  " . LOVE_USERS . ".username IS NOT NULL " . " AND " . REVIEW_REWARDER . ".period_id = " . $period_id . " GROUP BY receiver_id ";
     $teamSubQuery = "SELECT " . REVIEW_REWARDER . ".receiver_id AS team_receiver_id, IFNULL(COUNT(DISTINCT " . LOVE_LOVE . ".giver),0) AS team_givers " . " FROM " . LOVE_USERS . " INNER JOIN " . REVIEW_REWARDER . " ON " . LOVE_USERS . ".id =" . REVIEW_REWARDER . ".receiver_id " . " LEFT JOIN " . LOVE_LOVE . " ON username="******".receiver " . " AND " . LOVE_LOVE . ".at > '{$period['start_date']}' " . " AND " . LOVE_LOVE . ".at < '{$period['end_date']}' " . " AND " . LOVE_LOVE . ".giver IN (SELECT username FROM teamLoves) " . " WHERE  " . LOVE_USERS . ".username IS NOT NULL " . " AND " . REVIEW_REWARDER . ".period_id = " . $period_id . " GROUP BY receiver_id ";
     $query = "SELECT `" . REVIEW_REWARDER . "`.`receiver_id`, \n                    SUM(`" . REVIEW_REWARDER . "`.`rewarder_points`) AS `received_points`, \n                    SUM(`" . REVIEW_REWARDER . "`.`rewarded_percentage`) AS `received_percentage`, \n                    `givers`, `team_givers`, `username`, `nickname` \n                  FROM `" . REVIEW_REWARDER . "` \n                    LEFT JOIN " . REVIEW_USERS . " ON " . REVIEW_USERS . ".`id` = `" . REVIEW_REWARDER . "`.`receiver_id` \n                    LEFT JOIN ( " . $subQuery . " ) \n                        AS `givers_table` ON `givers_table`.`receiver_id` = `" . REVIEW_REWARDER . "`.`receiver_id` \n                    LEFT JOIN ( " . $teamSubQuery . " ) \n                        AS `team_givers_table` ON `team_givers_table`.`team_receiver_id` = `" . REVIEW_REWARDER . "`.`receiver_id` \n                  WHERE " . $date_filter . " GROUP BY `receiver_id` ORDER BY `received_points` DESC, givers DESC, team_givers DESC";
     $rt = mysql_query($query) or die("Couldn't execute query." . mysql_error());
     $receivers = array();
     while ($row = mysql_fetch_assoc($rt)) {
         $receivers[] = $row;
     }
     return $receivers;
 }