/** * Increment a user's greeting count and return instance * * This method handles the ins and outs of creating a new greeting_count for a * user or fetching the existing greeting count and incrementing its value. * * @param integer $user_id ID of the user to get a count for * * @return User_greeting_count instance for this user, with count already incremented. */ static function inc($user_id) { $gc = User_greeting_count::getKV('user_id', $user_id); if (empty($gc)) { $gc = new User_greeting_count(); $gc->user_id = $user_id; $gc->greeting_count = 1; $result = $gc->insert(); if (!$result) { // TRANS: Exception thrown when the user greeting count could not be saved in the database. // TRANS: %d is a user ID (number). throw new Exception(sprintf(_m('Could not save new greeting count for %d.'), $user_id)); } } else { $orig = clone $gc; $gc->greeting_count++; $result = $gc->update($orig); if (!$result) { // TRANS: Exception thrown when the user greeting count could not be saved in the database. // TRANS: %d is a user ID (number). throw new Exception(sprintf(_m('Could not increment greeting count for %d.'), $user_id)); } } return $gc; }
/** * Increment a user's greeting count and return instance * * This method handles the ins and outs of creating a new greeting_count for a * user or fetching the existing greeting count and incrementing its value. * * @param integer $user_id ID of the user to get a count for * * @return User_greeting_count instance for this user, with count already incremented. */ static function inc($user_id) { $gc = User_greeting_count::staticGet('user_id', $user_id); if (empty($gc)) { $gc = new User_greeting_count(); $gc->user_id = $user_id; $gc->greeting_count = 1; $result = $gc->insert(); if (!$result) { throw Exception(sprintf(_m("Could not save new greeting count for %d"), $user_id)); } } else { $orig = clone $gc; $gc->greeting_count++; $result = $gc->update($orig); if (!$result) { throw Exception(sprintf(_m("Could not increment greeting count for %d"), $user_id)); } } return $gc; }