diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-07 16:51:41 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-07 16:51:41 +0100 |
| commit | 83a49c006d3bb0d9e84ff5068d6d9c1478fe73cf (patch) | |
| tree | dc345f25b4ae15a89ff48c99a8d8dc8a2a0ad797 /includes | |
| parent | 5e7db08bf0b29843a80205a023157ae3e218d211 (diff) | |
| download | liberty-83a49c006d3bb0d9e84ff5068d6d9c1478fe73cf.tar.gz liberty-83a49c006d3bb0d9e84ff5068d6d9c1478fe73cf.tar.bz2 liberty-83a49c006d3bb0d9e84ff5068d6d9c1478fe73cf.zip | |
LibertyXrefInfo/LibertyXrefGroup: optional package-level guid support
Adds optional $packageGuid parameter to both constructors. When set,
the liberty_xref_group and liberty_xref_item queries use IN (type, pkg)
instead of = type, allowing package-level rows to be shared across
multiple content types (e.g. 'stock' shared by stockassembly and
stockcomponent).
Also removes duplicate ipackage attributes from templates.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
| -rw-r--r-- | includes/classes/LibertyXrefGroup.php | 16 | ||||
| -rw-r--r-- | includes/classes/LibertyXrefInfo.php | 21 |
2 files changed, 28 insertions, 9 deletions
diff --git a/includes/classes/LibertyXrefGroup.php b/includes/classes/LibertyXrefGroup.php index f8cb4d3..15beef7 100644 --- a/includes/classes/LibertyXrefGroup.php +++ b/includes/classes/LibertyXrefGroup.php @@ -40,17 +40,21 @@ class LibertyXrefGroup extends LibertyBase { public ?string $mTemplate; /** role_id gate from liberty_xref_group.role_id; 0 = visible to all */ public int $mRoleId; + /** optional package-level guid — xref_item rows with this guid are also matched */ + public ?string $mPackageGuid; /** @var array[] active liberty_xref data rows for the current content item */ public array $mXrefs = []; /** - * @param array $groupRow row from liberty_xref_group (x_group, title, sort_order, template, role_id) - * @param string $contentTypeGuid content type this group belongs to + * @param array $groupRow row from liberty_xref_group (x_group, title, sort_order, template, role_id) + * @param string $contentTypeGuid content type this group belongs to + * @param string|null $packageGuid optional package-level guid (e.g. 'stock') */ - public function __construct( array $groupRow, string $contentTypeGuid ) { + public function __construct( array $groupRow, string $contentTypeGuid, ?string $packageGuid = null ) { parent::__construct(); $this->mXGroup = $groupRow['x_group']; $this->mContentTypeGuid = $contentTypeGuid; + $this->mPackageGuid = $packageGuid; $this->mTitle = $groupRow['title']; $this->mSortOrder = (int)( $groupRow['sort_order'] ?? 0 ); $this->mTemplate = !empty( $groupRow['template'] ) ? trim( $groupRow['template'] ) : null; @@ -87,6 +91,10 @@ class LibertyXrefGroup extends LibertyBase { $userId = $gBitUser->mUserId; $bindVars = array_merge( [ $this->mDb->NOW(), $contentId ], $roles, [ $userId ] ); + $guidFilter = $this->mPackageGuid + ? "IN ('{$this->mContentTypeGuid}', '{$this->mPackageGuid}')" + : "= '{$this->mContentTypeGuid}'"; + $sql = "SELECT x.`xref_id`, x.`item`, x.`xref`, x.`xkey`, x.`xkey_ext`, x.`xorder`, x.`data`, x.`start_date`, x.`end_date`, x.`last_update_date`, s.`template`, s.`cross_ref_href`, @@ -98,7 +106,7 @@ class LibertyXrefGroup extends LibertyBase { 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` = '{$this->mContentTypeGuid}' + AND s.`content_type_guid` $guidFilter AND s.`x_group` = '{$this->mXGroup}' LEFT JOIN `" . BIT_DB_PREFIX . "address_postcode` pc ON pc.`postcode` = x.`xkey` LEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_roles_map` purm diff --git a/includes/classes/LibertyXrefInfo.php b/includes/classes/LibertyXrefInfo.php index f3f9622..0285968 100644 --- a/includes/classes/LibertyXrefInfo.php +++ b/includes/classes/LibertyXrefInfo.php @@ -33,12 +33,18 @@ namespace Bitweaver\Liberty; class LibertyXrefInfo { /** content_type_guid this info object was built for */ public string $mContentTypeGuid; + /** optional package-level guid whose xref_group/xref_item rows are also loaded (e.g. 'stock') */ + public ?string $mPackageGuid; /** @var LibertyXrefGroup[] keyed by x_group, ordered by sort_order */ public array $mGroups = []; - /** @param string $contentTypeGuid e.g. 'contact', 'stockmovement' */ - public function __construct( string $contentTypeGuid ) { + /** + * @param string $contentTypeGuid e.g. 'stockassembly', 'contact' + * @param string|null $packageGuid e.g. 'stock' — additional guid whose xref_group rows are merged in + */ + public function __construct( string $contentTypeGuid, ?string $packageGuid = null ) { $this->mContentTypeGuid = $contentTypeGuid; + $this->mPackageGuid = $packageGuid; } /** @@ -56,11 +62,15 @@ class LibertyXrefInfo { $userId = $gBitUser->mUserId; $bindVars = array_merge( $roles, [ $userId ] ); + $guidFilter = $this->mPackageGuid + ? "g.`content_type_guid` IN ('{$this->mContentTypeGuid}', '{$this->mPackageGuid}')" + : "g.`content_type_guid` = '{$this->mContentTypeGuid}'"; + $sql = "SELECT g.`x_group`, g.`title`, g.`sort_order`, g.`template`, g.`role_id` FROM `" . BIT_DB_PREFIX . "liberty_xref_group` g LEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_roles_map` purm ON purm.`user_id` = $userId AND purm.`role_id` = g.`role_id` - WHERE g.`content_type_guid` = '{$this->mContentTypeGuid}' + WHERE $guidFilter AND g.`sort_order` > 0 AND (g.`role_id` IN(" . implode( ',', array_fill( 0, count( $roles ), '?' ) ) . ") OR purm.`user_id` = ?) ORDER BY g.`sort_order`"; @@ -70,7 +80,7 @@ class LibertyXrefInfo { $allHistory = []; while( $row = $result->fetchRow() ) { - $group = new LibertyXrefGroup( $row, $this->mContentTypeGuid ); + $group = new LibertyXrefGroup( $row, $this->mContentTypeGuid, $this->mPackageGuid ); $allHistory = array_merge( $allHistory, $group->loadXrefs( $contentId ) ); $this->mGroups[$row['x_group']] = $group; } @@ -78,7 +88,8 @@ class LibertyXrefInfo { if( !empty( $allHistory ) ) { $historyGroup = new LibertyXrefGroup( [ 'x_group' => 'history', 'title' => 'History', 'sort_order' => 999, 'template' => null, 'role_id' => 0 ], - $this->mContentTypeGuid + $this->mContentTypeGuid, + $this->mPackageGuid ); $historyGroup->mXrefs = $allHistory; $this->mGroups['history'] = $historyGroup; |
