diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-06 15:03:51 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-06 15:03:51 +0100 |
| commit | 4269a36ce2ba9d5ce10ccc50bb698f5d78c32c48 (patch) | |
| tree | e96b3d98415838f8d8242988515441fcff4be65a /includes | |
| parent | cd200fda67728ed962ca7bfd60b2b02ecfa0b904 (diff) | |
| download | stock-4269a36ce2ba9d5ce10ccc50bb698f5d78c32c48.tar.gz stock-4269a36ce2ba9d5ce10ccc50bb698f5d78c32c48.tar.bz2 stock-4269a36ce2ba9d5ce10ccc50bb698f5d78c32c48.zip | |
xref: complete migration from loadXrefList to loadXrefInfo
Remove loadXrefList() overrides from StockBase, StockAssembly,
StockMovement; remove loadXrefList() calls from all load() methods.
StockMovement::load() gains ref_type and ref_from_data correlated
subqueries so templates no longer need mInfo.reference[0].
getDirection() reads mInfo.ref_type directly.
component_order.php/tpl: switch to loadXrefInfo + gXrefInfo path.
edit_assembly.php: remove stale bucket-clearing block.
view_movement.tpl: use mInfo.ref_from_data instead of mInfo.reference.0.data.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
| -rwxr-xr-x | includes/classes/StockAssembly.php | 29 | ||||
| -rwxr-xr-x | includes/classes/StockBase.php | 22 | ||||
| -rwxr-xr-x | includes/classes/StockComponent.php | 1 | ||||
| -rw-r--r-- | includes/classes/StockMovement.php | 39 |
4 files changed, 9 insertions, 82 deletions
diff --git a/includes/classes/StockAssembly.php b/includes/classes/StockAssembly.php index c8b2367..caf34c4 100755 --- a/includes/classes/StockAssembly.php +++ b/includes/classes/StockAssembly.php @@ -114,34 +114,6 @@ class StockAssembly extends StockBase { unset( $row ); } - public function loadXrefList(): void { - parent::loadXrefList(); - if( !empty( $this->mInfo['quantity'] ) ) { - usort( $this->mInfo['quantity'], fn($a,$b) => ($a['xorder'] <=> $b['xorder']) ?: strcmp($a['item'], $b['item']) ); - - $componentIds = array_values( array_unique( array_filter( array_column( $this->mInfo['quantity'], 'xref' ) ) ) ); - if( $componentIds ) { - $placeholders = implode( ',', array_fill( 0, count( $componentIds ), '?' ) ); - $components = $this->mDb->getAssoc( - "SELECT lc.`content_id`, lc.`title`, lc.`data`, pck.`xkey` AS `pack_size`, pck.`xkey_ext` AS `pack_size_ext` - FROM `".BIT_DB_PREFIX."liberty_content` lc - LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = lc.`content_id` AND pck.`item` = 'PCK' - WHERE lc.`content_id` IN ($placeholders)", - $componentIds - ); - foreach( $this->mInfo['quantity'] as &$row ) { - if( !empty( $row['xref'] ) && isset( $components[$row['xref']] ) ) { - $row['xref_title'] = $components[$row['xref']]['title']; - $row['xref_data'] = $components[$row['xref']]['data']; - $row['pack_size'] = $components[$row['xref']]['pack_size']; - $row['pack_size_ext'] = $components[$row['xref']]['pack_size_ext']; - } - } - unset( $row ); - } - } - } - public static function lookup( $pLookupHash, $pLoadFromCache=true ) { global $gBitDb; $ret = null; @@ -185,7 +157,6 @@ class StockAssembly extends StockBase { $this->mContentId = $rs['content_id']; $this->mContentTypeGuid = $rs['content_type_guid']; LibertyContent::load(); - $this->loadXrefList(); $this->mInfo['creator'] = $rs['creator_real_name'] ?? $rs['creator_user']; $this->mInfo['editor'] = $rs['modifier_real_name'] ?? $rs['modifier_user']; diff --git a/includes/classes/StockBase.php b/includes/classes/StockBase.php index 1de52a7..62d5294 100755 --- a/includes/classes/StockBase.php +++ b/includes/classes/StockBase.php @@ -33,28 +33,6 @@ abstract class StockBase extends LibertyContent parent::__construct(); } - public function loadXrefList(): void { - parent::loadXrefList(); - if( !empty( $this->mInfo['supplier'] ) ) { - $contactIds = array_values( array_unique( array_filter( array_column( $this->mInfo['supplier'], 'xref' ) ) ) ); - if( $contactIds ) { - $placeholders = implode( ',', array_fill( 0, count( $contactIds ), '?' ) ); - $contacts = $this->mDb->getAssoc( - "SELECT lc.`content_id`, lc.`title` - FROM `".BIT_DB_PREFIX."liberty_content` lc - WHERE lc.`content_id` IN ($placeholders)", - $contactIds - ); - foreach( $this->mInfo['supplier'] as &$row ) { - if( !empty( $row['xref'] ) && isset( $contacts[$row['xref']] ) ) { - $row['xref_title'] = $contacts[$row['xref']]; - } - } - unset( $row ); - } - } - } - public function loadXrefInfo(): void { parent::loadXrefInfo(); if( empty( $this->mXrefInfo ) ) return; diff --git a/includes/classes/StockComponent.php b/includes/classes/StockComponent.php index c9c7adb..929920e 100755 --- a/includes/classes/StockComponent.php +++ b/includes/classes/StockComponent.php @@ -75,7 +75,6 @@ class StockComponent extends StockBase { $this->mInfo['creator'] = $this->mInfo['creator_real_name'] ?? $this->mInfo['creator_user']; $this->mInfo['editor'] = $this->mInfo['modifier_real_name'] ?? $this->mInfo['modifier_user']; LibertyContent::load(); - $this->loadXrefList(); } return count( $this->mInfo ); } diff --git a/includes/classes/StockMovement.php b/includes/classes/StockMovement.php index ec70203..48d0bd5 100644 --- a/includes/classes/StockMovement.php +++ b/includes/classes/StockMovement.php @@ -82,6 +82,12 @@ class StockMovement extends LibertyContent { JOIN `{$X}liberty_content` lc2 ON lc2.`content_id` = x.`xref` WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') ORDER BY x.`xorder`) AS ref_contact_name + , (SELECT FIRST 1 x.`item` FROM `{$X}liberty_xref` x + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + ORDER BY x.`xorder`) AS ref_type + , (SELECT FIRST 1 x.`data` FROM `{$X}liberty_xref` x + WHERE x.`content_id` = lc.`content_id` AND x.`item` IN ('REQN','TRANS','ORDER') + ORDER BY x.`xorder`) AS ref_from_data FROM `".BIT_DB_PREFIX."liberty_content` lc LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON uue.`user_id` = lc.`modifier_user_id` LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON uuc.`user_id` = lc.`user_id` @@ -95,7 +101,6 @@ class StockMovement extends LibertyContent { $this->mInfo['creator'] = $rs['creator_real_name'] ?? $rs['creator_user']; $this->mInfo['editor'] = $rs['modifier_real_name'] ?? $rs['modifier_user']; LibertyContent::load(); - $this->loadXrefList(); } return !empty( $this->mInfo ); } @@ -151,37 +156,11 @@ class StockMovement extends LibertyContent { unset( $row ); } - public function loadXrefList(): void { - parent::loadXrefList(); - if( !empty( $this->mInfo['quantity'] ) ) { - $componentIds = array_values( array_unique( array_filter( array_column( $this->mInfo['quantity'], 'xref' ) ) ) ); - if( $componentIds ) { - $placeholders = implode( ',', array_fill( 0, count( $componentIds ), '?' ) ); - $components = $this->mDb->getAssoc( - "SELECT lc.`content_id`, lc.`title`, lc.`data` - FROM `".BIT_DB_PREFIX."liberty_content` lc - WHERE lc.`content_id` IN ($placeholders)", - $componentIds - ); - foreach( $this->mInfo['quantity'] as &$row ) { - if( !empty( $row['xref'] ) && isset( $components[$row['xref']] ) ) { - $row['xref_title'] = $components[$row['xref']]['title']; - $row['xref_data'] = $components[$row['xref']]['data']; - } - } - unset( $row ); - } - } - } - // Direction inferred from reference xref: REQN = out, TRANS/ORDER = in public function getDirection(): string { - if( !empty( $this->mInfo['reference'] ) ) { - foreach( $this->mInfo['reference'] as $row ) { - if( $row['item'] === 'REQN' ) return 'O'; - if( in_array( $row['item'], [ 'TRANS', 'ORDER' ] ) ) return 'I'; - } - } + $refType = $this->mInfo['ref_type'] ?? null; + if( $refType === 'REQN' ) return 'O'; + if( in_array( $refType, [ 'TRANS', 'ORDER' ] ) ) return 'I'; return 'O'; } |
