Proyectos de Subversion LeadersLinked - Services

Rev

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