Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3099 | Rev 5319 | 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
    /**
1 www 114
     *
115
     * @param ChatUser $chatUser
116
     * @return boolean
117
     */
118
    public function insert($chatUser)
119
    {
120
        $hydrator = new ObjectPropertyHydrator();
121
        $values = $hydrator->extract($chatUser);
122
        $values = $this->removeEmpty($values);
123
 
124
        $insert = $this->sql->insert(self::_TABLE);
125
        $insert->values($values);
126
        //echo $insert->getSqlString($this->adapter->platform); exit;
127
 
128
 
129
        $result =  $this->executeInsert($insert);
130
 
131
        if($result) {
132
            $chatUser->id = $this->lastInsertId;
133
        }
134
 
135
 
136
        return $result;
137
    }
3099 efrain 138
 
139
    /**
140
     *
141
     * @param int $id
142
     * @return boolean
143
     */
144
    public function markIsOpen1($id)
145
    {
146
        $update = $this->sql->update(self::_TABLE);
147
        $update->set(['user_open1' => ChatUser::OPEN_YES]);
148
        $update->where->equalTo('id', $id);
149
 
150
        return $this->executeUpdate($update);
151
    }
152
 
153
 
154
    /**
155
     *
156
     * @param int $id
157
     * @return boolean
158
     */
159
    public function markIsOpen2($id)
160
    {
161
        $update = $this->sql->update(self::_TABLE);
162
        $update->set(['user_open2' => ChatUser::OPEN_YES]);
163
        $update->where->equalTo('id', $id);
164
 
165
        return $this->executeUpdate($update);
166
    }
167
 
168
    /**
169
     *
170
     * @param int $id
171
     * @return boolean
172
     */
173
    public function markIsClose1($id)
174
    {
175
        $update = $this->sql->update(self::_TABLE);
176
        $update->set(['user_open1' => ChatUser::OPEN_NO]);
177
        $update->where->equalTo('id', $id);
178
 
179
        return $this->executeUpdate($update);
180
    }
181
 
182
 
183
    /**
184
     *
185
     * @param int $id
186
     * @return boolean
187
     */
188
    public function markIsClose2($id)
189
    {
190
        $update = $this->sql->update(self::_TABLE);
191
        $update->set(['user_open2' => ChatUser::OPEN_NO]);
192
        $update->where->equalTo('id', $id);
193
 
194
        return $this->executeUpdate($update);
195
    }
196
 
197
 
1 www 198
}