Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 2962 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\Notification;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\Db\Sql\Expression;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
 
14
class NotificationMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_notifications';
17
 
18
    /**
19
     *
20
     * @var NotificationMapper
21
     */
22
    private static $_instance;
23
 
24
    /**
25
     *
26
     * @param AdapterInterface $adapter
27
     */
28
    private function __construct($adapter)
29
    {
30
        parent::__construct($adapter);
31
    }
32
 
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return NotificationMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new NotificationMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $user_id
50
     * @return int
51
     */
52
    public function fetchUnreadNotificationsCount($user_id)
53
    {
54
        $select = $this->sql->select(self::_TABLE);
55
        $select->columns(['total' => new Expression('COUNT(*)')]);
56
        $select->where->equalTo('user_id', $user_id)->and->equalTo('read', Notification::NO);
57
 
58
        //echo $select->getSqlString($this->adapter->platform);
59
 
60
        $record = $this->executeFetchOneArray($select);
61
        return $record['total'];
62
    }
63
 
64
    /**
65
     *
66
     * @param int $user_id
67
     * @return Notification[]
68
     */
69
    public function fetchAllsUnreadByUserId($user_id)
70
    {
71
        $prototype = new Notification();
72
 
73
        $select = $this->sql->select(self::_TABLE);
74
        $select->where->equalTo('user_id', $user_id)->and->equalTo('read', Notification::NO);
75
 
76
        return $this->executeFetchAllObject($select, $prototype);
77
    }
2957 kerby 78
 
79
    /**
80
     *
81
     * @param int $user_id
82
     * @return Notification[]
83
     */
84
    public function fetchAllsReadByUserId($user_id)
85
    {
86
        $prototype = new Notification();
87
 
88
        $select = $this->sql->select(self::_TABLE);
89
        $select->where->equalTo('user_id', $user_id);
90
 
91
        return $this->executeFetchAllObject($select, $prototype);
92
    }
1 www 93
 
94
    /**
95
     *
96
     * @param int $user_id
97
     * @return boolean
98
     */
99
    public function markAllNotificationsAsReadByUserId($user_id)
100
    {
101
        $update = $this->sql->update(self::_TABLE);
102
        $update->set(['read' => Notification::YES]);
103
        $update->where->equalTo('user_id', $user_id);
104
        $update->where->equalTo('read',  Notification::NO);
105
 
106
        return $this->executeUpdate($update);
107
    }
108
 
109
 
110
    /**
111
     *
112
     * @param int $user_id
113
     * @param int $company_id
114
     * @return boolean
115
     */
116
    public function markAllNotificationsAsReadByUserIdAndCompanyId($user_id, $company_id)
117
    {
118
        $update = $this->sql->update(self::_TABLE);
119
        $update->set(['read' => Notification::YES]);
120
        $update->where->equalTo('user_id', $user_id);
121
        $update->where->equalTo('company_id', $company_id);
122
        $update->where->equalTo('read',  Notification::NO);
123
 
124
        return $this->executeUpdate($update);
125
    }
126
 
127
    /**
128
     *
129
     * @param int $user_id
130
     * @param int $group_id
131
     * @return boolean
132
     */
133
    public function markAllNotificationsAsReadByUserIdAndGroupId($user_id, $group_id)
134
    {
135
        $update = $this->sql->update(self::_TABLE);
136
        $update->set(['read' => Notification::YES]);
137
        $update->where->equalTo('user_id', $user_id);
138
        $update->where->equalTo('group_id', $group_id);
139
        $update->where->equalTo('read',  Notification::NO);
140
 
141
        return $this->executeUpdate($update);
142
    }
143
 
144
 
145
    /**
146
     *
147
     * @param int $user_id
148
     * @param int $feed_id
149
     * @return boolean
150
     */
151
    public function markAllNotificationsAsReadByUserIdAndFeedId($user_id, $feed_id)
152
    {
153
        $update = $this->sql->update(self::_TABLE);
154
        $update->set(['read' => Notification::YES]);
155
        $update->where->equalTo('user_id', $user_id);
156
        $update->where->equalTo('feed_id', $feed_id);
157
        $update->where->equalTo('read',  Notification::NO);
158
 
159
        return $this->executeUpdate($update);
160
    }
161
 
162
    /**
163
     *
164
     * @param string $type
165
     * @param int $user_id
166
     * @return boolean
167
     */
168
    public function markAllNotificationsAsReadByTypeAndUserId($type, $user_id)
169
    {
170
        $update = $this->sql->update(self::_TABLE);
171
        $update->where->equalTo('type', $type);
172
        $update->where->equalTo('user_id', $user_id);
173
        $update->where->equalTo('read',  Notification::NO);
174
 
175
        return $this->executeUpdate($update);
176
    }
177
 
178
    /**
179
     *
180
     * @param string $type
181
     * @param int $user_id
182
     * @param int $company_id
183
     * @return boolean
184
     */
185
    public function markAllNotificationsAsReadByTypeAndUserIdAndCompanyId($type, $user_id, $company_id)
186
    {
187
        $update = $this->sql->update(self::_TABLE);
188
        $update->where->equalTo('type', $type);
189
        $update->where->equalTo('user_id', $user_id);
190
        $update->where->equalTo('company_id', $company_id);
191
        $update->where->equalTo('read',  Notification::NO);
192
 
193
        return $this->executeUpdate($update);
194
    }
195
 
196
    /**
197
     *
198
     * @param string $type
199
     * @param int $user_id
200
     * @param int $group_id
201
     * @return boolean
202
     */
203
    public function markAllNotificationsAsReadByTypeAndUserIdAndGroupId($type, $user_id, $group_id)
204
    {
205
        $update = $this->sql->update(self::_TABLE);
206
        $update->where->equalTo('type', $type);
207
        $update->where->equalTo('user_id', $user_id);
208
        $update->where->equalTo('group_id', $group_id);
209
        $update->where->equalTo('read',  Notification::NO);
210
 
211
        return $this->executeUpdate($update);
212
    }
213
 
214
    /**
215
     *
216
     * @param string $type
217
     * @param int $user_id
218
     * @param int $feed_id
219
     * @return boolean
220
     */
221
    public function markAllNotificationsAsReadByTypeAndUserIdAndFeedId($type, $user_id, $feed_id)
222
    {
223
        $update = $this->sql->update(self::_TABLE);
224
        $update->where->equalTo('type', $type);
225
        $update->where->equalTo('user_id', $user_id);
226
        $update->where->equalTo('feed_id', $feed_id);
227
        $update->where->equalTo('read',  Notification::NO);
228
 
229
        return $this->executeUpdate($update);
230
    }
231
 
232
 
233
 
234
    /**
235
     *
236
     * @param Notification $notification
237
     * @return boolean
238
     */
239
    public function insert($notification)
240
    {
241
        $hydrator = new ObjectPropertyHydrator();
242
        $values = $hydrator->extract($notification);
243
        $values = $this->removeEmpty($values);
244
 
245
        $insert = $this->sql->insert(self::_TABLE);
246
        $insert->values($values);
247
 
248
        $result = $this->executeInsert($insert);
249
        if($result) {
250
            $notification->id = $this->getLastInsertId();
251
        }
252
 
253
        return $result;
254
 
255
    }
256
 
257
 
258
 
259
 
260
 
261
}