1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment\Modules; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A database driven model. |
7
|
|
|
*/ |
8
|
|
|
class Post extends ActiveRecordModelExtender |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string $tableName name of the database table. |
13
|
|
|
*/ |
14
|
|
|
protected $tableName = "ramverk1_posts"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Columns in the table. |
18
|
|
|
* |
19
|
|
|
* @var integer $id primary key auto incremented. |
20
|
|
|
*/ |
21
|
|
|
public $id; |
22
|
|
|
public $user; |
23
|
|
|
public $questionId; # Connection to new Question() |
24
|
|
|
|
25
|
|
|
public $type; # question/answer |
26
|
|
|
public $text; |
27
|
|
|
|
28
|
|
|
public $created; |
29
|
|
|
|
30
|
|
|
public $di; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns post with markdown and gravatar |
36
|
|
|
* @param string $sql |
37
|
|
|
* @param array $param |
|
|
|
|
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
1 |
|
public function getAllPosts($sql, $params) |
42
|
|
|
{ |
43
|
1 |
|
$posts = $this->findAllWhere("$sql", $params); |
44
|
|
|
|
45
|
1 |
|
return array_map(function ($post) { |
46
|
|
|
|
47
|
|
|
// Get e-mail for Post |
48
|
1 |
|
$user = new User($this->db); |
49
|
1 |
|
$user->find("name", $post->user); |
50
|
1 |
|
$post->img = $this->gravatar($user->email); |
51
|
|
|
|
52
|
|
|
// Get comments for Post |
53
|
1 |
|
$comment = new Comment($this->db); |
54
|
1 |
|
$post->comments = $comment->getComments("parentId = ?", [$post->id]); |
55
|
|
|
|
56
|
|
|
// Get text |
57
|
1 |
|
$post->markdown = $this->getMD($post->text); |
58
|
|
|
|
59
|
1 |
|
return $post; |
60
|
1 |
|
}, $posts); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* return question/answer, three attributes are set, comments connected to them is an array. |
65
|
|
|
* |
66
|
|
|
* @return object |
67
|
|
|
*/ |
68
|
1 |
|
public function getPost($sql, $params) |
69
|
|
|
{ |
70
|
1 |
|
$post = $this->findWhere("$sql", $params); |
71
|
|
|
|
72
|
|
|
// Get e-mail for question |
73
|
1 |
|
$user = new User($this->db); |
74
|
1 |
|
$user->find("name", $post->user); |
75
|
1 |
|
$post->img = $this->gravatar($user->email); |
76
|
|
|
|
77
|
|
|
|
78
|
1 |
|
$comment = new Comment($this->db); |
79
|
|
|
// Start setting attributes |
80
|
1 |
|
$post->img = $this->gravatar($user->email); |
81
|
1 |
|
$post->markdown = $this->getMD($post->text); |
82
|
1 |
|
$post->comments = $comment->getComments("parentId = ?", [$post->id]); |
83
|
|
|
|
84
|
1 |
|
return $post; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Check if a post belongs to user |
89
|
|
|
* |
90
|
|
|
* |
91
|
|
|
* @return boolean |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function controlAuthority($name) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$user = new User(); |
96
|
|
|
$user->setDb($this->di->get("db")); |
97
|
|
|
$user->find("name", $name); |
98
|
|
|
|
99
|
|
|
// IF AUTHORITY == admin, then continue |
100
|
|
|
if ($user->authority != "admin") { |
101
|
|
|
return ($user->name == $this->user); |
102
|
|
|
} |
103
|
|
|
return true; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.