Skip to content

Commit

Permalink
Merge pull request #26 from EzioBallarin/master
Browse files Browse the repository at this point in the history
2.2.5
  • Loading branch information
eballarin committed Oct 12, 2014
2 parents f44a272 + e8d0acb commit e6783bb
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 120 deletions.
2 changes: 1 addition & 1 deletion game-on.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: Gamification tools for teachers.
Authors: Semar Yousif, Vincent Astolfi, Ezio Ballarin, Forest Hoffman, Austin Vuong, Spencer Nussbaum, Isaac Canada, Charles Leon
Author URI: http://maclab.guhsd.net/
Version: 2.2.4
Version: 2.2.5
*/
include('go_datatable.php');
include('types/types.php');
Expand Down
22 changes: 9 additions & 13 deletions go_pnc.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,11 @@ function go_update_admin_bar ($type, $title, $value, $status = null) {
$display = go_display_points($value);
$rng = ($current_rank_points -$value) * -1;
$dom = ($next_rank_points - $current_rank_points);
if ($status == 0) {
echo "<script language='javascript'>
jQuery(document).ready(function() {
jQuery('#points_needed_to_level_up').html('{$rng}/{$dom}');
});
</script>";
} else {
echo "<script language='javascript'>
jQuery('#points_needed_to_level_up').html('{$rng}/{$dom}');
</script>";
}
echo "<script language='javascript'>
jQuery(document).ready(function() {
jQuery('#points_needed_to_level_up').html('{$rng}/{$dom}');
});
</script>";
} else if ($type == 'currency') {
$display = go_display_currency($value);
} else if ($type == 'bonus_currency') {
Expand All @@ -206,8 +200,10 @@ function go_update_admin_bar ($type, $title, $value, $status = null) {
}
$percentage = go_get_level_percentage(get_current_user_id());
echo "<script language='javascript'>
jQuery('#go_admin_bar_{$type}').html('{$title}: {$display}');
jQuery('#go_admin_bar_progress_bar').css({'width': '{$percentage}%'".(($color)?", 'background-color': '{$color}'":"")."});
jQuery(document).ready(function() {
jQuery('#go_admin_bar_{$type}').html('{$title}: {$display}');
jQuery('#go_admin_bar_progress_bar').css({'width': '{$percentage}%'".(($color)?", 'background-color': '{$color}'":"")."});
});
</script>";
}

Expand Down
81 changes: 63 additions & 18 deletions go_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,42 @@ function go_stats_move_stage () {
$count = $_POST['count'];
$message = $_POST['message'];
$custom_fields = get_post_custom($task_id);
$date_picker = ((unserialize($custom_fields['go_mta_date_picker'][0]))?array_filter(unserialize($custom_fields['go_mta_date_picker'][0])):false);
$rewards = unserialize($custom_fields['go_presets'][0]);
$current_status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$go_table_name} WHERE uid=%d AND post_id=%d",$user_id, $task_id));
$page_id = $wpdb->get_var($wpdb->prepare("SELECT page_id FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id));

$changed = array('type' => 'json', 'points' => 0, 'currency' => 0, 'bonus_currency' => 0);

if (!empty($date_picker)) {
$dates = $date_picker['date'];
$percentages = $date_picker['percent'];
$unix_today = strtotime(date('Y-m-d'));

$past_dates = array();

foreach ($dates as $key => $date) {
if ($unix_today >= strtotime($date)) {
$past_dates[$key] = abs($unix_today - strtotime($date));
}
}

if (!empty($past_dates)) {
asort($past_dates);
$update_percent = (float)(($percentages[key($past_dates)])/100);
} else {
$update_percent = 1;
}
} else {
$update_percent = 1;
}

if ($status == 1){
$current_rewards = $wpdb->get_results($wpdb->prepare("SELECT points, currency, bonus_currency FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id));
go_task_abandon($user_id, $task_id, $current_rewards[0]->points, $current_rewards[0]->currency, $current_rewards[0]->bonus_currency);
go_task_abandon($user_id, $task_id,
$current_rewards[0]->points,
$current_rewards[0]->currency,
$current_rewards[0]->bonus_currency * $update_percent);

$changed['points'] = -$current_rewards[0]->points;
$changed['currency'] = -$current_rewards[0]->currency;
Expand All @@ -198,38 +225,55 @@ function go_stats_move_stage () {
} else {

for ($count; $count > 0; $count--) {
go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, 'on', -1, null, null, null, null);
go_add_post($user_id, $task_id, $current_status,
floor(-$rewards['points'][$current_status] * $update_percent),
floor(-$rewards['currency'][$current_status] * $update_percent),
floor(-$rewards['bonus_currency'][$current_status] * $update_percent),
null, $page_id, 'on', -1, null, null, null, null);

$changed['points'] += -$rewards['points'][$current_status];
$changed['currency'] += -$rewards['currency'][$current_status];
$changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status];
$changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent);
$changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent);
$changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent);
}

while ($current_status != $status) {
if ($current_status > $status) {
$current_status--;

go_add_post($user_id, $task_id, $current_status, -$rewards['points'][$current_status], -$rewards['currency'][$current_status], -$rewards['bonus_currency'][$current_status], null, $page_id, null, null, null, null, null, null);
go_add_post($user_id, $task_id, $current_status,
floor(-$rewards['points'][$current_status] * $update_percent),
floor(-$rewards['currency'][$current_status] * $update_percent),
floor(-$rewards['bonus_currency'][$current_status] * $update_percent),
null, $page_id, null, null, null, null, null, null);

$changed['points'] += -$rewards['points'][$current_status];
$changed['currency'] += -$rewards['currency'][$current_status];
$changed['bonus_currency'] += -$rewards['bonus_currency'][$current_status];
$changed['points'] += floor(-$rewards['points'][$current_status] * $update_percent);
$changed['currency'] += floor(-$rewards['currency'][$current_status] * $update_percent);
$changed['bonus_currency'] += floor(-$rewards['bonus_currency'][$current_status] * $update_percent);

} elseif ($current_status < $status) {
$current_status++;
$current_count = $wpdb->get_var($wpdb->prepare("SELECT count FROM {$go_table_name} WHERE uid=%d AND post_id=%d", $user_id, $task_id));
if ($current_status == 5 && $current_count == 0) {
go_add_post($user_id, $task_id, $current_status-1, $rewards['points'][$current_status-1], $rewards['currency'][$current_status-1], $rewards['bonus_currency'][$current_status-1], null, $page_id, 'on', 1, null, null, null, null);
go_add_post($user_id, $task_id, $current_status-1,
floor($rewards['points'][$current_status-1] * $update_percent),
floor($rewards['currency'][$current_status-1] * $update_percent),
floor($rewards['bonus_currency'][$current_status-1] * $update_percent),
null, $page_id, 'on', 1, null, null, null, null);

$changed['points'] += floor($rewards['points'][$current_status-1] * $update_percent);
$changed['currency'] += floor($rewards['currency'][$current_status-1] * $update_percent);
$changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status-1] * $update_percent);

$changed['points'] += $rewards['points'][$current_status-1];
$changed['currency'] += $rewards['currency'][$current_status-1];
$changed['bonus_currency'] += $rewards['bonus_currency'][$current_status-1];
} elseif ($current_status < 5) {
go_add_post($user_id, $task_id, $current_status, $rewards['points'][$current_status-1], $rewards['currency'][$current_status-1], $rewards['bonus_currency'][$current_status-1], null, $page_id, null, null, null, null, null, null);
go_add_post($user_id, $task_id, $current_status,
floor($rewards['points'][$current_status-1] * $update_percent),
floor($rewards['currency'][$current_status-1] * $update_percent),
floor($rewards['bonus_currency'][$current_status-1] * $update_percent),
null, $page_id, null, null, null, null, null, null);

$changed['points'] += $rewards['points'][$current_status-1];
$changed['currency'] += $rewards['currency'][$current_status-1];
$changed['bonus_currency'] += $rewards['bonus_currency'][$current_status-1];
$changed['points'] += floor($rewards['points'][$current_status-1] * $update_percent);
$changed['currency'] += floor($rewards['currency'][$current_status-1] * $update_percent);
$changed['bonus_currency'] += floor($rewards['bonus_currency'][$current_status-1] * $update_percent);
}
}
}
Expand All @@ -247,6 +291,7 @@ function go_stats_move_stage () {
$changed['next_rank_points'] = $updated_rank[1][1];
}
}

echo json_encode($changed);
die();
}
Expand Down Expand Up @@ -296,7 +341,7 @@ function go_stats_item_list () {
?>
<li class='go_stats_item go_stats_purchased_item'>
<?php
echo "<a href='".get_permalink($item_id)."'>".get_the_title($item_id)."</a> ({$count_before} of {$item_count_total}) {$purchase_date}";
echo "<a href='#' onclick='go_lb_opener({$item_id})'>".get_the_title($item_id)."</a> ({$count_before} of {$item_count_total}) {$purchase_date}";
?>
</li>
<?php
Expand Down
2 changes: 1 addition & 1 deletion scripts/go_everypage.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function go_stats_move_stage (task_id, status) {
jQuery('div[task="' + task_id + '"][stage="' + i +'"]').removeClass('completed').removeClass('stage_url');
}
}
json = JSON.parse(html.substr(html.search('{"type"'), html.length));
var json = JSON.parse(html.substr(html.search('{"type"'), html.length));
jQuery('#go_stats_user_points_value').html(parseFloat(jQuery('#go_stats_user_points_value').html()) + json['points']);

if (json['rank']) {
Expand Down
3 changes: 2 additions & 1 deletion styles/go_every_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ input#go_store_item_url_input {
}

input.go_store_exchange_input[type='text'] {
width: 30%;
display: none;
width: 21.7%;
}

input#go_store_badge_id_input {
Expand Down
7 changes: 4 additions & 3 deletions types/store/includes/lightbox/buy-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function go_buy_item() {
if (isset($_POST['recipient']) && !empty($_POST['recipient']) && $_POST['recipient'] != '') {
$recipient = $_POST['recipient'];
$recipient_id = $wpdb->get_var('SELECT id FROM '.$wpdb->users.' WHERE display_name="'.$recipient.'"');
$recipient_purchase_count = $wpdb->get_var("SELECT count FROM {$table_name_go} WHERE post_id={$post_id} AND uid={$recipient_id} LIMIT 1");
$recipient_purchase_count = $wpdb->get_var("SELECT count FROM {$go_table_name} WHERE post_id={$post_id} AND uid={$recipient_id} LIMIT 1");
}

$user_id = get_current_user_id();
Expand Down Expand Up @@ -57,6 +57,7 @@ function go_buy_item() {
$exchange_currency = $store_exchange[1];
$exchange_points = $store_exchange[2];
$exchange_bonus_currency = $store_exchange[3];
$exchange_minutes = $store_exchange[4];
}
$item_url = $custom_fields['go_mta_store_item_url'][0];
$badge_id = $custom_fields['go_mta_badge_id'][0];
Expand Down Expand Up @@ -97,8 +98,8 @@ function go_buy_item() {
if ($recipient_id) {

go_message_user($recipient_id, get_userdata($user_id)->display_name." has purchased {$qty} <a href='javascript:;' onclick='go_lb_opener({$post_id})'>".get_the_title($post_id)."</a> for you.");
if ($exchange_currency || $exchange_points || $exchange_bonus_currency) {
go_add_post($recipient_id, $post_id, -1, $exchange_points, $exchange_currency, $exchange_bonus_currency, null, null, $repeat);
if ($exchange_currency || $exchange_points || $exchange_bonus_currency || $exchange_minutes) {
go_add_post($recipient_id, $post_id, -1, $exchange_points, $exchange_currency, $exchange_bonus_currency, $exchange_minutes, null, $repeat);
go_add_bonus_currency($recipient_id, $exchange_bonus_currency, get_userdata($user_id)->display_name." purchase of {$qty} ".get_the_title($post_id).".");
} else {
go_add_post($recipient_id, $post_id, -1, 0, 0, 0, null, $repeat);
Expand Down
Loading

0 comments on commit e6783bb

Please sign in to comment.