1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment\Modules; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A database driven model. |
7
|
|
|
*/ |
8
|
|
|
class Question extends ActiveRecordModelExtender |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string $tableName name of the database table. |
13
|
|
|
*/ |
14
|
|
|
protected $tableName = "ramverk1_questions"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Columns in the table. |
18
|
|
|
* |
19
|
|
|
* @var integer $id primary key auto incremented. |
20
|
|
|
*/ |
21
|
|
|
public $id; |
22
|
|
|
public $user; |
23
|
|
|
|
24
|
|
|
public $title; |
25
|
|
|
public $tags; |
26
|
|
|
|
27
|
|
|
public $created; |
28
|
|
|
public $status; # default is active |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns post with markdown and gravatar |
33
|
|
|
* @param string $sql |
34
|
|
|
* @param array $param |
|
|
|
|
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
2 |
|
public function getQuestions($sql = null, $params = null) |
39
|
|
|
{ |
40
|
2 |
|
if ($sql == null) { |
|
|
|
|
41
|
2 |
|
$questions = $this->findAll(); |
42
|
2 |
|
} |
43
|
2 |
|
if ($sql != null) { |
|
|
|
|
44
|
1 |
|
$questions = $this->findAllWhere($sql, $params); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
|
|
return array_map(function ($question) { |
48
|
|
|
// User email |
49
|
2 |
|
$user = new User($this->db); |
50
|
|
|
// Start setting attributes |
51
|
2 |
|
$question->img = $user->getGravatar($question->user); |
52
|
2 |
|
$question->title = $this->getMD($question->title); |
53
|
2 |
|
$question->tags = explode(',', $question->tags); |
54
|
|
|
|
55
|
2 |
|
return $question; |
56
|
2 |
|
}, $questions); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns one question with it's own question text and other answers |
61
|
|
|
* @param int $id |
62
|
|
|
* |
63
|
|
|
* @return object |
64
|
|
|
*/ |
65
|
2 |
|
public function getQuestion($id) |
66
|
|
|
{ |
67
|
2 |
|
$question = $this->find("id", $id); |
68
|
|
|
|
69
|
|
|
// Add attributes from Post class |
70
|
2 |
|
$post = new Post($this->db); |
71
|
|
|
|
72
|
2 |
|
$question->question = $post->getPost("questionId = ? AND type = ?", [$question->id, "question"]); |
73
|
2 |
|
$question->answers = $post->getAllPosts("questionId = ? AND type = ?", [$question->id, "answer"]); |
74
|
2 |
|
$question->answerCount = count($question->answers); |
75
|
|
|
|
76
|
|
|
// Start setting up own attributes |
77
|
2 |
|
$question->title = $this->getMD($question->title); |
78
|
2 |
|
$question->tags = explode(',', $question->tags); |
79
|
|
|
|
80
|
|
|
|
81
|
2 |
|
return $question; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns array of tags, keys are name, value is the integer of how many. |
86
|
|
|
* |
87
|
|
|
* @return array |
88
|
|
|
*/ |
89
|
1 |
|
public function getPopularTags() |
90
|
|
|
{ |
91
|
1 |
|
$question = $this->findAll(); |
92
|
|
|
|
93
|
1 |
|
$tagsMultiArray = array_map(function ($question) { |
94
|
1 |
|
return explode(',', $question->tags); |
95
|
1 |
|
}, $question); |
96
|
|
|
|
97
|
|
|
// Merge multi array, count values, sort high to low |
98
|
1 |
|
$tagArr = array_count_values(call_user_func_array("array_merge", $tagsMultiArray)); |
99
|
1 |
|
arsort($tagArr); |
100
|
1 |
|
return $tagArr; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.