Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2380 | 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
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use LeadersLinked\Model\CompanyUser;
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\Sql\Expression;
2085 nelberth 12
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
2086 nelberth 13
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
14
 
1 www 15
class CompanyUserMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_company_users';
18
 
19
 
20
    /**
21
     *
22
     * @var CompanyUserMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @param LoggerInterface $logger
39
     * @param int $user_id
40
     * @return \LeadersLinked\Mapper\CompanyUserMapper
41
     */
42
    public static function getInstance($adapter)
43
    {
44
        if(self::$_instance == null) {
45
            self::$_instance = new CompanyUserMapper($adapter);
46
        }
47
        return self::$_instance;
48
    }
49
 
50
    /**
51
     *
52
     * @param int $company_id
53
     * @return CompanyUser[]
54
     */
55
    public function fetchAllByCompanyId($company_id)
56
    {
57
        $prototype = new CompanyUser();
58
        $select = $this->sql->select(self::_TABLE);
59
        $select->where->equalTo('company_id', $company_id);
60
 
61
        return $this->executeFetchAllObject($select, $prototype);
62
    }
2380 nelberth 63
 
64
    /**
65
     *
66
     * @param int $company_id
67
     * @return CompanyUser[]
68
     */
69
    public function fetchAllByCompanyIdAndNotUserId($company_id,$user_id)
70
    {
71
        $prototype = new CompanyUser();
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('company_id', $company_id);
74
        $select->where->notEqualTo('user_id', $user_id);
75
        $select->where->equalTo('owner', CompanyUser::OWNER_NO);
76
        return $this->executeFetchAllObject($select, $prototype);
77
    }
1 www 78
 
79
    /**
80
     *
81
     * @param int $company_id
82
     * @return CompanyUser[]
83
     */
84
    public function fetchAllByUserId($user_id)
85
    {
86
        $prototype = new CompanyUser();
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('user_id', $user_id);
89
 
90
        return $this->executeFetchAllObject($select, $prototype);
91
    }
92
 
93
    /**
94
     *
95
     * @param int $id
96
     * @return CompanyUser
97
     */
98
    public function fetchOne($id)
99
    {
100
        $prototype = new CompanyUser();
101
        $select = $this->sql->select(self::_TABLE);
102
        $select->where->equalTo('id', $id);
103
 
104
        return $this->executeFetchOneObject($select, $prototype);
105
    }
106
 
107
    /**
108
     *
109
     * @param int $company_id
110
     * @return CompanyUser
111
     */
112
    public function fetchOwnerByCompanyId($company_id)
113
    {
114
        $prototype = new CompanyUser();
115
        $select = $this->sql->select(self::_TABLE);
116
        $select->where->equalTo('company_id', $company_id);
117
        $select->where->equalTo('owner', CompanyUser::OWNER_YES);
118
 
119
        return $this->executeFetchOneObject($select, $prototype);
120
    }
121
 
122
    /**
123
     *
124
     * @param int $company_id
125
     * @return CompanyUser
126
     */
127
    public function fetchCreatorByCompanyId($company_id)
128
    {
129
        $prototype = new CompanyUser();
130
        $select = $this->sql->select(self::_TABLE);
131
        $select->where->equalTo('company_id', $company_id);
132
        $select->where->equalTo('creator', CompanyUser::CREATOR_YES);
133
 
134
        return $this->executeFetchOneObject($select, $prototype);
135
    }
136
 
137
    /**
138
     *
139
     * @param int $company_id
140
     * @param int $user_id
141
     * @return CompanyUser
142
     */
143
    public function fetchOneByCompanyIdAndUserId($company_id, $user_id)
144
    {
145
        $prototype = new CompanyUser();
146
        $select = $this->sql->select(self::_TABLE);
147
        $select->where->equalTo('company_id', $company_id);
148
        $select->where->equalTo('user_id', $user_id);
149
 
150
       // echo $select->getSqlString($this->adapter->platform); exit;
151
 
152
        return $this->executeFetchOneObject($select, $prototype);
153
    }
154
 
5205 efrain 155
    /**
156
     *
157
     * @param int $company_id
158
     * @param int $user_id
159
     * @return CompanyUser
160
     */
161
    public function fetchOneAcceptedByCompanyIdAndUserId($company_id, $user_id)
162
    {
163
        $prototype = new CompanyUser();
164
        $select = $this->sql->select(self::_TABLE);
165
        $select->where->equalTo('company_id', $company_id);
166
        $select->where->equalTo('user_id', $user_id);
167
        $select->where->equalTo('status', CompanyUser::STATUS_ACCEPTED);
168
 
169
        // echo $select->getSqlString($this->adapter->platform); exit;
170
 
171
        return $this->executeFetchOneObject($select, $prototype);
172
    }
1 www 173
 
5205 efrain 174
 
1 www 175
    /**
176
     *
177
     * @param int $company_id
178
     * @param int $user_id
179
     * @return int
180
     */
181
    public function fetchCountOtherCompaniesByCompanyIdAndUserId($company_id, $user_id)
182
    {
183
        $prototype = new CompanyUser();
184
        $select = $this->sql->select();
185
        $select->columns(['total' => new Expression('COUNT(*)') ]);
186
        $select->from(self::_TABLE);
187
        $select->where->notEqualTo('company_id', $company_id);
188
        $select->where->equalTo('user_id', $user_id);
189
 
190
        $record = $this->executeFetchOneArray($select);
191
 
192
        return $record['total'];
193
    }
194
 
195
    /**
196
     *
197
     * @param CompanyUser $companyUser
198
     * @return boolean
199
     */
200
    public function insert($companyUser)
201
    {
202
        $hydrator = new ObjectPropertyHydrator();
203
        $values = $hydrator->extract($companyUser);
204
        $values = $this->removeEmpty($values);
205
 
206
 
207
        $insert = $this->sql->insert(self::_TABLE);
208
        $insert->values($values);
209
 
210
        $result = $this->executeInsert($insert);
211
        if($result) {
212
            $companyUser->id = $this->lastInsertId;
213
        }
214
 
215
        return $result;
216
    }
217
 
218
    /**
219
     *
220
     * @param CompanyUser $companyUser
221
     * @return boolean
222
     */
223
    public function update($companyUser)
224
    {
225
        $hydrator = new ObjectPropertyHydrator();
226
        $values = $hydrator->extract($companyUser);
227
        $values = $this->removeEmpty($values);
228
 
229
        $update = $this->sql->update(self::_TABLE);
230
        $update->set($values);
231
        $update->where->equalTo('id', $companyUser->id);
232
 
233
        return $this->executeUpdate($update);
234
    }
235
 
236
    /**
237
     *
238
     * @param int $id
239
     * @return boolean
240
     */
241
    public function delete($id)
242
    {
243
        $delete = $this->sql->select(self::_TABLE);
244
        $delete->where->equalTo('id', $id);
245
 
246
        return $this->executeDelete($delete);
247
    }
248
 
249
 
2093 nelberth 250
 
1 www 251
}