Issues (67)

src/User/Answers.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 Answers extends ActiveRecordModel
11
{
12
    /**
13
     * @var string $tableName name of the database table.
14
     */
15
    protected $tableName = "Answers";
16
17
    /**
18
     * Columns in the table.
19
     *
20
     * @var integer $id primary key auto incremented.
21
     */
22
    public $id;
23
    public $questionId;
24
    public $acronym;
25
    public $answer;
26
    public $points;
27
    public $created;
28
29
    /**
30
     * Verify the acronym and the password, if successful the object
31
     * contains all details from the databse row.
32
     *
33
     * @param string $acronym acronym to check.
34
     * @param string $question the question asked.
35
     *
36
     * @return boolean true if okey, false if something went wrong.
37
     */
38
    public function saveAnswer($di)
39
    {
40
        $db = $di->get("dbqb");
41
        $db->connect()
42
            ->insert("Answers", ["questionId", "acronym", "answer", "points", "created"])
43
            ->execute([$this->questionId, $this->acronym, $this->answer, $this->points, $this->created]);
44
    }
45
46
47
    /**
48
     * Change character to ÅÄÖ if needed.
49
     *
50
     * @param string $text     The string/text to be checked.
51
     *
52
     * @return array
53
     */
54
    public function changeCharacter($text)
55
    {
56
        $characters = [
57
            "/&Aring;/" => "Å",
58
            "/&aring;/" => "å",
59
            "/&Auml;/" => "Ä",
60
            "/&auml;/" => "ä",
61
            "/&Ouml;/" => "Ö",
62
            "/&ouml;/" => "ö"
63
        ];
64
65
        foreach ($characters as $key => $val) {
66
            $text = preg_replace($key, $val, $text);
67
        }
68
        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...
69
    }
70
}
71