Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 426 | Rev 428 | 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
 
424 geraldo 134
 
135
 
1 www 136
        return $this->executeUpdate($update);
137
    }
138
 
139
    /**
140
     *
141
     * @param Feed $feed
142
     * @return boolean
143
     */
144
    public function insert($feed)
145
    {
146
        $hydrator = new ObjectPropertyHydrator();
147
        $values = $hydrator->extract($feed);
427 geraldo 148
        //$values = $this->removeEmpty($values);
1 www 149
 
150
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 151
        $insert->values($values);
1 www 152
 
153
        $response = $this->executeInsert($insert);
154
        if($response) {
155
            $feed->id = $this->lastInsertId;
156
        }
157
 
426 geraldo 158
        return $values;
1 www 159
    }
160
 
161
    /**
162
     *
163
     * @param int $id
164
     * @return int
165
     */
166
    public function fetchTotalComments($id)
167
    {
168
        $select = $this->sql->select(self::_TABLE);
169
        $select->columns(['total_comments']);
170
        $select->where->equalTo('id', $id);
171
 
172
        $record = $this->executeFetchOneArray($select);
173
        return $record['total_comments'];
174
    }
175
 
176
    /**
177
     *
178
     * @param int $feed_id
179
     * @return boolean
180
     */
181
     /*
182
    public function incTotalComments($id)
183
    {
184
 
185
        $update = $this->sql->update(self::_TABLE);
186
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
187
        $update->where->equalTo('id', $id);
188
 
189
        return $this->executeUpdate($update);
190
    }
191
    */
192
 
193
    /**
194
     *
195
     * @param int $feed_id
196
     * @return boolean
197
     */
198
    public function incTotalShared($id)
199
    {
200
        $update = $this->sql->update(self::_TABLE);
201
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
202
        $update->where->equalTo('id', $id);
203
 
204
        return $this->executeUpdate($update);
205
    }
206
 
207
    /**
208
     *
209
     * @param int $id
210
     * @return int
211
     */
212
    public function fetchTotalShared($id)
213
    {
214
        $select = $this->sql->select(self::_TABLE);
215
        $select->columns(['total_shared']);
216
        $select->where->equalTo('id', $id);
217
 
218
        $record = $this->executeFetchOneArray($select);
219
        return $record['total_shared'];
220
    }
221
 
222
    /**
223
     *
224
     * @param int $feed_id
225
     * @return boolean
226
     */
227
    public function delete($feed_id)
228
    {
229
        $update = $this->sql->update(self::_TABLE);
230
        $update->set([
231
            'status' => Feed::STATUS_DELETED
232
        ]);
233
        $update->where->equalTo('id', $feed_id);
234
 
235
        return $this->executeUpdate($update);
236
    }
237
}