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 | |
| 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>
| -rw-r--r-- | includes/classes/LibertyXrefGroup.php | 16 | ||||
| -rw-r--r-- | includes/classes/LibertyXrefInfo.php | 21 | ||||
| -rw-r--r-- | templates/admin_xref_groups.tpl | 2 | ||||
| -rw-r--r-- | templates/admin_xref_sources.tpl | 2 | ||||
| -rwxr-xr-x | templates/center_list_generic.tpl | 2 | ||||
| -rwxr-xr-x | templates/display_comment.tpl | 2 | ||||
| -rwxr-xr-x | templates/display_structure.tpl | 2 |
7 files changed, 33 insertions, 14 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; diff --git a/templates/admin_xref_groups.tpl b/templates/admin_xref_groups.tpl index 212428a..8847844 100644 --- a/templates/admin_xref_groups.tpl +++ b/templates/admin_xref_groups.tpl @@ -85,7 +85,7 @@ <td> {if $grp.num_sources eq 0} <a href="{$smarty.const.LIBERTY_PKG_URL}admin/admin_xref_groups.php?fDeleteGroup=1&x_group={$grp.x_group|escape}&del_content_type_guid={$grp.content_type_guid|escape}&content_type_guid={$activeGuid|escape}" - onclick="return confirm('{tr}Delete this group?{/tr}')">{biticon ipackage="icons" iname="user-trash" ipackage="icons" iforce=icon_text iexplain="Delete"}</a> + onclick="return confirm('{tr}Delete this group?{/tr}')">{biticon ipackage="icons" iname="user-trash" iforce=icon_text iexplain="Delete"}</a> {/if} </td> diff --git a/templates/admin_xref_sources.tpl b/templates/admin_xref_sources.tpl index 8812772..29c67bb 100644 --- a/templates/admin_xref_sources.tpl +++ b/templates/admin_xref_sources.tpl @@ -105,7 +105,7 @@ <td> {if $src.num_entries eq 0} <a href="{$smarty.const.LIBERTY_PKG_URL}admin/admin_xref_sources.php?fDeleteSource=1&source={$src.item|escape}&del_content_type_guid={$src.content_type_guid|escape}&content_type_guid={$activeGuid|escape}" - onclick="return confirm('{tr}Delete this source?{/tr}')">{biticon ipackage="icons" iname="user-trash" ipackage="icons" iforce=icon_text iexplain="Delete"}</a> + onclick="return confirm('{tr}Delete this source?{/tr}')">{biticon ipackage="icons" iname="user-trash" iforce=icon_text iexplain="Delete"}</a> {/if} </td> </tr> diff --git a/templates/center_list_generic.tpl b/templates/center_list_generic.tpl index dc78aea..4ce5c80 100755 --- a/templates/center_list_generic.tpl +++ b/templates/center_list_generic.tpl @@ -21,7 +21,7 @@ {form id="checkform"} <ul class="list-inline navbar"> - <li>{biticon ipackage="icons" iname="go-next" ipackage="icons" iexplain="sort by"}</li> + <li>{biticon ipackage="icons" iname="go-next" iexplain="sort by"}</li> <li>{smartlink ititle="Title" isort="title" icontrol=$listInfo}</li> <li>{smartlink ititle="Last Modified" iorder="desc" idefault=1 isort="last_modified" icontrol=$listInfo}</li> <li>{smartlink ititle="Author" isort="creator_user" icontrol=$listInfo}</li> diff --git a/templates/display_comment.tpl b/templates/display_comment.tpl index 647c35f..4fb122f 100755 --- a/templates/display_comment.tpl +++ b/templates/display_comment.tpl @@ -14,7 +14,7 @@ {/if} {/if} {if $comment.is_editable} - <a href="{$comments_return_url}&post_comment_id={$comment.comment_id}&post_comment_request=1#editcomments" rel="nofollow">{biticon ipackage="icons" iname="edit" ipackage="icons" iexplain="Edit"}</a> + <a href="{$comments_return_url}&post_comment_id={$comment.comment_id}&post_comment_request=1#editcomments" rel="nofollow">{biticon ipackage="icons" iname="edit" iexplain="Edit"}</a> {/if} {if $gBitUser->hasPermission('p_liberty_admin_comments')} <a href="{$comments_return_url}&delete_comment_id={$comment.comment_id}" rel="nofollow">{biticon ipackage="icons" iname="user-trash" iexplain="Remove"}</a> diff --git a/templates/display_structure.tpl b/templates/display_structure.tpl index d4b63ec..6ef27b2 100755 --- a/templates/display_structure.tpl +++ b/templates/display_structure.tpl @@ -22,7 +22,7 @@ {if $structureInfo.prev && $structureInfo.prev.structure_id} <a href="index.php?structure_id={$structureInfo.prev.structure_id}"> {if $wikibook_use_icons eq 'y'} - {biticon ipackage="icons" iname="go-previous" ipackage="icons" iexplain=Previous} + {biticon ipackage="icons" iname="go-previous" iexplain=Previous} {else} « {$structureInfo.prev.title|escape} {/if} |
