if (!$fresh_checkin_data->count()) { return json_encode(['msg' => 'No new data in the `checkin_data` collection. Nothing to process.']); } /** * Determine winners and losers from the $checkin_doc payload data. */ $match_results = array_map(function ($checkin_doc) { $checkin = new \BarracksMaster\Checkin($checkin_doc); /** * All checkin data should be stage 3. Stage 1/2 moved to task update_ladder_partials. */ if ($checkin->getStage() == 3) { $winners = $checkin->getWinners(); $losers = $checkin->getLosers(); } $checkin->markAsProcessed(); return array('_id' => $checkin_doc['_id'], 'match_id' => $checkin->matchID, 'winners' => $winners, 'losers' => $losers); }, iterator_to_array($fresh_checkin_data, 0)); /** * Remove match results with no winners, as results are provided for both stage 2 and stage 3. */ $match_results = array_filter($match_results, function ($match_result) { if (empty($match_result['winners']) && empty($match_result['losers'])) { return false; } else { return true; } }); print_r($match_results); /** * Winners and losers have been determined. Perform major procedures here.