Archived
1
0
Fork 0
This repository has been archived on 2021-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
ifnews/app/Commands/Freshlist.php

63 lines
1.4 KiB
PHP

<?php
namespace App\Commands;
use LaravelZero\Framework\Commands\Command;
use Log;
use App\Models\Game;
class Freshlist extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'freshlist {keyword?}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Print new games';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$now = date('Y-m-d');
$week_ago = date('Y-m-d', strtotime('1 week ago'));
$games = Game::with('authors')
->where('release_date', '<=', $now)
->where('release_date', '>', $week_ago)
->orderBy('source')
->get();
echo '<ul>';
foreach ($games as $game) {
echo '<li>';
$authors = $game->authors->toArray();
if (!empty($authors)) {
echo '<em>';
echo implode(', ', array_map(function($model) {
return trim($model['name']);
}, $authors));
echo '</em> — ';
}
echo "<a rel='nofollow' target='_blank' href='".trim($game->url)."'>«".htmlentities(trim($game->title))."»</a>";
$description = $game->short_description;
if (empty($description)) {
$description = $game->description;
}
if (!empty($description)) {
echo PHP_EOL.'<blockquote>'.htmlentities(html_entity_decode($description)).'</blockquote>';
}
echo '</li>'.PHP_EOL;
}
echo '</ul>';
}
}