Comment::getAvatar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 1
1
<?php
2
namespace CJ\Comment;
3
4
use \Anax\Database\ActiveRecordModel;
5
6
/**
7
 * A database driven model.
8
 */
9
class Comment extends ActiveRecordModel
10
{
11
    /**
12
     * @var string $tableName name of the database table.
13
     */
14
    protected $tableName = "c_comments";
15
16
    /**
17
     * Columns in the table.
18
     *
19
     * @var integer $id primary key auto incremented.
20
     */
21
    public $id;
22
    public $userId;
23
    public $userMail;
24
    public $msg;
25
    public $heading;
26
    public $postDate;
27
    public $deleted;
28
    public $updated;
29
    public $liked;
30
31
32
    /**
33
    *  Inits the object with the dabase
34
    */
35 5
    public function init($db)
36
    {
37 5
        $this->setDb($db);
38 5
    }
39
40
    /**
41
     * Gets all comments from Db
42
     */
43 1
    public function getComments()
44
    {
45 1
        return $this->findAll();
46
    }
47
48
    /**
49
     * Gets all comments from Db
50
     */
51 1
    public function getComment($index)
52
    {
53 1
        return $this->find("id", $index);
54
    }
55
56
57
    /**
58
     * Delete comment with a specific ID
59
     */
60 1
    public function deleteComment($index)
61
    {
62 1
        $this->find("id", $index);
63 1
        $this->delete();
64 1
    }
65
66
67
    /**
68
     * @return string
69
     * Get the avatar HTML
70
     */
71 1
    public function getAvatar($index, $classes = "", $size = 125)
72
    {
73 1
        $this->find("id", $index);
74 1
        $hash = md5($this->userMail);
75
76 1
        $html = "<img src='https://www.gravatar.com/avatar/$hash?s=$size&default=mm' class='$classes'>";
77 1
        return $html;
78
    }
79
}
80