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 = "Call VPost('true', ?, null, null, null)"; |
53
|
|
|
$res = $this->findAllSql($sql, $params); |
54
|
|
|
$this->getNext(); |
55
|
|
|
return $res; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getTags($params) |
59
|
|
|
{ |
60
|
|
|
$sql = "Call VCategory(?)"; |
61
|
|
|
$res = $this->findAllSql($sql, $params); |
62
|
|
|
$this->getNext(); |
63
|
|
|
return $res; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function getAllPosts() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$sql = "Call VPost(null, null, null, null, null)"; |
69
|
|
|
$res = $this->findAllSql($sql); |
70
|
|
|
$this->getNext(); |
71
|
|
|
$id = []; |
72
|
|
|
$newRes = []; |
73
|
|
|
foreach ($res as $r) { |
74
|
|
|
if (!in_array($r->postid, $id)) { |
75
|
|
|
array_push($id, $r->postid); |
76
|
|
|
array_push($newRes, $r); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
return $newRes; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getNext() |
83
|
|
|
{ |
84
|
|
|
return $this->next(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.