Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
 
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Db\ResultSet\HydratingResultSet;
10
use Laminas\Paginator\Adapter\DbSelect;
11
use Laminas\Paginator\Paginator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\Hydrator\ArraySerializableHydrator;
14
 
15
 
16
use LeadersLinked\Model\CompanyLocation;
17
use LeadersLinked\Mapper\Common\MapperCommon;
18
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
19
 
20
class CompanyLocationMapper extends MapperCommon
21
{
22
    const _TABLE = 'tbl_company_locations';
23
 
24
 
25
    /**
26
     *
27
     * @var CompanyLocationMapper
28
     */
29
    private static $_instance;
30
 
31
    /**
32
     *
33
     * @param AdapterInterface $adapter
34
     */
35
    private function __construct($adapter)
36
    {
37
        parent::__construct($adapter);
38
    }
39
 
40
    /**
41
     *
42
     * @param AdapterInterface $adapter
43
     * @return CompanyLocationMapper
44
     */
45
    public static function getInstance($adapter)
46
    {
47
        if(self::$_instance == null) {
48
            self::$_instance = new CompanyLocationMapper($adapter);
49
        }
50
        return self::$_instance;
51
    }
52
 
53
    /**
54
     *
55
     * @param int $company_id
56
     * @return array
57
     */
58
    public function fetchAllLocationByCompanyId($company_id)
59
    {
60
        $select = $this->sql->select();
61
        $select->columns(['formatted_address', 'country']);
62
        $select->from(['l' => LocationMapper::_TABLE]);
63
        $select->join(['cl' => self::_TABLE], 'l.id = cl.location_id', ['company_location_id' => 'id', 'company_location_uuid' => 'uuid', 'location_id', 'is_main']);
64
        $select->where->equalTo('company_id', $company_id);
65
        $select->order('is_main, formatted_address');
66
 
1296 efrain 67
        //echo $select->getSqlString($this->adapter->platform);
1294 efrain 68
 
1 www 69
        return $this->executeFetchAllArray($select);
70
 
71
    }
72
 
73
    /**
74
     *
75
     * @param int $company_id
76
     * @return CompanyLocation[]
77
     */
78
    public function fetchAllByCompanyId($company_id)
79
    {
80
        $prototype = new CompanyLocation();
81
 
82
        $select = $this->sql->select(self::_TABLE);
83
        $select->where->equalTo('company_id', $company_id);
84
 
85
        return $this->executeFetchAllObject($select, $prototype);
86
 
87
    }
88
 
89
    /**
90
     *
91
     * @param int $id
92
     * @return CompanyLocation
93
     */
94
    public function fetchOne($id)
95
    {
96
        $prototype = new CompanyLocation();
97
 
98
        $select = $this->sql->select(self::_TABLE);
99
        $select->where->equalTo('id', $id);
100
 
101
        return $this->executeFetchOneObject($select, $prototype);
102
 
103
 
104
    }
105
 
106
    /**
107
     *
108
     * @param string $uuid
109
     * @return CompanyLocation
110
     */
111
    public function fetchOneByUuid($uuid)
112
    {
113
        $prototype = new CompanyLocation();
114
 
115
        $select = $this->sql->select(self::_TABLE);
116
        $select->where->equalTo('uuid', $uuid);
117
 
118
        return $this->executeFetchOneObject($select, $prototype);
119
 
120
 
121
    }
122
 
123
    /**
124
     *
125
     * @param int $company_id
126
     * @return CompanyLocation
127
     */
128
    public function fetchOneMainLocationByCompanyId($company_id)
129
    {
130
        $prototype = new CompanyLocation();
131
 
132
        $select = $this->sql->select(self::_TABLE);
133
        $select->where->equalTo('company_id', $company_id);
134
        $select->where->equalTo('is_main', CompanyLocation::IS_MAIN_YES);
135
 
136
        return $this->executeFetchOneObject($select, $prototype);
137
    }
138
 
139
    /**
140
     *
141
     * @param int $id
142
     * @return boolean
143
     */
144
    public function delete($id)
145
    {
146
        $delete = $this->sql->delete(self::_TABLE);
147
        $delete->where->equalTo('id', $id);
148
 
149
        return $this->executeDelete($delete);
150
    }
151
 
152
    /**
153
     *
154
     * @param CompanyLocation $companyLocation
155
     * @return true
156
     */
157
    public function insert($companyLocation)
158
    {
159
        $hydrator = new ObjectPropertyHydrator();
160
        $values = $hydrator->extract($companyLocation);
161
        $values = $this->removeEmpty($values);
162
 
163
 
164
        $insert = $this->sql->insert(self::_TABLE);
165
        $insert->values($values);
166
 
167
        $result = $this->executeInsert($insert);
168
        if($result) {
169
            $companyLocation->id = $this->lastInsertId;
170
        }
171
        return $result;
172
 
173
    }
174
 
175
    /**
176
     *
177
     * @param CompanyLocation $companyLocation
178
     * @return true
179
     */
180
    public function update($companyLocation)
181
    {
182
        $hydrator = new ObjectPropertyHydrator();
183
        $values = $hydrator->extract($companyLocation);
184
        $values = $this->removeEmpty($values);
185
 
186
        $update = $this->sql->update(self::_TABLE);
187
        $update->where->equalTo('id', $companyLocation->id);
188
        $update->set($values);
189
 
190
        return $this->executeUpdate($update);
191
 
192
    }
193
 
194
}