/** * Updates the total amount of points the user has. * * @return Array */ public function updateTotalPoints() { global $wgEnableFacebook, $wgUserLevels; if ($this->user_id == 0) { return array(); } $stats_data = array(); if (is_array($wgUserLevels)) { // Load points before update $stats = new UserStats($this->user_id, $this->user_name); $stats_data = $stats->getUserStats(); $points_before = $stats_data['points']; // Load Honorific Level before update $user_level = new UserLevel($points_before); $level_number_before = $user_level->getLevelNumber(); } $dbw = wfGetDB(DB_MASTER); $res = $dbw->select('user_stats', '*', array("stats_user_id = {$this->user_id}"), __METHOD__); $row = $dbw->fetchObject($res); if ($row) { // recaculate point total $new_total_points = 1000; if ($this->point_values) { foreach ($this->point_values as $point_field => $point_value) { if ($this->stats_fields[$point_field]) { $field = $this->stats_fields[$point_field]; $new_total_points += $point_value * $row->{$field}; } } } if ($wgEnableFacebook) { $s = $dbw->selectRow('fb_link_view_opinions', array('fb_user_id', 'fb_user_session_key'), array('fb_user_id_wikia' => $this->user_id), __METHOD__); if ($s !== false) { $new_total_points += $this->point_values['facebook']; } } $dbw->update('user_stats', array('stats_total_points' => $new_total_points), array('stats_user_id' => $this->user_id), __METHOD__); // If user levels is in settings, check to see if user advanced with update if (is_array($wgUserLevels)) { // Get New Honorific Level $user_level = new UserLevel($new_total_points); $level_number_after = $user_level->getLevelNumber(); // Check if the user advanced to a new level on this update if ($level_number_after > $level_number_before) { $m = new UserSystemMessage(); $m->addMessage($this->user_name, 2, wfMessage('level-advanced-to', $user_level->getLevelName())->inContentLanguage()->parse()); $m->sendAdvancementNotificationEmail($this->user_id, $user_level->getLevelName()); } } $this->clearCache(); } return $stats_data; }