Пример #1
0
 /**
  * Sends the number of points specified in $points to $groupID
  *
  * @param int $groupID
  * @param int $points
  * @return bool
  */
 public function sendPointsToGroup($groupID, $points)
 {
     //If the user is banned, they can't give points
     if ($this->getHidden()) {
         return false;
     }
     //Nice try... you can't send negative points or send more points than
     //you've got or send a non-numeric number of points
     if ($points < 1 || $this->getPoints() < $points || !is_numeric($points)) {
         return false;
     }
     $group = GroupPeer::retrieveByPK($groupID);
     if (!$group) {
         return false;
     }
     //Move the points
     $group->setPoints($group->getPoints() + $points);
     $this->setPoints($this->getPoints() - $points);
     //If the group was bankrupt but now isn't, set the group as no longer
     //bankrupt
     if ($group->getPoints() >= 0 && $group->getBankruptSince() != null) {
         $group->setBankruptSince(null);
     }
     //Return true if the transaction worked on both ends
     return $group->save() && $this->save();
 }