Issues (67)

src/User/Comments.php (1 issue)

1
<?php
2
3
namespace Alfs18\User;
4
5
use Anax\DatabaseActiveRecord\ActiveRecordModel;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class Comments extends ActiveRecordModel
11
{
12
    /**
13
     * @var string $tableName name of the database table.
14
     */
15
    protected $tableName = "Comments";
16
17
    /**
18
     * Columns in the table.
19
     *
20
     * @var integer $id primary key auto incremented.
21
     * @var integer $questionId the id of the question the
22
     *                          comment is connected to.
23
     * @var integer $answerId the id of the answer the
24
     *                        comment is connected to.
25
     * @var string $acronym the creator of the comment.
26
     * @var string $comment the comment.
27
     * @var integer $points the points of the comment.
28
     * @var string $created date and time of comment's creation.
29
     */
30
    public $id;
31
    public $questionId;
32
    public $answerId;
33
    public $acronym;
34
    public $comment;
35
    public $points;
36
    public $created;
37
38
    /**
39
     * Save comment to database.
40
     *
41
     * @param object $di.
42
     *
43
     * @return void
44
     */
45
    public function saveComment($di)
46
    {
47
        $db = $di->get("dbqb");
48
        $db->connect()
49
            ->insert("Comments", ["questionId", "acronym", "comment", "points", "created"])
50
            ->execute([$this->questionId, $this->acronym, $this->comment, $this->points, $this->created]);
51
    }
52
53
54
    /**
55
     * Save answer comment to database.
56
     *
57
     * @param object $di.
58
     *
59
     * @return void
60
     */
61
    public function saveAnswerComment($di)
62
    {
63
        $db = $di->get("dbqb");
64
        $db->connect()
65
            ->insert("AnswerComments", ["answerId", "acronym", "comment", "points", "created"])
66
            ->execute([$this->answerId, $this->acronym, $this->comment, $this->points, $this->created]);
67
    }
68
69
70
    /**
71
     * Change character to ÅÄÖ if needed.
72
     *
73
     * @param string $text     The string/text to be checked.
74
     *
75
     * @return array
76
     */
77
    public function changeCharacter($text)
78
    {
79
        $characters = [
80
            "/&Aring;/" => "Å",
81
            "/&aring;/" => "å",
82
            "/&Auml;/" => "Ä",
83
            "/&auml;/" => "ä",
84
            "/&Ouml;/" => "Ö",
85
            "/&ouml;/" => "ö"
86
        ];
87
88
        foreach ($characters as $key => $val) {
89
            $text = preg_replace($key, $val, $text);
90
        }
91
        return $text;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $text returns the type string which is incompatible with the documented return type array.
Loading history...
92
    }
93
}
94