Proyectos de Subversion LeadersLinked - Services

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\ChatGroupMessage;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Db\ResultSet\HydratingResultSet;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
use Laminas\Log\LoggerInterface;
15
use LeadersLinked\Model\ChatGroup;
16
 
17
class ChatGroupMessageMapper extends MapperCommon
18
{
19
    const _TABLE = 'tbl_chat_group_messages';
20
 
21
    /**
22
     *
23
     * @var ChatGroupMessageMapper
24
     */
25
    private static $_instance;
26
 
27
    /**
28
     *
29
     * @param AdapterInterface $adapter
30
     * @param int $user_id
31
     */
32
    private function __construct($adapter)
33
    {
34
        parent::__construct($adapter);
35
    }
36
 
37
    /**
38
     *
39
     * @param AdapterInterface $adapter
40
     * @return ChatGroupMessageMapper
41
     */
42
    public static function getInstance($adapter)
43
    {
44
        if(self::$_instance == null) {
45
            self::$_instance = new ChatGroupMessageMapper($adapter);
46
        }
47
        return self::$_instance;
48
    }
49
 
50
    /**
51
     *
52
     * @param int[] $message_ids
53
     * @return ChatGroupMessage[]
54
     */
55
    public function fetchAllByMessagesIds($message_ids)
56
    {
57
        $prototype = new ChatGroupMessage();
58
 
59
        $select = $this->sql->select(self::_TABLE);
60
        $select->where->in('id', $message_ids);
61
        $select->order('id ASC');
62
 
63
        return $this->executeFetchAllObject($select, $prototype);
64
    }
65
 
66
    /**
67
     *
68
     * @param array $message_ids
69
     * @param string $group_id
70
     * @return ChatGroupMessage[]
71
     */
72
    public function fetchAllByMessagesIdsAndGroupId($message_ids, $group_id)
73
    {
74
        $prototype = new ChatGroupMessage();
75
 
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->where->in('id', $message_ids)->and->equalTo('group_id', $group_id);
78
        $select->order('id ASC');
79
 
80
        return $this->executeFetchAllObject($select, $prototype);
81
    }
82
 
83
    /**
84
     *
85
     * @param int $id
86
     * @return ChatGroupMessage
87
     */
88
    public function fetchOne($id)
89
    {
90
        $prototype = new ChatGroupMessage();
91
 
92
        $select = $this->sql->select(self::_TABLE);
93
        $select->where->equalTo('id', $id);
94
 
95
        return $this->executeFetchOneObject($select, $prototype);
96
    }
97
 
98
 
99
    /**
100
     *
192 efrain 101
     * @param string $uuid
102
     * @return ChatGroupMessage
103
     */
104
    public function fetchOneByUuid($uuid)
105
    {
106
        $prototype = new ChatGroupMessage();
107
 
108
        $select = $this->sql->select(self::_TABLE);
109
        $select->where->equalTo('uuid', $uuid);
110
 
111
        return $this->executeFetchOneObject($select, $prototype);
112
    }
113
 
114
    /**
115
     *
1 efrain 116
     * @param int $id
117
     * @return ChatGroupMessage[]
118
     */
119
    public function fetchAllByGroupId($group_id)
120
    {
121
        $prototype = new ChatGroupMessage();
122
 
123
        $select = $this->sql->select(self::_TABLE);
124
        $select->where->equalTo('group_id', $group_id);
125
        $select->order('ASC');
126
 
127
        return $this->executeFetchAllObject($select, $prototype);
128
    }
129
 
130
    /**
131
     *
132
     * @param array $message_ids
133
     * @param string $group_id
134
     * @param int $page
135
     * @param int $records_per_page
136
     * @return Paginator
137
     */
138
    public function getAllMessagesPaginatorByMessagesIdsAndGroupId($message_ids, $group_id, $page = 1, $records_per_page = 10)
139
    {
140
        $prototype = new ChatGroupMessage();
141
 
142
        $select = $this->sql->select(self::_TABLE);
143
        $select->where->in('id', $message_ids)->and->equalTo('group_id', $group_id);
144
        $select->order('id DESC');
145
 
146
 
147
 
148
        $hydrator   = new ObjectPropertyHydrator();
149
        $resultset  = new HydratingResultSet($hydrator, $prototype);
150
 
151
        $adapter    = new DbSelect($select, $this->sql, $resultset);
152
        $paginator  = new Paginator($adapter);
153
        $paginator->setCurrentPageNumber($page);
154
        $paginator->setItemCountPerPage($records_per_page);
155
 
156
        return $paginator;
157
    }
158
 
159
    /**
160
     *
161
     * @param array $message_ids
162
     * @param string $group_id
163
     * @param int $page
164
     * @param int $records_per_page
165
     * @return Paginator
166
     */
167
    public function getPaginatorByGroupId($group_id, $page = 1, $records_per_page = 10)
168
    {
169
        $prototype = new ChatGroupMessage();
170
 
171
        $select = $this->sql->select(self::_TABLE);
172
        $select->where->equalTo('group_id', $group_id);
173
        $select->order('id DESC');
174
 
175
 
176
 
177
        $hydrator   = new ObjectPropertyHydrator();
178
        $resultset  = new HydratingResultSet($hydrator, $prototype);
179
 
180
        $adapter    = new DbSelect($select, $this->sql, $resultset);
181
        $paginator  = new Paginator($adapter);
182
        $paginator->setCurrentPageNumber($page);
183
        $paginator->setItemCountPerPage($records_per_page);
184
 
185
        return $paginator;
186
    }
187
 
188
    /**
189
     *
190
     * @param ChatGroupMessage $chatGroupMessage
191
     * @return boolean
192
     */
193
    public function insert($chatGroupMessage)
194
    {
195
 
196
        $hydrator = new ObjectPropertyHydrator();
197
        $values = $hydrator->extract($chatGroupMessage);
198
        $values = $this->removeEmpty($values);
199
 
200
        $insert = $this->sql->insert(self::_TABLE);
201
        $insert->values($values);
202
 
203
        $result =  $this->executeInsert($insert);
204
        if($result) {
205
            $chatGroupMessage->id = $this->lastInsertId;
206
        }
207
 
208
 
209
        //echo $insert->getSqlString($this->adapter->getPlatform()); exit;
210
 
211
        return $result;
212
    }
213
 
214
    /**
215
     *
216
     * @param int[] $message_ids
217
     * @return boolean
218
     */
219
    public function deleteAllByMessageIds($message_ids)
220
    {
221
        $delete = $this->sql->delete(self::_TABLE);
222
        $delete->where->in('id', $message_ids);
223
 
224
        return $this->executeDelete($delete);
225
    }
226
 
227
    /**
228
     *
229
     * @param string $group_id
230
     * @return boolean
231
     */
232
    public function deleteAllByGroupId($group_id)
233
    {
234
        $delete = $this->sql->delete(self::_TABLE);
235
        $delete->where->equalTo('group_id', $group_id);
236
 
237
        //echo $delete->getSqlString($this->adapter->platform); exit;
238
 
239
        return $this->executeDelete($delete);
240
    }
241
 
242
}