TTi18n::gettext( 'Rating' ), '-1200-note' => TTi18n::gettext( 'Note' ), '-1300-tag' => TTi18n::gettext( 'Tags' ), '-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 = [ 'rating', 'note', ]; break; } return $retval; } /** * @param $data * @return array */ function _getVariableToFunctionMap( $data ) { $variable_function_map = [ 'id' => 'ID', 'user_review_control_id' => 'UserReviewControl', 'kpi_id' => 'KPI', 'display_order' => false, 'name' => false, 'type_id' => false, 'status_id' => false, 'minimum_rate' => false, 'maximum_rate' => false, 'description' => false, 'rating' => 'Rating', 'note' => 'Note', 'tag' => 'Tag', 'deleted' => 'Deleted', ]; return $variable_function_map; } /** * @return bool */ function getKPIObject() { return $this->getGenericObject( 'KPIListFactory', $this->getKPI(), 'kpi_obj' ); } /** * @return bool|mixed */ function getKPI() { return $this->getGenericDataValue( 'kpi_id' ); } /** * @param string $value UUID * @return bool */ function setKPI( $value ) { $value = TTUUID::castUUID( $value ); return $this->setGenericDataValue( 'kpi_id', $value ); } /** * @return bool|mixed */ function getUserReviewControl() { return $this->getGenericDataValue( 'user_review_control_id' ); } /** * @param string $value UUID * @return bool */ function setUserReviewControl( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'user_review_control_id', $value ); } /** * @return bool|mixed */ function getRating() { return $this->getGenericDataValue( 'rating' ); } /** * @param $value * @return bool */ function setRating( $value ) { $value = trim( $value ); if ( $value == '' ) { $value = null; } return $this->setGenericDataValue( 'rating', $value ); } /** * @return bool|mixed */ function getNote() { return $this->getGenericDataValue( 'note' ); } /** * @param $value * @return bool */ function setNote( $value ) { $value = trim( $value ); return $this->setGenericDataValue( 'note', $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->getKPIObject() ) && TTUUID::isUUID( $this->getKPIObject()->getCompany() ) && $this->getKPIObject()->getCompany() != TTUUID::getZeroID() && $this->getKPIObject()->getCompany() != TTUUID::getNotExistID() && TTUUID::isUUID( $this->getID() ) && $this->getID() != TTUUID::getZeroID() && $this->getID() != TTUUID::getNotExistID() ) { return CompanyGenericTagMapListFactory::getStringByCompanyIDAndObjectTypeIDAndObjectID( $this->getKPIObject()->getCompany(), 330, $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 ) { //$this->setProvince( $this->getProvince() ); //Not sure why this was there, but it causes duplicate errors if the province is incorrect. // // BELOW: Validation code moved from set*() functions. // // KPI $klf = TTnew( 'KPIListFactory' ); /** @var KPIListFactory $klf */ $this->Validator->isResultSetWithRows( 'kpi_id', $klf->getById( $this->getKPI() ), TTi18n::gettext( 'Invalid KPI' ) ); // review control $urclf = TTnew( 'UserReviewControlListFactory' ); /** @var UserReviewControlListFactory $urclf */ $this->Validator->isResultSetWithRows( 'user_review_control_id', $urclf->getById( $this->getUserReviewControl() ), TTi18n::gettext( 'Invalid review control' ) ); // Rating if ( $this->getRating() != null ) { $this->Validator->isNumeric( 'rating', $this->getRating(), TTi18n::gettext( 'Rating must only be digits' ) ); if ( $this->Validator->isError( 'rating' ) == false ) { $this->Validator->isLengthBeforeDecimal( 'rating', $this->getRating(), TTi18n::gettext( 'Invalid Rating' ), 0, 7 ); } if ( $this->Validator->isError( 'rating' ) == false ) { $this->Validator->isLengthAfterDecimal( 'rating', $this->getRating(), TTi18n::gettext( 'Invalid Rating' ), 0, 2 ); } } // Note if ( $this->getNote() != '' ) { $this->Validator->isLength( 'note', $this->getNote(), TTi18n::gettext( 'Note is too long' ), 0, 4096 ); } // // ABOVE: Validation code moved from set*() functions. // return true; } /** * @return bool */ function postSave() { $this->removeCache( $this->getId() ); if ( $this->getDeleted() == false ) { Debug::text( 'Setting Tags...', __FILE__, __LINE__, __METHOD__, 10 ); CompanyGenericTagMapFactory::setTags( $this->getKPIObject()->getCompany(), 330, $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 ) { 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 'name': case 'type_id': case 'status_id': case 'minimum_rate': case 'maximum_rate': case 'description': case 'display_order': $data[$variable] = $this->getColumn( $variable ); break; default: if ( method_exists( $this, $function ) ) { $data[$variable] = $this->$function(); } break; } } } $this->getPermissionColumns( $data, $this->getCreatedBy(), false, $permission_children_ids, $include_columns ); $this->getCreatedAndUpdatedColumns( $data, $include_columns ); } return $data; } /** * @param $log_action * @return bool */ function addLog( $log_action ) { $kpi_obj = $this->getKPIObject(); if ( is_object( $kpi_obj ) ) { return TTLog::addEntry( $this->getUserReviewControl(), $log_action, TTi18n::getText( 'Employee Review KPI' ) . ' - ' . TTi18n::getText( 'KPI' ) . ': ' . $kpi_obj->getName(), null, $this->getTable(), $this ); } return false; } } ?>