diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-12 10:41:35 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-12 10:41:35 +0100 |
| commit | 96fa98e388aaca189de0134bb8d1c8374bb75b91 (patch) | |
| tree | fd112f6e1b53dcb7d107a61aee6064db5f2a6e5e | |
| parent | 6aa6a828fd9f7b43a1a526dbf8c5e4d5910b8f1d (diff) | |
| download | liberty-96fa98e388aaca189de0134bb8d1c8374bb75b91.tar.gz liberty-96fa98e388aaca189de0134bb8d1c8374bb75b91.tar.bz2 liberty-96fa98e388aaca189de0134bb8d1c8374bb75b91.zip | |
LibertyXref: propagate mPackageGuid so dual-guid types resolve correctly in load/verify; loadContent: add linked_title from joined liberty_content
LibertyXref gains mPackageGuid; load() and verify() now use IN(contentTypeGuid,packageGuid)
so package-level xref items (e.g. stock/supplier) are found when editing a sub-type record
(e.g. stockcomponent). LibertyContent propagates mPackageGuid to LibertyXref in loadXref(),
storeXref() and stepXref(). LibertyXrefType::loadContent() LEFT JOINs liberty_content on
x.xref to expose linked_title for templates that display a linked content item's name.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | includes/classes/LibertyContent.php | 3 | ||||
| -rw-r--r-- | includes/classes/LibertyXref.php | 26 | ||||
| -rw-r--r-- | includes/classes/LibertyXrefType.php | 4 |
3 files changed, 28 insertions, 5 deletions
diff --git a/includes/classes/LibertyContent.php b/includes/classes/LibertyContent.php index 4f94a0d..ef2f9b4 100755 --- a/includes/classes/LibertyContent.php +++ b/includes/classes/LibertyContent.php @@ -3999,6 +3999,7 @@ class LibertyContent extends LibertyBase implements BitCacheable { if ( BitBase::verifyId( $pXrefId ) ) { $xref = new LibertyXref(); $xref->mContentTypeGuid = $this->mContentTypeGuid; + $xref->mPackageGuid = $this->mPackageGuid; $xref->load( $pXrefId ); if ( $xref->mContentId ) { $this->load( $xref->mContentId ); @@ -4025,6 +4026,7 @@ class LibertyContent extends LibertyBase implements BitCacheable { public function storeXref( &$pParamHash ): bool { $xref = new LibertyXref(); $xref->mContentTypeGuid = $this->mContentTypeGuid; + $xref->mPackageGuid = $this->mPackageGuid; if ( BitBase::verifyId( $pParamHash['xref_id'] ?? null ) ) { $xref->load( $pParamHash['xref_id'] ); } @@ -4052,6 +4054,7 @@ class LibertyContent extends LibertyBase implements BitCacheable { public function stepXref( &$pParamHash ): bool { $xref = new LibertyXref(); $xref->mContentTypeGuid = $this->mContentTypeGuid; + $xref->mPackageGuid = $this->mPackageGuid; $xref->load( $pParamHash['xref_id'] ); if ( $xref->stepXref( $pParamHash ) ) { $this->mInfo['xref_title'] = $xref->mContentId; diff --git a/includes/classes/LibertyXref.php b/includes/classes/LibertyXref.php index 6c5b821..56b77ed 100644 --- a/includes/classes/LibertyXref.php +++ b/includes/classes/LibertyXref.php @@ -46,6 +46,8 @@ class LibertyXref extends BitBase implements \ArrayAccess { public $mDate; /** when set, scopes liberty_xref_item lookups to this content type */ public $mContentTypeGuid = ''; + /** when set alongside mContentTypeGuid, extends the scope to include package-level items (dual-guid schema) */ + public string $mPackageGuid = ''; /** flat row data — populated by load() and fromRow(); underpins ArrayAccess */ protected array $mRow = []; @@ -104,8 +106,16 @@ class LibertyXref extends BitBase implements \ArrayAccess { */ public function load( $pXrefId = NULL ) { if( BitBase::verifyId( $pXrefId ) ) { - $guidFilter = !empty( $this->mContentTypeGuid ) ? "AND s.`content_type_guid` = ?" : ''; - $bindVars = !empty( $this->mContentTypeGuid ) ? [ $this->mContentTypeGuid, $pXrefId ] : [ $pXrefId ]; + if( !empty( $this->mContentTypeGuid ) && !empty( $this->mPackageGuid ) ) { + $guidFilter = "AND s.`content_type_guid` IN(?,?)"; + $bindVars = [ $this->mContentTypeGuid, $this->mPackageGuid, $pXrefId ]; + } elseif( !empty( $this->mContentTypeGuid ) ) { + $guidFilter = "AND s.`content_type_guid` = ?"; + $bindVars = [ $this->mContentTypeGuid, $pXrefId ]; + } else { + $guidFilter = ''; + $bindVars = [ $pXrefId ]; + } $sql = "SELECT x.*, CASE WHEN x.`xorder` = 0 THEN s.`cross_ref_title` ELSE s.`cross_ref_title` || '-' || x.`xorder` END @@ -164,8 +174,16 @@ class LibertyXref extends BitBase implements \ArrayAccess { if( isset( $pParamHash['fAddXref'] ) ) { $pParamHash['xref_store']['item'] = isset( $pParamHash['Array_xref_type_list'] ) ? $pParamHash['Array_xref_type_list']['Array.item'] : $pParamHash['item']; $pParamHash['xref_store']['content_id'] = $pParamHash['content_id']; - $guidWhere = !empty( $this->mContentTypeGuid ) ? "AND x.`content_type_guid` = ?" : ''; - $guidBind = !empty( $this->mContentTypeGuid ) ? [ $pParamHash['xref_store']['item'], $this->mContentTypeGuid ] : [ $pParamHash['xref_store']['item'] ]; + if( !empty( $this->mContentTypeGuid ) && !empty( $this->mPackageGuid ) ) { + $guidWhere = "AND x.`content_type_guid` IN(?,?)"; + $guidBind = [ $pParamHash['xref_store']['item'], $this->mContentTypeGuid, $this->mPackageGuid ]; + } elseif( !empty( $this->mContentTypeGuid ) ) { + $guidWhere = "AND x.`content_type_guid` = ?"; + $guidBind = [ $pParamHash['xref_store']['item'], $this->mContentTypeGuid ]; + } else { + $guidWhere = ''; + $guidBind = [ $pParamHash['xref_store']['item'] ]; + } $sql = "SELECT x.`multiple` FROM `".BIT_DB_PREFIX."liberty_xref_item` x WHERE x.`item` = ? $guidWhere"; $next = $this->mDb->getOne( $sql, $guidBind ); if( $next > 0 ) { diff --git a/includes/classes/LibertyXrefType.php b/includes/classes/LibertyXrefType.php index 1ef71ca..89b1419 100644 --- a/includes/classes/LibertyXrefType.php +++ b/includes/classes/LibertyXrefType.php @@ -254,13 +254,15 @@ class LibertyXrefType { ELSE s.`cross_ref_title` || '-' || x.`xorder` END AS xref_title, CASE WHEN x.`end_date` IS NOT NULL AND x.`end_date` < ? THEN 'history' ELSE s.`x_group` END AS type_source, - pc.`add1` || ',' || pc.`add2` || ',' || pc.`add4` || ',' || pc.`town` AS address + pc.`add1` || ',' || pc.`add2` || ',' || pc.`add4` || ',' || pc.`town` AS address, + lc_linked.`title` AS linked_title FROM `".BIT_DB_PREFIX."liberty_xref` x JOIN `".BIT_DB_PREFIX."liberty_xref_item` s ON s.`item` = x.`item` AND s.`content_type_guid` $guidFilter AND s.`x_group` = '$xGroup' LEFT JOIN `".BIT_DB_PREFIX."address_postcode` pc ON pc.`postcode` = x.`xkey` + LEFT JOIN `".BIT_DB_PREFIX."liberty_content` lc_linked ON lc_linked.`content_id` = x.`xref` LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` purm ON purm.`user_id` = $userId AND purm.`role_id` = s.`role_id` WHERE x.`content_id` = ? |
