/** * @param $arrayGamesPlays * @return array */ public static function getPlaysRelatedArrays($arrayGamesPlays) { $arrayTotalPlays = []; $arrayPlaysByMonth = []; $arrayPlaysByYear = []; $arrayPlaysByDayWeek = []; $arrayPlaysByDate = []; $allDatesPlayed = []; $countAllPlays = 0; foreach ($arrayGamesPlays as $play) { // Informations missing for this game if (!isset($play['item'])) { continue; } $idGame = $play['item']['@attributes']['objectid']; $quantityPlay = $play['@attributes']['quantity']; $datePlay = $play['@attributes']['date']; if ($datePlay != '0000-00-00') { $allDatesPlayed[] = $datePlay; $timestampDate = Utility::dateToYearMonthTimestamp($datePlay); Utility::arrayIncrementValue($arrayPlaysByMonth[$timestampDate], $idGame, $quantityPlay, 'nbPlayed'); $timestampDate = Utility::dateToDayWeek($datePlay); Utility::arrayIncrementValue($arrayPlaysByDayWeek, $timestampDate, $quantityPlay); $timestampDate = Utility::dateToYear($datePlay); Utility::arrayIncrementValue($arrayPlaysByYear[$timestampDate], $idGame, $quantityPlay, 'nbPlayed'); $timestampDate = Utility::dateToTimestamp($datePlay); Utility::arrayIncrementValue($arrayPlaysByDate[$timestampDate], $idGame, $quantityPlay, 'nbPlayed'); } $countAllPlays += $quantityPlay; Utility::arrayIncrementValue($arrayTotalPlays, $idGame, $quantityPlay, 'nbPlayed'); $arrayTotalPlays[$idGame]['id'] = $idGame; $arrayTotalPlays[$idGame]['name'] = $play['item']['@attributes']['name']; $arrayTotalPlays[$idGame]['plays'][] = ['date' => Utility::dateToTimestamp($datePlay), 'quantity' => $quantityPlay]; } // Get first play of each game foreach ($arrayTotalPlays as $idGame => $game) { uasort($game['plays'], 'App\\Lib\\Utility::compareDate'); $firstPlay = last(array_reverse($game['plays'])); $arrayTotalPlays[$idGame]['firstPlay'] = $firstPlay['date']; } arsort($allDatesPlayed); arsort($arrayTotalPlays); ksort($arrayPlaysByYear); ksort($arrayPlaysByMonth); ksort($arrayPlaysByDayWeek); ksort($arrayPlaysByDate); $hindex = self::getHIndex($arrayTotalPlays); $GLOBALS['data']['arrayTotalPlays'] = $arrayTotalPlays; $GLOBALS['data']['arrayPlaysByMonth'] = $arrayPlaysByMonth; $GLOBALS['data']['arrayPlaysByYear'] = $arrayPlaysByYear; $GLOBALS['data']['arrayPlaysByDayWeek'] = $arrayPlaysByDayWeek; $GLOBALS['data']['arrayPlaysByDate'] = $arrayPlaysByDate; $GLOBALS['data']['countAllPlays'] = $countAllPlays; $GLOBALS['data']['hindex'] = $hindex; if (count($allDatesPlayed) > 0) { $GLOBALS['data']['firstDatePlayRecorded'] = Utility::dateStrToCarbon(last($allDatesPlayed)); $GLOBALS['data']['nbDaysSinceFirstPlay'] = $GLOBALS['data']['firstDatePlayRecorded']->diffInDays(); } }