1<?php
2
3/**
4 * Employee form base class.
5 *
6 * @method Employee getObject() Returns the current form's model object
7 *
8 * @package    orangehrm
9 * @subpackage form
10 * @author     Your name here
11 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
12 */
13abstract class BaseEmployeeForm extends BaseFormDoctrine
14{
15  public function setup()
16  {
17    $this->setWidgets(array(
18      'empNumber'             => new sfWidgetFormInputHidden(),
19      'lastName'              => new sfWidgetFormInputText(),
20      'firstName'             => new sfWidgetFormInputText(),
21      'middleName'            => new sfWidgetFormInputText(),
22      'nickName'              => new sfWidgetFormInputText(),
23      'smoker'                => new sfWidgetFormInputText(),
24      'ssn'                   => new sfWidgetFormInputText(),
25      'sin'                   => new sfWidgetFormInputText(),
26      'otherId'               => new sfWidgetFormInputText(),
27      'licenseNo'             => new sfWidgetFormInputText(),
28      'militaryService'       => new sfWidgetFormInputText(),
29      'street1'               => new sfWidgetFormInputText(),
30      'street2'               => new sfWidgetFormInputText(),
31      'city'                  => new sfWidgetFormInputText(),
32      'country'               => new sfWidgetFormInputText(),
33      'province'              => new sfWidgetFormInputText(),
34      'employeeId'            => new sfWidgetFormInputText(),
35      'ethnic_race_code'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('EthnicRace'), 'add_empty' => true)),
36      'emp_birthday'          => new sfWidgetFormDate(),
37      'nation_code'           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Nationality'), 'add_empty' => true)),
38      'emp_gender'            => new sfWidgetFormInputText(),
39      'emp_marital_status'    => new sfWidgetFormInputText(),
40      'emp_dri_lice_exp_date' => new sfWidgetFormDate(),
41      'emp_status'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('employeeStatus'), 'add_empty' => true)),
42      'job_title_code'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('jobTitle'), 'add_empty' => true)),
43      'eeo_cat_code'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('JobCategory'), 'add_empty' => true)),
44      'work_station'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('subDivision'), 'add_empty' => true)),
45      'emp_zipcode'           => new sfWidgetFormInputText(),
46      'emp_hm_telephone'      => new sfWidgetFormInputText(),
47      'emp_mobile'            => new sfWidgetFormInputText(),
48      'emp_work_telephone'    => new sfWidgetFormInputText(),
49      'emp_work_email'        => new sfWidgetFormInputText(),
50      'sal_grd_code'          => new sfWidgetFormInputText(),
51      'joined_date'           => new sfWidgetFormDate(),
52      'emp_oth_email'         => new sfWidgetFormInputText(),
53      'terminated_date'       => new sfWidgetFormDate(),
54      'termination_reason'    => new sfWidgetFormTextarea(),
55      'custom1'               => new sfWidgetFormInputText(),
56      'custom2'               => new sfWidgetFormInputText(),
57      'custom3'               => new sfWidgetFormInputText(),
58      'custom4'               => new sfWidgetFormInputText(),
59      'custom5'               => new sfWidgetFormInputText(),
60      'custom6'               => new sfWidgetFormInputText(),
61      'custom7'               => new sfWidgetFormInputText(),
62      'custom8'               => new sfWidgetFormInputText(),
63      'custom9'               => new sfWidgetFormInputText(),
64      'custom10'              => new sfWidgetFormInputText(),
65      'supervisors_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Employee')),
66      'locations_list'        => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Location')),
67      'subordinates_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Employee')),
68    ));
69
70    $this->setValidators(array(
71      'empNumber'             => new sfValidatorChoice(array('choices' => array($this->getObject()->get('empNumber')), 'empty_value' => $this->getObject()->get('empNumber'), 'required' => false)),
72      'lastName'              => new sfValidatorString(array('max_length' => 100, 'required' => false)),
73      'firstName'             => new sfValidatorString(array('max_length' => 100, 'required' => false)),
74      'middleName'            => new sfValidatorString(array('max_length' => 100, 'required' => false)),
75      'nickName'              => new sfValidatorString(array('max_length' => 100, 'required' => false)),
76      'smoker'                => new sfValidatorInteger(array('required' => false)),
77      'ssn'                   => new sfValidatorString(array('max_length' => 100, 'required' => false)),
78      'sin'                   => new sfValidatorString(array('max_length' => 100, 'required' => false)),
79      'otherId'               => new sfValidatorString(array('max_length' => 100, 'required' => false)),
80      'licenseNo'             => new sfValidatorString(array('max_length' => 100, 'required' => false)),
81      'militaryService'       => new sfValidatorString(array('max_length' => 100, 'required' => false)),
82      'street1'               => new sfValidatorString(array('max_length' => 100, 'required' => false)),
83      'street2'               => new sfValidatorString(array('max_length' => 100, 'required' => false)),
84      'city'                  => new sfValidatorString(array('max_length' => 100, 'required' => false)),
85      'country'               => new sfValidatorString(array('max_length' => 100, 'required' => false)),
86      'province'              => new sfValidatorString(array('max_length' => 100, 'required' => false)),
87      'employeeId'            => new sfValidatorString(array('max_length' => 50, 'required' => false)),
88      'ethnic_race_code'      => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('EthnicRace'), 'required' => false)),
89      'emp_birthday'          => new sfValidatorDate(array('required' => false)),
90      'nation_code'           => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Nationality'), 'required' => false)),
91      'emp_gender'            => new sfValidatorInteger(array('required' => false)),
92      'emp_marital_status'    => new sfValidatorString(array('max_length' => 20, 'required' => false)),
93      'emp_dri_lice_exp_date' => new sfValidatorDate(array('required' => false)),
94      'emp_status'            => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('employeeStatus'), 'required' => false)),
95      'job_title_code'        => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('jobTitle'), 'required' => false)),
96      'eeo_cat_code'          => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('JobCategory'), 'required' => false)),
97      'work_station'          => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('subDivision'), 'required' => false)),
98      'emp_zipcode'           => new sfValidatorString(array('max_length' => 20, 'required' => false)),
99      'emp_hm_telephone'      => new sfValidatorString(array('max_length' => 50, 'required' => false)),
100      'emp_mobile'            => new sfValidatorString(array('max_length' => 50, 'required' => false)),
101      'emp_work_telephone'    => new sfValidatorString(array('max_length' => 50, 'required' => false)),
102      'emp_work_email'        => new sfValidatorString(array('max_length' => 50, 'required' => false)),
103      'sal_grd_code'          => new sfValidatorString(array('max_length' => 13, 'required' => false)),
104      'joined_date'           => new sfValidatorDate(array('required' => false)),
105      'emp_oth_email'         => new sfValidatorString(array('max_length' => 50, 'required' => false)),
106      'terminated_date'       => new sfValidatorDate(array('required' => false)),
107      'termination_reason'    => new sfValidatorString(array('max_length' => 256, 'required' => false)),
108      'custom1'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
109      'custom2'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
110      'custom3'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
111      'custom4'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
112      'custom5'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
113      'custom6'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
114      'custom7'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
115      'custom8'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
116      'custom9'               => new sfValidatorString(array('max_length' => 250, 'required' => false)),
117      'custom10'              => new sfValidatorString(array('max_length' => 250, 'required' => false)),
118      'supervisors_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Employee', 'required' => false)),
119      'locations_list'        => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Location', 'required' => false)),
120      'subordinates_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Employee', 'required' => false)),
121    ));
122
123    $this->widgetSchema->setNameFormat('employee[%s]');
124
125    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
126
127    $this->setupInheritance();
128
129    parent::setup();
130  }
131
132  public function getModelName()
133  {
134    return 'Employee';
135  }
136
137  public function updateDefaultsFromObject()
138  {
139    parent::updateDefaultsFromObject();
140
141    if (isset($this->widgetSchema['supervisors_list']))
142    {
143      $this->setDefault('supervisors_list', $this->object->supervisors->getPrimaryKeys());
144    }
145
146    if (isset($this->widgetSchema['locations_list']))
147    {
148      $this->setDefault('locations_list', $this->object->locations->getPrimaryKeys());
149    }
150
151    if (isset($this->widgetSchema['subordinates_list']))
152    {
153      $this->setDefault('subordinates_list', $this->object->subordinates->getPrimaryKeys());
154    }
155
156  }
157
158  protected function doSave($con = null)
159  {
160    $this->savesupervisorsList($con);
161    $this->savelocationsList($con);
162    $this->savesubordinatesList($con);
163
164    parent::doSave($con);
165  }
166
167  public function savesupervisorsList($con = null)
168  {
169    if (!$this->isValid())
170    {
171      throw $this->getErrorSchema();
172    }
173
174    if (!isset($this->widgetSchema['supervisors_list']))
175    {
176      // somebody has unset this widget
177      return;
178    }
179
180    if (null === $con)
181    {
182      $con = $this->getConnection();
183    }
184
185    $existing = $this->object->supervisors->getPrimaryKeys();
186    $values = $this->getValue('supervisors_list');
187    if (!is_array($values))
188    {
189      $values = array();
190    }
191
192    $unlink = array_diff($existing, $values);
193    if (count($unlink))
194    {
195      $this->object->unlink('supervisors', array_values($unlink));
196    }
197
198    $link = array_diff($values, $existing);
199    if (count($link))
200    {
201      $this->object->link('supervisors', array_values($link));
202    }
203  }
204
205  public function savelocationsList($con = null)
206  {
207    if (!$this->isValid())
208    {
209      throw $this->getErrorSchema();
210    }
211
212    if (!isset($this->widgetSchema['locations_list']))
213    {
214      // somebody has unset this widget
215      return;
216    }
217
218    if (null === $con)
219    {
220      $con = $this->getConnection();
221    }
222
223    $existing = $this->object->locations->getPrimaryKeys();
224    $values = $this->getValue('locations_list');
225    if (!is_array($values))
226    {
227      $values = array();
228    }
229
230    $unlink = array_diff($existing, $values);
231    if (count($unlink))
232    {
233      $this->object->unlink('locations', array_values($unlink));
234    }
235
236    $link = array_diff($values, $existing);
237    if (count($link))
238    {
239      $this->object->link('locations', array_values($link));
240    }
241  }
242
243  public function savesubordinatesList($con = null)
244  {
245    if (!$this->isValid())
246    {
247      throw $this->getErrorSchema();
248    }
249
250    if (!isset($this->widgetSchema['subordinates_list']))
251    {
252      // somebody has unset this widget
253      return;
254    }
255
256    if (null === $con)
257    {
258      $con = $this->getConnection();
259    }
260
261    $existing = $this->object->subordinates->getPrimaryKeys();
262    $values = $this->getValue('subordinates_list');
263    if (!is_array($values))
264    {
265      $values = array();
266    }
267
268    $unlink = array_diff($existing, $values);
269    if (count($unlink))
270    {
271      $this->object->unlink('subordinates', array_values($unlink));
272    }
273
274    $link = array_diff($values, $existing);
275    if (count($link))
276    {
277      $this->object->link('subordinates', array_values($link));
278    }
279  }
280
281}
282