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,246 @@
<?php
/*
* $License$
*/
/**
* @package Modules\UIKit
*/
class UIKitChildSampleFactory extends Factory {
protected $table = 'ui_kit_child';
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'combo_box':
$retval = [
10 => TTi18n::gettext( 'Option 1' ),
20 => TTi18n::gettext( 'Option 2' ),
30 => TTi18n::gettext( 'Option 3' ),
40 => TTi18n::gettext( 'Option 4' ),
];
break;
case 'columns':
$retval = [
'-1010-text_input' => TTi18n::gettext( 'Name' ),
'-1030-combo_box' => TTi18n::gettext( 'Combo Box' ),
'-1070-checkbox' => TTi18n::gettext( 'Checkbox' ),
'-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 = [
'text_input',
'combo_box',
'checkbox',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'company_id' => 'Company',
'text_input' => 'TextInput',
'checkbox' => 'Checkbox',
'combo_box' => 'ComboBox',
'parent_id' => 'Parent',
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool|mixed
*/
function getCompany() {
return $this->getGenericDataValue( 'company_id' );
}
/**
* @param $value
* @return bool
*/
function setCompany( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'company_id', $value );
}
/**
* @return string
*/
function getTextInput() {
return $this->getGenericDataValue( 'text_input' );
}
/**
* @param $value
* @return bool
*/
function setTextInput( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'text_input', $value );
}
/**
* @param bool $value
* @return bool
*/
function setCheckbox( $value ) {
return $this->setGenericDataValue( 'checkbox', $this->toBool( $value ) );
}
/**
* @return bool
*/
function getCheckbox() {
return $this->fromBool( $this->getGenericDataValue( 'checkbox' ) );
}
/**
* @return bool|int
*/
function getComboBox() {
return $this->getGenericDataValue( 'combo_box' );
}
/**
* @param $value
* @return bool
*/
function setComboBox( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'combo_box', $value );
}
/**
* Parent ID is the main ui kit sample ID.
* @return bool
*/
function getParent() {
return $this->getGenericDataValue( 'parent_id' );
}
/**
* @param string $value UUID
* @return bool
*/
function setParent( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'parent_id', $value );
}
/**
* @param bool $ignore_warning
* @return bool
*/
function Validate( $ignore_warning = true ) {
return true;
}
/**
* @return bool
*/
function preSave() {
return true;
}
/**
* @return bool
*/
function postSave() {
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
* @return array
*/
function getObjectAsArray( $include_columns = null ) {
$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->getCreatedAndUpdatedColumns( $data, $include_columns );
}
return $data;
}
/**
* @param $log_action
* @return bool
*/
function addLog( $log_action ) {
return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'UI Kit Child Sample' ), null, $this->getTable(), $this );
}
}
?>

View File

@@ -0,0 +1,203 @@
<?php
/*
* $License$
*/
/**
* @package Modules\UIKit
*/
class UIKitChildSampleListFactory extends UIKitChildSampleFactory 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|UIKitChildSampleListFactory
*/
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 $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|UIKitChildSampleListFactory
*/
function getByCompanyId( $id, $limit = null, $page = null, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $order == null ) {
$order = [ 'created_date' => 'desc' ];
$strict = false;
} else {
$strict = true;
}
$ph = [
'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, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param string $company_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|UIKitChildSampleListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $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->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|UIKitChildSampleListFactory
*/
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'] ];
}
}
$order = $this->getColumnsFromAliases( $order, [] );
if ( $order == null ) {
$order = [ 'created_date' => 'desc'];
$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();
$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['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['parent_id'] ) ) ? $this->getWhereClauseSQL( 'a.parent_id', $filter_data['parent_id'], 'uuid_list', $ph ) : null;
$query .= ' AND a.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
//debug log the query
Debug::Query( $query, $ph, __FILE__, __LINE__, __METHOD__, 10);
return $this;
}
}
?>

View File

@@ -0,0 +1,539 @@
<?php
/*
* $License$
*/
/**
* @package Modules\UIKit
*/
class UIKitSampleFactory extends Factory {
protected $table = 'ui_kit';
/**
* @param $name
* @param null $parent
* @return array|null
*/
function _getFactoryOptions( $name, $parent = null ) {
$retval = null;
switch ( $name ) {
case 'combo_box':
$retval = [
10 => TTi18n::gettext( 'Option 1' ),
20 => TTi18n::gettext( 'Option 2' ),
30 => TTi18n::gettext( 'Option 3' ),
40 => TTi18n::gettext( 'Option 4' ),
];
break;
case 'columns':
$retval = [
'-1010-text_input' => TTi18n::gettext( 'Name' ),
'-1020-tag' => TTi18n::gettext( 'Tags' ),
'-1030-combo_box_parent' => TTi18n::gettext( 'Combo Box Parent' ),
'-1030-combo_box_child' => TTi18n::gettext( 'Combo Box Child' ),
'-1040-date' => TTi18n::gettext( 'Date' ),
'-1060-time' => TTi18n::gettext( 'Time' ),
'-1070-checkbox' => TTi18n::gettext( 'Checkbox' ),
'-1080-numeric_input' => TTi18n::gettext( 'Numeric' ),
'-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' ),
];
$retval = $this->getCustomFieldsColumns( $retval, null );
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 = [
'text_input',
'tag',
'combo_box_parent',
'combo_box_child',
'date',
'time',
'checkbox',
'numeric_input',
];
break;
}
return $retval;
}
/**
* @param $data
* @return array
*/
function _getVariableToFunctionMap( $data ) {
$variable_function_map = [
'id' => 'ID',
'company_id' => 'Company',
'text_input' => 'TextInput',
'password_input' => 'PasswordInput',
'numeric_input' => 'NumericInput',
'textarea' => 'Textarea',
'checkbox' => 'Checkbox',
'wysiwg_text' => 'WYSIWGText',
'tag' => 'Tag',
'combo_box' => 'ComboBox',
'combo_box_parent' => 'ComboBoxParent',
'combo_box_child' => 'ComboBoxChild',
'awesome_box_multi' => 'AwesomeBoxMulti',
'awesome_box_single' => 'AwesomeBoxSingle',
'date' => 'Date',
'date_range' => 'DateRange',
'time' => 'Time',
'color' => 'Color',
'formula_builder' => 'FormulaBuilder',
'deleted' => 'Deleted',
];
return $variable_function_map;
}
/**
* @return bool|mixed
*/
function getCompany() {
return $this->getGenericDataValue( 'company_id' );
}
/**
* @param $value
* @return bool
*/
function setCompany( $value ) {
$value = TTUUID::castUUID( $value );
return $this->setGenericDataValue( 'company_id', $value );
}
/**
* @return string
*/
function getTextInput() {
return $this->getGenericDataValue( 'text_input' );
}
/**
* @param $value
* @return bool
*/
function setTextInput( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'text_input', $value );
}
/**
* @return string
*/
function getPasswordInput() {
return $this->getGenericDataValue( 'password_input' );
}
/**
* @param $value
* @return bool
*/
function setPasswordInput( $value ) {
$password = trim( $value );
//Check to see if the password is hashed and being passed back into itself from the LogDetailFactory or UIKitSample
if ( strlen( $password ) > 100 && strpos( $password, ':' ) !== false ) {
Debug::Text( 'Password is hashed, ignoring: ' . $password, __FILE__, __LINE__, __METHOD__, 10 );
return false;
}
return $this->setGenericDataValue( 'password_input', TTPassword::encryptPassword( $password, $this->getCompany() ) );
}
/**
* @return string
*/
function getNumericInput() {
return (float)$this->getGenericDataValue( 'numeric_input' ); //Needs to return float so TTi18n::NumberFormat() can always handle it properly.
}
/**
* @param $value
* @return bool
*/
function setNumericInput( $value ) {
//Pull out only digits and periods.
$value = $this->Validator->stripNonFloat( $value );
return $this->setGenericDataValue( 'numeric_input', $value );
}
/**
* @return string
*/
function getTag() {
return $this->getGenericDataValue( 'tag' );
}
/**
* @param $value
* @return bool
*/
function setTag( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'tag', $value );
}
/**
* @return string
*/
function getTextarea() {
return $this->getGenericDataValue( 'textarea' );
}
/**
* @param $value
* @return bool
*/
function setTextarea( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'textarea', $value );
}
/**
* @return string
*/
function getWYSIWGText() {
return $this->getGenericDataValue( 'wysiwg_text' );
}
/**
* @param $value
* @return bool
*/
function setWYSIWGText( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'wysiwg_text', $value );
}
/**
* @param bool $value
* @return bool
*/
function setCheckbox( $value ) {
return $this->setGenericDataValue( 'checkbox', $this->toBool( $value ) );
}
/**
* @return bool
*/
function getCheckbox() {
return $this->fromBool( $this->getGenericDataValue( 'checkbox' ) );
}
/**
* @return bool|int
*/
function getComboBox() {
return $this->getGenericDataValue( 'combo_box' );
}
/**
* @param $value
* @return bool
*/
function setComboBox( $value ) {
$value = (int)trim( $value );
return $this->setGenericDataValue( 'combo_box', $value );
}
/**
* @return bool|int
*/
function getComboBoxParent() {
return $this->getGenericDataValue( 'combo_box_parent' );
}
/**
* @param $value
* @return bool
*/
function setComboBoxParent( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'combo_box_parent', $value );
}
/**
* @return bool|int
*/
function getComboBoxChild() {
return $this->getGenericDataValue( 'combo_box_child' );
}
/**
* @param $value
* @return bool
*/
function setComboBoxChild( $value ) {
$value = trim( $value );
return $this->setGenericDataValue( 'combo_box_child', $value );
}
/**
* @return array
*/
function getAwesomeBoxMulti() {
return $this->getGenericJSONDataValue( 'awesome_box_multi' );
}
/**
* @param array $value records.
* @return bool
*/
function setAwesomeBoxMulti( $value ) {
return $this->setGenericJSONDataValue( 'awesome_box_multi', $value );
}
/**
* @return array
*/
function getAwesomeBoxSingle() {
return $this->getGenericDataValue( 'awesome_box_single' );
}
/**
* @param array $value records.
* @return bool
*/
function setAwesomeBoxSingle( $value ) {
return $this->setGenericDataValue( 'awesome_box_single', $value );
}
/**
* @param bool $raw
* @return bool|mixed
*/
function getDate( $raw = false ) {
$value = $this->getGenericDataValue( 'date' );
if ( $value !== false ) {
if ( $raw === true ) {
return $value;
} else {
return TTDate::strtotime( $value );
}
}
return false;
}
/**
* @param $value
* @return bool
*/
function setDate( $value ) {
return $this->setGenericDataValue( 'date', TTDate::getISODateStamp( $value ) );
}
/**
* @return array
*/
function getDateRange() {
return $this->getGenericJSONDataValue( 'date_range' );
}
/**
* @param array $value records.
* @return bool
*/
function setDateRange( $value ) {
return $this->setGenericJSONDataValue( 'date_range', $value );
}
/**
* @param bool $raw
* @return bool|int
*/
function getTime( $raw = false ) {
$value = $this->getGenericDataValue( 'time' );
if ( $value !== false ) {
if ( $raw === true ) {
return $value;
} else {
return TTDate::strtotime( $value );
}
}
return false;
}
/**
* @param $value
* @return bool
*/
function setTime( $value ) {
$value = ( !is_int( $value ) && $value !== null ) ? trim( $value ) : $value;//Dont trim integer values, as it changes them to strings.
return $this->setGenericDataValue( 'time', $value );
}
/**
* @return bool|mixed
*/
function getColor() {
return $this->getGenericJSONDataValue( 'color' );
}
/**
* @param $value
* @return bool
*/
function setColor( $value ) {
$value = trim( $value );
return $this->setGenericJSONDataValue( 'color', $value );
}
/**
* @return bool|mixed
*/
function getFormulaBuilder() {
return $this->getGenericJSONDataValue( 'formula_builder' );
}
/**
* @param $value
* @return bool
*/
function setFormulaBuilder( $value ) {
$value = trim( $value );
return $this->setGenericJSONDataValue( 'formula_builder', $value );
}
/**
* @param bool $ignore_warning
* @return bool
*/
function Validate( $ignore_warning = true ) {
$this->validateCustomFields( $this->getCompany() );
return true;
}
/**
* @return bool
*/
function preSave() {
return true;
}
/**
* @return bool
*/
function postSave() {
return true;
}
/**
* @param $data
* @return bool
*/
function setObjectFromArray( $data ) {
if ( is_array( $data ) ) {
$data = $this->parseCustomFieldsFromArray( $data );
$variable_function_map = $this->getVariableToFunctionMap();
foreach ( $variable_function_map as $key => $function ) {
if ( isset( $data[$key] ) ) {
$function = 'set' . $function;
switch ( $key ) {
case 'time':
case 'date':
if ( method_exists( $this, $function ) ) {
$this->$function( TTDate::parseDateTime( $data[$key] ) );
}
break;
case 'numeric_input':
$this->$function( TTi18n::parseFloat( $data[$key] ) );
break;
default:
if ( method_exists( $this, $function ) ) {
$this->$function( $data[$key] );
}
break;
}
}
}
$this->setCreatedAndUpdatedColumns( $data );
return true;
}
return false;
}
/**
* @param null $include_columns
* @return array
*/
function getObjectAsArray( $include_columns = null ) {
$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 'date':
if ( method_exists( $this, $function ) ) {
$data[ $variable ] = TTDate::getAPIDate( 'DATE', $this->$function() );
}
break;
case 'time':
$data[$variable] = ( defined( 'TIMETREX_API' ) ) ? TTDate::getAPIDate( 'TIME', TTDate::strtotime( $this->$function() ) ) : $this->$function();
break;
case 'numeric_input':
$data[$variable] = Misc::removeTrailingZeros( $this->$function(), 2 );
break;
case 'password_input': //Must not be returned to the API ever due to security risks. Replicating that in this UIkit
break;
default:
if ( method_exists( $this, $function ) ) {
$data[$variable] = $this->$function();
}
break;
}
}
}
$this->getCreatedAndUpdatedColumns( $data, $include_columns );
$data = $this->getCustomFields( $this->getCompany(), $data, $include_columns );
}
return $data;
}
/**
* @param $log_action
* @return bool
*/
function addLog( $log_action ) {
return TTLog::addEntry( $this->getId(), $log_action, TTi18n::getText( 'UI Kit Sample' ), null, $this->getTable(), $this );
}
}
?>

View File

@@ -0,0 +1,205 @@
<?php
/*
* $License$
*/
/**
* @package Modules\UIKit
*/
class UIKitSampleListFactory extends UIKitSampleFactory 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|UIKitSampleListFactory
*/
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 $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|UIKitSampleListFactory
*/
function getByCompanyId( $id, $limit = null, $page = null, $where = null, $order = null ) {
if ( $id == '' ) {
return false;
}
if ( $order == null ) {
$order = [ 'created_date' => 'desc' ];
$strict = false;
} else {
$strict = true;
}
$ph = [
'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, $limit, $page );
return $this;
}
/**
* @param string $id UUID
* @param string $company_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|UIKitSampleListFactory
*/
function getByIdAndCompanyId( $id, $company_id, $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->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|UIKitSampleListFactory
*/
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'] ];
}
}
$order = $this->getColumnsFromAliases( $order, [] );
if ( $order == null ) {
$order = [ 'created_date' => 'desc'];
$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();
$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['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;
if ( getTTProductEdition() >= TT_PRODUCT_CORPORATE ) {
$query .= $this->getCustomFieldWhereSQL( $company_id, 'a.custom_field', $filter_data, $ph );
}
$query .= ' AND a.deleted = 0';
$query .= $this->getWhereSQL( $where );
$query .= $this->getSortSQL( $order, $strict );
$this->rs = $this->ExecuteSQL( $query, $ph, $limit, $page );
//debug log the query
Debug::Query( $query, $ph, __FILE__, __LINE__, __METHOD__, 10);
return $this;
}
}
?>