TimeTrex Community Edition v16.2.0

This commit is contained in:
2022-12-13 07:10:06 +01:00
commit 472f000c1b
6810 changed files with 2636142 additions and 0 deletions

View File

@ -0,0 +1,620 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class KPIFactory extends Factory {
protected $table = 'kpi';
protected $pk_sequence_name = 'kpi_id_seq'; //PK Sequence name
protected $company_obj = null;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'status':
$retval = [
10 => TTi18n::gettext( 'Enabled (Required)' ),
15 => TTi18n::gettext( 'Enabled (Optional)' ),
20 => TTi18n::gettext( 'Disabled' ),
];
break;
case 'type':
$retval = [
10 => TTi18n::gettext( 'Scale Rating' ),
20 => TTi18n::gettext( 'Yes/No' ),
30 => TTi18n::gettext( 'Text' ),
];
break;
case 'columns':
$retval = [
'-1000-status' => TTi18n::gettext( 'Status' ),
'-1020-type' => TTi18n::getText( 'Type' ),
'-1030-name' => TTi18n::gettext( 'Name' ),
'-1040-description' => TTi18n::gettext( 'Description' ),
'-1050-minimum_rate' => TTi18n::gettext( 'Minimum Rating' ),
'-1060-maximum_rate' => TTi18n::gettext( 'Maximum Rating' ),
'-1080-kpi_group' => TTi18n::gettext( 'Group' ),
'-1090-display_order'=> TTi18n::gettext( 'Display Order' ),
'-1900-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 = [
'status',
'type',
'name',
'minimum_rate',
'maximum_rate',
'kpi_group',
];
break;
case 'unique_columns': //Columns that are unique, and disabled for mass editing.
$retval = [ 'name', ];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'company_id' => 'Company',
'name' => 'Name',
'display_order' => 'DisplayOrder',
'group_id' => 'Group',
'kpi_group' => false,
'type_id' => 'Type',
'type' => false,
'tag' => 'Tag',
'description' => 'Description',
'minimum_rate' => 'MinimumRate',
'maximum_rate' => 'MaximumRate',
'status_id' => 'Status',
'status' => false,
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool
*/
function getCompanyObject() {
return $this->getGenericObject( 'CompanyListFactory', $this->getCompany(), 'company_obj' );
}
/**
* @return bool
*/
function getCompany() {
return $this->getGenericDataValue( 'company_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setCompany( $value ) {
$value = TTUUID::castUUID( $value );
Debug::Text( 'Company ID: ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
Debug::Text( 'Setting company_id data... ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'company_id', $value );
}
/**
* @return bool|int
*/
function getStatus() {
return $this->getGenericDataValue( 'status_id' );
}
/**
* @param $value
* @return bool
*/
function setStatus( $value ) {
$value = (int)trim( $value );
Debug::Text( 'Setting status_id data... ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'status_id', $value );
}
/**
* @return bool|int
*/
function getType() {
return $this->getGenericDataValue( 'type_id' );
}
/**
* @param int $value
* @return bool
*/
function setType( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'type_id', $value );
}
/**
* @param $name
* @return bool
*/
function isUniqueName( $name ) {
$name = trim( $name );
if ( $name == '' ) {
return false;
}
$ph = [
'company_id' => TTUUID::castUUID( $this->getCompany() ),
'name' => TTi18n::strtolower( $name ),
];
$query = 'select id from ' . $this->table . '
where company_id = ?
AND lower(name) = ?
AND deleted = 0';
$name_id = $this->db->GetOne( $query, $ph );
Debug::Arr( $name_id, 'Unique Name: ' . $name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $name_id === false ) {
return true;
} else {
if ( $name_id == $this->getId() ) {
return true;
}
}
return false;
}
/**
* @return bool
*/
function getName() {
return $this->getGenericDataValue( 'name' );
}
/**
* @param $value
* @return bool
*/
function setName( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'name', $value );
}
/**
* @return mixed
*/
function getDisplayOrder() {
return $this->getGenericDataValue( 'display_order' );
}
/**
* @param $value
* @return bool
*/
function setDisplayOrder( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'display_order', $value );
}
/**
* @return array|bool
*/
function getGroup() {
return CompanyGenericMapListFactory::getArrayByCompanyIDAndObjectTypeIDAndObjectID( $this->getCompany(), 2020, $this->getID() );
}
/**
* @param string|string[] $ids UUID
* @return bool
*/
function setGroup( $ids ) {
Debug::text( 'Setting Groups IDs : ', __FILE__, __LINE__, __METHOD__, 10 );
Debug::Arr( $ids, 'Setting Group data... ', __FILE__, __LINE__, __METHOD__, 10 );
return CompanyGenericMapFactory::setMapIDs( $this->getCompany(), 2020, $this->getID(), $ids );
}
/**
* @return bool
*/
function getDescription() {
return $this->getGenericDataValue( 'description' );
}
/**
* @param $value
* @return bool
*/
function setDescription( $value ) {
$value = trim( $value );
Debug::Text( 'Setting description data... ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'description', $value );
}
/**
* @return bool|string
*/
function getMinimumRate() {
$value = $this->getGenericDataValue( 'minimum_rate' );
if ( $value !== false ) {
return Misc::removeTrailingZeros( (float)$value, 2 );
}
return false;
}
/**
* @param $value
* @return bool
*/
function setMinimumRate( $value ) {
$value = trim( $value );
$value = $this->Validator->stripNonFloat( $value );
if ( $this->getType() == 10 ) {
Debug::Text( 'Setting minimum_rate data... ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'minimum_rate', $value );
}
return false;
}
/**
* @return bool|string
*/
function getMaximumRate() {
$value = $this->getGenericDataValue( 'maximum_rate' );
if ( $value !== false ) {
return Misc::removeTrailingZeros( (float)$value, 2 );
}
return false;
}
/**
* @param $value
* @return bool
*/
function setMaximumRate( $value ) {
$value = trim( $value );
$value = $this->Validator->stripNonFloat( $value );
if ( $this->getType() == 10 ) {
Debug::Text( 'Setting maximum_rate data...' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'maximum_rate', $value );
}
return false;
}
/**
* @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 ( TTUUID::isUUID( $this->getCompany() ) && $this->getCompany() != TTUUID::getZeroID() && $this->getCompany() != TTUUID::getNotExistID()
&& TTUUID::isUUID( $this->getID() ) && $this->getID() != TTUUID::getZeroID() && $this->getID() != TTUUID::getNotExistID() ) {
return CompanyGenericTagMapListFactory::getStringByCompanyIDAndObjectTypeIDAndObjectID( $this->getCompany(), 310, $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.
//
// Company
$clf = TTnew( 'CompanyListFactory' ); /** @var CompanyListFactory $clf */
$this->Validator->isResultSetWithRows( 'company',
$clf->getByID( $this->getCompany() ),
TTi18n::gettext( 'Company is invalid' )
);
// Status
if ( $this->getStatus() !== false ) {
$this->Validator->inArrayKey( 'status',
$this->getStatus(),
TTi18n::gettext( 'Incorrect Status' ),
$this->getOptions( 'status' )
);
}
// Type
if ( $this->getType() !== false ) {
$this->Validator->inArrayKey( 'type_id',
$this->getType(),
TTi18n::gettext( 'Type is invalid' ),
$this->getOptions( 'type' )
);
}
// Name
if ( $this->getName() !== false ) {
$this->Validator->isLength( 'name',
$this->getName(),
TTi18n::gettext( 'Name is too long, consider using description instead' ),
3,
100
);
if ( $this->Validator->isError( 'name' ) == false ) {
$this->Validator->isTrue( 'name',
$this->isUniqueName( $this->getName() ),
TTi18n::gettext( 'Name is already taken' )
);
}
}
// Display Order
if ( $this->getDisplayOrder() == '' ) {
$this->Validator->isTRUE( 'display_order',
false,
TTi18n::gettext( 'Display Order must be specified' )
);
}
if ( $this->getDisplayOrder() != '' && $this->Validator->isError( 'display_order' ) == false ) {
$this->Validator->isNumeric( 'display_order',
$this->getDisplayOrder(),
TTi18n::gettext( 'Invalid Display Order' )
);
}
// Description
$this->Validator->isLength( 'description',
$this->getDescription(),
TTi18n::gettext( 'Description is invalid' ),
0,
255
);
// Minimum Rating
if ( $this->getType() == 10 ) {
if ( $this->getMinimumRate() !== false ) {
$this->Validator->isLength( 'minimum_rate',
$this->getMinimumRate(),
TTi18n::gettext( 'Invalid Minimum Rating' ),
1
);
if ( $this->Validator->isError( 'minimum_rate' ) == false ) {
$this->Validator->isNumeric( 'minimum_rate',
$this->getMinimumRate(),
TTi18n::gettext( 'Minimum Rating must only be digits' )
);
}
if ( $this->Validator->isError( 'minimum_rate' ) == false ) {
$this->Validator->isLengthAfterDecimal( 'minimum_rate',
$this->getMinimumRate(),
TTi18n::gettext( 'Invalid Minimum Rating' ),
0,
2
);
}
}
}
// Maximum Rating
if ( $this->getType() == 10 ) {
if ( $this->getMaximumRate() !== false ) {
$this->Validator->isLength( 'maximum_rate',
$this->getMaximumRate(),
TTi18n::gettext( 'Invalid Maximum Rating' ),
1
);
if ( $this->Validator->isError( 'maximum_rate' ) == false ) {
$this->Validator->isNumeric( 'maximum_rate',
$this->getMaximumRate(),
TTi18n::gettext( 'Maximum Rating must only be digits' )
);
}
if ( $this->Validator->isError( 'maximum_rate' ) == false ) {
$this->Validator->isLengthAfterDecimal( 'maximum_rate',
$this->getMaximumRate(),
TTi18n::gettext( 'Invalid Maximum Rating' ),
0,
2
);
}
}
}
//
// ABOVE: Validation code moved from set*() functions.
//
if ( $this->getType() == 10 && $this->getMinimumRate() != '' && $this->getMaximumRate() != '' ) {
if ( $this->getMinimumRate() >= $this->getMaximumRate() ) {
$this->Validator->isTrue( 'minimum_rate', false, TTi18n::gettext( 'Minimum Rating should be lesser than Maximum Rating' ) );
}
}
if ( $this->getDeleted() == true ) {
$urlf = TTnew( 'UserReviewListFactory' ); /** @var UserReviewListFactory $urlf */
$urlf->getByKpiId( $this->getId() );
if ( $urlf->getRecordCount() > 0 ) {
$this->Validator->isTRUE( 'in_use', false, TTi18n::gettext( 'KPI is in use' ) );
}
}
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->getCompany(), 310, $this->getID(), $this->getTag() );
}
return true;
}
/**
* Support setting created_by, updated_by especially for importing data.
* Make sure data is set based on the getVariableToFunctionMap order.
* @param $data
* @return bool
*/
function setObjectFromArray( $data ) {
Debug::Arr( $data, 'setObjectFromArray...', __FILE__, __LINE__, __METHOD__, 10 );
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 'type':
case 'status':
$function = 'get' . $variable;
if ( method_exists( $this, $function ) ) {
$data[$variable] = Option::getByKey( $this->$function(), $this->getOptions( $variable ) );
}
break;
case 'kpi_group':
$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 ) {
return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'KPI' ), null, $this->getTable(), $this );
}
}
?>

View File

@ -0,0 +1,382 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class KPIGroupFactory extends Factory {
protected $table = 'kpi_group';
protected $pk_sequence_name = 'kpi_group_id_seq'; //PK Sequence name
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$retval = [
'-1030-name' => TTi18n::gettext( 'Name' ),
'-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 'unique_columns': //Columns that are displayed by default.
$retval = [
'name',
];
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 = [
'name',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'company_id' => 'Company',
'parent_id' => 'Parent',
'name' => 'Name',
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool
*/
function getCompany() {
return $this->getGenericDataValue( 'company_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setCompany( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'company_id', $value );
}
/**
* @return bool|mixed
*/
function getParent() {
return $this->getGenericDataValue( 'parent_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setParent( $value ) {
return $this->setGenericDataValue( 'parent_id', TTUUID::castUUID( $value ) );
}
/**
* @param $name
* @return bool
*/
function isUniqueName( $name ) {
$name = trim( $name );
if ( $name == '' ) {
return false;
}
$ph = [
'company_id' => TTUUID::castUUID( $this->getCompany() ),
'name' => TTi18n::strtolower( $name ),
];
$query = 'select id from ' . $this->table . '
where company_id = ?
AND lower(name) = ?
AND deleted = 0';
$name_id = $this->db->GetOne( $query, $ph );
Debug::Arr( $name_id, 'Unique Name: ' . $name, __FILE__, __LINE__, __METHOD__, 10 );
if ( $name_id === false ) {
return true;
} else {
if ( $name_id == $this->getId() ) {
return true;
}
}
return false;
}
/**
* @return bool
*/
function getName() {
return $this->getGenericDataValue( 'name' );
}
/**
* @param $value
* @return bool
*/
function setName( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'name', $value );
}
/**
* @param bool $ignore_warning
* @return bool
*/
function Validate( $ignore_warning = true ) {
//
// BELOW: Validation code moved from set*() functions.
//
// Company
if ( $this->getCompany() != TTUUID::getZeroID() ) {
$clf = TTnew( 'CompanyListFactory' ); /** @var CompanyListFactory $clf */
$this->Validator->isResultSetWithRows( 'company_id',
$clf->getByID( $this->getCompany() ),
TTi18n::gettext( 'Company is invalid' )
);
}
// Name
$this->Validator->isLength( 'name',
$this->getName(),
TTi18n::gettext( 'Name is too short or too long' ),
2,
100
);
if ( $this->Validator->isError( 'name' ) == false ) {
$this->Validator->isTrue( 'name',
$this->isUniqueName( $this->getName() ),
TTi18n::gettext( 'Group already exists' )
);
}
//
// ABOVE: Validation code moved from set*() functions.
//
if ( $this->isNew() == false
&& $this->getId() == $this->getParent() ) {
$this->Validator->isTrue( 'parent',
false,
TTi18n::gettext( 'Cannot re-parent group to itself' )
);
} else {
if ( $this->isNew() == false ) {
$kglf = TTnew( 'KPIGroupListFactory' ); /** @var KPIGroupListFactory $kglf */
$nodes = $kglf->getByCompanyIdArray( $this->getCompany() );
$children_ids = TTTree::getElementFromNodes( TTTree::flattenArray( TTTree::createNestedArrayWithDepth( $nodes, $this->getId() ) ), 'id' );
if ( is_array( $children_ids ) && in_array( $this->getParent(), $children_ids ) == true ) {
Debug::Text( ' Objects cant be re-parented to their own children...', __FILE__, __LINE__, __METHOD__, 10 );
$this->Validator->isTrue( 'parent',
false,
TTi18n::gettext( 'Unable to change parent to a child of itself' )
);
}
}
}
return true;
}
/**
* Must be postSave because we need the ID of the object.
* @return bool
*/
function postSave() {
$this->StartTransaction();
if ( $this->getDeleted() == true ) {
//Get parent of this object, and re-parent all groups to it.
$kglf = TTnew( 'KPIGroupListFactory' ); /** @var KPIGroupListFactory $kglf */
$kglf->getByCompanyIdAndParentId( $this->getCompany(), $this->getId() );
if ( $kglf->getRecordCount() > 0 ) {
foreach ( $kglf as $kg_obj ) {
Debug::Text( ' Re-Parenting ID: ' . $kg_obj->getId() . ' To: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10 );
$kg_obj->setParent( $this->getParent() );
if ( $kg_obj->isValid() ) {
$kg_obj->Save();
}
}
}
//Get items by group id.
$klf = TTnew( 'KPIListFactory' ); /** @var KPIListFactory $klf */
$cgmlf = TTnew( 'CompanyGenericMapListFactory' ); /** @var CompanyGenericMapListFactory $cgmlf */
$cgmf = TTnew( 'CompanyGenericMapFactory' ); /** @var CompanyGenericMapFactory $cgmf */
$klf->getByCompanyIdAndGroupId( $this->getCompany(), $this->getId() );
$ids = [];
if ( $klf->getRecordCount() > 0 ) {
foreach ( $klf as $obj ) {
Debug::Text( ' Re-Grouping Item: ' . $obj->getId(), __FILE__, __LINE__, __METHOD__, 10 );
$ids[] = $obj->getId();
}
}
$cgmlf->getByCompanyIDAndObjectTypeAndMapID( $this->getCompany(), 2010, $this->getID() );
if ( $cgmlf->getRecordCount() > 0 ) {
foreach ( $cgmlf as $cgm_obj ) {
Debug::text( 'Deleting from Company Generic Map: ' . $cgm_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 );
$cgm_obj->Delete();
}
}
if ( empty( $ids ) == false ) {
foreach ( $ids as $id ) {
if ( $this->getParent() != '' ) {
$cgmlf->getByCompanyIDAndObjectTypeAndObjectIDAndMapID( $this->getCompany(), 2020, $id, $this->getParent() );
if ( $cgmlf->getRecordCount() == 0 ) {
$cgmf->setCompany( $this->getCompany() );
$cgmf->setObjectType( 2020 );
$cgmf->setObjectID( $id );
$cgmf->setMapId( $this->getParent() );
$cgmf->Save();
}
}
$cgmlf->getByCompanyIDAndObjectTypeAndObjectIDAndMapID( $this->getCompany(), 2020, $id, $this->getId() );
if ( $cgmlf->getRecordCount() > 0 ) {
foreach ( $cgmlf as $cgm_obj ) {
Debug::text( 'Deleting from Company Generic Map: ' . $cgm_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 );
$cgm_obj->Delete();
}
}
}
}
}
$this->CommitTransaction();
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 ) {
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 ) {
return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'KPI Group' ), null, $this->getTable(), $this );
}
}
?>

View File

@ -0,0 +1,349 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class KPIGroupListFactory extends KPIGroupFactory implements IteratorAggregate {
/**
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return $this
*/
function getAll( $limit = null, $page = null, $where = null, $order = null ) {
$query = '
select *
from ' . $this->getTable() . '
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, null, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIGroupListFactory
*/
function getById( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIGroupListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where company_id = ?
AND id = ?
AND deleted = 0
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIGroupListFactory
*/
function getByCompanyId( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where company_id = ?
AND deleted = 0
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $parent_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIGroupListFactory
*/
function getByCompanyIdAndParentId( $id, $parent_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $parent_id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
'parent_id' => TTUUID::castUUID( $parent_id ),
];
$query = '
select *
from ' . $this->getTable() . '
where company_id = ?
AND parent_id = ?
AND deleted = 0
';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @return array|bool
*/
function getByCompanyIdArray( $id ) {
$lf = new KPIGroupListFactory();
$lf->getAPISearchByCompanyIdAndArrayCriteria( $id, [] );
if ( $lf->getRecordCount() > 0 ) {
$nodes = [];
foreach ( $lf as $obj ) {
$nodes[] = $obj->getObjectAsArray(); //this needs to have created and updated info for the audit tab.
}
$retarr = TTTree::flattenArray( TTTree::FormatArray( $nodes ) );
return $retarr;
}
return false;
}
/**
* @param string $id UUID
* @param string $group_id UUID
* @param bool $include_sub_groups
* @return array|bool
*/
function getByCompanyIdAndGroupIdAndSubGroupsArray( $id, $group_id, $include_sub_groups = true ) {
$lf = new KPIGroupListFactory();
$lf->getByCompanyId( $id );
if ( $lf->getRecordCount() > 0 ) {
foreach ( $lf as $obj ) {
$nodes[] = [ 'id' => $obj->getId(), 'name' => $obj->getName(), 'parent_id' => $obj->getParent() ];
}
$retarr = TTTree::getElementFromNodes( TTTree::flattenArray( TTTree::createNestedArrayWithDepth( $nodes, $group_id ) ), 'id' );
return $retarr;
}
return false;
}
/**
* @param $lf
* @param bool $include_blank
* @return array|bool
*/
function getArrayByListFactory( $lf, $include_blank = true ) {
if ( !is_object( $lf ) ) {
return false;
}
$list = [];
if ( $include_blank == true ) {
$list[TTUUID::getZeroID()] = '--';
}
foreach ( $lf as $obj ) {
$list[$obj->getID()] = $obj->getName();
}
if ( empty( $list ) == false ) {
return $list;
}
return false;
}
/**
* @param string $company_id UUID
* @param $filter_data
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIGroupListFactory
*/
function getAPISearchByCompanyIdAndArrayCriteria( $company_id, $filter_data, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( !is_array( $order ) ) {
//Use Filter Data ordering if its set.
if ( isset( $filter_data['sort_column'] ) && $filter_data['sort_order'] ) {
$order = [ Misc::trimSortPrefix( $filter_data['sort_column'] ) => $filter_data['sort_order'] ];
}
}
$additional_order_fields = [];
if ( $order == null ) {
$order = [ 'name' => 'asc' ];
$strict = false;
} else {
//Always sort by last name, first name after other columns
if ( !isset( $order['name'] ) ) {
$order['name'] = 'asc';
}
$strict = true;
}
//Debug::Arr($order, 'Order Data:', __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10);
$uf = new UserFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select a.*,
y.first_name as created_by_first_name,
y.middle_name as created_by_middle_name,
y.last_name as created_by_last_name,
z.first_name as updated_by_first_name,
z.middle_name as updated_by_middle_name,
z.last_name as updated_by_last_name
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
where a.company_id = ?
';
$query .= ( isset( $filter_data['permission_children_ids'] ) ) ? $this->getWhereClauseSQL( 'a.created_by', $filter_data['permission_children_ids'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['exclude_id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['exclude_id'], 'not_uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['name'] ) ) ? $this->getWhereClauseSQL( 'a.name', $filter_data['name'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['created_date'] ) ) ? $this->getWhereClauseSQL( 'a.created_date', $filter_data['created_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['updated_date'] ) ) ? $this->getWhereClauseSQL( 'a.updated_date', $filter_data['updated_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['created_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.created_by', 'y.first_name', 'y.last_name' ], $filter_data['created_by'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['updated_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.updated_by', 'z.first_name', 'z.last_name' ], $filter_data['updated_by'], 'user_id_or_name', $ph ) : null;
$query .= ' AND a.deleted = 0 ';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
}
?>

View File

@ -0,0 +1,396 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class KPIListFactory extends KPIFactory implements IteratorAggregate {
/**
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return $this
*/
function getAll( $limit = null, $page = null, $where = null, $order = null ) {
$query = '
select *
from ' . $this->getTable() . '
WHERE deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, null, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIListFactory
*/
function getById( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$ph = [
'id' => TTUUID::castUUID( $id ),
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
AND company_id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIListFactory
*/
function getByCompanyId( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $order == null ) {
$order = [ 'name' => 'asc' ];
$strict = false;
} else {
$strict = true;
}
$ph = [
'company_id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where company_id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIListFactory
*/
function getByCompanyIDAndGroupID( $company_id, $id, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( $id == '' ) {
return false;
}
$cgmf = new CompanyGenericMapFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
'map_id' => TTUUID::castUUID( $id ),
];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $cgmf->getTable() . ' as b ON ( a.id = b.object_id AND b.company_id = a.company_id AND b.object_type_id = 2020 AND b.deleted = 0 )
where a.company_id = ?
AND b.map_id = ?
AND a.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param $filter_data
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|KPIListFactory
*/
function getAPISearchByCompanyIdAndArrayCriteria( $company_id, $filter_data, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( isset( $filter_data['kpi_id'] ) ) {
$filter_data['id'] = $filter_data['kpi_id'];
}
if ( isset( $filter_data['kpi_status_id'] ) ) {
$filter_data['status_id'] = $filter_data['kpi_status_id'];
}
if ( isset( $filter_data['kpi_type_id'] ) ) {
$filter_data['type_id'] = $filter_data['kpi_type_id'];
}
if ( isset( $filter_data['kpi_group_id'] ) ) {
$filter_data['group_id'] = $filter_data['kpi_group_id'];
}
if ( !is_array( $order ) ) {
//Use Filter Data ordering if its set.
if ( isset( $filter_data['sort_column'] ) && $filter_data['sort_order'] ) {
$order = [ Misc::trimSortPrefix( $filter_data['sort_column'] ) => $filter_data['sort_order'] ];
}
}
$additional_order_fields = [ 'type_id', 'status_id', 'kpi_group' ];
$sort_column_aliases = [
'type' => 'type_id',
'status' => 'status_id',
];
$order = $this->getColumnsFromAliases( $order, $sort_column_aliases );
if ( $order == null ) {
$order = [ 'display_order' => 'asc', 'name' => 'asc' ];
$strict = false;
} else {
$strict = true;
}
//Debug::Arr($order, 'Order Data:', __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10);
$uf = new UserFactory();
$cgmf = new CompanyGenericMapFactory();
$kgf = new KPIGroupFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$kpi_group_all_label = TTi18n::getText( '-- All --' );
$query = '
select DISTINCT a.*,
x.kpi_group as kpi_group,
y.first_name as created_by_first_name,
y.middle_name as created_by_middle_name,
y.last_name as created_by_last_name,
z.first_name as updated_by_first_name,
z.middle_name as updated_by_middle_name,
z.last_name as updated_by_last_name
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $cgmf->getTable() . ' as b ON ( a.id = b.object_id AND b.company_id = a.company_id AND b.object_type_id = 2020 AND b.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
LEFT JOIN (
SELECT a.id,
string_agg( CASE WHEN b.map_id = \'ffffffff-ffff-ffff-ffff-ffffffffffff\' THEN \''. $kpi_group_all_label .'\' ELSE c.name END, \', \' ) as kpi_group
FROM '. $this->getTable() .' as a
LEFT JOIN '. $cgmf->getTable() .' as b ON ( a.id = b.object_id AND b.company_id = a.company_id AND b.object_type_id = 2020 AND b.deleted = 0 )
LEFT JOIN '. $kgf->getTable() .' as c ON ( b.map_id = c.id )
GROUP BY a.id
) as x ON ( a.id = x.id )
where a.company_id = ?
';
$query .= ( isset( $filter_data['permission_children_ids'] ) ) ? $this->getWhereClauseSQL( 'a.created_by', $filter_data['permission_children_ids'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['name'] ) ) ? $this->getWhereClauseSQL( 'a.name', $filter_data['name'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['description'] ) ) ? $this->getWhereClauseSQL( 'a.description', $filter_data['description'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['minimum_rate'] ) ) ? $this->getWhereClauseSQL( 'a.minimum_rate', $filter_data['minimum_rate'], 'numeric', $ph ) : null;
$query .= ( isset( $filter_data['maximum_rate'] ) ) ? $this->getWhereClauseSQL( 'a.maximum_rate', $filter_data['maximum_rate'], 'numeric', $ph ) : null;
if ( isset( $filter_data['status'] ) && !is_array( $filter_data['status'] ) && trim( $filter_data['status'] ) != '' && !isset( $filter_data['status_id'] ) ) {
$filter_data['status_id'] = Option::getByFuzzyValue( $filter_data['status'], $this->getOptions( 'status' ) );
}
$query .= ( isset( $filter_data['status_id'] ) ) ? $this->getWhereClauseSQL( 'a.status_id', $filter_data['status_id'], 'numeric_list', $ph ) : null;
if ( isset( $filter_data['type'] ) && !is_array( $filter_data['type'] ) && trim( $filter_data['type'] ) != '' && !isset( $filter_data['type_id'] ) ) {
$filter_data['type_id'] = Option::getByFuzzyValue( $filter_data['type'], $this->getOptions( 'type' ) );
}
$query .= ( isset( $filter_data['type_id'] ) ) ? $this->getWhereClauseSQL( 'a.type_id', $filter_data['type_id'], 'numeric_list', $ph ) : null;
//This is special in that there is an "--ALL--" group that KPIs must actually be assigned to (in addition to any other group if needed), in order to appear when a review is created using the "--ALL--" group.
$query .= ( isset( $filter_data['group_id'] ) ) ? $this->getWhereClauseSQL( 'b.map_id', $filter_data['group_id'], 'uuid_list_with_all', $ph ) : null;
$query .= ( isset( $filter_data['tag'] ) ) ? $this->getWhereClauseSQL( 'a.id', [ 'company_id' => TTUUID::castUUID( $company_id ), 'object_type_id' => 310, 'tag' => $filter_data['tag'] ], 'tag', $ph ) : null;
if ( isset( $filter_data['created_date'] ) && !is_array( $filter_data['created_date'] ) && trim( $filter_data['created_date'] ) != '' ) {
$date_filter = $this->getDateRangeSQL( $filter_data['created_date'], 'a.created_date' );
if ( $date_filter != false ) {
$query .= ' AND ' . $date_filter;
}
unset( $date_filter );
}
if ( isset( $filter_data['updated_date'] ) && !is_array( $filter_data['updated_date'] ) && trim( $filter_data['updated_date'] ) != '' ) {
$date_filter = $this->getDateRangeSQL( $filter_data['updated_date'], 'a.updated_date' );
if ( $date_filter != false ) {
$query .= ' AND ' . $date_filter;
}
unset( $date_filter );
}
$query .= ( isset( $filter_data['created_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.created_by', 'y.first_name', 'y.last_name' ], $filter_data['created_by'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['updated_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.updated_by', 'z.first_name', 'z.last_name' ], $filter_data['updated_by'], 'user_id_or_name', $ph ) : null;
$query .= ' AND a.deleted = 0 ';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
//Debug::Query( $query, $ph, __FILE__, __LINE__, __METHOD__, 10 );
return $this;
}
/**
* @param string $company_id UUID
* @param bool $include_blank
* @return array|bool
*/
function getByCompanyIdArray( $company_id, $include_blank = true ) {
$klf = new KPIListFactory();
$klf->getByCompanyId( $company_id );
$list = [];
if ( $include_blank == true ) {
$list[TTUUID::getZeroID()] = '--';
}
foreach ( $klf as $kpi_obj ) {
$list[$kpi_obj->getID()] = $kpi_obj->getName();
}
if ( empty( $list ) == false ) {
return $list;
}
return false;
}
/**
* @param $lf
* @param bool $include_blank
* @return array|bool
*/
function getArrayByListFactory( $lf, $include_blank = true ) {
if ( !is_object( $lf ) ) {
return false;
}
$list = [];
if ( $include_blank == true ) {
$list[TTUUID::getZeroID()] = '--';
}
foreach ( $lf as $obj ) {
$list[$obj->getID()] = $obj->getName();
}
if ( empty( $list ) == false ) {
return $list;
}
return false;
}
}
?>

View File

@ -0,0 +1,671 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class UserReviewControlFactory extends Factory {
protected $table = 'user_review_control';
protected $pk_sequence_name = 'user_review_control_id_seq'; //PK Sequence name
protected $user_obj = null;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'type':
$retval = [
10 => TTi18n::gettext( 'Accolade' ),
15 => TTi18n::gettext( 'Discipline' ),
20 => TTi18n::gettext( 'Review (General)' ),
25 => TTi18n::gettext( 'Review (Wage)' ),
30 => TTi18n::gettext( 'Review (Performance)' ),
33 => TTi18n::gettext( 'Incident' ), //Something not resulting in an Accident/Injury
35 => TTi18n::gettext( 'Accident/Injury' ),
37 => TTi18n::gettext( 'Background Check' ),
38 => TTi18n::gettext( 'Drug Test' ),
39 => TTi18n::gettext( 'Health/Immunization' ),
40 => TTi18n::gettext( 'Entrance Interview' ),
45 => TTi18n::gettext( 'Exit Interview' ),
100 => TTi18n::gettext( 'Miscellaneous' ),
];
break;
case 'term':
$retval = [
10 => TTi18n::gettext( 'Positive' ),
20 => TTi18n::gettext( 'Neutral' ),
30 => TTi18n::gettext( 'Negative' ),
];
break;
case 'severity':
$retval = [
10 => TTi18n::gettext( 'Normal' ),
20 => TTi18n::gettext( 'Low' ),
30 => TTi18n::gettext( 'Medium' ),
40 => TTi18n::gettext( 'High' ),
50 => TTi18n::gettext( 'Critical' ),
];
break;
case 'status':
$retval = [
10 => TTi18n::gettext( 'Scheduled' ),
20 => TTi18n::gettext( 'Being Reviewed' ),
30 => TTi18n::gettext( 'Complete' ),
];
break;
case 'columns':
$retval = [
'-4070-user' => TTi18n::gettext( 'Employee Name' ),
'-4080-reviewer_user' => TTi18n::gettext( 'Reviewer Name' ),
'-1170-start_date' => TTi18n::gettext( 'Start Date' ),
'-1180-end_date' => TTi18n::gettext( 'End Date' ),
'-4090-due_date' => TTi18n::gettext( 'Due Date' ),
'-1040-type' => TTi18n::gettext( 'Type' ),
'-1060-term' => TTi18n::gettext( 'Terms' ),
'-1010-severity' => TTi18n::gettext( 'Severity/Importance' ),
'-1020-status' => TTi18n::gettext( 'Status' ),
'-1050-rating' => TTi18n::gettext( 'Overall Rating' ),
'-1200-note' => TTi18n::gettext( 'Notes' ),
'-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 = [
'user',
'reviewer_user',
'type',
'term',
'severity',
'start_date',
'end_date',
'due_date',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'user_id' => 'User',
'user' => false,
'reviewer_user_id' => 'ReviewerUser',
'reviewer_user' => false,
'type_id' => 'Type',
'type' => false,
'term_id' => 'Term',
'term' => false,
'severity_id' => 'Severity',
'severity' => false,
'status_id' => 'Status',
'status' => false,
'start_date' => 'StartDate',
'end_date' => 'EndDate',
'due_date' => 'DueDate',
'rating' => 'Rating',
'note' => 'Note',
'tag' => 'Tag',
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool
*/
function getUserObject() {
return $this->getGenericObject( 'UserListFactory', $this->getUser(), 'user_obj' );
}
/**
* @return bool|mixed
*/
function getUser() {
return $this->getGenericDataValue( 'user_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setUser( $value ) {
$value = TTUUID::castUUID( $value );
//$cgmlf = TTnew( 'CompanyGenericMapListFactory' );
return $this->setGenericDataValue( 'user_id', $value );
}
/**
* @return bool|mixed
*/
function getReviewerUser() {
return $this->getGenericDataValue( 'reviewer_user_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setReviewerUser( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'reviewer_user_id', $value );
}
/**
* @return bool|int
*/
function getType() {
return $this->getGenericDataValue( 'type_id' );
}
/**
* @param $value
* @return bool
*/
function setType( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'type_id', $value );
}
/**
* @return bool|int
*/
function getTerm() {
return $this->getGenericDataValue( 'term_id' );
}
/**
* @param $value
* @return bool
*/
function setTerm( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'term_id', $value );
}
/**
* @return bool|int
*/
function getSeverity() {
return $this->getGenericDataValue( 'severity_id' );
}
/**
* @param $value
* @return bool
*/
function setSeverity( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'severity_id', $value );
}
/**
* @return bool|int
*/
function getStatus() {
return $this->getGenericDataValue( 'status_id' );
}
/**
* @param $value
* @return bool
*/
function setStatus( $value ) {
$value = (int)trim( $value );
Debug::Text( 'Setting status_id data... ' . $value, __FILE__, __LINE__, __METHOD__, 10 );
return $this->setGenericDataValue( 'status_id', $value );
}
/**
* @return bool|int
*/
function getStartDate() {
return (int)$this->getGenericDataValue( 'start_date' );
}
/**
* @param int $value EPOCH
* @return bool
*/
function setStartDate( $value ) {
$value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings.
return $this->setGenericDataValue( 'start_date', $value );
}
/**
* @return bool|int
*/
function getEndDate() {
return (int)$this->getGenericDataValue( 'end_date' );
}
/**
* @param int $value EPOCH
* @return bool
*/
function setEndDate( $value ) {
$value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings.
return $this->setGenericDataValue( 'end_date', $value );
}
/**
* @return bool|int
*/
function getDueDate() {
return (int)$this->getGenericDataValue( 'due_date' );
}
/**
* @param int $value EPOCH
* @return bool
*/
function setDueDate( $value ) {
$value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings.
return $this->setGenericDataValue( 'due_date', $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->getUserObject() )
&& TTUUID::isUUID( $this->getUserObject()->getCompany() ) && $this->getUserObject()->getCompany() != TTUUID::getZeroID() && $this->getUserObject()->getCompany() != TTUUID::getNotExistID()
&& TTUUID::isUUID( $this->getID() ) && $this->getID() != TTUUID::getZeroID() && $this->getID() != TTUUID::getNotExistID()
) {
return CompanyGenericTagMapListFactory::getStringByCompanyIDAndObjectTypeIDAndObjectID( $this->getUserObject()->getCompany(), 320, $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
$ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */
$this->Validator->isResultSetWithRows( 'user_id',
$ulf->getByID( $this->getUser() ),
TTi18n::gettext( 'Invalid employee' )
);
// reviewer
$ulf = TTnew( 'UserListFactory' ); /** @var UserListFactory $ulf */
$this->Validator->isResultSetWithRows( 'reviewer_user_id',
$ulf->getByID( $this->getReviewerUser() ),
TTi18n::gettext( 'Invalid reviewer' )
);
// Type
$this->Validator->inArrayKey( 'type',
$this->getType(),
TTi18n::gettext( 'Incorrect Type' ),
$this->getOptions( 'type' )
);
// Terms
$this->Validator->inArrayKey( 'term',
$this->getTerm(),
TTi18n::gettext( 'Incorrect Terms' ),
$this->getOptions( 'term' )
);
// Severity
$this->Validator->inArrayKey( 'severity',
$this->getSeverity(),
TTi18n::gettext( 'Incorrect Severity' ),
$this->getOptions( 'severity' )
);
// Status
$this->Validator->inArrayKey( 'status',
$this->getStatus(),
TTi18n::gettext( 'Incorrect Status' ),
$this->getOptions( 'status' )
);
// start date
if ( $this->getStartDate() != '' ) {
$this->Validator->isDate( 'start_date',
$this->getStartDate(),
TTi18n::gettext( 'Incorrect start date' )
);
}
// end date
if ( $this->getEndDate() != '' ) {
$this->Validator->isDate( 'end_date',
$this->getEndDate(),
TTi18n::gettext( 'Incorrect end date' )
);
}
// due date
if ( $this->getDueDate() != '' ) {
$this->Validator->isDate( 'due_date',
$this->getDueDate(),
TTi18n::gettext( 'Incorrect due date' )
);
}
// 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->isLengthAfterDecimal( 'rating',
$this->getRating(),
TTi18n::gettext( 'Invalid Rating' ),
0,
2
);
}
if ( $this->Validator->isError( 'rating' ) == false ) {
$this->Validator->isLessThan( 'rating',
$this->getRating(),
TTi18n::gettext( 'Rating must be less than 99999' ),
99999
);
}
if ( $this->Validator->isError( 'rating' ) == false ) {
$this->Validator->isGreaterThan( 'rating',
$this->getRating(),
TTi18n::gettext( 'Rating must be higher than -99999' ),
-99999
);
}
}
// Note
if ( $this->getNote() != '' ) {
$this->Validator->isLength( 'note',
$this->getNote(),
TTi18n::gettext( 'Note is too short or too long' ),
2, 2048
);
}
//
// ABOVE: Validation code moved from set*() functions.
//
$start_date = $this->getStartDate();
$end_date = $this->getEndDate();
$due_date = $this->getDueDate();
if ( $start_date != '' && $end_date != '' && $due_date != '' ) {
if ( $end_date < $start_date ) {
$this->Validator->isTrue( 'end_date',
false,
TTi18n::gettext( 'End date should be after start date' )
);
}
if ( $due_date < $start_date ) {
$this->Validator->isTrue( 'due_date',
false,
TTi18n::gettext( 'Due date should be after start date' )
);
}
}
return true;
}
/**
* @return bool
*/
function preSave() {
//SQL schema has NOT NULL constraints on start_date, end_date and due_date, which causes problem when trying to copy these records. So force them to always be set here.
if ( empty( $this->getStartDate() ) ) {
$this->setStartDate( 0 );
}
if ( empty( $this->getEndDate() ) ) {
$this->setEndDate( 0 );
}
if ( empty( $this->getDueDate() ) ) {
$this->setDueDate( 0 );
}
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->getUserObject()->getCompany(), 320, $this->getID(), $this->getTag() );
}
return true;
}
/**
* Support setting created_by, updated_by especially for importing data.
* Make sure data is set based on the getVariableToFunctionMap order.
* @param $data
* @return bool
*/
function setObjectFromArray( $data ) {
Debug::Arr( $data, 'setObjectFromArray...', __FILE__, __LINE__, __METHOD__, 10 );
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 'start_date':
$this->setStartDate( TTDate::parseDateTime( $data['start_date'] ) );
break;
case 'end_date':
$this->setEndDate( TTDate::parseDateTime( $data['end_date'] ) );
break;
case 'due_date':
$this->setDueDate( TTDate::parseDateTime( $data['due_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 'type':
case 'term':
case 'severity':
case 'status':
$function = 'get' . $variable;
if ( method_exists( $this, $function ) ) {
$data[$variable] = Option::getByKey( $this->$function(), $this->getOptions( $variable ) );
}
break;
case 'user':
$data[$variable] = Misc::getFullName( $this->getColumn( 'user_first_name' ), null, $this->getColumn( 'user_last_name' ), false, false );
break;
case 'reviewer_user':
$data[$variable] = Misc::getFullName( $this->getColumn( 'reviewer_user_first_name' ), null, $this->getColumn( 'reviewer_user_last_name' ), false, false );
break;
case 'start_date':
$data['start_date'] = TTDate::getAPIDate( 'DATE', $this->getStartDate() );
break;
case 'end_date':
$data['end_date'] = TTDate::getAPIDate( 'DATE', $this->getEndDate() );
break;
case 'due_date':
$data['due_date'] = TTDate::getAPIDate( 'DATE', $this->getDueDate() );
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( 'Employee Review' ) . ' - ' . TTi18n::getText( 'Type' ) . ': ' . Option::getByKey( $this->getType(), $this->getOptions( 'type' ) ) . ', ' . TTi18n::getText( 'Status' ) . ': ' . Option::getByKey( $this->getStatus(), $this->getOptions( 'status' ) ), null, $this->getTable(), $this );
}
}
?>

View File

@ -0,0 +1,420 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class UserReviewControlListFactory extends UserReviewControlFactory implements IteratorAggregate {
/**
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return $this
*/
function getAll( $limit = null, $page = null, $where = null, $order = null ) {
$query = '
select *
from ' . $this->getTable() . '
WHERE deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, null, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getById( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$this->rs = $this->getCache( $id );
if ( $this->rs === false ) {
$ph = [
'id' => TTUUID::castUUID( $id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
$this->saveCache( $this->rs, $id );
}
return $this;
}
/**
* @param string $user_id UUID
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getByUserId( $user_id, $order = null ) {
if ( $user_id == '' ) {
return false;
}
$ph = [
'user_id' => TTUUID::castUUID( $user_id ),
];
$query = '
select *
from ' . $this->getTable() . '
where user_id = ?
AND deleted = 0';
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $user_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getByIdAndUserId( $id, $user_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$cache_id = $id . $user_id;
$this->rs = $this->getCache( $cache_id );
if ( $this->rs === false ) {
$ph = [
'id' => TTUUID::castUUID( $id ),
'user_id' => TTUUID::castUUID( $user_id ),
];
$query = '
select *
from ' . $this->getTable() . '
where id = ?
AND user_id = ?
AND deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
$this->saveCache( $this->rs, $cache_id );
}
return $this;
}
/**
* @param string $company_id UUID
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getByCompanyId( $company_id, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( $order == null ) {
$order = [ 'a.due_date' => 'desc' ];
$strict = false;
} else {
$strict = true;
}
$uf = new UserFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $uf->getTable() . ' as u ON ( a.user_id = u.id AND u.deleted = 0 )
where u.company_id = ?
AND a.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$uf = new UserFactory();
$ph = [
'id' => TTUUID::castUUID( $id ),
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $uf->getTable() . ' as u ON ( a.user_id = u.id AND u.deleted = 0 )
where a.id = ?
AND u.company_id = ?
AND a.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param $filter_data
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewControlListFactory
*/
function getAPISearchByCompanyIdAndArrayCriteria( $company_id, $filter_data, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( isset( $filter_data['user_review_control_id'] ) ) {
$filter_data['id'] = $filter_data['user_review_control_id'];
}
if ( isset( $filter_data['user_review_control_status_id'] ) ) {
$filter_data['status_id'] = $filter_data['user_review_control_status_id'];
}
if ( isset( $filter_data['user_review_control_type_id'] ) ) {
$filter_data['type_id'] = $filter_data['user_review_control_type_id'];
}
if ( isset( $filter_data['include_user_id'] ) ) {
$filter_data['user_id'] = $filter_data['include_user_id'];
}
if ( isset( $filter_data['exclude_user_id'] ) ) {
$filter_data['exclude_id'] = $filter_data['exclude_user_id'];
}
if ( isset( $filter_data['include_reviewer_user_id'] ) ) {
$filter_data['reviewer_user_id'] = $filter_data['include_reviewer_user_id'];
}
if ( isset( $filter_data['review_tag'] ) ) {
$filter_data['tag'] = $filter_data['review_tag'];
}
if ( !is_array( $order ) ) {
//Use Filter Data ordering if its set.
if ( isset( $filter_data['sort_column'] ) && $filter_data['sort_order'] ) {
$order = [ Misc::trimSortPrefix( $filter_data['sort_column'] ) => $filter_data['sort_order'] ];
}
}
$additional_order_fields = [ 'uf.first_name', 'u.first_name', 'status_id', 'type_id', 'term_id', 'severity_id' ];
$sort_column_aliases = [
'type' => 'type_id',
'status' => 'status_id',
'term' => 'term_id',
'severity' => 'severity_id',
];
$order = $this->getColumnsFromAliases( $order, $sort_column_aliases );
if ( $order == null ) {
$order = [ 'uf.first_name' => 'asc' ];
$strict = false;
} else {
if ( isset( $order['user'] ) ) {
$order['uf.first_name'] = $order['user'];
unset( $order['user'] );
}
if ( isset( $order['first_name'] ) ) {
$order['uf.first_name'] = $order['first_name'];
unset( $order['first_name'] );
}
if ( isset( $order['last_name'] ) ) {
$order['uf.last_name'] = $order['last_name'];
unset( $order['last_name'] );
}
if ( isset( $order['reviewer_user'] ) ) {
$order['u.first_name'] = $order['reviewer_user'];
unset( $order['reviewer_user'] );
}
$strict = true;
}
//Debug::Arr($order, 'Order Data:', __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10);
$uf = new UserFactory();
$urf = new UserReviewFactory();
$ph = [
'company_id' => TTUUID::castUUID( $company_id ),
];
$query = '
select distinct a.*,
uf.first_name as user_first_name,
uf.last_name as user_last_name,
u.first_name as reviewer_user_first_name,
u.last_name as reviewer_user_last_name,
y.first_name as created_by_first_name,
y.middle_name as created_by_middle_name,
y.last_name as created_by_last_name,
z.first_name as updated_by_first_name,
z.middle_name as updated_by_middle_name,
z.last_name as updated_by_last_name
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $urf->getTable() . ' as urf ON ( urf.user_review_control_id = a.id AND urf.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as uf ON ( a.user_id = uf.id AND uf.deleted = 0)
LEFT JOIN ' . $uf->getTable() . ' as u ON ( a.reviewer_user_id = u.id AND u.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
where uf.company_id = ? ';
$query .= ( isset( $filter_data['permission_children_ids'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['permission_children_ids'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['user_id'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['user_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['exclude_id'] ) ) ? $this->getWhereClauseSQL( 'a.user_id', $filter_data['exclude_id'], 'not_uuid_list', $ph ) : null;
if ( isset( $filter_data['status'] ) && !is_array( $filter_data['status'] ) && trim( $filter_data['status'] ) != '' && !isset( $filter_data['status_id'] ) ) {
$filter_data['status_id'] = Option::getByFuzzyValue( $filter_data['status'], $this->getOptions( 'status' ) );
}
if ( isset( $filter_data['type'] ) && !is_array( $filter_data['type'] ) && trim( $filter_data['type'] ) != '' && !isset( $filter_data['type_id'] ) ) {
$filter_data['type_id'] = Option::getByFuzzyValue( $filter_data['type'], $this->getOptions( 'type' ) );
}
if ( isset( $filter_data['term'] ) && !is_array( $filter_data['term'] ) && trim( $filter_data['term'] ) != '' && !isset( $filter_data['term_id'] ) ) {
$filter_data['term_id'] = Option::getByFuzzyValue( $filter_data['term'], $this->getOptions( 'term' ) );
}
if ( isset( $filter_data['severity'] ) && !is_array( $filter_data['severity'] ) && trim( $filter_data['severity'] ) != '' && !isset( $filter_data['severity_id'] ) ) {
$filter_data['severity_id'] = Option::getByFuzzyValue( $filter_data['severity'], $this->getOptions( 'severity' ) );
}
$query .= ( isset( $filter_data['reviewer_user_id'] ) ) ? $this->getWhereClauseSQL( 'a.reviewer_user_id', $filter_data['reviewer_user_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['reviewer_user'] ) ) ? $this->getWhereClauseSQL( [ 'a.reviewer_user_id', 'uf.first_name', 'uf.last_name' ], $filter_data['reviewer_user'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['user'] ) ) ? $this->getWhereClauseSQL( [ 'a.user_id', 'uf.first_name', 'uf.last_name' ], $filter_data['user'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['exclude_reviewer_user_id'] ) ) ? $this->getWhereClauseSQL( 'a.reviewer_user_id', $filter_data['exclude_reviewer_user_id'], 'not_uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['status_id'] ) ) ? $this->getWhereClauseSQL( 'a.status_id', $filter_data['status_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['type_id'] ) ) ? $this->getWhereClauseSQL( 'a.type_id', $filter_data['type_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['term_id'] ) ) ? $this->getWhereClauseSQL( 'a.term_id', $filter_data['term_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['severity_id'] ) ) ? $this->getWhereClauseSQL( 'a.severity_id', $filter_data['severity_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['tag'] ) ) ? $this->getWhereClauseSQL( 'a.id', [ 'company_id' => TTUUID::castUUID( $company_id ), 'object_type_id' => 320, 'tag' => $filter_data['tag'] ], 'tag', $ph ) : null;
$query .= ( isset( $filter_data['due_date'] ) ) ? $this->getWhereClauseSQL( 'a.due_date', $filter_data['due_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['kpi_id'] ) ) ? $this->getWhereClauseSQL( 'urf.kpi_id', $filter_data['kpi_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['rating'] ) ) ? $this->getWhereClauseSQL( 'a.rating', $filter_data['rating'], 'numeric', $ph ) : null;
$query .= ( isset( $filter_data['note'] ) ) ? $this->getWhereClauseSQL( 'a.note', $filter_data['note'], 'text', $ph ) : null;
if ( isset( $filter_data['time_period'] ) ) {
$query .= ( isset( $filter_data['start_date'] ) ) ? $this->getWhereClauseSQL( 'a.due_date', $filter_data['start_date'], 'start_date', $ph ) : null;
$query .= ( isset( $filter_data['end_date'] ) ) ? $this->getWhereClauseSQL( 'a.due_date', $filter_data['end_date'], 'end_date', $ph ) : null;
/*
if ( isset($filter_data['start_date']) AND !is_array($filter_data['start_date']) AND trim($filter_data['start_date']) != '' ) {
$ph[] = (int)$filter_data['start_date'];
$query .= ' AND a.due_date >= ?';
}
if ( isset($filter_data['end_date']) AND !is_array($filter_data['end_date']) AND trim($filter_data['end_date']) != '' ) {
$ph[] = (int)$filter_data['end_date'];
$query .= ' AND a.due_date <= ?';
}
*/
} else {
$query .= ( isset( $filter_data['start_date'] ) ) ? $this->getWhereClauseSQL( 'a.start_date', $filter_data['start_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['end_date'] ) ) ? $this->getWhereClauseSQL( 'a.end_date', $filter_data['end_date'], 'date_range', $ph ) : null;
}
$query .= ( isset( $filter_data['created_date'] ) ) ? $this->getWhereClauseSQL( 'a.created_date', $filter_data['created_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['updated_date'] ) ) ? $this->getWhereClauseSQL( 'a.updated_date', $filter_data['updated_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['created_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.created_by', 'y.first_name', 'y.last_name' ], $filter_data['created_by'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['updated_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.updated_by', 'z.first_name', 'z.last_name' ], $filter_data['updated_by'], 'user_id_or_name', $ph ) : null;
$query .= ' AND a.deleted = 0 ';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
//Debug::Query( $query, $ph, __FILE__, __LINE__, __METHOD__, 10);
return $this;
}
}
?>

View File

@ -0,0 +1,377 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class UserReviewFactory extends Factory {
protected $table = 'user_review';
protected $pk_sequence_name = 'user_review_id_seq'; //PK Sequence name
protected $kpi_obj = null;
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'columns':
$retval = [
'-2050-rating' => 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;
}
}
?>

View File

@ -0,0 +1,301 @@
<?php
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @package Modules\KPI
*/
class UserReviewListFactory extends UserReviewFactory implements IteratorAggregate {
/**
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return $this
*/
function getAll( $limit = null, $page = null, $where = null, $order = null ) {
$urcf = new UserReviewControlFactory();
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
WHERE a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, null, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getById( $id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
$this->rs = $this->getCache( $id );
if ( $this->rs === false ) {
$urcf = new UserReviewControlFactory();
$ph = [ 'id' => TTUUID::castUUID( $id ), ];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
where a.id = ?
AND a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
$this->saveCache( $this->rs, $id );
}
return $this;
}
/**
* @param string $id UUID
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getByUserReviewControlId( $id, $order = null ) {
if ( $id == '' ) {
return false;
}
$urcf = new UserReviewControlFactory();
$ph = [ 'user_review_control_id' => TTUUID::castUUID( $id ), ];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
where a.user_review_control_id = ?
AND a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getByKpiId( $id, $order = null ) {
if ( $id == '' ) {
return false;
}
$urcf = new UserReviewControlFactory();
$ph = [ 'kpi_id' => TTUUID::castUUID( $id ), ];
$query = '
select *
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
where a.kpi_id = ?
AND a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getByCompanyId( $company_id, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
$kf = new KPIFactory();
$urcf = new UserReviewControlFactory();
$ph = [ 'company_id' => TTUUID::castUUID( $company_id ), ];
$query = '
select a.*
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $kf->getTable() . ' as k ON ( a.kpi_id = k.id AND k.deleted = 0 )
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
where k.company_id = ?
AND a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $id UUID
* @param string $company_id UUID
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $company_id == '' ) {
return false;
}
$kf = new KPIFactory();
$urcf = new UserReviewControlFactory();
$ph = [ 'id' => TTUUID::castUUID( $id ), 'company_id' => TTUUID::castUUID( $company_id ), ];
$query = '
select a.*,
urcf.user_id as user_id
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $kf->getTable() . ' as k ON ( a.kpi_id = k.id AND k.deleted = 0 )
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
where a.id = ?
AND k.company_id = ?
AND a.deleted = 0 AND urcf.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order );
$this->rs = $this->ExecuteSQL( $query, $ph );
return $this;
}
/**
* @param string $company_id UUID
* @param $filter_data
* @param int $limit Limit the number of records returned
* @param int $page Page number of records to return for pagination
* @param array $where Additional SQL WHERE clause in format of array( $column => $filter, ... ). ie: array( 'id' => 1, ... )
* @param array $order Sort order passed to SQL in format of array( $column => 'asc', 'name' => 'desc', ... ). ie: array( 'id' => 'asc', 'name' => 'desc', ... )
* @return bool|UserReviewListFactory
*/
function getAPISearchByCompanyIdAndArrayCriteria( $company_id, $filter_data, $limit = null, $page = null, $where = null, $order = null ) {
if ( $company_id == '' ) {
return false;
}
if ( !is_array( $order ) ) {
//Use Filter Data ordering if its set.
if ( isset( $filter_data['sort_column'] ) && $filter_data['sort_order'] ) {
$order = [ Misc::trimSortPrefix( $filter_data['sort_column'] ) => $filter_data['sort_order'] ];
}
}
$additional_order_fields = [];
$sort_column_aliases = [];
$order = $this->getColumnsFromAliases( $order, $sort_column_aliases );
if ( $order == null ) {
$order = [ 'kf.display_order' => 'asc', 'kf.name' => 'asc' ];
$strict = false;
} else {
$strict = true;
}
//Debug::Arr($order, 'Order Data:', __FILE__, __LINE__, __METHOD__, 10);
//Debug::Arr($filter_data, 'Filter Data:', __FILE__, __LINE__, __METHOD__, 10);
$uf = new UserFactory();
$kf = new KPIFactory();
$urcf = new UserReviewControlFactory();
$ph = [ 'company_id' => TTUUID::castUUID( $company_id ), ];
$query = '
select a.*,
kf.name,
kf.type_id,
kf.status_id,
kf.minimum_rate,
kf.maximum_rate,
kf.description,
kf.display_order,
y.first_name as created_by_first_name,
y.middle_name as created_by_middle_name,
y.last_name as created_by_last_name,
z.first_name as updated_by_first_name,
z.middle_name as updated_by_middle_name,
z.last_name as updated_by_last_name
from ' . $this->getTable() . ' as a
LEFT JOIN ' . $kf->getTable() . ' as kf ON ( a.kpi_id = kf.id AND kf.deleted = 0 )
LEFT JOIN ' . $urcf->getTable() . ' as urcf ON ( a.user_review_control_id = urcf.id )
LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
where kf.company_id = ? AND urcf.deleted = 0';
$query .= ( isset( $filter_data['permission_children_ids'] ) ) ? $this->getWhereClauseSQL( 'urcf.user_id', $filter_data['permission_children_ids'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['id'] ) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['id'], 'uuid_list', $ph ) : null;
//$query .= ( isset($filter_data['exclude_id']) ) ? $this->getWhereClauseSQL( 'a.id', $filter_data['exclude_id'], 'not_uuid_list', $ph ) : NULL;
$query .= ( isset( $filter_data['user_review_control_id'] ) ) ? $this->getWhereClauseSQL( 'a.user_review_control_id', $filter_data['user_review_control_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['kpi_id'] ) ) ? $this->getWhereClauseSQL( 'a.kpi_id', $filter_data['kpi_id'], 'uuid_list', $ph ) : null;
$query .= ( isset( $filter_data['term_id'] ) ) ? $this->getWhereClauseSQL( 'urcf.term_id', $filter_data['term_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['severity_id'] ) ) ? $this->getWhereClauseSQL( 'urcf.severity_id', $filter_data['severity_id'], 'numeric_list', $ph ) : null;
$query .= ( isset( $filter_data['rating'] ) ) ? $this->getWhereClauseSQL( 'a.rating', $filter_data['rating'], 'numeric', $ph ) : null;
$query .= ( isset( $filter_data['note'] ) ) ? $this->getWhereClauseSQL( 'a.note', $filter_data['note'], 'text', $ph ) : null;
$query .= ( isset( $filter_data['tag'] ) ) ? $this->getWhereClauseSQL( 'a.id', [ 'company_id' => TTUUID::castUUID( $company_id ), 'object_type_id' => 330, 'tag' => $filter_data['tag'] ], 'tag', $ph ) : null;
$query .= ( isset( $filter_data['created_date'] ) ) ? $this->getWhereClauseSQL( 'a.created_date', $filter_data['created_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['updated_date'] ) ) ? $this->getWhereClauseSQL( 'a.updated_date', $filter_data['updated_date'], 'date_range', $ph ) : null;
$query .= ( isset( $filter_data['created_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.created_by', 'y.first_name', 'y.last_name' ], $filter_data['created_by'], 'user_id_or_name', $ph ) : null;
$query .= ( isset( $filter_data['updated_by'] ) ) ? $this->getWhereClauseSQL( [ 'a.updated_by', 'z.first_name', 'z.last_name' ], $filter_data['updated_by'], 'user_id_or_name', $ph ) : null;
$query .= ' AND a.deleted = 0 ';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict, $additional_order_fields );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
return $this;
}
}
?>