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 | |
| 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>
| -rwxr-xr-x | component_order.php | 8 | ||||
| -rwxr-xr-x | edit_assembly.php | 6 | ||||
| -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 | ||||
| -rwxr-xr-x | templates/component_order.tpl | 4 | ||||
| -rw-r--r-- | templates/view_movement.tpl | 4 |
8 files changed, 16 insertions, 97 deletions
diff --git a/component_order.php b/component_order.php index 05d9eef..eefc8ac 100755 --- a/component_order.php +++ b/component_order.php @@ -38,11 +38,9 @@ if( !empty( $_REQUEST['cancel'] ) ) { $xrefObj->store( $pHash ); } } - // Reload so fresh xorder data is displayed - foreach( [ 'supplier', 'quantity', 'values', 'kitlocker', 'history' ] as $_xg ) { - unset( $gContent->mInfo[$_xg] ); - } - $gContent->loadXrefList(); } +$gContent->loadXrefInfo(); +$gBitSmarty->assign( 'gXrefInfo', $gContent->mXrefInfo ); + $gBitSystem->display( 'bitpackage:stock/component_order.tpl', KernelTools::tra('Parts List').': '.$gContent->getTitle(), [ 'display_mode' => 'display' ] ); diff --git a/edit_assembly.php b/edit_assembly.php index d4a59fc..c3199b7 100755 --- a/edit_assembly.php +++ b/edit_assembly.php @@ -132,12 +132,6 @@ if( !empty( $_REQUEST['savegallery'] ) ) { fclose($fh); } } - // Clear stale xref buckets so loadXrefList() re-reads from DB for the display below - foreach( [ 'supplier', 'quantity', 'values', 'kitlocker', 'history' ] as $_xg ) { - unset( $gContent->mInfo[$_xg] ); - } - $gContent->loadXrefList(); - $gBitSmarty->assign( 'csvLoaded', $csvLoaded ); $gBitSmarty->assign( 'csvSkipped', $csvSkipped ); $gBitSmarty->assign( 'csvErrors', $csvErrors ); 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'; } diff --git a/templates/component_order.tpl b/templates/component_order.tpl index 70136ef..a1ac4c5 100755 --- a/templates/component_order.tpl +++ b/templates/component_order.tpl @@ -22,8 +22,8 @@ </thead> <tbody> {assign var=lastGroup value=-1} - {if $gContent->mInfo.quantity} - {foreach from=$gContent->mInfo.quantity item=row} + {if $gXrefInfo->mGroups.quantity && $gXrefInfo->mGroups.quantity->mXrefs} + {foreach from=$gXrefInfo->mGroups.quantity->mXrefs item=row} {math equation="floor(x/1000)" x=$row.xorder|default:0 assign=thisGroup} {if $thisGroup != $lastGroup} <tr class="active"> diff --git a/templates/view_movement.tpl b/templates/view_movement.tpl index 72932b2..f46ca6c 100644 --- a/templates/view_movement.tpl +++ b/templates/view_movement.tpl @@ -20,9 +20,9 @@ <dd> <a href="{$smarty.const.CONTACT_PKG_URL}display.php?content_id={$gContent->mInfo.ref_contact_id}">{$gContent->mInfo.ref_contact_name|escape}</a> </dd> - {elseif $gContent->mInfo.reference.0.data} + {elseif $gContent->mInfo.ref_from_data} <dt>{tr}From{/tr}</dt> - <dd>{$gContent->mInfo.reference.0.data|escape}</dd> + <dd>{$gContent->mInfo.ref_from_data|escape}</dd> {/if} <dt>{tr}Created{/tr}</dt> <dd>{$gContent->mInfo.created|bit_short_datetime} {tr}by{/tr} {$gContent->mInfo.creator|escape}</dd> |
