Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2048 eleazar 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use LeadersLinked\Mapper\Common\MapperCommon;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Model\FeedTopic;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
15
class FeedTopicMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_topics_feed';
18
 
19
    /**
20
     *
21
     * @var FeedTopicMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return FeedTopicMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new FeedTopicMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return FeedTopic
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new FeedTopic();
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
61
 
62
 
63
    /**
64
     *
65
     * @param int $uuid
66
     * @return FeedTopic
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new FeedTopic();
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
2061 eleazar 73
       // echo $select->getSqlString($this->adapter->platform); exit;
2048 eleazar 74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
2057 eleazar 76
 
2059 eleazar 77
    /**
2057 eleazar 78
     *
79
     * @param int $feed_id
80
     * @return FeedTopic
81
     */
82
    public function fetchAllByFeedId($feed_id)
83
    {
84
        $prototype = new FeedTopic();
2060 eleazar 85
 
2057 eleazar 86
        $select = $this->sql->select(self::_TABLE);
2060 eleazar 87
 
2057 eleazar 88
        $select->where->equalTo('feed_id', $feed_id);
2060 eleazar 89
 
2061 eleazar 90
        //echo $select->getSqlString($this->adapter->platform); exit;
2060 eleazar 91
 
2057 eleazar 92
        return $this->executeFetchAllObject($select, $prototype);
93
    }
2048 eleazar 94
 
95
    /**
96
     *
97
     * @param FeedTopic $record
98
     * @return boolean
99
     */
100
    public function insert($record)
101
    {
102
        $hydrator = new ObjectPropertyHydrator();
103
        $values = $hydrator->extract($record);
104
        $values = $this->removeEmpty($values);
105
 
106
        $insert = $this->sql->insert(self::_TABLE);
107
        $insert->values($values);
108
 
109
        //echo $insert->getSqlString($this->adapter->platrecord); exit;
110
 
111
        $result = $this->executeInsert($insert);
112
        if($result) {
113
            $record->id = $this->lastInsertId;
114
        }
115
        return $result;
116
    }
117
 
118
    /**
119
     *
120
     * @param FeedTopic $record
121
     * @return boolean
122
     */
123
    public function update($record)
124
    {
125
        $hydrator = new ObjectPropertyHydrator();
126
        $values = $hydrator->extract($record);
127
        $values = $this->removeEmpty($values);
128
 
129
        $update = $this->sql->update(self::_TABLE);
130
        $update->set($values);
131
        $update->where->equalTo('id', $record->id);
132
 
133
        return $this->executeUpdate($update);
134
    }
135
 
136
    /**
137
     *
138
     * @param int $record_id
139
     * @return boolean
140
     */
141
    public function delete($id)
142
    {
143
        $delete = $this->sql->delete(self::_TABLE);
144
        $delete->where->equalTo('id', $id);
145
 
146
        return $this->executeDelete($delete);
147
    }
148
 
149
}