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 ohrmWidgetEmployeeList extends sfWidgetForm implements ohrmEmbeddableWidget { 21 use ohrmWidgetTrait; 22 23 private $whereClauseCondition; 24 25 public function configure($options = array(), $attributes = array()) { 26 27 $employeeNameList = $this->_getEmployeeList(); 28 29 $this->addOption('choices', $employeeNameList); 30 } 31 32 public function render($name, $value = null, $attributes = array(), $errors = array()) { 33 $value = $value === null ? 'null' : $value; 34 35 $options = array(); 36 37 foreach ($this->getOption('choices') as $key => $option) { 38 $attributes = array('value' => self::escapeOnce($key)); 39 40 $options[] = $this->renderContentTag( 41 'option', 42 self::escapeOnce($option), 43 $attributes 44 ); 45 } 46 47 return $this->renderContentTag( 48 'select', 49 "\n" . implode("\n", $options) . "\n", 50 array_merge(array('name' => $name), $attributes 51 )); 52 } 53 54 /** 55 * Gets all the names of available projects, including deleted projects. 56 * @return array() $projectNameList 57 */ 58 private function _getEmployeeList() { 59 60 $employeeNameList = array(); 61 62 $userObj = sfContext::getInstance()->getUser()->getAttribute("user"); 63 $employeeList = $userObj->getEmployeeList(); 64 65 if ($employeeList != null) { 66 foreach ($employeeList as $employee) { 67 68 $employeeNameList[$employee->getEmpNumber()] = $employee->getEmpFirstname() . " " . $employee->getEmpLastname(); 69 } 70 } else { 71 $employeeNameList[null] = "--No Employee--"; 72 } 73 74 return $employeeNameList; 75 } 76 77 /** 78 * Embeds this widget into the form. Sets label and validator for this widget. 79 * @param sfForm $form 80 */ 81 public function embedWidgetIntoForm(sfForm &$form) { 82 83 $widgetSchema = $form->getWidgetSchema(); 84 $widgetSchema[$this->attributes['id']] = $this; 85 $label = ucwords(str_replace("_", " ", $this->attributes['id'])); 86 $validator = new sfValidatorString(); 87 if ($this->attributes['required'] == "true") { 88 $label .= "<span class='required'> * </span>"; 89 $validator = new sfValidatorString(array('required' => true), array('required' => 'No employees added to the system')); 90 } 91 $widgetSchema[$this->attributes['id']]->setLabel($label); 92 $form->setValidator($this->attributes['id'], $validator); 93 } 94 95 /** 96 * Sets whereClauseCondition. 97 * @param string $condition 98 */ 99 public function setWhereClauseCondition($condition) { 100 101 $this->whereClauseCondition = $condition; 102 } 103 104 /** 105 * Gets whereClauseCondition. ( if whereClauseCondition is set returns that, else returns default condition ) 106 * @return string ( a condition ) 107 */ 108 public function getWhereClauseCondition() { 109 110 if (isset($this->whereClauseCondition)) { 111 $setCondition = $this->whereClauseCondition; 112 return $setCondition; 113 } else { 114 $defaultCondition = "="; 115 return $defaultCondition; 116 } 117 } 118 119 /** 120 * This method generates the where clause part. 121 * @param string $fieldName 122 * @param string $value 123 * @return string 124 */ 125 public function generateWhereClausePart($fieldName, $value) { 126 127 $whereClausePart = $fieldName . " " . $this->getWhereClauseCondition() . " " . $this->getEscapedString($value); 128 129 return $whereClausePart; 130 } 131 132} 133 134