Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5561 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4235 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Model\DiscoveryContact;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
 
15
 
16
class DiscoveryContactMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_discovery_contacts';
19
 
20
    /**
21
     *
22
     * @var DiscoveryContactMapper
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
     * @return DiscoveryContactMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new DiscoveryContactMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return DiscoveryContact
52
     */
53
    public function fetchOne($id)
54
    {
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        $prototype = new DiscoveryContact();
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
 
64
    /**
65
     *
66
     * @param String $uuid
67
     * @return DiscoveryContact
68
     */
69
    public function fetchOneByUuid($uuid)
70
    {
71
 
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('uuid', $uuid);
74
 
75
        $prototype = new DiscoveryContact();
76
        return $this->executeFetchOneObject($select, $prototype);
77
    }
78
 
79
 
80
    /**
81
     *
5561 efrain 82
     * @param String $uuid
83
     * @return DiscoveryContact
84
     */
85
    public function fetchOneByCorporateEmail($corporate_email)
86
    {
87
 
88
        $select = $this->sql->select(self::_TABLE);
89
        $select->where->equalTo('corporate_email', $corporate_email);
90
 
91
        $prototype = new DiscoveryContact();
92
        return $this->executeFetchOneObject($select, $prototype);
93
    }
94
 
95
 
6330 efrain 96
    /**
97
     *
98
     * @param  int $company_id
99
     * @return DiscoveryContact[]
100
     */
101
    public function fetchAllByCompanyId($company_id)
102
    {
103
 
104
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('company_id', $company_id);
106
 
107
        $prototype = new DiscoveryContact();
108
        return $this->executeFetchAllObject($select, $prototype);
109
    }
5561 efrain 110
 
111
 
6330 efrain 112
 
113
 
114
 
5561 efrain 115
    /**
116
     *
4235 efrain 117
     * @param string $search
118
     * @param int $company_id
119
     * @param int $page
120
     * @param int $records_per_page
121
     * @param string $order_field
122
     * @param string $order_direction
123
     * @return Paginator
124
     */
125
    public function fetchAllDataTableForCompanyId($search, $company_id,  $page = 1, $records_per_page = 10, $order_field= 'last_name', $order_direction = 'ASC')
126
    {
127
        $prototype = new DiscoveryContact();
128
        $select = $this->sql->select(self::_TABLE);
129
        $select->where->equalTo('company_id', $company_id);
130
 
5561 efrain 131
 
4235 efrain 132
        if($search) {
133
            $select->where->like('uuid', '%' . $search . '%')
134
            ->or->like('first_name', '%' . $search . '%')
135
            ->or->like('last_name', '%' . $search . '%')
136
            ->or->like('corporate_email', '%' . $search . '%')
137
            ->or->like('company', '%' . $search . '%')
138
            ->or->like('position', '%' . $search . '%')
139
            ->or->like('country', '%' . $search . '%');
140
        }
141
        $select->order($order_field . ' ' . $order_direction);
5561 efrain 142
 
4235 efrain 143
        $hydrator   = new ObjectPropertyHydrator();
144
        $resultset  = new HydratingResultSet($hydrator, $prototype);
145
 
146
        $adapter = new DbSelect($select, $this->sql, $resultset);
147
        $paginator = new Paginator($adapter);
148
        $paginator->setItemCountPerPage($records_per_page);
149
        $paginator->setCurrentPageNumber($page);
150
 
151
 
152
        return $paginator;
153
    }
154
 
155
 
156
    /**
157
     *
158
     * @param DiscoveryContact $record
159
     * @return boolean
160
     */
161
    public function insert($record)
162
    {
163
        $hydrator = new ObjectPropertyHydrator();
164
        $values = $hydrator->extract($record);
165
        $values = $this->removeEmpty($values);
166
 
167
        $insert = $this->sql->insert(self::_TABLE);
168
        $insert->values($values);
169
        $result = $this->executeInsert($insert);
170
 
171
        if($result) {
172
            $record->id = $this->lastInsertId;
173
        }
174
 
175
        return $result;
176
    }
177
 
178
 
179
    /**
180
     *
181
     * @param DiscoveryContact $record
182
     * @return boolean
183
     */
184
    public function update($record)
185
    {
186
        $hydrator = new ObjectPropertyHydrator();
187
        $values = $hydrator->extract($record);
188
        $values = $this->removeEmpty($values);
189
 
190
        $update = $this->sql->update(self::_TABLE);
191
        $update->set($values);
192
        $update->where->equalTo('id', $record->id);
193
 
194
        return $this->executeUpdate($update);
195
    }
196
 
197
 
198
 
199
    /**
200
     *
201
     * @param DiscoveryContact $record
202
     * @return boolean
203
     */
204
    public function delete($record)
205
    {
206
        $delete = $this->sql->delete(self::_TABLE);
207
        $delete->where->equalTo('id', $record->id);
208
 
209
        return $this->executeDelete($delete);
210
 
211
    }
212
 
213
 
214
}