Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 419 | Rev 424 | 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 Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Db\Sql\Expression;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\Common\MapperCommon;
11
use LeadersLinked\Model\Feed;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
 
14
 
15
class FeedMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_feeds';
18
 
19
 
20
    /**
21
     *
22
     * @var FeedMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\FeedMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new FeedMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /*
49
    public function fetchCountSharesByFeedId(int $shared_feed_id)
50
    {
51
        $select = $this->sql->select(self::_TABLE);
52
        $select->columns(['total' => new Expression('COUNT(*)') ]);
53
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
54
 
55
        $record = $this->executeFetchOneArray($select);
56
        return $record['total'];
57
    }*/
58
 
59
    /**
60
     *
61
     * @param int $id
62
     * @return Feed
63
     */
64
    public function fetchOne($id)
65
    {
66
        $select = $this->sql->select(self::_TABLE);
67
        $select->where->equalTo('id', $id);
68
 
69
        $prototype = new Feed();
70
        return $this->executeFetchOneObject($select, $prototype);
71
    }
72
 
73
    /**
74
     *
75
     * @param int $feed_uuid
76
     * @return Feed
77
     */
78
    public function fetchOneByUuid($uuid)
79
    {
80
        $select = $this->sql->select(self::_TABLE);
81
        $select->where->equalTo('uuid', $uuid);
82
 
83
        $prototype = new Feed();
84
        return $this->executeFetchOneObject($select, $prototype);
85
    }
86
 
87
    /**
88
     *
242 efrain 89
     * @return Feed[]
90
     */
91
    public function fetchAllTypeVideo()
92
    {
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('file_type', Feed::FILE_TYPE_VIDEO);
95
 
96
        //echo $select->getSqlString($this->adapter->platform);
97
 
98
        $prototype = new Feed();
99
        return $this->executeFetchAllObject($select, $prototype);
100
    }
101
 
102
 
103
    /**
104
     *
1 www 105
     * @param int $shared_feed_id
106
     * @return int
107
     */
108
    public function fetchCountSharedByFeedId($shared_feed_id)
109
    {
110
        $select = $this->sql->select(self::_TABLE);
111
        $select->columns(['total' => new Expression('COUNT(*)') ]);
112
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
113
 
114
        $record = $this->executeFetchOneArray($select);
115
        return $record['total'];
116
    }
117
 
118
 
119
    /**
120
     *
121
     * @param Feed $feed
122
     * @return boolean
123
     */
124
    public function update($feed)
125
    {
126
        $hydrator = new ObjectPropertyHydrator();
127
        $values = $hydrator->extract($feed);
128
        $values = $this->removeEmpty($values);
129
 
130
        $update = $this->sql->update(self::_TABLE);
131
        $update->set($values);
132
        $update->where->equalTo('id', $feed->id);
133
 
421 geraldo 134
 
1 www 135
        return $this->executeUpdate($update);
136
    }
137
 
138
    /**
139
     *
140
     * @param Feed $feed
141
     * @return boolean
142
     */
143
    public function insert($feed)
144
    {
145
        $hydrator = new ObjectPropertyHydrator();
146
        $values = $hydrator->extract($feed);
147
        $values = $this->removeEmpty($values);
148
 
149
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 150
        $insert->values($values);
1 www 151
 
152
        $response = $this->executeInsert($insert);
153
        if($response) {
154
            $feed->id = $this->lastInsertId;
155
        }
156
 
157
        return $response;
158
    }
159
 
160
    /**
161
     *
162
     * @param int $id
163
     * @return int
164
     */
165
    public function fetchTotalComments($id)
166
    {
167
        $select = $this->sql->select(self::_TABLE);
168
        $select->columns(['total_comments']);
169
        $select->where->equalTo('id', $id);
170
 
171
        $record = $this->executeFetchOneArray($select);
172
        return $record['total_comments'];
173
    }
174
 
175
    /**
176
     *
177
     * @param int $feed_id
178
     * @return boolean
179
     */
180
     /*
181
    public function incTotalComments($id)
182
    {
183
 
184
        $update = $this->sql->update(self::_TABLE);
185
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
186
        $update->where->equalTo('id', $id);
187
 
188
        return $this->executeUpdate($update);
189
    }
190
    */
191
 
192
    /**
193
     *
194
     * @param int $feed_id
195
     * @return boolean
196
     */
197
    public function incTotalShared($id)
198
    {
199
        $update = $this->sql->update(self::_TABLE);
200
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
201
        $update->where->equalTo('id', $id);
202
 
203
        return $this->executeUpdate($update);
204
    }
205
 
206
    /**
207
     *
208
     * @param int $id
209
     * @return int
210
     */
211
    public function fetchTotalShared($id)
212
    {
213
        $select = $this->sql->select(self::_TABLE);
214
        $select->columns(['total_shared']);
215
        $select->where->equalTo('id', $id);
216
 
217
        $record = $this->executeFetchOneArray($select);
218
        return $record['total_shared'];
219
    }
220
 
221
    /**
222
     *
223
     * @param int $feed_id
224
     * @return boolean
225
     */
226
    public function delete($feed_id)
227
    {
228
        $update = $this->sql->update(self::_TABLE);
229
        $update->set([
230
            'status' => Feed::STATUS_DELETED
231
        ]);
232
        $update->where->equalTo('id', $feed_id);
233
 
234
        return $this->executeUpdate($update);
235
    }
236
}