Passed
Pull Request — master (#264)
by John
05:44
created

AnnouncementModel::formatPostTime()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 18
nc 9
nop 1
dl 0
loc 31
rs 9.0444
c 1
b 0
f 1
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('post_date','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["post_date"]);
29
            $item["content_parsed"]=clean(convertMarkdownToHtml($item["content"]));
30
        }
31
        return $list;
32
    }
33
}
34