From 35a7d853ff99667305d72fddb035f05ba53bc495 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 12 Nov 2019 21:49:56 +0100 Subject: [PATCH] Migrate view to the NewsComments model --- includes/pages/user_news.php | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index 643d9d04..8ce3dffb 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -1,8 +1,6 @@ ' . __('Comments') . ' » ' . '' - . count(DB::select('SELECT `ID` FROM `NewsComments` WHERE `Refid`=?', [$news->id])) + . $news->comments()->count() . ''; } $html .= ''; @@ -141,17 +139,10 @@ function user_news_comments() ) { if ($request->hasPostData('submit') && $request->has('text')) { $text = $request->input('text'); - DB::insert(' - INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) - VALUES (?, ?, ?, ?) - ', - [ - $nid, - date('Y-m-d H:i:s'), - $text, - $user->id, - ] - ); + $news->comments()->create([ + 'text' => $text, + 'user_id' => $user->id, + ]); engelsystem_log('Created news_comment: ' . $text); $html .= success(__('Entry saved.'), true); @@ -159,18 +150,12 @@ function user_news_comments() $html .= display_news($news); - $comments = DB::select( - 'SELECT * FROM `NewsComments` WHERE `Refid`=? ORDER BY \'ID\'', - [$nid] - ); - foreach ($comments as $comment) { - $user_source = User::find($comment['UID']); - + foreach ($news->comments as $comment) { $html .= '
'; - $html .= '
' . nl2br(htmlspecialchars($comment['Text'])) . '
'; + $html .= '
' . nl2br(htmlspecialchars($comment->text)) . '
'; $html .= ''; $html .= '
'; }