Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4131 | 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
 
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use LeadersLinked\Model\ChatUser;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
 
14
class ChatUserMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_chat_users';
17
 
18
    /**
19
     *
20
     * @var ChatUserMapper
21
     */
22
    private static $_instance;
23
 
24
    /**
25
     *
26
     * @param AdapterInterface $adapter
27
     * @param int $user_id
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return ChatUserMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new ChatUserMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return ChatUser
51
     */
52
    public function fetchOne($id)
53
    {
54
        $select = $this->sql->select(self::_TABLE);
55
        $select->where->equalTo('id', $id);
56
 
57
        $prototype = new ChatUser();
58
        return $this->executeFetchOneObject($select, $prototype);
59
    }
60
 
61
    /**
62
     *
63
     * @param string $uuid
64
     * @return ChatUser
65
     */
66
    public function fetchOneByUuid($uuid)
67
    {
68
        $prototype = new ChatUser();
69
        $select = $this->sql->select(self::_TABLE);
70
        $select->where->equalTo('uuid', $uuid);
71
        $select->limit(1);
72
        return $this->executeFetchOneObject($select, $prototype);
73
    }
74
 
75
 
76
    /**
77
     *
78
     * @param int $user1
79
     * @param int $user2
80
     * @return ChatUser
81
     */
82
    public function fetchOneByUserId1AndUserId2($user1, $user2)
83
    {
84
        $select = $this->sql->select(self::_TABLE);
85
        $select->where->nest()->equalTo('user_id1', $user1)->and->equalTo('user_id2', $user2)->unnest()
86
            ->or->nest()->equalTo('user_id1', $user2)->and->equalTo('user_id2', $user1)->unnest();
87
 
88
          //echo $select->getSqlString($this->adapter->platform); exit;
89
 
90
        $prototype = new ChatUser();
91
        return $this->executeFetchOneObject($select, $prototype);
92
    }
93
 
94
 
95
    /**
4131 efrain 96
     *
97
     * @param int $user_id
98
 
99
     * @return ChatUser[]
100
     */
101
    public function fetchAllByUserId($user_id)
102
    {
103
        $select = $this->sql->select(self::_TABLE);
104
        $select->where->equalTo('user_id1', $user_id)->or->equalTo('user_id2', $user_id);
105
 
106
        //echo $select->getSqlString($this->adapter->platform); exit;
107
 
108
        $prototype = new ChatUser();
109
        return $this->executeFetchAllObject($select, $prototype);
110
    }
111
 
112
 
113
    /**
5319 efrain 114
     *
115
     * @param int $user_id
116
 
117
     * @return ChatUser[]
118
     */
119
    public function fetchAllByUserIdOnlyOpen($user_id)
120
    {
121
        $select = $this->sql->select(self::_TABLE);
122
        $select->where->nest()
123
            ->equalTo('user_id1', $user_id)
124
            ->and->equalTo('user_open1', ChatUser::OPEN_YES)
125
        ->unnest()->or->nest()
126
            ->equalTo('user_id2', $user_id)
127
            ->and->equalTo('user_open2', ChatUser::OPEN_YES)
128
        ->unnest();
129
 
130
        //echo $select->getSqlString($this->adapter->platform); exit;
131
 
132
        $prototype = new ChatUser();
133
        return $this->executeFetchAllObject($select, $prototype);
134
    }
135
 
136
 
137
    /**
1 www 138
     *
139
     * @param ChatUser $chatUser
140
     * @return boolean
141
     */
142
    public function insert($chatUser)
143
    {
144
        $hydrator = new ObjectPropertyHydrator();
145
        $values = $hydrator->extract($chatUser);
146
        $values = $this->removeEmpty($values);
147
 
148
        $insert = $this->sql->insert(self::_TABLE);
149
        $insert->values($values);
150
        //echo $insert->getSqlString($this->adapter->platform); exit;
151
 
152
 
153
        $result =  $this->executeInsert($insert);
154
 
155
        if($result) {
156
            $chatUser->id = $this->lastInsertId;
157
        }
158
 
159
 
160
        return $result;
161
    }
3099 efrain 162
 
163
    /**
164
     *
165
     * @param int $id
166
     * @return boolean
167
     */
168
    public function markIsOpen1($id)
169
    {
170
        $update = $this->sql->update(self::_TABLE);
171
        $update->set(['user_open1' => ChatUser::OPEN_YES]);
172
        $update->where->equalTo('id', $id);
173
 
174
        return $this->executeUpdate($update);
175
    }
176
 
177
 
178
    /**
179
     *
180
     * @param int $id
181
     * @return boolean
182
     */
183
    public function markIsOpen2($id)
184
    {
185
        $update = $this->sql->update(self::_TABLE);
186
        $update->set(['user_open2' => ChatUser::OPEN_YES]);
187
        $update->where->equalTo('id', $id);
188
 
189
        return $this->executeUpdate($update);
190
    }
191
 
192
    /**
193
     *
194
     * @param int $id
195
     * @return boolean
196
     */
197
    public function markIsClose1($id)
198
    {
199
        $update = $this->sql->update(self::_TABLE);
200
        $update->set(['user_open1' => ChatUser::OPEN_NO]);
201
        $update->where->equalTo('id', $id);
202
 
203
        return $this->executeUpdate($update);
204
    }
205
 
206
 
207
    /**
208
     *
209
     * @param int $id
210
     * @return boolean
211
     */
212
    public function markIsClose2($id)
213
    {
214
        $update = $this->sql->update(self::_TABLE);
215
        $update->set(['user_open2' => ChatUser::OPEN_NO]);
216
        $update->where->equalTo('id', $id);
217
 
218
        return $this->executeUpdate($update);
219
    }
220
 
221
 
1 www 222
}