/src/plugins/orangehrmRESTPlugin/lib/Api/Leave/Entity/LeaveRequest.php

https://github.com/orangehrm/OrangeHRM · PHP · 386 lines · 206 code · 53 blank · 127 comment · 1 complexity · 488d7efe41a76808cfcc03a740dd2407 MD5 · raw file

  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. */
  19. namespace Orangehrm\Rest\Api\Leave\Entity;
  20. use Orangehrm\Rest\Api\Entity\Serializable;
  21. class LeaveRequest implements Serializable
  22. {
  23. /**
  24. * @var
  25. */
  26. private $appliedDate;
  27. private $employeeName;
  28. private $leaveType;
  29. private $leaveBalance;
  30. private $numberOfDays;
  31. private $status;
  32. private $comments;
  33. private $id;
  34. private $action;
  35. private $empId;
  36. private $fromDate;
  37. private $toDate;
  38. private $date;
  39. private $duration;
  40. private $days;
  41. private $leaveBreakdown;
  42. /**
  43. * LeaveType constructor.
  44. *
  45. * @param $id
  46. * @param $type
  47. */
  48. public function __construct($id, $type)
  49. {
  50. $this->setId($id);
  51. $this->setLeaveType($type);
  52. return $this;
  53. }
  54. /**
  55. * @return mixed
  56. */
  57. public function getFromDate()
  58. {
  59. return $this->fromDate;
  60. }
  61. /**
  62. * @param mixed $fromDate
  63. */
  64. public function setFromDate($fromDate)
  65. {
  66. $this->fromDate = $fromDate;
  67. }
  68. /**
  69. * @return mixed
  70. */
  71. public function getDate()
  72. {
  73. return $this->date;
  74. }
  75. /**
  76. * @param mixed $fromDate
  77. */
  78. public function setDate($date)
  79. {
  80. $this->date = $date;
  81. }
  82. /**
  83. * @return mixed
  84. */
  85. public function getToDate()
  86. {
  87. return $this->toDate;
  88. }
  89. /**
  90. * @param mixed $toDate
  91. */
  92. public function setToDate($toDate)
  93. {
  94. $this->toDate = $toDate;
  95. }
  96. /**
  97. * @return mixed
  98. */
  99. public function getAppliedDate()
  100. {
  101. return $this->appliedDate;
  102. }
  103. /**
  104. * @param mixed $date
  105. */
  106. public function setAppliedDate($date)
  107. {
  108. $this->appliedDate = $date;
  109. }
  110. /**
  111. * @return mixed
  112. */
  113. public function getEmployeeName()
  114. {
  115. return $this->employeeName;
  116. }
  117. /**
  118. * @param mixed $employeeName
  119. */
  120. public function setEmployeeName($employeeName)
  121. {
  122. $this->employeeName = $employeeName;
  123. }
  124. /**
  125. * @return mixed
  126. */
  127. public function getLeaveType()
  128. {
  129. return $this->leaveType;
  130. }
  131. /**
  132. * @param mixed $leaveType
  133. */
  134. public function setLeaveType($leaveType)
  135. {
  136. $this->leaveType = $leaveType;
  137. }
  138. /**
  139. * @return mixed
  140. */
  141. public function getLeaveBalance()
  142. {
  143. return $this->leaveBalance;
  144. }
  145. /**
  146. * @param mixed $leaveBalance
  147. */
  148. public function setLeaveBalance($leaveBalance)
  149. {
  150. $this->leaveBalance = $leaveBalance;
  151. }
  152. /**
  153. * @return mixed
  154. */
  155. public function getNumberOfDays()
  156. {
  157. return $this->numberOfDays;
  158. }
  159. /**
  160. * @param mixed $numberOfDays
  161. */
  162. public function setNumberOfDays($numberOfDays)
  163. {
  164. $this->numberOfDays = $numberOfDays;
  165. }
  166. /**
  167. * @return mixed
  168. */
  169. public function getStatus()
  170. {
  171. return $this->status;
  172. }
  173. /**
  174. * @param mixed $status
  175. */
  176. public function setStatus($status)
  177. {
  178. $this->status = $status;
  179. }
  180. /**
  181. * @return mixed
  182. */
  183. public function getComments()
  184. {
  185. return $this->comments;
  186. }
  187. /**
  188. * @param mixed $comments
  189. */
  190. public function setComments($comments)
  191. {
  192. $this->comments = $comments;
  193. }
  194. /**
  195. * @return mixed
  196. */
  197. public function getId()
  198. {
  199. return $this->id;
  200. }
  201. /**
  202. * @param mixed $id
  203. */
  204. public function setId($id)
  205. {
  206. $this->id = $id;
  207. }
  208. /**
  209. * @return mixed
  210. */
  211. public function getAction()
  212. {
  213. return $this->action;
  214. }
  215. /**
  216. * @param mixed $action
  217. */
  218. public function setAction($action)
  219. {
  220. $this->action = $action;
  221. }
  222. /**
  223. * @return mixed
  224. */
  225. public function getEmpId()
  226. {
  227. return $this->empId;
  228. }
  229. /**
  230. * @param mixed $empId
  231. */
  232. public function setEmpId($empId)
  233. {
  234. $this->empId = $empId;
  235. }
  236. /**
  237. * @return mixed
  238. */
  239. public function getDuration()
  240. {
  241. return $this->duration;
  242. }
  243. /**
  244. * @param mixed $duration
  245. */
  246. public function setDuration($duration)
  247. {
  248. $this->duration = $duration;
  249. }
  250. /**
  251. * @return mixed
  252. */
  253. public function getDays()
  254. {
  255. return $this->days;
  256. }
  257. /**
  258. * @param mixed $days
  259. */
  260. public function setDays($days)
  261. {
  262. $this->days = $days;
  263. }
  264. /**
  265. * @return string
  266. */
  267. public function getLeaveBreakdown()
  268. {
  269. return $this->leaveBreakdown;
  270. }
  271. /**
  272. * @param string $leaveBreakDown
  273. */
  274. public function setLeaveBreakdown($leaveBreakDown)
  275. {
  276. $this->leaveBreakdown = $leaveBreakDown;
  277. }
  278. public function toArray()
  279. {
  280. return array(
  281. 'employeeName' => $this->getEmployeeName(),
  282. 'employeeId' => $this->getEmpId(),
  283. 'id' => $this->getId(),
  284. 'fromDate' => $this->getFromDate(),
  285. 'toDate' => $this->getToDate(),
  286. 'type' => $this->getLeaveType(),
  287. 'leaveBalance' => $this->getLeaveBalance(),
  288. 'numberOfDays' => $this->getNumberOfDays(),
  289. 'comments' => $this->getComments(),
  290. 'days' => $this->getDays()
  291. );
  292. }
  293. /**
  294. * build
  295. *
  296. * @param \LeaveRequest $leaveRequest
  297. */
  298. public function buildLeaveRequest(\LeaveRequest $leaveRequest)
  299. {
  300. $this->setAppliedDate($leaveRequest->getDateApplied());
  301. $leaveDates = $leaveRequest->getLeaveStartAndEndDate();
  302. $this->setFromDate($leaveDates[0]);
  303. $this->setToDate($leaveDates[1]);
  304. $this->setLeaveBalance(number_format((float)$leaveRequest->getLeaveBalance(), 2, '.', ''));
  305. $this->setNumberOfDays($leaveRequest->getNumberOfDays());
  306. $this->setEmployeeName($leaveRequest->getEmployee()->getFullName());
  307. $this->setEmpId($leaveRequest->getEmpNumber());
  308. $this->setLeaveType($leaveRequest->getLeaveTypeName());
  309. $commentsList = [];
  310. if (!empty($leaveRequest->getLeaveRequestComment())) {
  311. foreach ($leaveRequest->getLeaveRequestComment() as $comment) {
  312. $datetime = explode(" ", $comment->getCreated());
  313. $leaveComment = new LeaveRequestComment($comment->getCreatedByName(), $datetime[0],
  314. $datetime[1], $comment->getComments());
  315. $commentsList[] = $leaveComment->toArray();
  316. }
  317. }
  318. $this->setComments($commentsList);
  319. $days = null;
  320. foreach ($leaveRequest->getLeave() as $leave) {
  321. $leaveEntity = new Leave();
  322. $leaveEntity->buildLeave($leave);
  323. $days[] = $leaveEntity->toArray();
  324. }
  325. $this->setDays($days);
  326. $this->setLeaveBreakdown($leaveRequest->getLeaveBreakdown());
  327. }
  328. protected function getStatusText($statusId)
  329. {
  330. $statusList = \Leave::getStatusTextList();
  331. return $statusList[$statusId];
  332. }
  333. }