foreach (Season::find('1=1') as $season) { $weeksCount = $season->getWeeksCount(); for ($week = 1; $week <= $weeksCount; $week++) { if ($season->getWeekDate($week) == $date) { $weekName = $season->getWeekName($week); $matches = Match::find('seasonid = ? and week = ?', [$season->seasonid, $week]); foreach ($matches as $match) { /** @var Team $team1 */ $team1 = $match->getTeam1(); /** @var Team $team2 */ $team2 = $match->getTeam2(); $video1 = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team1->teamid, 1]); $video2 = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team2->teamid, 1]); if ($video1 || $video2) { $msg = "{$weekName} {$season->name}: #" . $team1->getHashtag() . " VS #" . $team2->getHashtag(); $msg .= " @{$team1->username} VS @{$team2->username}"; if ($video1) { $msg .= " {$video1->link}"; } if ($video2) { $msg .= " {$video2->link}"; } echo "-> {$msg}\n"; TwitterAuth::botSendTweet($msg); sleep(1); } } } } } }