getOptions( $name ); break; case 'columns': $retval = [ '-1010-first_name' => TTi18n::gettext( 'First Name' ), '-1020-last_name' => TTi18n::gettext( 'Last Name' ), '-2050-qualification' => TTi18n::gettext( 'License Type' ), '-2040-group' => TTi18n::gettext( 'Group' ), '-3080-license_number' => TTi18n::gettext( 'License Number' ), '-3090-license_issued_date' => TTi18n::gettext( 'Issued Date' ), '-4000-license_expiry_date' => TTi18n::gettext( 'Expiry Date' ), '-1300-tag' => TTi18n::gettext( 'Tags' ), '-1090-title' => TTi18n::gettext( 'Title' ), '-1099-user_group' => TTi18n::gettext( 'Employee Group' ), '-1100-default_branch' => TTi18n::gettext( 'Branch' ), '-1110-default_department' => TTi18n::gettext( 'Department' ), '-2000-created_by' => TTi18n::gettext( 'Created By' ), '-2010-created_date' => TTi18n::gettext( 'Created Date' ), '-2020-updated_by' => TTi18n::gettext( 'Updated By' ), '-2030-updated_date' => TTi18n::gettext( 'Updated Date' ), ]; break; case 'list_columns': $retval = Misc::arrayIntersectByKey( $this->getOptions( 'default_display_columns' ), Misc::trimSortPrefix( $this->getOptions( 'columns' ) ) ); break; case 'default_display_columns': //Columns that are displayed by default. $retval = [ 'first_name', 'last_name', 'qualification', 'license_number', 'license_issued_date', 'license_expiry_date', ]; break; } return $retval; } /** * @param $data * @return array */ function _getVariableToFunctionMap( $data ) { $variable_function_map = [ 'id' => 'ID', 'user_id' => 'User', 'first_name' => false, 'last_name' => false, 'qualification_id' => 'Qualification', 'qualification' => false, 'group' => false, 'license_number' => 'LicenseNumber', 'license_issued_date' => 'LicenseIssuedDate', 'license_expiry_date' => 'LicenseExpiryDate', 'tag' => 'Tag', 'default_branch' => false, 'default_department' => false, 'user_group' => false, 'title' => false, 'deleted' => 'Deleted', ]; return $variable_function_map; } /** * @return bool */ function getQualificationObject() { return $this->getGenericObject( 'QualificationListFactory', $this->getQualification(), 'qualification_obj' ); } /** * @return bool|mixed */ function getUser() { return $this->getGenericDataValue( 'user_id' ); } /** * @param string $value UUID * @return bool */ function setUser( $value ) { $value = TTUUID::castUUID( $value ); return $this->setGenericDataValue( 'user_id', $value ); } /** * @return bool */ function getQualification() { return $this->getGenericDataValue( 'qualification_id' ); } /** * @param string $value UUID * @return bool */ function setQualification( $value ) { $value = TTUUID::castUUID( $value ); return $this->setGenericDataValue( 'qualification_id', $value ); } /** * @return bool */ function getLicenseNumber() { return $this->getGenericDataValue( 'license_number' ); } /** * @param $value * @return bool */ function setLicenseNumber( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'license_number', $value ); } /** * @return bool|int */ function getLicenseIssuedDate() { return (int)$this->getGenericDataValue( 'license_issued_date' ); } /** * @param int $value EPOCH * @return bool */ function setLicenseIssuedDate( $value ) { $value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings. return $this->setGenericDataValue( 'license_issued_date', $value ); } /** * @return bool|int */ function getLicenseExpiryDate() { return (int)$this->getGenericDataValue( 'license_expiry_date' ); } /** * @param int $value EPOCH * @return bool */ function setLicenseExpiryDate( $value ) { $value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings. return $this->setGenericDataValue( 'license_expiry_date', $value ); } /** * @return bool|string */ function getTag() { //Check to see if any temporary data is set for the tags, if not, make a call to the database instead. //postSave() needs to get the tmp_data. $value = $this->getGenericTempDataValue( 'tags' ); if ( $value !== false ) { return $value; } else if ( is_object( $this->getQualificationObject() ) && TTUUID::isUUID( $this->getQualificationObject()->getCompany() ) && $this->getQualificationObject()->getCompany() != TTUUID::getZeroID() && $this->getQualificationObject()->getCompany() != TTUUID::getNotExistID() && TTUUID::isUUID( $this->getID() ) && $this->getID() != TTUUID::getZeroID() && $this->getID() != TTUUID::getNotExistID() ) { return CompanyGenericTagMapListFactory::getStringByCompanyIDAndObjectTypeIDAndObjectID( $this->getQualificationObject()->getCompany(), 253, $this->getID() ); } return false; } /** * @param $value * @return bool */ function setTag( $value ) { $value = trim( $value ); //Save the tags in temporary memory to be committed in postSave() return $this->setGenericTempDataValue( 'tags', $value ); } /** * @param bool $ignore_warning * @return bool */ function Validate( $ignore_warning = true ) { // // BELOW: Validation code moved from set*() functions. // // Employee if ( $this->getUser() !== false ) { $ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */ $this->Validator->isResultSetWithRows( 'user_id', $ulf->getByID( $this->getUser() ), TTi18n::gettext( 'Employee must be specified' ) ); } // Qualification if ( $this->getQualification() !== false ) { $qlf = TTnew( 'QualificationListFactory' ); /** @var QualificationListFactory $qlf */ $this->Validator->isResultSetWithRows( 'qualification_id', $qlf->getById( $this->getQualification() ), TTi18n::gettext( 'License must be specified' ) ); } // License number if ( $this->getLicenseNumber() != '' ) { $this->Validator->isRegEx( 'license_number', $this->getLicenseNumber(), TTi18n::gettext( 'License number is invalid' ), $this->license_number_validator_regex //This should match the same validation as JobApplicantLicenseFactory ); } // License issued date if ( $this->getLicenseIssuedDate() != '' ) { $this->Validator->isDate( 'license_issued_date', $this->getLicenseIssuedDate(), TTi18n::gettext( 'Incorrect license issued date' ) ); } // License expiry date if ( $this->getLicenseExpiryDate() != '' ) { $this->Validator->isDate( 'license_expiry_date', $this->getLicenseExpiryDate(), TTi18n::gettext( 'Incorrect license expiry date' ) ); } // // ABOVE: Validation code moved from set*() functions. // return true; } /** * @return bool */ function postSave() { $this->removeCache( $this->getId() ); $this->removeCache( $this->getUser() . $this->getQualification() ); if ( $this->getDeleted() == false ) { Debug::text( 'Setting Tags...', __FILE__, __LINE__, __METHOD__, 10 ); CompanyGenericTagMapFactory::setTags( $this->getQualificationObject()->getCompany(), 253, $this->getID(), $this->getTag() ); } return true; } /** * @param $data * @return bool */ function setObjectFromArray( $data ) { if ( is_array( $data ) ) { $variable_function_map = $this->getVariableToFunctionMap(); foreach ( $variable_function_map as $key => $function ) { if ( isset( $data[$key] ) ) { $function = 'set' . $function; switch ( $key ) { case 'license_issued_date': $this->setLicenseIssuedDate( TTDate::parseDateTime( $data['license_issued_date'] ) ); break; case 'license_expiry_date': $this->setLicenseExpiryDate( TTDate::parseDateTime( $data['license_expiry_date'] ) ); break; default: if ( method_exists( $this, $function ) ) { $this->$function( $data[$key] ); } break; } } } $this->setCreatedAndUpdatedColumns( $data ); return true; } return false; } /** * @param null $include_columns * @param bool $permission_children_ids * @return array */ function getObjectAsArray( $include_columns = null, $permission_children_ids = false ) { $data = []; $variable_function_map = $this->getVariableToFunctionMap(); if ( is_array( $variable_function_map ) ) { foreach ( $variable_function_map as $variable => $function_stub ) { if ( $include_columns == null || ( isset( $include_columns[$variable] ) && $include_columns[$variable] == true ) ) { $function = 'get' . $function_stub; switch ( $variable ) { case 'qualification': case 'group': case 'first_name': case 'last_name': case 'title': case 'user_group': case 'default_branch': case 'default_department': $data[$variable] = $this->getColumn( $variable ); break; case 'license_issued_date': $data['license_issued_date'] = TTDate::getAPIDate( 'DATE', $this->getLicenseIssuedDate() ); break; case 'license_expiry_date': $data['license_expiry_date'] = TTDate::getAPIDate( 'DATE', $this->getLicenseExpiryDate() ); break; default: if ( method_exists( $this, $function ) ) { $data[$variable] = $this->$function(); } break; } } } $this->getPermissionColumns( $data, $this->getUser(), $this->getCreatedBy(), $permission_children_ids, $include_columns ); $this->getCreatedAndUpdatedColumns( $data, $include_columns ); } return $data; } /** * @param $log_action * @return bool */ function addLog( $log_action ) { return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'License' ), null, $this->getTable(), $this ); } } ?>