Ejemplo n.º 1
0
 /**
  * Ensure a tally exists for a given notice. If we can't find
  * one create one with the total number of existing faves
  *
  * @param integer $noticeID
  *
  * @return Fave_tally the tally data object
  */
 static function ensureTally($noticeID)
 {
     $tally = Fave_tally::staticGet('notice_id', $noticeID);
     if (!$tally) {
         $tally = new Fave_tally();
         $tally->notice_id = $noticeID;
         $tally->count = Fave_tally::countExistingFaves($noticeID);
         $result = $tally->insert();
         if (!$result) {
             $msg = sprintf(_m("Couldn't create favorite tally for notice ID %d."), $noticeID);
             throw new ServerException($msg);
         }
     }
     return $tally;
 }