public function getVoteCount(Work $a)
 {
     static $cache;
     if (!$cache) {
         $cache = [];
     }
     if (!isset($cache[$a->getId()])) {
         $count = $this->getEntityManager()->getConnection()->fetchColumn("SELECT COUNT(*) FROM ProjectVote WHERE work_id = ?", [$a->getId()], 0);
         $cache[$a->getId()] = $count;
     }
     return $cache[$a->getId()];
 }
 /**
  * @param Work $project
  * @param bool|false $userRatings
  * @return float
  */
 public function calculateProjectRating(Work $project, $userRatings = false)
 {
     $partyId = $project->getParty()->getId();
     if (!isset($this->ratingsCache[$partyId][(string) $userRatings])) {
         $em = $this->getEntityManager();
         /** @var PartyRepository $repo */
         $repo = $em->getRepository('GeekPartyBundle:Party');
         $this->ratingsCache[$partyId][(string) $userRatings] = $userRatings ? $repo->getUserRatings($project->getParty()) : $repo->getRatings($project->getParty());
     }
     if (!isset($this->ratingsCache[$partyId][(string) $userRatings][$project->getId()])) {
         return 0.0;
     }
     return $this->ratingsCache[$partyId][(string) $userRatings][$project->getId()];
 }
 /**
  * @param $editForm
  * @param $entity
  */
 private function uploadFiles(Form $editForm, Work $entity)
 {
     $partyDir = $this->get('kernel')->getRootDir() . '/../public_html/works/' . $entity->getParty()->getId();
     if (!is_dir($partyDir)) {
         mkdir($partyDir, 0777, true);
     }
     if ($iconFile = $editForm['icon']->getData()) {
         $this->uploadIcon($iconFile, $entity->getId(), $partyDir);
     }
     if ($gameFile = $editForm['file']->getData()) {
         if ($entity->getParty()->isCurrent() || $this->isAdmin()) {
             $this->uploadGame($gameFile, $entity->getId(), $partyDir);
         } else {
             $message = "Событие " . $entity->getParty()->getName() . " еще не началось или уже закончилось.\n                    Чтобы обновить работу, обратитесь к администрации сайта.";
             $this->addErrorMessage($message);
         }
     }
 }
 /**
  * @param Work $work
  * @return bool
  */
 public function isWebBuildUploaded(Work $work)
 {
     $path = '/works/' . $work->getParty()->getId() . '/' . $work->getId() . '/index.html';
     return file_exists($this->rootDir . '/../public_html' . $path);
 }