Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 428 | Rev 1855 | 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
    }
1776 nelberth 101
 
102
    public function fetchAllTypeCalendar($highPerformanceTeamsGroups_id)
103
    {
104
        $select = $this->sql->select(self::_TABLE);
105
        $select->where->equalTo('file_type', Feed::FILE_TYPE_MEETING);
106
 
107
        $select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups_id);
108
        //echo $select->getSqlString($this->adapter->platform);
109
 
110
        $prototype = new Feed();
111
        return $this->executeFetchAllObject($select, $prototype);
112
    }
242 efrain 113
 
114
    /**
115
     *
1 www 116
     * @param int $shared_feed_id
117
     * @return int
118
     */
119
    public function fetchCountSharedByFeedId($shared_feed_id)
120
    {
121
        $select = $this->sql->select(self::_TABLE);
122
        $select->columns(['total' => new Expression('COUNT(*)') ]);
123
        $select->where->equalTo('shared_feed_id', $shared_feed_id);
124
 
125
        $record = $this->executeFetchOneArray($select);
126
        return $record['total'];
127
    }
128
 
129
 
130
    /**
131
     *
132
     * @param Feed $feed
133
     * @return boolean
134
     */
135
    public function update($feed)
136
    {
137
        $hydrator = new ObjectPropertyHydrator();
138
        $values = $hydrator->extract($feed);
139
        $values = $this->removeEmpty($values);
140
 
141
        $update = $this->sql->update(self::_TABLE);
142
        $update->set($values);
143
        $update->where->equalTo('id', $feed->id);
144
 
424 geraldo 145
 
146
 
1 www 147
        return $this->executeUpdate($update);
148
    }
149
 
150
    /**
151
     *
152
     * @param Feed $feed
153
     * @return boolean
154
     */
155
    public function insert($feed)
156
    {
157
        $hydrator = new ObjectPropertyHydrator();
158
        $values = $hydrator->extract($feed);
428 geraldo 159
        $values = $this->removeEmpty($values);
1 www 160
 
161
        $insert = $this->sql->insert(self::_TABLE);
421 geraldo 162
        $insert->values($values);
1 www 163
 
164
        $response = $this->executeInsert($insert);
165
        if($response) {
166
            $feed->id = $this->lastInsertId;
167
        }
168
 
426 geraldo 169
        return $values;
1 www 170
    }
171
 
172
    /**
173
     *
174
     * @param int $id
175
     * @return int
176
     */
177
    public function fetchTotalComments($id)
178
    {
179
        $select = $this->sql->select(self::_TABLE);
180
        $select->columns(['total_comments']);
181
        $select->where->equalTo('id', $id);
182
 
183
        $record = $this->executeFetchOneArray($select);
184
        return $record['total_comments'];
185
    }
186
 
187
    /**
188
     *
189
     * @param int $feed_id
190
     * @return boolean
191
     */
192
     /*
193
    public function incTotalComments($id)
194
    {
195
 
196
        $update = $this->sql->update(self::_TABLE);
197
        $update->set(['total_comments' => new Expression('total_comments + 1')]);
198
        $update->where->equalTo('id', $id);
199
 
200
        return $this->executeUpdate($update);
201
    }
202
    */
203
 
204
    /**
205
     *
206
     * @param int $feed_id
207
     * @return boolean
208
     */
209
    public function incTotalShared($id)
210
    {
211
        $update = $this->sql->update(self::_TABLE);
212
        $update->set(['total_shared' => new Expression('total_shared + 1')]);
213
        $update->where->equalTo('id', $id);
214
 
215
        return $this->executeUpdate($update);
216
    }
217
 
218
    /**
219
     *
220
     * @param int $id
221
     * @return int
222
     */
223
    public function fetchTotalShared($id)
224
    {
225
        $select = $this->sql->select(self::_TABLE);
226
        $select->columns(['total_shared']);
227
        $select->where->equalTo('id', $id);
228
 
229
        $record = $this->executeFetchOneArray($select);
230
        return $record['total_shared'];
231
    }
232
 
233
    /**
234
     *
235
     * @param int $feed_id
236
     * @return boolean
237
     */
238
    public function delete($feed_id)
239
    {
240
        $update = $this->sql->update(self::_TABLE);
241
        $update->set([
242
            'status' => Feed::STATUS_DELETED
243
        ]);
244
        $update->where->equalTo('id', $feed_id);
245
 
246
        return $this->executeUpdate($update);
247
    }
248
}