7016 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Mapper;
|
|
|
6 |
|
|
|
7 |
use LeadersLinked\Model\PlanningGoal;
|
|
|
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 PlanningGoalMapper extends MapperCommon
|
|
|
17 |
{
|
|
|
18 |
const _TABLE = 'tbl_planning_goals';
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
*
|
|
|
22 |
* @var PlanningGoalMapper
|
|
|
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\PlanningGoalMapper
|
|
|
39 |
*/
|
|
|
40 |
public static function getInstance($adapter)
|
|
|
41 |
{
|
|
|
42 |
if(self::$_instance == null) {
|
|
|
43 |
self::$_instance = new PlanningGoalMapper($adapter);
|
|
|
44 |
}
|
|
|
45 |
return self::$_instance;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @param int $company_id
|
|
|
53 |
* @param int $period_id
|
|
|
54 |
* @param int $objective_id
|
|
|
55 |
* @param string $search
|
|
|
56 |
* @param int $page
|
|
|
57 |
* @param int $records_per_page
|
|
|
58 |
* @param string $order_field
|
|
|
59 |
* @param string $order_direction
|
|
|
60 |
* @return \Laminas\Paginator\Paginator
|
|
|
61 |
*/
|
|
|
62 |
public function fetchAllDataTableByCompanyIdAndPeriodId($company_id, $period_id, $objective_id, $search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC')
|
|
|
63 |
{
|
|
|
64 |
$prototype = new PlanningGoal();
|
|
|
65 |
$select = $this->sql->select(self::_TABLE);
|
|
|
66 |
$select->where->equalTo('company_id', $company_id);
|
|
|
67 |
$select->where->equalTo('period_id', $period_id);
|
|
|
68 |
$select->where->equalTo('objective_id', $objective_id);
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
if($search) {
|
|
|
72 |
$select->where->like('title', '%' . $search . '%');
|
|
|
73 |
}
|
|
|
74 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
81 |
$resultset = new HydratingResultSet($hydrator, $prototype);
|
|
|
82 |
|
|
|
83 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
84 |
$paginator = new Paginator($adapter);
|
|
|
85 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
86 |
$paginator->setCurrentPageNumber($page);
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
return $paginator;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
*
|
|
|
94 |
* @param int $objective_id
|
|
|
95 |
* @return PlanningGoal[]
|
|
|
96 |
*/
|
|
|
97 |
public function fetchAllByObjectiveId($objective_id)
|
|
|
98 |
{
|
|
|
99 |
$prototype = new PlanningGoal();
|
|
|
100 |
$select = $this->sql->select(self::_TABLE);
|
|
|
101 |
$select->where->equalTo('objective_id', $objective_id);
|
|
|
102 |
$select->order('title');
|
|
|
103 |
|
|
|
104 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
*
|
|
|
111 |
* @param int $objective_id
|
|
|
112 |
* @return PlanningGoal[]
|
|
|
113 |
*/
|
|
|
114 |
public function fetchAllActiveByObjectiveId($objective_id)
|
|
|
115 |
{
|
|
|
116 |
$prototype = new PlanningGoal();
|
|
|
117 |
$select = $this->sql->select(self::_TABLE);
|
|
|
118 |
$select->where->equalTo('objective_id', $objective_id);
|
|
|
119 |
$select->where->equalTo('status', PlanningGoal::STATUS_ACTIVE);
|
|
|
120 |
|
|
|
121 |
$select->order('title');
|
|
|
122 |
|
|
|
123 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/**
|
|
|
130 |
*
|
|
|
131 |
* @param int $company_id
|
|
|
132 |
* @param int $objective_id
|
|
|
133 |
* @return PlanningGoal[]
|
|
|
134 |
*/
|
|
|
135 |
public function fetchAllActiveByCompanyIdAndObjectiveId($company_id, $objective_id)
|
|
|
136 |
{
|
|
|
137 |
$prototype = new PlanningGoal();
|
|
|
138 |
$select = $this->sql->select(self::_TABLE);
|
|
|
139 |
$select->where->equalTo('company_id', $company_id);
|
|
|
140 |
$select->where->equalTo('objective_id', $objective_id);
|
|
|
141 |
$select->where->equalTo('status', PlanningGoal::STATUS_ACTIVE);
|
|
|
142 |
|
|
|
143 |
$select->order('title');
|
|
|
144 |
|
|
|
145 |
// echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
*
|
|
|
154 |
* @param PlanningGoal $record
|
|
|
155 |
* @return boolean
|
|
|
156 |
*/
|
|
|
157 |
public function insert($record)
|
|
|
158 |
{
|
|
|
159 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
160 |
$values = $hydrator->extract($record);
|
|
|
161 |
$values = $this->removeEmpty($values);
|
|
|
162 |
|
|
|
163 |
|
|
|
164 |
$values['budget'] = empty($values['budget']) ? 0 : $values['budget'];
|
|
|
165 |
$values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
|
|
|
166 |
|
|
|
167 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
168 |
$insert->values($values);
|
|
|
169 |
|
|
|
170 |
$result = $this->executeInsert($insert);
|
|
|
171 |
if($result) {
|
|
|
172 |
$record->id = $this->lastInsertId;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
return $result;
|
|
|
176 |
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
*
|
|
|
181 |
* @param PlanningGoal $record
|
|
|
182 |
* @return boolean
|
|
|
183 |
*/
|
|
|
184 |
public function update($record)
|
|
|
185 |
{
|
|
|
186 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
187 |
$values = $hydrator->extract($record);
|
|
|
188 |
$values = $this->removeEmpty($values);
|
|
|
189 |
|
|
|
190 |
$values['budget'] = empty($values['budget']) ? 0 : $values['budget'];
|
|
|
191 |
$values['progress'] = empty($values['progress']) ? 0 : $values['progress'];
|
|
|
192 |
|
|
|
193 |
$update = $this->sql->update(self::_TABLE);
|
|
|
194 |
$update->set($values);
|
|
|
195 |
$update->where->equalTo('id', $record->id);
|
|
|
196 |
return $this->executeUpdate($update);
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
/**
|
|
|
200 |
*
|
|
|
201 |
* @param PlanningGoal $record
|
|
|
202 |
* @return boolean
|
|
|
203 |
*/
|
|
|
204 |
public function delete($record)
|
|
|
205 |
{
|
|
|
206 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
207 |
$delete->where->equalTo('id', $record->id);
|
|
|
208 |
|
|
|
209 |
return $this->executeDelete($delete);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
*
|
|
|
214 |
* @param string $uuid
|
|
|
215 |
* @return PlanningGoal
|
|
|
216 |
*/
|
|
|
217 |
public function fetchOneByUuid($uuid)
|
|
|
218 |
{
|
|
|
219 |
$prototype = new PlanningGoal();
|
|
|
220 |
$select = $this->sql->select(self::_TABLE);
|
|
|
221 |
$select->where->equalTo('uuid', $uuid);
|
|
|
222 |
|
|
|
223 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
}
|