Proyectos de Subversion LeadersLinked - Services

Rev

| Ultima modificación | Ver Log |

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