Пример #1
0
 /**
  * Get winning photo
  * @since Version 3.9.1
  * @return array
  */
 public function getWinningPhoto()
 {
     if ($this->VotingDateClose >= new DateTime()) {
         return false;
     }
     $photos = $this->getPhotosAsArrayByVotes();
     $num_votes = false;
     $tied = [];
     if (count($photos) == 0) {
         return false;
     }
     foreach ($photos as $photo) {
         if ($num_votes === false) {
             $num_votes = count($photo['votes']);
             $tied[] = $photo;
             continue;
         }
         if ($num_votes == count($photo['votes'])) {
             $tied[] = $photo;
             continue;
         }
         if (count($photo['votes']) < $num_votes) {
             continue;
         }
     }
     if (count($tied) > 1) {
         Utility\CompetitionUtility::NotifyTied($this);
         return false;
     }
     $tied[0]['image']['user_id'] = $tied[0]['author']['id'];
     $result = $tied[0]['image'];
     #print_r($result);die;
     if (!isset($result['winner']) || $result['winner'] == "0") {
         $data = ["winner" => 1];
         $where = ["id = ?" => $result['id']];
         $this->db->update("image_competition_submissions", $data, $where);
     }
     $photo = $this->getPhoto($result);
     return $photo;
 }