1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: root |
5
|
|
|
* Date: 2017-09-27 |
6
|
|
|
* Time: 10:27 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Radchasay\Comment; |
10
|
|
|
|
11
|
|
|
use \Anax\Database\ActiveRecordModel; |
12
|
|
|
|
13
|
|
|
class Post extends ActiveRecordModel |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string $tableName name of the database table. |
18
|
|
|
*/ |
19
|
|
|
protected $tableName = "Posts"; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Columns in the table. |
23
|
|
|
* |
24
|
|
|
* @var integer $id primary key auto incremented. |
25
|
|
|
*/ |
26
|
|
|
public $id; |
27
|
|
|
public $posttitle; |
28
|
|
|
public $postname; |
29
|
|
|
public $posttext; |
30
|
|
|
|
31
|
1 |
|
public function getInformation($name) |
32
|
|
|
{ |
33
|
1 |
|
$res = $this->find("postname", $name); |
34
|
1 |
|
return $res; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getAllInformationWhere($name) |
38
|
|
|
{ |
39
|
|
|
$res = $this->findAllWhere("postname = ?", $name); |
40
|
|
|
return $res; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function checkId($id) |
44
|
|
|
{ |
45
|
|
|
$row = $this->find("id", $id); |
46
|
|
|
return !$row ? false : true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getPostInfo($params) |
50
|
|
|
{ |
51
|
|
|
$this->getNext(); |
52
|
|
|
$sql = "SELECT * FROM VPost WHERE postid = ?"; |
53
|
|
|
$res = $this->findAllSql($sql, $params); |
54
|
|
|
return $res; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getTags($params) |
58
|
|
|
{ |
59
|
|
|
$sql = "SELECT Category FROM VCategory WHERE postid = ?"; |
60
|
|
|
$res = $this->findAllSql($sql, $params); |
61
|
|
|
return $res; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function getAllPosts() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$sql = "SELECT * FROM VPost"; |
67
|
|
|
$res = $this->findAllSql($sql); |
68
|
|
|
$id = []; |
69
|
|
|
$newRes = []; |
70
|
|
|
foreach ($res as $r) { |
71
|
|
|
if (!in_array($r->postid, $id)) { |
72
|
|
|
array_push($id, $r->postid); |
73
|
|
|
array_push($newRes, $r); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
return $newRes; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getNext() |
80
|
|
|
{ |
81
|
|
|
return $this->next(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.