Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev Autor Línea Nro. Línea
167 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\DiscoveryContactBlackList;
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 DiscoveryContactBlackListMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_discovery_contact_blacklist';
19
 
20
    /**
21
     *
22
     * @var DiscoveryContactBlackListMapper
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 DiscoveryContactBlackListMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new DiscoveryContactBlackListMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return DiscoveryContactBlackList
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 DiscoveryContactBlackList();
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
    /**
64
     *
65
     * @param int $contact_id
66
     * @return DiscoveryContactBlackList
67
     */
175 efrain 68
    public function fetchOneByContactId($contact_id)
167 efrain 69
    {
70
 
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('contact_id', $contact_id);
175 efrain 73
 
167 efrain 74
        $prototype = new DiscoveryContactBlackList();
75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
77
 
175 efrain 78
    /**
79
     *
80
     * @param int $company_id
81
     * @return int[]
82
     */
83
    public function fetchAllContactIdsByCompanyId($company_id)
84
    {
85
        $select = $this->sql->select(self::_TABLE);
86
        $select->columns(['contact_id']);
87
        $select->where->equalTo('company_id', $company_id);
88
 
89
        $ids = [];
90
        $records = $this->executeFetchAllArray($select);
91
        foreach($records as $record)
92
        {
93
            array_push($ids, $record['contact_id']);
94
        }
95
 
96
        return $ids;
97
 
98
 
99
 
100
 
101
    }
167 efrain 102
 
175 efrain 103
 
167 efrain 104
    /**
105
     *
106
     * @param string $uuid
107
     * @return DiscoveryContactBlackList
108
     */
109
    public function fetchOneByUuid($uuid)
110
    {
111
 
112
        $select = $this->sql->select(self::_TABLE);
113
        $select->where->equalTo('uuid', $uuid);
114
 
115
        $prototype = new DiscoveryContactBlackList();
116
        return $this->executeFetchOneObject($select, $prototype);
117
    }
118
 
119
    /**
120
     *
121
     * @param int $company_id
122
     * @param int $contact_id
123
     * @param int $page
124
     * @param int $records_per_page
125
     * @return Paginator
126
     */
127
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
128
    {
129
        $prototype = new DiscoveryContactBlackList();
130
        $select = $this->sql->select(self::_TABLE);
131
        $select->where->equalTo('company_id', $company_id);
132
        $select->where->equalTo('contact_id', $contact_id);
133
        $select->order('added_on DESC');
134
 
135
        $hydrator   = new ObjectPropertyHydrator();
136
        $resultset  = new HydratingResultSet($hydrator, $prototype);
137
 
138
        $adapter = new DbSelect($select, $this->sql, $resultset);
139
        $paginator = new Paginator( $adapter);
140
        $paginator->setItemCountPerPage($records_per_page);
141
        $paginator->setCurrentPageNumber($page);
142
 
143
 
144
        return $paginator;
145
    }
146
 
147
 
148
    /**
149
     *
150
     * @param DiscoveryContactBlackList $record
151
     * @return boolean
152
     */
153
    public function insert($record)
154
    {
155
        $hydrator = new ObjectPropertyHydrator();
156
        $values = $hydrator->extract($record);
157
        $values = $this->removeEmpty($values);
158
 
159
        $insert = $this->sql->insert(self::_TABLE);
160
        $insert->values($values);
161
        $result = $this->executeInsert($insert);
162
 
163
        if($result) {
164
            $record->id = $this->lastInsertId;
165
        }
166
 
167
        return $result;
168
    }
169
 
170
 
175 efrain 171
 
167 efrain 172
    /**
173
     *
175 efrain 174
     * @param DiscoveryContactBlackList $record
175
     * @return boolean
176
     */
177
    public function update($record)
178
    {
179
        $hydrator = new ObjectPropertyHydrator();
180
        $values = $hydrator->extract($record);
181
        $values = $this->removeEmpty($values);
182
 
183
        $update = $this->sql->update(self::_TABLE);
184
        $update->set($values);
185
        $update->where->equalTo('id', $record->id);
186
 
187
        return $this->executeUpdate($update);
188
 
189
 
190
    }
191
 
192
 
193
 
194
    /**
195
     *
167 efrain 196
     * @param array $values
197
     * @return boolean
198
     */
199
    public function insertRaw($values)
200
    {
201
        $insert = $this->sql->insert(self::_TABLE);
202
        $insert->values($values);
203
        return $this->executeInsert($insert);
204
 
205
    }
206
 
207
 
208
 
209
    /**
210
     *
211
     * @param DiscoveryContactBlackList $record
212
     * @return boolean
213
     */
214
    public function delete($record)
215
    {
216
        $delete = $this->sql->delete(self::_TABLE);
217
        $delete->where->equalTo('id', $record->id);
218
 
219
        return $this->executeDelete($delete);
220
 
221
    }
222
 
223
 
224
}