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