Ejemplo n.º 1
0
 /**
  * Check whether the user can have the badge
  *
  * @param  Users $user
  * @return boolean
  */
 public function canHave(Users $user)
 {
     $ids = [];
     $noBountyCategories = $this->getNoBountyCategories();
     $conditions = '(IF(votes_up IS NULL, 0, votes_up) - IF(votes_down IS NULL, 0, votes_down)) >= 5';
     $replies = $user->getReplies([$conditions, 'columns' => 'id, posts_id', 'order' => 'created_at DESC']);
     foreach ($replies as $reply) {
         $have = UsersBadges::count(['users_id = ?0 AND badge = ?1 AND type = "C" AND code1 = ?2', 'bind' => [$user->id, $this->getName(), $reply->id]]);
         if (!$have) {
             $ids[] = [$reply->posts_id, $reply->id];
         }
     }
     return $ids;
 }