Passed
Pull Request — master (#492)
by John
10:55
created

AnnouncementModel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 14 3
1
<?php
2
3
namespace App\Models;
4
5
use GrahamCampbell\Markdown\Facades\Markdown;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\DB;
8
9
class AnnouncementModel extends Model
10
{
11
    protected $tableName='announcement';
12
    protected $table='announcement';
13
    protected $primaryKey='anid';
14
    const DELETED_AT=null;
15
    const UPDATED_AT=null;
16
    const CREATED_AT=null;
17
18
    public function fetch()
19
    {
20
        $list=DB::table($this->table)->orderBy('created_at','desc')->get()->all();
21
        if (empty($list)) {
22
            return [];
23
        }
24
        foreach ($list as &$item) {
25
            $notice_author=DB::table("users")->where(["id"=>$item["uid"]])->first();
26
            $item["name"]=$notice_author["name"];
27
            $item["avatar"]=$notice_author["avatar"];
28
            $item["post_date_parsed"]=formatHumanReadableTime($item["created_at"]);
29
            $item["content_parsed"]=clean(convertMarkdownToHtml($item["content"]));
30
        }
31
        return $list;
32
    }
33
}
34