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 20/** 21 * CustomFields Service 22 * @package pim 23 * @todo Rename to CustomFieldsConfigurationService [DONE] 24 * @todo Remove exceptions that only wraps DAO exceptions [DONE] 25 */ 26class CustomFieldConfigurationService extends BaseService { 27 //not sure of the business purpose of the constants, need to check their references 28 const FIELD_TYPE_STRING = 0 ; 29 const FIELD_TYPE_DROP_DOWN = 1 ; 30 const NUMBER_OF_FIELDS = 10 ; 31 32 /** 33 * @ignore 34 * @var CustomFieldConfigurationDao 35 */ 36 private $customFieldsDao; 37 38 /** 39 * Constructor 40 */ 41 public function __construct() { 42 $this->customFieldsDao = new CustomFieldConfigurationDao(); 43 } 44 45 /** 46 * @ignore 47 * 48 * Sets CustomFieldsDao 49 * @param CustomFieldConfigurationDao $customFieldsDao 50 */ 51 public function setCustomFieldsDao(CustomFieldConfigurationDao $customFieldsDao) { 52 $this->customFieldsDao = $customFieldsDao; 53 } 54 55 /** 56 * @ignore 57 * 58 * Returns CustomFieldsDao 59 * @return CustomFieldConfigurationDao 60 */ 61 public function getCustomFieldsDao() { 62 return $this->customFieldsDao; 63 } 64 65 /** 66 * Retrieve Custom Fields 67 * @param String $screen 68 * @param String $orderField 69 * @param String $orderBy 70 * @returns Collection 71 * @throws DaoException 72 * 73 * @todo rename method as searchCustomFieldList( $sortField , $sortOrder, $filters ) [DONE: Won't change. Can be implemented on request] 74 */ 75 public function getCustomFieldList($screen = null, $orderField = "name", $orderBy = "ASC") { 76 return $this->customFieldsDao->getCustomFieldList($screen, $orderField, $orderBy); 77 } 78 79 /** 80 * Save sustom field 81 * 82 * Saves the given custom field object 83 * 84 * @param CustomField $customField 85 * @return CustomField 86 * @throws DaoException, DuplicateNameException 87 * 88 * @todo return saved entity [Done] 89 * @todo rename entity as CustomField [Done] 90 */ 91 public function saveCustomField(CustomField $customField) { 92 93 $customField = $this->customFieldsDao->saveCustomField($customField); 94 95 $reportGeneratorService = new ReportGeneratorService(); 96 $reportGeneratorService->saveCustomDisplayField($customField, "3"); 97 98 return $customField; 99 100 } 101 102 /** 103 * Delete CustomField 104 * @param array $customFieldIdList 105 * @returns integer Number of records deleted 106 * @throws DaoException 107 * 108 * @todo rename method as deleteCustomFields [DONE: There was no change to be done] 109 * @todo return number of items deleted [DONE] 110 */ 111 public function deleteCustomFields($customFieldIdList) { 112 113 $reportGeneratorService = new ReportGeneratorService(); 114 $reportGeneratorService->deleteCustomDisplayFieldList($customFieldIdList); 115 116 return $this->customFieldsDao->deleteCustomFields($customFieldIdList); 117 118 } 119 120 /** 121 * Returns CustomField by Id. This need to be update to retrieve entity object 122 * @param int $id 123 * @return CustomField CustomField object on success and null if not found 124 * @throws DaoException 125 * 126 * @todo rename method as getCustomeField [DONE] 127 */ 128 public function getCustomField($id) { 129 return $this->customFieldsDao->getCustomField($id); 130 } 131 132 /** 133 * @ignore 134 * 135 * Retrievs available field numbers 136 * @returns array() 137 * @throws AdminServiceException 138 * 139 * @todo remove method since it not used any where [DONE] 140 */ 141 /* 142 public function getAvailableFieldNumbers() { 143 144 $availableFields = array(); 145 146 $customFieldList = $this->getCustomFieldList(); 147 for( $i=1 ; $i<= self::NUMBER_OF_FIELDS ; $i++) { 148 $avaliabe = true; 149 foreach( $customFieldList as $customField) { 150 if($customField->getFieldNum() == $i ) { 151 $avaliabe = false; 152 } 153 } 154 if( $avaliabe ) 155 array_push($availableFields,$i); 156 } 157 158 return $availableFields; 159 160 } 161 */ 162 163 164} 165