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 *
20 */
21class PayGradeForm extends BaseForm {
22
23	private $payGradeId;
24	protected $payGradeService;
25        protected $currencyService;
26
27	/**
28	 * Get CurrencyService
29	 * @returns CurrencyService
30	 */
31	public function getCurrencyService() {
32		if (is_null($this->currencyService)) {
33			$this->currencyService = new CurrencyService();
34		}
35		return $this->currencyService;
36	}
37
38	public function getPayGradeService() {
39		if (is_null($this->payGradeService)) {
40			$this->payGradeService = new PayGradeService();
41			$this->payGradeService->setPayGradeDao(new PayGradeDao());
42		}
43		return $this->payGradeService;
44	}
45
46	public function configure() {
47
48		$this->payGradeId = $this->getOption('payGradeId');
49
50		$this->setWidgets(array(
51		    'payGradeId' => new sfWidgetFormInputHidden(),
52		    'name' => new sfWidgetFormInputText(),
53		));
54
55		$this->setValidators(array(
56		    'payGradeId' => new sfValidatorNumber(array('required' => false)),
57		    'name' => new sfValidatorString(array('required' => true, 'max_length' => 52)),
58		));
59
60		$this->widgetSchema->setNameFormat('payGrade[%s]');
61
62		if ($this->payGradeId != null) {
63			$this->setDefaultValues($this->payGradeId);
64		}
65        $this->getWidgetSchema()->setLabels($this->getFormLabels());
66
67	}
68
69	private function setDefaultValues($payGradeId) {
70
71		$payGrade = $this->getPayGradeService()->getPayGradeById($payGradeId);
72		$this->setDefault('payGradeId', $payGradeId);
73		$this->setDefault('name', $payGrade->getName());
74	}
75
76	public function save() {
77		$payGradeId = $this->getValue('payGradeId');
78
79		if (!empty($payGradeId)) {
80			$payGrade = $this->getPayGradeService()->getPayGradeById($payGradeId);
81		} else {
82			$payGrade = new PayGrade();
83		}
84		$payGrade->setName($this->getValue('name'));
85		$payGrade->save();
86
87		return $payGrade->getId();
88	}
89
90	public function getCurrencyListAsJson() {
91
92		$list = array();
93		$currencies = $this->getCurrencyService()->getCurrencyList();
94		foreach ($currencies as $currency) {
95			$list[] = array('id' => $currency->getCurrencyId(), 'name' => $currency->getCurrencyId()." - ".__($currency->getCurrencyName()));
96		}
97		return json_encode($list);
98	}
99
100	public function getPayGradeListAsJson() {
101
102		$list = array();
103		$payGrades = $this->getPayGradeService()->getPayGradeList();
104		foreach ($payGrades as $payGrade) {
105			$list[] = array('id' => $payGrade->getId(), 'name' => $payGrade->getName());
106		}
107		return json_encode($list);
108	}
109
110	public function getAssignedCurrencyListAsJson($payGradeId) {
111
112		$list = array();
113		$currencies = $this->getPayGradeService()->getCurrencyListByPayGradeId($payGradeId);
114		foreach ($currencies as $currency) {
115			$list[] = array('id' => $currency->getCurrencyId(), 'name' => $currency->getCurrencyId()." - ".__($currency->getCurrencyType()->getCurrencyName()));
116		}
117		return json_encode($list);
118	}
119
120    /**
121     *
122     * @return string
123     */
124    public function getFormLabels() {
125        $requiredMarker = ' <em>*</em>';
126        $labels = array(
127            'name' => __('Name') . $requiredMarker,
128        );
129        return $labels;
130    }
131}
132
133?>
134