1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alfs18\User; |
4
|
|
|
|
5
|
|
|
use Anax\DatabaseActiveRecord\ActiveRecordModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Example of FormModel implementation. |
9
|
|
|
*/ |
10
|
|
|
class Question extends ActiveRecordModel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string $tableName name of the database table. |
14
|
|
|
*/ |
15
|
|
|
protected $tableName = "Question"; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Columns in the table. |
19
|
|
|
* |
20
|
|
|
* @var integer $id primary key auto incremented. |
21
|
|
|
*/ |
22
|
|
|
public $id; |
23
|
|
|
public $acronym; |
24
|
|
|
public $question; |
25
|
|
|
// public $qComments; |
26
|
|
|
// public $answer; |
27
|
|
|
// public $aComments; |
28
|
|
|
public $tags; |
29
|
|
|
public $points; |
30
|
|
|
public $created; |
31
|
|
|
public $updated; |
32
|
|
|
public $deleted; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Verify the acronym and the password, if successful the object |
36
|
|
|
* contains all details from the databse row. |
37
|
|
|
* |
38
|
|
|
* @param string $acronym acronym to check. |
39
|
|
|
* @param string $question the question asked. |
40
|
|
|
* |
41
|
|
|
* @return boolean true if okey, false if something went wrong. |
42
|
|
|
*/ |
43
|
|
|
public function saveQuestion($di) |
44
|
|
|
{ |
45
|
|
|
$db = $di->get("dbqb"); |
46
|
|
|
// $db->connect(); |
47
|
|
|
// $user = $db->select("question, tags") |
48
|
|
|
// ->from("Question") |
49
|
|
|
// ->where("acronym = ?") |
50
|
|
|
// ->execute([$this->acronym]) |
51
|
|
|
// ->fetchAll(); |
52
|
|
|
// var_dump($user) |
53
|
|
|
$db->connect() |
54
|
|
|
->insert("Question", ["acronym", "question", "tags", "points", "created"]) |
55
|
|
|
->execute([$this->acronym, $this->question, $this->tags, $this->points, $this->created]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Change character to ÅÄÖ if needed. |
61
|
|
|
* |
62
|
|
|
* @param string $text The string/text to be checked. |
63
|
|
|
* |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function changeCharacter($text) |
67
|
|
|
{ |
68
|
|
|
$characters = [ |
69
|
|
|
"/Å/" => "Å", |
70
|
|
|
"/å/" => "å", |
71
|
|
|
"/Ä/" => "Ä", |
72
|
|
|
"/ä/" => "ä", |
73
|
|
|
"/Ö/" => "Ö", |
74
|
|
|
"/ö/" => "ö" |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
foreach ($characters as $key => $val) { |
78
|
|
|
$text = preg_replace($key, $val, $text); |
79
|
|
|
} |
80
|
|
|
return $text; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|