public static function getOnceAwards() { $awards = []; foreach (Award::getAwards() as $type) { $type = (object) $type; if (Award::isOnce($type->name)) { array_push($awards, $type); } } return $awards; }
public function checkAwardForUser($user) { $awards = Award::getAwards(); $this->log(['user' => $user->getName(), 'createdTasks' => $user->createdTasks->count(), 'claimedTasks' => $user->claimedTasks->count()]); foreach ($awards as $award) { $type = $award->name; $freq = Award::frequencyForType($type); // ------------------------------------- if ($user->hasAward($type) == false && $freq == Award::AWARD_FREQ_ONCE) { $this->log("running [{$type}] query..."); $results = []; // ------------------------------------- if ($type == Award::AWARD_CLAIMED_5 && $user->claimedTasks->count() >= 5) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type], true)); } // ------------------------------------- if ($type == Award::AWARD_CLAIMED_10 && $user->claimedTasks->count() >= 10) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type], true)); } // ------------------------------------- if ($type == Award::AWARD_CLAIMED_25 && $user->claimedTasks->count() >= 25) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type], true)); } // ------------------------------------- if ($type == Award::AWARD_CLAIMED_50 && $user->claimedTasks->count() >= 50) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type], true)); } // ------------------------------------- if ($type == Award::AWARD_CLAIMED_75 && $user->claimedTasks->count() >= 75) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type], true)); } // ------------------------------------- if ($type == Award::AWARD_CLAIMED_100 && $user->claimedTasks->count() >= 100) { array_push($results, $this->store(['user_id' => $user->id, 'name' => $type])); } if (empty($results)) { $this->log("*** User Not Eligible ***"); } else { $this->log($results); } } else { // $this->log("*** user_id({$user->id}) $type Found ***"); } } }