Exemplo n.º 1
0
 function save()
 {
     global $database, $jTips;
     $bind = array();
     $this->set('updated', gmdate('Y-m-d H:i:s'));
     foreach ($this as $prop => $val) {
         $bind[$prop] = $val;
     }
     if (!$this->bind($bind)) {
         return false;
     }
     //jTipsDebug("IDA: " .$this->id);
     if (!$this->check()) {
         return false;
     }
     if (!$this->user_id) {
         jTipsLogger::_log('attempt to save jtipsuser with no related josuser. aborted', 'ERROR');
         return false;
     }
     //jTipsDebug("IDB: " .$this->id);
     if (empty($this->id) and !empty($this->season_id)) {
         $newUser = true;
     } else {
         $newUser = false;
     }
     //Bug 36: Set the image property to empty string instead of null
     if (!$this->store(true)) {
         jTipsLogger::_log($this->_db->getErrorMsg(), 'ERROR');
         return false;
     }
     //jTipsDebug("IDC " .$this->id);
     //late entry points here
     jTipsLogger::_log('saving user with id ' . $this->id . ' and season ' . $this->season_id);
     if ($newUser) {
         // BUG 406 - optionally set reminders as on by default
         if ($jTips['DefaultReminders']) {
             jTipsLogger::_log('setting email reminder option as on by default');
             $this->setPreference('email_reminder', 1);
         }
         jTipsLogger::_log('setting default points for new user for season ' . $this->season_id);
         $jSeason = new jSeason($database);
         $jSeason->load($this->season_id);
         jTipsLogger::_log('comparing dates ' . date('Y-m-d') . ' >? ' . TimeDate::toDatabaseDate($jSeason->start_time));
         if (date('Y-m-d') > TimeDate::toDatabaseDate($jSeason->start_time)) {
             $jSeason->getDefaultPoints($this->id);
         }
         if ($jTips['JomSocialActivities'] and $jTips['JomSocialOnUserJoin']) {
             // BUG 334 - typo in user_id variable.
             jTipsJomSocial::writeJoinMessage($this->user_id, $jSeason);
         }
     }
     return true;
 }
Exemplo n.º 2
0
 function process()
 {
     global $database, $jTips, $mosConfig_absolute_path;
     $this->clearHistory();
     $params = array('round_id' => $this->id);
     $jSeason = new jSeason($database);
     $jSeason->load($this->season_id);
     $jGame = new jGame($database);
     $jGames = forceArray($jGame->loadByParams($params));
     $params = array('season_id' => $this->season_id);
     $jTipsUser = new jTipsUser($database);
     $jTipsUsers = forceArray($jTipsUser->loadByParams($params));
     $noTips = $scores = $worst_precision = array();
     $played = count($jGames);
     foreach ($jTipsUsers as $jTipsUser) {
         jTipsLogger::_log("Processing scores for user " . $jTipsUser->id);
         $score = $matching = $precision = $allAwayScore = 0;
         if ($jTipsUser->hasTipped($this->id)) {
             jTipsLogger::_log($jTipsUser->id . " has tipped in round " . $this->id);
             foreach ($jGames as $jGame) {
                 jTipsLogger::_log("Processing game " . $jGame->id);
                 $params = array('user_id' => $jTipsUser->id, 'game_id' => $jGame->id);
                 $jTip = new jTip($database);
                 $jTip->loadByParams($params);
                 // make sure this is not a bye game
                 if (!$jGame->home_id or !$jGame->away_id or !$jGame->winner_id) {
                     jTipsLogger::_log('attempting to process tips on a bye game, skipping', 'INFO');
                     continue;
                 }
                 /*
                  * Feature Request 101 - Team Starts
                  * Determine the winner when we take the starts into account
                  * We only care about the starts for picking the winner/draw
                  * For picking the margins and scores, use the actual winner
                  */
                 if ($jSeason->team_starts) {
                     jTipsLogger::_log('processing team starts');
                     $homeScore = $awayScore = 0;
                     $homeScore = $jGame->home_score + ($jGame->home_start + 0);
                     $awayScore = $jGame->away_score + ($jGame->away_start + 0);
                     if ($homeScore > $awayScore) {
                         $winnerID = $jGame->home_id;
                     } else {
                         if ($homeScore < $awayScore) {
                             $winnerID = $jGame->away_id;
                         } else {
                             if ($homeScore == $awayScore) {
                                 $winnerID = -1;
                             }
                         }
                     }
                     jTipsLogger::_log('feature 101: With starts, the winner is ' . $winnerID . ', otherwise the winner is ' . $jGame->winner_id . " HOME {$homeScore} v AWAY {$awayScore}");
                 } else {
                     $winnerID = $jGame->winner_id;
                 }
                 if ($jTip->tip_id == $winnerID) {
                     //User tipped right!
                     jTipsLogger::_log("CORRECT TIP by " . $jTipsUser->id . " in round_id " . $this->id . " in game_id " . $jGame->id);
                     //BUG 248 - Add ToughScore if enabled
                     if ($jSeason->tough_score and $jGame->tough_score) {
                         $score += $jGame->tough_score;
                     }
                     if ($winnerID == -1) {
                         $score += isset($jSeason->user_draw) ? $jSeason->user_draw : 0;
                         jTipsLogger::_log("Draw correctly picked!");
                     } else {
                         $score += isset($jSeason->user_correct) ? $jSeason->user_correct : 0;
                     }
                     $matching++;
                 }
                 if ($winnerID == $jGame->away_id) {
                     $allAwayScore += $jSeason->user_correct;
                 }
                 //Check for correct margins and handle precision score gathering
                 if ($jSeason->pick_margin == 1 and $jGame->has_margin == 1) {
                     $margin = abs($jGame->home_score - $jGame->away_score);
                     if ($jTip->margin == $margin) {
                         $score += isset($jSeason->user_pick_margin) ? $jSeason->user_pick_margin : 0;
                         jTipsLogger::_log("correct margin picked!");
                     }
                     if ($jSeason->precision_score == 1) {
                         if ($jGame->winner_id == $jTip->tip_id) {
                             $margin_offset = abs($margin - $jTip->margin);
                         } else {
                             $margin_offset = abs($margin + $jTip->margin);
                         }
                         if (isset($worst_precision[$jGame->id]) && $margin_offset > $worst_precision[$jGame->id] || empty($worst_precision[$jGame->id])) {
                             $worst_precision[$jGame->id] = $margin_offset;
                         }
                         $precision += $margin_offset;
                         jTipsLogger::_log("PICK_MARGIN: Adding {$margin_offset} to precision of {$precision}");
                     }
                 }
                 //Check for correct scores and handle precision score gathering
                 if ($jSeason->pick_score == 1 and $jGame->has_score == 1) {
                     $margin = abs($jGame->home_score - $jGame->away_score);
                     if ($jTip->home_score == $jGame->home_score and $jTip->away_score == $jGame->away_score) {
                         $score += isset($jSeason->user_pick_score) ? $jSeason->user_pick_score : 0;
                         jTipsLogger::_log("Correct scores picked!");
                     }
                     if ($jSeason->precision_score == 1) {
                         $pickedScoreMargin = abs($jTip->home_score - $jTips->away_score);
                         if ($jGame->winner_id == $jTip->tip_id) {
                             $score_offset = abs($margin - $pickedScoreMargin);
                         } else {
                             $score_offset = abs($margin + $pickedScoreMargin);
                         }
                         if (isset($worst_precision[$jGame->id]) and $score_offset > $worst_precision[$jGame->id] or empty($worst_precision[$jGame->id])) {
                             $worst_precision[$jGame->id] = $score_offset;
                         }
                         $precision += $score_offset;
                         jTipsLogger::_log("PICK_SCORE: Adding {$score_offset} to precision of {$precision}");
                         jTipsLogger::_log("PREC DEBUG: {$jTipsUser->id}-{$jTipsUser->user_id} Picked Margin: {$pickedScoreMargin}. Actual Margin: {$margin}. Applied Precision: {$score_offset}. Running Precision: {$precision}", 'INFO');
                     }
                 }
                 //Check for a bonus team selection
                 if ($jSeason->pick_bonus >= 1 and $jGame->has_bonus == 1) {
                     if ($jTip->bonus_id == $jGame->bonus_id && $jGame->bonus_id != -1) {
                         $score += isset($jSeason->user_pick_bonus) ? $jSeason->user_pick_bonus : 0;
                     }
                 }
             }
             //was a perfect round picked?
             if ($matching == $played) {
                 $score += isset($jSeason->user_bonus) ? $jSeason->user_bonus : 0;
             }
             //did the user use their 'doubleup'
             if ($jTipsUser->doubleup == $this->id and $jTips['DoubleUp'] == 1) {
                 $score = $score * 2;
             }
             $scores[] = $score;
             //Save the data to the history object
             $jHistory = new jHistory($database);
             $jHistory->user_id = $jTipsUser->id;
             $jHistory->round_id = $this->id;
             jTipsLogger::_log("Score for user_id " . $jTipsUser->id . " in round_id " . $this->id . " is {$score}");
             $jHistory->points = $score;
             //Update rank after all users have been saved
             $jHistory->outof = count($jTipsUsers);
             //$jHistory->comment	= $jTipsUser->comment;
             if ($jSeason->precision_score == 1) {
                 jTipsLogger::_log("setting precision to {$precision} for user_id " . $jTipsUser->id . " in round_id " . $this->id);
                 $jHistory->precision = $precision;
             } else {
                 $jHistory->precision = 0;
             }
             if ($jHistory->save() !== false) {
                 $results[] = 1;
             } else {
                 jTipsLogger::_log("Error saving history: " . $jHistory->_error);
                 $results[] = 0;
             }
             //remove the current comment
             $jTipsUser->comment = null;
             $jTipsUser->save();
             // Check if the AlphaUserPoints config option is set
             if (isJoomla15()) {
                 $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php';
             } else {
                 $api_AUP = $mosConfig_absolute_path . 'components/com_alphauserpoints/helper.php';
             }
             if (!$this->scored and $jTips['AlphaUserPoints'] and jTipsFileExists($api_AUP)) {
                 require_once $api_AUP;
                 jTipsLogger::_log('sending ' . $score . ' points for user ' . $jTipsUser->user_id, 'INFO');
                 $refID = AlphaUserPointsHelper::getAnyUserReferreID($jTipsUser->user_id);
                 AlphaUserPointsHelper::newpoints('plgaup_jtips_total_points', $refID, '', '', $score);
             }
             if (!$this->scored and $jTips['JomSocialActivities'] and $jTips['JomSocialUserResults']) {
                 global $mosConfig_absolute_path;
                 require_once $mosConfig_absolute_path . '/administrator/components/com_jtips/utils/jTipsJomSocial.php';
                 jTipsJomSocial::writeRoundResult($jSeason, $this, $jTipsUser->user_id, $score);
             }
         } else {
             $noTips[] = $jTipsUser;
         }
     }
     if (count($noTips) > 0) {
         /////////////////////////////////////////////////
         // Feature Request 71
         // Allow users that did not to be assigned
         // all the away teams
         //
         /*if ($jSeason->user_none != -1) {
         		$thisRound = $jSeason->user_none;
         		} else if (is_array($scores) && count($scores) > 0) {
         		$thisRound = min($scores);
         		} else {
         		$thisRound = 0;
         		}*/
         if ($jSeason->user_none == -2) {
             //handle all away teams
             $thisRound = $allAwayScore;
             jTipsLogger::_log("didn't tip? You'll be stuck with the away teams. You got {$thisRound}");
         } else {
             if ($jSeason->user_none == -1) {
                 //handle lowest possible score
                 if (is_array($scores) and count($scores) > 0) {
                     $thisRound = min($scores);
                     jTipsLogger::_log("didn't tip? You'll be stuck with the lowest score this round, {$thisRound}");
                 } else {
                     $thisRound = 0;
                     jTipsLogger::_log("didn't tip? You'll be stuck {$thisRound}");
                 }
             } else {
                 //handle allocated score
                 $thisRound = $jSeason->user_none;
                 jTipsLogger::_log("didn't tip? You're getting {$thisRound}");
             }
         }
         //
         // END Feature Request 71
         ////////////////////////////////////////////////////
         foreach ($noTips as $jTipsUser) {
             $jHistory = new jHistory($database);
             $jHistory->user_id = $jTipsUser->id;
             $jHistory->round_id = $this->id;
             $jHistory->points = $thisRound;
             $jHistory->precision = array_sum($worst_precision);
             //$jHistory->outof		= count($jTipsUsers);
             //$jHistory->comment	= $jTipsUser->comment;
             if ($jHistory->save() !== false) {
                 $results[] = 1;
             } else {
                 $results[] = 0;
             }
             $jTipsUser->save();
             // Check if the AlphaUserPoints config option is set
             if (isJoomla15()) {
                 $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php';
             } else {
                 $api_AUP = $mosConfig_absolute_path . 'components/com_alphauserpoints/helper.php';
             }
             if (!$this->scored and $jTips['AlphaUserPoints'] and jTipsFileExists($api_AUP)) {
                 require_once $api_AUP;
                 jTipsLogger::_log('sending ' . $score . ' points for user ' . $jTipsUser->user_id, 'INFO');
                 $refID = AlphaUserPointsHelper::getAnyUserReferreID($jTipsUser->user_id);
                 AlphaUserPointsHelper::newpoints('plgaup_jtips_total_points', $refID, '', '', $thisRound);
             }
             if (!$this->scored and $jTips['JomSocialActivities']) {
                 global $mosConfig_absolute_path;
                 require_once $mosConfig_absolute_path . '/administrator/components/com_jtips/utils/jTipsJomSocial.php';
                 if ($jTips['JomSocialUserResults']) {
                     jTipsJomSocial::writeRoundResult($jSeason, $this, $jTipsUser->user_id, $score);
                 }
                 if ($jTips['JomSocialOnNoTips']) {
                     jTipsJomSocial::writeOnNoTips($jTipsUser->user_id, $jSeason, $this);
                 }
             }
         }
     }
     $jHistory = new jHistory($database);
     $jHistory->setRanks($this->id, true);
     if (!$this->scored and $jTips['JomSocialActivities']) {
         // find out who won the round and write it to the JomSocial stream
         $winners = $this->getRoundWinners();
         jTipsJomSocial::writeRoundWinners($winners, $this, $jSeason);
     }
     $this->scored = 1;
     $result = $this->save();
     //if ($this->scored != 1) {
     jTeam::updateLadder($this, $jSeason);
     //}
     //$this->scored = 1;
     //return $this->save();
     return $result;
 }
Exemplo n.º 3
0
}
$comment = trim(strip_tags(stripslashes(jTipsGetParam($_REQUEST, 'comment', ''))));
$comment = cleanComment(str_replace('\\', '', $comment));
if ($jTips['EnableComments'] == 1 && !empty($comment)) {
    jTipsLogger::_log('saving comment');
    $jComment = new jComment($database);
    $jCommentParams = array('user_id' => $jTipsCurrentUser->id, 'round_id' => $jRound->id);
    $jComment->loadByParams($jCommentParams);
    $jComment->user_id = $jTipsCurrentUser->id;
    $jComment->round_id = $jRound->id;
    $jComment->comment = $comment;
    $jComment->save();
    jTipsLogger::_log('comment saved');
}
$emailResult = '';
if ($jTips['TipsNotifyEnable'] and $jTipsCurrentUser->getPreference('tips_notifications')) {
    if (sendTipsConfirmation($jTipsCurrentUser, $myTips)) {
        $emailResult = '. ' . $jLang['_COM_TIPS_EMAIL_SUCCESS'];
    } else {
        $emailResult = '. ' . $jLang['_COM_TIPS_EMAIL_FAILURE'];
    }
}
// BUG 312 - more JomSocial Integration
if ($jTips['JomSocialActivities'] and $jTips['JomSocialOnSaveTips']) {
    require_once $mosConfig_absolute_path . '/administrator/components/com_jtips/utils/jTipsJomSocial.php';
    jTipsJomSocial::writeOnSaveTips($jTipsCurrentUser->user_id, $isUpdate, $jSeason, $jRound);
}
jTipsLogger::_log('done saving tips, redirecting...');
//die('save done');
$message = $jLang['_COM_TIPS_SAVED_MESSAGE'] . $emailResult;
jTipsRedirect('index.php?option=com_jtips&view=Tips&Itemid=' . jTipsGetParam($_REQUEST, 'Itemid', '') . '&season=' . $jSeason->id, $message);
Exemplo n.º 4
0
 /**
  * Build a proper string to write to the Activity Stream
  *
  * @since 2.1.9
  * @param string The string to find substitutes in
  * @param array An associative array of keys and values to match and replace
  * @return string The parse string
  */
 function parseString($string, $variables, $jSeason = false)
 {
     if (!empty($variables)) {
         foreach ($variables as $search => $replace) {
             // TODO: if $string = season, link to competition dashboard
             if ($search == 'season' and $jSeason) {
                 $replace = jTipsJomSocial::getDashboardLink($jSeason);
             }
             $string = str_replace('{' . $search . '}', $replace, $string);
         }
     }
     return $string;
 }