Proyectos de Subversion LeadersLinked - Services

Rev

Rev 203 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
192 efrain 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\AbuseReport;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
 
18
 
19
 
20
class AbuseReportMapper extends MapperCommon
21
{
22
    const _TABLE = 'tbl_abuse_reports';
23
 
24
    /**
25
     *
26
     * @var AbuseReportMapper
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 AbuseReportMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
46
        if(self::$_instance == null) {
47
            self::$_instance = new AbuseReportMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
51
 
52
 
53
 
54
 
55
    /**
56
     *
57
     * @param int $id
58
     * @return AbuseReport
59
     */
60
    public function fetchOne($id)
61
    {
62
        $select = $this->sql->select(self::_TABLE);
63
        $select->where->equalTo('id', $id);
64
        $select->limit(1);
65
 
66
        $prototype = new AbuseReport();
67
        return $this->executeFetchOneObject($select, $prototype);
68
    }
69
 
70
    /**
71
     *
72
     * @param string $uuid
73
     * @return AbuseReport
74
     */
75
    public function fetchOneByUuid($uuid)
76
    {
77
        $select = $this->sql->select(self::_TABLE);
78
        $select->where->equalTo('uuid', $uuid);
79
        $select->limit(1);
80
 
81
        $prototype = new AbuseReport();
82
        return $this->executeFetchOneObject($select, $prototype);
83
    }
84
 
85
    /**
86
     *
87
     * @param string $search
88
     * @param int $page
89
     * @param int $records_per_page
90
     * @param string $order_field
91
     * @param string $order_direction
92
     * @return Paginator
93
     */
94
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
95
    {
96
        $prototype = new AbuseReport();
97
        $select = $this->sql->select(self::_TABLE);
98
 
99
        if($search) {
100
            //$select->where->like('name', '%' . $search . '%');
101
        }
102
        $select->order($order_field . ' ' . $order_direction);
103
 
104
        $hydrator   = new ObjectPropertyHydrator();
105
        $resultset  = new HydratingResultSet($hydrator, $prototype);
106
 
107
        $adapter = new DbSelect($select, $this->sql, $resultset);
108
        $paginator = new Paginator($adapter);
109
        $paginator->setItemCountPerPage($records_per_page);
110
        $paginator->setCurrentPageNumber($page);
111
 
112
 
113
        return $paginator;
114
    }
115
 
116
    /**
117
     *
118
     * @param int $user_reporting_id
119
     * @param string $search
120
     * @param int $page
121
     * @param int $records_per_page
122
     * @param string $order_field
123
     * @param string $order_direction
124
     * @return Paginator
125
     */
126
    public function fetchAllDataTableByUserReportingId($user_reporting_id, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
127
    {
128
        $prototype = new AbuseReport();
129
        $select = $this->sql->select(self::_TABLE);
130
        $select->where->equalTo('user_reporting_id', $user_reporting_id);
131
 
132
        if($search) {
133
            //$select->where->like('name', '%' . $search . '%');
134
        }
135
        $select->order($order_field . ' ' . $order_direction);
136
 
137
        $hydrator   = new ObjectPropertyHydrator();
138
        $resultset  = new HydratingResultSet($hydrator, $prototype);
139
 
140
        $adapter = new DbSelect($select, $this->sql, $resultset);
141
        $paginator = new Paginator($adapter);
142
        $paginator->setItemCountPerPage($records_per_page);
143
        $paginator->setCurrentPageNumber($page);
144
 
145
 
146
        return $paginator;
147
    }
148
 
149
    /**
150
     *
151
     * @param int $user_reporting_id
152
     * @param string $type
153
     * @return int[]
154
     */
155
    public function fetchAllDataByUserReportingIdAndTypeReturnIds($user_reporting_id, $type)
156
    {
157
        $select = $this->sql->select(self::_TABLE);
158
        $select->columns(['related_id']);
159
        $select->where->equalTo('user_reporting_id', $user_reporting_id);
160
        $select->where->equalTo('type',  $type);
161
 
162
        //echo $select->getSqlString($this->adapter->platform);
163
 
164
        $ids = [];
165
        $records = $this->executeFetchAllArray($select);
166
 
167
        foreach($records as $record)
168
        {
169
            array_push($ids, $record['related_id']);
170
        }
171
        return $ids;
172
    }
173
 
174
    /**
175
     *
176
     * @param AbuseReport $abuseReport
177
     * @return boolean
178
     */
179
    public function insert($abuseReport)
180
    {
181
        $hydrator = new ObjectPropertyHydrator();
182
        $values = $hydrator->extract($abuseReport);
183
 
184
        $insert = $this->sql->insert(self::_TABLE);
185
        $insert->values($values);
186
 
187
 
188
        $result = $this->executeInsert($insert);
189
        if($result) {
190
            $abuseReport->id = $this->lastInsertId;
191
        }
192
 
193
        return $result;
194
 
195
    }
196
 
197
    /**
198
     *
199
     * @param AbuseReport $abuseReport
200
     * @return boolean
201
     */
202
    public function update($abuseReport)
203
    {
204
        $hydrator = new ObjectPropertyHydrator();
205
        $values = $hydrator->extract($abuseReport);
206
 
207
        $update = $this->sql->update(self::_TABLE);
208
        $update->set($values);
209
        $update->where->equalTo('id', $abuseReport->id);
210
 
211
        return $this->executeUpdate($update);
212
    }
213
 
214
    /**
215
     *
216
     * @param AbuseReport $abuseReport
217
     * @return boolean
218
     */
219
    public function delete($abuseReport)
220
    {
221
        $delete = $this->sql->delete(self::_TABLE);
222
        $delete->where->equalTo('id', $abuseReport->id);
223
 
224
        return $this->executeDelete($delete);
225
 
226
 
227
    }
228
 
229
 
230
}