1<?php
2
3/**
4 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
5 * all the essential functionalities required for any enterprise.
6 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
7 *
8 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
9 * the GNU General Public License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with this program;
17 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA  02110-1301, USA
19 */
20class deletePayGradesAction extends baseAdminAction {
21
22    private $payGradeService;
23
24    public function getPayGradeService() {
25        if (is_null($this->payGradeService)) {
26            $this->payGradeService = new PayGradeService();
27            $this->payGradeService->setPayGradeDao(new PayGradeDao());
28        }
29        return $this->payGradeService;
30    }
31
32    public function execute($request) {
33
34        $payGradePermissions = $this->getDataGroupPermissions('pay_grades');
35
36        if ($payGradePermissions->canDelete()) {
37
38            $form = new DefaultListForm();
39            $form->bind($request->getParameter($form->getName()));
40
41            if ($form->isValid()) {
42                $toBeDeletedPayGradeIds = $request->getParameter('chkSelectRow');
43                if (!empty($toBeDeletedPayGradeIds)) {
44
45                    foreach ($toBeDeletedPayGradeIds as $toBeDeletedPayGradeId) {
46
47                        $payGrade = $this->getPayGradeService()->getPayGradeById($toBeDeletedPayGradeId);
48                        if ($payGrade instanceof PayGrade) {
49                            $payGrade->delete();
50                        }
51                    }
52                    $this->getUser()->setFlash('success', __(TopLevelMessages::DELETE_SUCCESS));
53                }
54            } else {
55                $this->handleBadRequest();
56                $this->forwardToSecureAction();
57            }
58
59            $this->redirect('admin/viewPayGrades');
60        }
61    }
62
63}
64
65