Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2093 | Rev 5205 | 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
 
155
 
156
    /**
157
     *
158
     * @param int $company_id
159
     * @param int $user_id
160
     * @return int
161
     */
162
    public function fetchCountOtherCompaniesByCompanyIdAndUserId($company_id, $user_id)
163
    {
164
        $prototype = new CompanyUser();
165
        $select = $this->sql->select();
166
        $select->columns(['total' => new Expression('COUNT(*)') ]);
167
        $select->from(self::_TABLE);
168
        $select->where->notEqualTo('company_id', $company_id);
169
        $select->where->equalTo('user_id', $user_id);
170
 
171
        $record = $this->executeFetchOneArray($select);
172
 
173
        return $record['total'];
174
    }
175
 
176
    /**
177
     *
178
     * @param CompanyUser $companyUser
179
     * @return boolean
180
     */
181
    public function insert($companyUser)
182
    {
183
        $hydrator = new ObjectPropertyHydrator();
184
        $values = $hydrator->extract($companyUser);
185
        $values = $this->removeEmpty($values);
186
 
187
 
188
        $insert = $this->sql->insert(self::_TABLE);
189
        $insert->values($values);
190
 
191
        $result = $this->executeInsert($insert);
192
        if($result) {
193
            $companyUser->id = $this->lastInsertId;
194
        }
195
 
196
        return $result;
197
    }
198
 
199
    /**
200
     *
201
     * @param CompanyUser $companyUser
202
     * @return boolean
203
     */
204
    public function update($companyUser)
205
    {
206
        $hydrator = new ObjectPropertyHydrator();
207
        $values = $hydrator->extract($companyUser);
208
        $values = $this->removeEmpty($values);
209
 
210
        $update = $this->sql->update(self::_TABLE);
211
        $update->set($values);
212
        $update->where->equalTo('id', $companyUser->id);
213
 
214
        return $this->executeUpdate($update);
215
    }
216
 
217
    /**
218
     *
219
     * @param int $id
220
     * @return boolean
221
     */
222
    public function delete($id)
223
    {
224
        $delete = $this->sql->select(self::_TABLE);
225
        $delete->where->equalTo('id', $id);
226
 
227
        return $this->executeDelete($delete);
228
    }
229
 
230
 
2093 nelberth 231
 
1 www 232
}