Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 663 | Ir a la última revisión | | 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
use LeadersLinked\Model\Location;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
 
13
 
14
class LocationMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_locations';
17
 
18
 
19
    /**
20
     *
21
     * @var LocationMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return LocationMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new LocationMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @return Location[]
50
     */
51
    public function fetchAll()
52
    {
53
        $prototype = new Location;
54
        $select = $this->sql->select(self::_TABLE);
55
 
56
        return $this->executeFetchAllObject($select, $prototype);
57
    }
58
 
59
    /**
60
     *
61
     * @param int $id
62
     * @return Location
63
     */
64
    public function fetchOne($id)
65
    {
66
        $prototype = new Location;
67
        $select = $this->sql->select(self::_TABLE);
68
        $select->where->equalTo('id', $id);
69
 
70
        return $this->executeFetchOneObject($select, $prototype);
71
    }
72
 
73
 
74
    /**
75
     *
76
     * @param int $uuid
77
     * @return Location
78
     */
79
    public function fetchOneBuUuid($uuid)
80
    {
81
        $prototype = new Location;
82
        $select = $this->sql->select(self::_TABLE);
83
        $select->where->equalTo('uuid', $uuid);
84
 
85
        return $this->executeFetchOneObject($select, $prototype);
86
    }
87
 
88
    /**
89
     *
90
     * @param Location $location
91
     * @return boolean
92
     */
93
    public function insert($location)
94
    {
95
        $hydrator = new ObjectPropertyHydrator();
96
        $values = $hydrator->extract($location);
97
        $values = $this->removeEmpty($values);
98
 
99
 
100
        $insert = $this->sql->insert(self::_TABLE);
101
        $insert->values($values);
102
 
103
        $response = $this->executeInsert($insert);
104
        if($response) {
105
            $location->id = $this->lastInsertId;
106
        }
107
 
108
        return $response;
109
 
110
    }
111
 
112
    /**
113
     *
114
     * @param Location $location
115
     * @return location
116
     */
117
    public function update($location)
118
    {
119
        $hydrator = new ObjectPropertyHydrator();
120
        $values = $hydrator->extract($location);
121
        $values = $this->removeEmpty($values);
122
 
123
        $update= $this->sql->update(self::_TABLE);
124
        $update->set($values);
125
        $update->where->equalTo('id', $location->id);
126
 
127
        //echo $update->getSqlString($this->adapter->platform); exit;
128
 
129
        return $this->executeUpdate($update);
130
    }
131
 
132
    /**
133
     *
134
     * @param int $id
135
     * @return boolean
136
     */
137
    public function delete($id)
138
    {
139
 
140
        $delete= $this->sql->delete(self::_TABLE);
141
        $delete->where->equalTo('id', $id);
142
 
143
        return $this->executeDelete($delete);
144
    }
145
}