Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| 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 LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\Paginator\Paginator;
13
use Laminas\Paginator\Adapter\DbSelect;
14
 
15
use LeadersLinked\Model\VideoConvert;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
 
18
 
19
class VideoConvertMapper extends MapperCommon
20
{
21
    const _TABLE = 'tbl_video_converter';
22
 
23
 
24
    /**
25
     *
26
     * @var VideoConvertMapper
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 \LeadersLinked\Mapper\VideoConvertMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
46
        if(self::$_instance == null) {
47
            self::$_instance = new VideoConvertMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
51
 
52
    /**
53
     *
54
     * @param int $id
55
     * @return  VideoConvert
56
     */
57
    public function fetchOne($id)
58
    {
59
        $prototype = new VideoConvert();
60
        $select = $this->sql->select(self::_TABLE);
61
        $select->where->equalTo('id', $id);
62
        $select->limit(1);
63
 
64
        return $this->executeFetchOneObject($select, $prototype);
65
    }
66
 
67
    /**
68
     *
69
     * @return VideoConvert[]
70
     */
71
    public function fetchBatch($batchSize = 10)
72
    {
73
 
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->order('added_on ASC');
76
        $select->limit($batchSize);
77
 
78
        $prototype = new VideoConvert();
79
        return $this->executeFetchAllObject($select, $prototype);
80
    }
81
   /**
82
     *
83
     * @param VideoConvert $videoConvert
84
     * @return boolean
85
     */
86
    public function insert($videoConvert)
87
    {
88
        $hydrator = new ObjectPropertyHydrator();
89
        $values = $hydrator->extract($videoConvert);
90
        $values = $this->removeEmpty($values);
91
 
92
        $insert = $this->sql->insert(self::_TABLE);
93
        $insert->values($values);
94
 
95
 
96
        return $this->executeInsert($insert);
97
    }
98
 
99
    /**
100
     *
101
     * @param VideoConvert $videoConvert
102
     * @return boolean
103
     */
104
    public function update($videoConvert)
105
    {
106
        $hydrator = new ObjectPropertyHydrator();
107
        $values = $hydrator->extract($videoConvert);
108
 
109
        $update = $this->sql->update(self::_TABLE);
110
        $update->set($values);
111
        $update->where->equalTo('id', $videoConvert->id);
112
 
113
        return $this->executeUpdate($update);
114
    }
115
 
116
    /**
117
     *
118
     * @param VideoConvert $videoConvert
119
     * @return boolean
120
     */
121
    public function delete($videoConvert)
122
    {
123
        $delete = $this->sql->delete(self::_TABLE);
124
        $delete->where->equalTo('id', $videoConvert->id);
125
 
126
        return $this->executeDelete($delete);
127
 
128
    }
129
 
130
    /**
131
     *
132
     * @return boolean
133
     */
134
    public function deleteAll()
135
    {
136
        $delete = $this->sql->delete(self::_TABLE);
137
 
138
        return $this->executeDelete($delete);
139
    }
140
 
141
 
142
    /**
143
     *
144
     * @return boolean
145
     */
146
    public function truncate()
147
    {
148
        $sql = sprintf('TRUNCATE TABLE `%s` ', self::_TABLE);
149
        return $this->executeSentenceWithParameters($sql);
150
    }
151
 
152
}