| 307 |
www |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Mapper;
|
|
|
6 |
|
|
|
7 |
use LeadersLinked\Model\ChatGroupUser;
|
|
|
8 |
use LeadersLinked\Mapper\Common\MapperCommon;
|
|
|
9 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
10 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
11 |
use Laminas\Db\Sql\Expression;
|
|
|
12 |
|
|
|
13 |
class ChatGroupUserMapper extends MapperCommon
|
|
|
14 |
{
|
|
|
15 |
const _TABLE = 'tbl_chat_group_users';
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
*
|
|
|
19 |
* @var ChatGroupUserMapper
|
|
|
20 |
*/
|
|
|
21 |
private static $_instance;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
*
|
|
|
25 |
* @param AdapterInterface $adapter
|
|
|
26 |
* @param int $user_id
|
|
|
27 |
*/
|
|
|
28 |
private function __construct($adapter)
|
|
|
29 |
{
|
|
|
30 |
parent::__construct($adapter);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @param AdapterInterface $adapter
|
|
|
36 |
* @return ChatGroupUserMapper
|
|
|
37 |
*/
|
|
|
38 |
public static function getInstance($adapter)
|
|
|
39 |
{
|
|
|
40 |
if(self::$_instance == null) {
|
|
|
41 |
self::$_instance = new ChatGroupUserMapper($adapter);
|
|
|
42 |
}
|
|
|
43 |
return self::$_instance;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @param int $user_id
|
|
|
49 |
* @return ChatGroupUser[]
|
|
|
50 |
*/
|
|
|
51 |
public function fetchAllByUserId($user_id)
|
|
|
52 |
{
|
|
|
53 |
$prototype = new ChatGroupUser();
|
|
|
54 |
|
|
|
55 |
$select = $this->sql->select(self::_TABLE);
|
|
|
56 |
$select->where->equalTo('user_id', $user_id);
|
|
|
57 |
|
|
|
58 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
*
|
|
|
63 |
* @param int $group_id
|
|
|
64 |
* @return ChatGroupUser[]
|
|
|
65 |
*/
|
|
|
66 |
public function fetchAllByGroupId($group_id)
|
|
|
67 |
{
|
|
|
68 |
$prototype = new ChatGroupUser();
|
|
|
69 |
|
|
|
70 |
$select = $this->sql->select(self::_TABLE);
|
|
|
71 |
$select->where->equalTo('group_id', $group_id);
|
|
|
72 |
|
|
|
73 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
74 |
|
|
|
75 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
*
|
|
|
82 |
* @param ChatGroupUser $chatGroupUser
|
|
|
83 |
* @return boolean
|
|
|
84 |
*/
|
|
|
85 |
public function insert($chatGroupUser)
|
|
|
86 |
{
|
|
|
87 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
88 |
$values = $hydrator->extract($chatGroupUser);
|
|
|
89 |
$values = $this->removeEmpty($values);
|
|
|
90 |
|
|
|
91 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
92 |
$insert->values($values);
|
|
|
93 |
|
|
|
94 |
return $this->executeInsert($insert);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
*
|
|
|
100 |
* @param int $group_id
|
|
|
101 |
* @return boolean
|
|
|
102 |
*/
|
|
|
103 |
public function deleteAllByGroupId($group_id)
|
|
|
104 |
{
|
|
|
105 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
106 |
$delete->where->equalTo('group_id', $group_id);
|
|
|
107 |
|
|
|
108 |
//echo $delete->getSqlString($this->adapter->platform); exit;
|
|
|
109 |
|
|
|
110 |
return $this->executeDelete($delete);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
*
|
|
|
115 |
* @param int $group_id
|
|
|
116 |
* @param int $user_id
|
|
|
117 |
* @return boolean
|
|
|
118 |
*/
|
|
|
119 |
public function deleteByGroupIdAndUserId($group_id, $user_id)
|
|
|
120 |
{
|
|
|
121 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
122 |
$delete->where->equalTo('user_id', $user_id)->and->equalTo('group_id', $group_id);
|
|
|
123 |
|
|
|
124 |
return $this->executeDelete($delete);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
*
|
|
|
129 |
* @param int $group_id
|
|
|
130 |
* @return int
|
|
|
131 |
*/
|
|
|
132 |
public function getCountByGroupId($group_id)
|
|
|
133 |
{
|
|
|
134 |
$select = $this->sql->select(self::_TABLE);
|
|
|
135 |
$select->columns(['total' => new Expression('COUNT(*)')]);
|
|
|
136 |
$select->where->equalTo('group_id', $group_id);
|
|
|
137 |
|
|
|
138 |
$record = $this->executeFetchOneArray($select);
|
|
|
139 |
return $record['total'];
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
/**
|
|
|
144 |
*
|
|
|
145 |
* @param int $group_id
|
|
|
146 |
* @param int $user_id
|
|
|
147 |
* @return ChatGroupUser
|
|
|
148 |
*/
|
|
|
149 |
public function fetchOneByGroupIdAndUserId($group_id, $user_id)
|
|
|
150 |
{
|
|
|
151 |
$prototype = new ChatGroupUser();
|
|
|
152 |
$select = $this->sql->select(self::_TABLE);
|
|
|
153 |
$select->where->equalTo('user_id', $user_id)->and->equalTo('group_id', $group_id);
|
|
|
154 |
$select->limit(1);
|
|
|
155 |
|
|
|
156 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
/**
|
|
|
160 |
*
|
|
|
161 |
* @param int $group_id
|
|
|
162 |
* @return ChatGroupUser
|
|
|
163 |
*/
|
|
|
164 |
public function fetchOwnerByGroupId($group_id)
|
|
|
165 |
{
|
|
|
166 |
$prototype = new ChatGroupUser();
|
|
|
167 |
$select = $this->sql->select(self::_TABLE);
|
|
|
168 |
$select->where->equalTo('owner', ChatGroupUser::OWNER_YES)->and->equalTo('group_id', $group_id);
|
|
|
169 |
$select->limit(1);
|
|
|
170 |
|
|
|
171 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public function updateHptg($form)
|
|
|
175 |
{
|
|
|
176 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
177 |
$values = $hydrator->extract($form);
|
|
|
178 |
$values = $this->removeEmpty($values);
|
|
|
179 |
|
|
|
180 |
$update = $this->sql->update(self::_TABLE);
|
|
|
181 |
$update->set($values);
|
|
|
182 |
$update->where->equalTo('group_id', $form->group_id)->and->equalTo('user_id', $form->user_id);
|
|
|
183 |
|
|
|
184 |
return $this->executeUpdate($update);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
/**
|
|
|
189 |
*
|
|
|
190 |
* @param int $group_id
|
|
|
191 |
* @param int $user_id
|
|
|
192 |
* @return boolean
|
|
|
193 |
*/
|
|
|
194 |
public function markIsOpen($group_id, $user_id)
|
|
|
195 |
{
|
|
|
196 |
$update = $this->sql->update(self::_TABLE);
|
|
|
197 |
$update->set(['open' => ChatGroupUser::OPEN_YES]);
|
|
|
198 |
$update->where->equalTo('group_id', $group_id)->and->equalTo('user_id', $user_id);
|
|
|
199 |
|
|
|
200 |
return $this->executeUpdate($update);
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
/**
|
|
|
206 |
*
|
|
|
207 |
* @param int $group_id
|
|
|
208 |
* @param int $user_id
|
|
|
209 |
* @return boolean
|
|
|
210 |
*/
|
|
|
211 |
public function markIsClose($group_id, $user_id)
|
|
|
212 |
{
|
|
|
213 |
$update = $this->sql->update(self::_TABLE);
|
|
|
214 |
$update->set(['open' => ChatGroupUser::OPEN_NO]);
|
|
|
215 |
$update->where->equalTo('group_id', $group_id)->and->equalTo('user_id', $user_id);
|
|
|
216 |
|
|
|
217 |
return $this->executeUpdate($update);
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
}
|