Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7123 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
8
use LeadersLinked\Model\DailyPulse;
9
use LeadersLinked\Mapper\Common\MapperCommon;
10
 
11
class DailyPulseMapper extends MapperCommon
12
{
13
    const _TABLE = 'tbl_daily_pulse';
14
 
15
    /**
16
     *
17
     * @var DailyPulseMapper
18
     */
19
    private static $_instance;
20
 
21
    /**
22
     *
23
     * @param AdapterInterface $adapter
24
     */
25
    private function __construct($adapter)
26
    {
27
        parent::__construct($adapter);
28
    }
29
 
30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     * @return DailyPulseMapper
34
     */
35
    public static function getInstance($adapter)
36
    {
37
        if(self::$_instance == null) {
38
            self::$_instance = new DailyPulseMapper($adapter);
39
        }
40
        return self::$_instance;
41
    }
42
 
43
 
44
    /**
45
     *
46
     * @param int $id
47
     * @return DailyPulse
48
     */
49
    public function fetchOne($id)
50
    {
51
        $select = $this->sql->select(self::_TABLE);
52
        $select->where->equalTo('id', $id);
53
        $select->limit(1);
54
 
55
        $prototype = new DailyPulse();
56
        return $this->executeFetchOneObject($select, $prototype);
57
    }
58
 
59
    /**
60
     *
61
     * @param string $uuid
62
     * @return DailyPulse
63
     */
64
    public function fetchOneByUuid($uuid)
65
    {
66
        $select = $this->sql->select(self::_TABLE);
67
        $select->where->equalTo('uuid', $uuid);
68
        $select->limit(1);
69
 
70
        $prototype = new DailyPulse();
71
        return $this->executeFetchOneObject($select, $prototype);
72
    }
73
 
74
 
75
    /**
76
     *
77
     * @param int $company_id
78
     * @return DailyPulse
79
     */
80
    public function fetchOneByCompanyId($company_id)
81
    {
82
        $select = $this->sql->select(self::_TABLE);
83
        $select->where->equalTo('company_id', $company_id);
84
 
85
        $prototype = new DailyPulse();
86
        return $this->executeFetchOneObject($select, $prototype);
87
    }
88
 
89
    /**
90
     *
91
     * @param DailyPulse $record
92
     * @return boolean
93
     */
94
    public function insert($record)
95
    {
96
        $hydrator = new ObjectPropertyHydrator();
97
        $values = $hydrator->extract($record);
98
        $values = $this->removeEmpty($values);
99
 
100
        $insert = $this->sql->insert(self::_TABLE);
101
        $insert->values($values);
102
 
103
 
104
 
105
        $result = $this->executeInsert($insert);
106
        if($result) {
107
            $record->id = $this->lastInsertId;
108
        }
109
 
110
        return $result;
111
 
112
    }
113
 
114
    /**
115
     *
116
     * @param DailyPulse $record
117
     * @return boolean
118
     */
119
    public function update($record)
120
    {
121
        $hydrator = new ObjectPropertyHydrator();
122
        $values = $hydrator->extract($record);
123
        $values = $this->removeEmpty($values);
124
 
125
        $update = $this->sql->update(self::_TABLE);
126
        $update->set($values);
127
        $update->where->equalTo('id', $record->id);
128
 
129
        return $this->executeUpdate($update);
130
    }
131
 
132
    /**
133
     *
134
     * @param DailyPulse $record
135
     * @return boolean
136
     */
137
    public function delete($record)
138
    {
139
        $delete = $this->sql->delete(self::_TABLE);
140
        $delete->where->equalTo('id', $record->id);
141
 
142
        return $this->executeDelete($delete);
143
 
144
 
145
    }
146
 
147
}