예제 #1
0
 private function cacheScoreHandlingAfterRemoveLog(GeoCacheLog $log)
 {
     $db = OcDb::instance();
     // remove cache from users top caches, because the found log was deleted for some reason
     $query = "DELETE FROM `cache_rating` WHERE `user_id` = :1 AND `cache_id` = :2 ";
     $db->multiVariableQuery($query, $log->getUser()->getUserId(), $log->getGeoCache()->getCacheId());
     // Notify OKAPI's replicate module of the change.
     // Details: https://github.com/opencaching/okapi/issues/265
     require_once __DIR__ . '/../../okapi/facade.php';
     \okapi\Facade::schedule_user_entries_check($log->getGeoCache()->getCacheId(), $log->getUser()->getUserId());
     \okapi\Facade::disable_error_handling();
     // recalc scores for this cache
     $queryDel = "DELETE FROM `scores` WHERE `user_id` = :1 AND `cache_id` = :2 ";
     $db->multiVariableQuery($queryDel, $log->getUser()->getUserId(), $log->getGeoCache()->getCacheId());
     $query = "SELECT count(*) FROM scores WHERE cache_id= :1 ";
     $liczba = $db->multiVariableQueryValue($query, 0, $log->getGeoCache()->getCacheId());
     $querySel = "SELECT SUM(score) FROM scores WHERE cache_id= :1 ";
     $suma = $db->multiVariableQueryValue($querySel, 0, $log->getGeoCache()->getCacheId());
     // obliczenie nowej sredniej
     if ($liczba != 0) {
         $srednia = $suma / $liczba;
     } else {
         $srednia = 0;
     }
     $updateQuery = "UPDATE caches SET votes = :1 , score= :2 WHERE cache_id= :3 ";
     $db->multiVariableQuery($updateQuery, $liczba, $srednia, $log->getGeoCache()->getCacheId());
 }
예제 #2
0
 public static function sendRemoveLogNotification($emailTemplateFile, GeoCacheLog $log, User $loggedUser)
 {
     $formattedMessage = new EmailFormatter($emailTemplateFile);
     $formattedMessage->setVariable("log_owner", $log->getUser()->getUserName());
     $formattedMessage->setVariable("waypointId", $log->getGeoCache()->getWaypointId());
     $formattedMessage->setVariable("serviceUrl", OcConfig::getAbsolute_server_URI());
     $formattedMessage->setVariable("logRemover", $loggedUser->getUserName());
     $formattedMessage->setVariable("logRemoverId", $loggedUser->getUserId());
     $formattedMessage->setVariable("cache_name", $log->getGeoCache()->getCacheName());
     $formattedMessage->setVariable("log_entry", $log->getText());
     $formattedMessage->setVariable("removedLog_01", tr('removedLog_01'));
     $formattedMessage->setVariable("removedLog_02", tr('removedLog_02'));
     $formattedMessage->addFooterAndHeader($log->getUser()->getUserName());
     $email = new Email();
     $email->addToAddr($log->getUser()->getEmail());
     $email->setReplyToAddr(OcConfig::getNoreplyEmailAddress());
     $email->setFromAddr(OcConfig::getNoreplyEmailAddress());
     $email->setSubject(tr('removed_log_title'));
     $email->setBody($formattedMessage->getEmailContent(), true);
     $email->send();
 }