forked from PHPierrre/forum-mineweb
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathForum.php
125 lines (111 loc) · 4.48 KB
/
Forum.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
class Forum extends ForumAppModel
{
public function getForum($type = '', $id = false)
{
switch ($type) {
case 'id' :
return $this->find('first', ['conditions' => ['id' => $id]]);
break;
case 'forum' :
return $this->find('all', ['conditions' => ['id_parent' => 0], 'order' => ['position' => 'ASC']]);
break;
case 'withoutforum' :
return $this->find('all', ['conditions' => ['id_parent >' => 0], 'order' => ['position' => 'ASC']]);
break;
case 'categorie' :
return $this->find('all', ['conditions' => ['id_parent' => $id], 'order' => ['position' => 'ASC']]);
break;
default :
return $this->find('all', ['order' => ['position' => 'ASC']]);
}
}
public function userOnline($userModel, $limit = null)
{
$date = date('Y-m-d H:i:s', strtotime('-5 minutes'));
return $userModel->find('all', ['fields' => ['id', 'pseudo'], 'conditions' => ['forum-last_activity >' => $date], 'limit' => $limit]);
}
public function addForum($idUser, $name, $position, $image, $description)
{
$this->create();
$this->set(['id_user' => $idUser, 'id_parent' => 0, 'forum_name' => $name, 'position' => $position, 'forum_image' => $image, 'forum_description' => $description]);
return $this->save();
}
public function addCategory($idUser, $name, $position, $parent, $image, $lock, $automaticLock)
{
$this->create();
$this->set(['id_user' => $idUser, 'forum_name' => $name, 'position' => $position, 'id_parent' => $parent, 'forum_image' => $image, 'lock' => $lock, 'automatic_lock' => $automaticLock]);
return $this->save();
}
public function admin_delete($id)
{
return $this->delete($id);
}
//Get a information
public function info($type = false, $id = false, $name = false)
{
switch ($type) {
case 'forum' :
return $this->find('all', ['conditions' => ['id' => $id]]);
break;
case 'parent_title' :
return $this->find('first', ['conditions' => ['id' => $id]]);
break;
case 'parent_href' :
return $this->find('first', ['conditions' => ['id' => $id]]);
break;
case 'id_parent' :
return $this->find('first', ['conditions' => ['id' => $id]])['Forum']['id_parent'];
break;
}
}
public function update($type = false, $id = false, $datas = false)
{
if ($type == 'forum') {
return $this->updateAll(['forum_name' => "'".$datas['name']."'", 'position' => "'".$datas['position']."'", 'forum_image' => "'".$datas['image']."'", 'forum_description' => "'".$datas['forum_description']."'"], ['id' => $id]);;
} elseif ($type == 'category') {
return $this->updateAll(['forum_name' => "'".$datas['name']."'", 'id_parent' => "'".$datas['id_parent']."'", 'position' => $datas['position'], 'forum_image' => "'".$datas['forum_image']."'", 'lock' => $datas['lock'], 'automatic_lock' => $datas['automatic_lock']], ['id' => $id]);;
}
}
public function forumExist($id, $slug)
{
if($this->hasAny(['id' => $id, 'forum_name' => $slug])) return true;
}
public function getConfig()
{
$config = $this->find('first');
if(empty($config)) {
return true;
}
}
public function isLock($id)
{
return ($this->hasAny(['id' => $id, 'lock' => true])) ? true : false;
}
public function isAutoLock($id)
{
return $this->find('first', ['conditions' => ['id' => $id]])['Forum']['automatic_lock'];
}
public function updateVisible($id, $visible)
{
return $this->updateAll(['visible' => "'".$visible."'"], ['id' => $id]);
}
public function viewVisible($id)
{
return $this->find('first', ['conditions' => ['id' => $id]])['Forum']['visible'];
}
public function count($type)
{
switch ($type) {
case 'all':
return $this->find('count');
break;
case 'category':
return $this->find('count', ['conditions' => ['id_parent !=' => 0]]);
break;
case 'forum':
return $this->find('count', ['conditions' => ['id_parent' => 0]]);
break;
}
}
}