diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2019-11-10 21:30:26 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-11-10 22:10:11 +0100 |
commit | b878740f80ce7cfe2a0bc53956e3f7e4e0aa2f78 (patch) | |
tree | 4003b59c5ea2a731f8881711b95e2b736ae04626 /src | |
parent | 6534191d59521e1e5a88638b1c6a1c77f74dd12a (diff) |
News: Bug fixes, cleanup, comments & formatting
Use more magically available methods and properties
Fixed atom feed and stats not using the new model
Diffstat (limited to 'src')
-rw-r--r-- | src/Controllers/Metrics/Stats.php | 9 | ||||
-rw-r--r-- | src/Models/News.php | 45 | ||||
-rw-r--r-- | src/Models/News/News.php | 30 | ||||
-rw-r--r-- | src/Models/User/User.php | 2 |
4 files changed, 48 insertions, 38 deletions
diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index af453cde..2d58f999 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -5,6 +5,7 @@ namespace Engelsystem\Controllers\Metrics; use Carbon\Carbon; use Engelsystem\Database\Database; use Engelsystem\Models\EventConfig; +use Engelsystem\Models\News; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression as QueryExpression; @@ -209,16 +210,10 @@ class Stats /** * @param bool $meeting * @return int - * @codeCoverageIgnore */ public function announcements($meeting = null) { - $query = $this - ->getQuery('News'); - - if (!is_null($meeting)) { - $query->where('Treffen', '=', $meeting); - } + $query = is_null($meeting) ? News::query() : News::whereIsMeeting($meeting); return $query->count(); } diff --git a/src/Models/News.php b/src/Models/News.php new file mode 100644 index 00000000..55ab9c1d --- /dev/null +++ b/src/Models/News.php @@ -0,0 +1,45 @@ +<?php + +declare(strict_types=1); + +namespace Engelsystem\Models; + +use Carbon\Carbon; +use Engelsystem\Models\User\UsesUserModel; +use Illuminate\Database\Query\Builder as QueryBuilder; + +/** + * @property int $id + * @property string $title + * @property string $text + * @property bool $is_meeting + * @property Carbon|null $created_at + * @property Carbon|null $updated_at + * + * @method static QueryBuilder|LogEntry[] whereId($value) + * @method static QueryBuilder|LogEntry[] whereTitle($value) + * @method static QueryBuilder|LogEntry[] whereText($value) + * @method static QueryBuilder|LogEntry[] whereIsMeeting($value) + * @method static QueryBuilder|LogEntry[] whereCreatedAt($value) + * @method static QueryBuilder|LogEntry[] whereUpdatedAt($value) + */ +class News extends BaseModel +{ + use UsesUserModel; + + /** @var bool Enable timestamps */ + public $timestamps = true; + + /** @var array */ + protected $casts = [ + 'is_meeting' => 'boolean', + ]; + + /** @var array */ + protected $fillable = [ + 'title', + 'text', + 'is_meeting', + 'user_id', + ]; +} diff --git a/src/Models/News/News.php b/src/Models/News/News.php deleted file mode 100644 index ae67752b..00000000 --- a/src/Models/News/News.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -declare(strict_types=1); - -namespace Engelsystem\Models\News; - -use Engelsystem\Models\User\UsesUserModel; -use Illuminate\Database\Eloquent\Model; - -/** - * This class represents a news item. - */ -class News extends Model -{ - use UsesUserModel; - - protected $casts = [ - 'is_meeting' => 'boolean', - ]; - - protected $attributes = [ - 'is_meeting' => false, - ]; - - protected $fillable = [ - 'title', - 'text', - 'is_meeting', - 'user_id', - ]; -} diff --git a/src/Models/User/User.php b/src/Models/User/User.php index cca96dbe..058f9a8c 100644 --- a/src/Models/User/User.php +++ b/src/Models/User/User.php @@ -4,7 +4,7 @@ namespace Engelsystem\Models\User; use Carbon\Carbon; use Engelsystem\Models\BaseModel; -use Engelsystem\Models\News\News; +use Engelsystem\Models\News; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Query\Builder as QueryBuilder; |