Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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