Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4235 | Ir a la última revisión | | 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
 
96
 
97
 
98
    /**
99
     *
4235 efrain 100
     * @param string $search
101
     * @param int $company_id
102
     * @param int $page
103
     * @param int $records_per_page
104
     * @param string $order_field
105
     * @param string $order_direction
106
     * @return Paginator
107
     */
108
    public function fetchAllDataTableForCompanyId($search, $company_id,  $page = 1, $records_per_page = 10, $order_field= 'last_name', $order_direction = 'ASC')
109
    {
110
        $prototype = new DiscoveryContact();
111
        $select = $this->sql->select(self::_TABLE);
112
        $select->where->equalTo('company_id', $company_id);
113
 
5561 efrain 114
 
4235 efrain 115
        if($search) {
116
            $select->where->like('uuid', '%' . $search . '%')
117
            ->or->like('first_name', '%' . $search . '%')
118
            ->or->like('last_name', '%' . $search . '%')
119
            ->or->like('corporate_email', '%' . $search . '%')
120
            ->or->like('company', '%' . $search . '%')
121
            ->or->like('position', '%' . $search . '%')
122
            ->or->like('country', '%' . $search . '%');
123
        }
124
        $select->order($order_field . ' ' . $order_direction);
5561 efrain 125
 
4235 efrain 126
        $hydrator   = new ObjectPropertyHydrator();
127
        $resultset  = new HydratingResultSet($hydrator, $prototype);
128
 
129
        $adapter = new DbSelect($select, $this->sql, $resultset);
130
        $paginator = new Paginator($adapter);
131
        $paginator->setItemCountPerPage($records_per_page);
132
        $paginator->setCurrentPageNumber($page);
133
 
134
 
135
        return $paginator;
136
    }
137
 
138
 
139
    /**
140
     *
141
     * @param DiscoveryContact $record
142
     * @return boolean
143
     */
144
    public function insert($record)
145
    {
146
        $hydrator = new ObjectPropertyHydrator();
147
        $values = $hydrator->extract($record);
148
        $values = $this->removeEmpty($values);
149
 
150
        $insert = $this->sql->insert(self::_TABLE);
151
        $insert->values($values);
152
        $result = $this->executeInsert($insert);
153
 
154
        if($result) {
155
            $record->id = $this->lastInsertId;
156
        }
157
 
158
        return $result;
159
    }
160
 
161
 
162
    /**
163
     *
164
     * @param DiscoveryContact $record
165
     * @return boolean
166
     */
167
    public function update($record)
168
    {
169
        $hydrator = new ObjectPropertyHydrator();
170
        $values = $hydrator->extract($record);
171
        $values = $this->removeEmpty($values);
172
 
173
        $update = $this->sql->update(self::_TABLE);
174
        $update->set($values);
175
        $update->where->equalTo('id', $record->id);
176
 
177
        return $this->executeUpdate($update);
178
    }
179
 
180
 
181
 
182
    /**
183
     *
184
     * @param DiscoveryContact $record
185
     * @return boolean
186
     */
187
    public function delete($record)
188
    {
189
        $delete = $this->sql->delete(self::_TABLE);
190
        $delete->where->equalTo('id', $record->id);
191
 
192
        return $this->executeDelete($delete);
193
 
194
    }
195
 
196
 
197
}