Przeglądaj źródła

Add rating rendering

staging
Christopher Ross Hind 3 lat temu
rodzic
commit
3e5e4075a8
3 zmienionych plików z 44 dodań i 11 usunięć
  1. +6
    -2
      app/Knockout/Post.php
  2. +31
    -0
      app/Knockout/Rating.php
  3. +7
    -9
      resources/views/partial/post.blade.php

+ 6
- 2
app/Knockout/Post.php Wyświetl plik

@@ -14,6 +14,7 @@ class Post {

// related
public User $user;
public $ratings = [];

public static function unwrap($post)
{
@@ -23,13 +24,16 @@ class Post {
$s->date = Carbon::parse($post->createdAt)->format('d/m/Y H:i');
$s->content = $post->content;

//$s->content = '[quote mentionsUser="1427" postId="659032" threadPage="1" threadId="19764" username="Dr. Magnusson"][/quote]';

// grab user if available
if (isset($post->user)) {
$s->user = User::unwrap($post->user);
}

// grab ratings if available
$s->ratings = array_map(function($rating) {
return Rating::unwrap($rating);
}, $post->ratings ?? []);

return $s;
}



+ 31
- 0
app/Knockout/Rating.php Wyświetl plik

@@ -0,0 +1,31 @@
<?php

namespace App\Knockout;

use App\Helper\BBCode;
use Carbon\Carbon;

class Rating {

// meta
public $id;
public $name;
public $count;

public static function unwrap($rating)
{
$s = new self();

$s->id = $rating->id;
$s->name = $rating->rating;
$s->count = $rating->count;

return $s;
}

public function icon()
{
return sprintf('/img/ratings/%s-24.gif', $this->name);
}

}

+ 7
- 9
resources/views/partial/post.blade.php Wyświetl plik

@@ -15,17 +15,15 @@
<div class="marginBreak"></div>
{!! $post->render() !!}
</div>
<div class="postRatings" style="display:none">
<div class="postRatings">
<table class="ratings" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<img src="/img/ratings/agree-24.gif" />
<br/>16
</td>
<td align="center">
<img src="/img/ratings/idea-24.gif" />
<br/>2
</td>
@foreach ($post->ratings as $rating)
<td align="center">
<img src="{{ $rating->icon() }}" />
<br/>{{ $rating->count }}
</td>
@endforeach
</tr>
</table>
</div>


Ładowanie…
Anuluj
Zapisz