1635 |
nelberth |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Mapper;
|
|
|
6 |
|
|
|
7 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsViewTopic;
|
|
|
8 |
use LeadersLinked\Mapper\Common\MapperCommon;
|
|
|
9 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
10 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
11 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
12 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
13 |
use Laminas\Paginator\Paginator;
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
class HighPerformanceTeamsGroupsViewTopicMapper extends MapperCommon{
|
|
|
17 |
const _TABLE = 'tbl_high_performance_team_group_topics';
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
*
|
|
|
21 |
* @var HighPerformanceTeamsGroupsViewTopicMapper
|
|
|
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 \LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper
|
|
|
38 |
*/
|
|
|
39 |
public static function getInstance($adapter)
|
|
|
40 |
{
|
|
|
41 |
if(self::$_instance == null) {
|
|
|
42 |
self::$_instance = new HighPerformanceTeamsGroupsViewTopicMapper($adapter);
|
|
|
43 |
}
|
|
|
44 |
return self::$_instance;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $group_id)
|
|
|
50 |
{
|
|
|
51 |
$prototype = new HighPerformanceTeamsGroupsViewTopic();
|
|
|
52 |
$select = $this->sql->select(self::_TABLE);
|
|
|
53 |
$select->where->equalTo('group_id', $group_id);
|
|
|
54 |
$select->where->notEqualTo('status', HighPerformanceTeamsGroupsViewTopic::STATUS_DELETE);
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
if($search) {
|
|
|
58 |
$select->where->like('title', '%' . $search . '%');
|
|
|
59 |
}
|
|
|
60 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
65 |
$resultset = new HydratingResultSet($hydrator, $prototype);
|
|
|
66 |
|
|
|
67 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
68 |
$paginator = new Paginator($adapter);
|
|
|
69 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
70 |
$paginator->setCurrentPageNumber($page);
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
return $paginator;
|
|
|
74 |
}
|
|
|
75 |
|
1650 |
nelberth |
76 |
public function fetchAllByGroup($group_id)
|
1635 |
nelberth |
77 |
{
|
|
|
78 |
$prototype = new HighPerformanceTeamsGroupsViewTopic();
|
|
|
79 |
$select = $this->sql->select(self::_TABLE);
|
|
|
80 |
$select->where->equalTo('group_id', $group_id);
|
|
|
81 |
$select->where->notEqualTo('status', HighPerformanceTeamsGroupsViewTopic::STATUS_DELETE);
|
|
|
82 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
83 |
}
|
|
|
84 |
public function insert($datos)
|
|
|
85 |
{
|
|
|
86 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
87 |
$values = $hydrator->extract($datos);
|
|
|
88 |
$values = $this->removeEmpty($values);
|
|
|
89 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
90 |
$insert->values($values);
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
$result = $this->executeInsert($insert);
|
|
|
94 |
if($result) {
|
|
|
95 |
$datos->id = $this->lastInsertId;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
return $result;
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public function update($form)
|
|
|
103 |
{
|
|
|
104 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
105 |
$values = $hydrator->extract($form);
|
|
|
106 |
$values = $this->removeEmpty($values);
|
|
|
107 |
|
|
|
108 |
$update = $this->sql->update(self::_TABLE);
|
|
|
109 |
$update->set($values);
|
|
|
110 |
$update->where->equalTo('id', $form->id);
|
|
|
111 |
return $this->executeUpdate($update);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public function delete($form_id)
|
|
|
115 |
{
|
|
|
116 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
117 |
$delete->where->equalTo('id', $form_id);
|
|
|
118 |
|
|
|
119 |
return $this->executeDelete($delete);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
public function fetchOneByUuid($uuid)
|
|
|
123 |
{
|
|
|
124 |
$prototype = new HighPerformanceTeamsGroupsViewTopic();
|
|
|
125 |
$select = $this->sql->select(self::_TABLE);
|
|
|
126 |
$select->where->equalTo('uuid', $uuid);
|
|
|
127 |
|
|
|
128 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
}
|