Passed
Push — master ( 9df631...0f56b8 )
by
unknown
10:44
created

ForumTopic::show()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 10
nc 8
nop 0
dl 0
loc 16
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CourseBundle\Component\CourseCopy\Resources;
6
7
class ForumTopic extends Resource
8
{
9
    public ?string $title = null;
10
    public ?string $topic_poster_name = null;
11
    public ?string $title_qualify = null;
12
13
    public function __construct($obj)
14
    {
15
        parent::__construct($obj->thread_id, RESOURCE_FORUMTOPIC);
16
        $this->obj = $obj;
17
18
        $this->title             = (string)($obj->thread_title ?? $obj->title ?? '');
19
        $this->topic_poster_name = (string)($obj->thread_poster_name ?? $obj->topic_poster_name ?? '');
20
        $this->title_qualify     = (string)($obj->thread_title_qualify ?? $obj->title_qualify ?? '');
21
    }
22
23
    public function show()
24
    {
25
        parent::show();
26
27
        $date  = $this->obj->thread_date ?? ($this->obj->time ?? null);
28
        $extra = $date ? api_convert_and_format_date($date) : '';
29
30
        if (!empty($this->obj->thread_poster_id)) {
31
            $ui = api_get_user_info($this->obj->thread_poster_id);
32
            $name = $ui['complete_name'] ?? $this->topic_poster_name;
33
            $extra = ($name ? $name.', ' : '').$extra;
34
        } elseif (!empty($this->topic_poster_name)) {
35
            $extra = $this->topic_poster_name.', '.$extra;
36
        }
37
38
        echo $this->title.($this->title_qualify ? ' ['.$this->title_qualify.']' : '').($extra ? ' ('.$extra.')' : '');
39
    }
40
}
41