From e979cd1ddcfc3f86f55b6385ac65372ec84796a5 Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Sat, 6 Jun 2026 09:40:55 +0100 Subject: xref group templates: drop Link column; tighten text item edit gating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - list_xref.tpl: remove dead Link ; add 30/30/40% column widths; fix colspan to conditional 6/3; support both LibertyXrefGroup and legacy $source paths - view_xref_text_item.tpl: remove   Link cell; wrap date/updated/ edit cells under single {if $xrefAllowEdit|default:false} - LibertyXrefGroup: new class — loads xref rows for one x_group, separates expired rows into history Co-Authored-By: Claude Sonnet 4.6 --- includes/classes/LibertyXrefGroup.php | 87 +++++++++++++++++++++++++++++++++++ templates/list_xref.tpl | 66 ++++++++++++++++++++------ templates/view_xref_text_item.tpl | 31 ++++++------- 3 files changed, 153 insertions(+), 31 deletions(-) create mode 100644 includes/classes/LibertyXrefGroup.php diff --git a/includes/classes/LibertyXrefGroup.php b/includes/classes/LibertyXrefGroup.php new file mode 100644 index 0000000..1114c88 --- /dev/null +++ b/includes/classes/LibertyXrefGroup.php @@ -0,0 +1,87 @@ +mXGroup = $groupRow['x_group']; + $this->mContentTypeGuid = $contentTypeGuid; + $this->mTitle = $groupRow['title']; + $this->mSortOrder = (int)( $groupRow['sort_order'] ?? 0 ); + $this->mTemplate = !empty( $groupRow['template'] ) ? trim( $groupRow['template'] ) : null; + $this->mRoleId = (int)( $groupRow['role_id'] ?? 0 ); + } + + /** + * Load xref rows for this group. Active rows go into mXrefs. + * Expired rows (type_source='history') are returned for LibertyXrefInfo to collect. + * Requires mContentTypeGuid — fails loudly if not set. + * + * @return array expired rows to be added to the history group + */ + public function loadXrefs( int $contentId ): array { + global $gBitUser; + + if( empty( $this->mContentTypeGuid ) ) { + $this->mErrors[] = 'LibertyXrefGroup::load() requires mContentTypeGuid — cannot scope liberty_xref_item query without it.'; + return []; + } + + $roles = array_keys( $gBitUser->mRoles ?? [] ) ?: [-1]; + $userId = $gBitUser->mUserId; + $bindVars = array_merge( [ $this->mDb->NOW(), $contentId ], $roles, [ $userId ] ); + + $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`, + CASE WHEN x.`xorder` = 0 THEN s.`cross_ref_title` + 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 + 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.`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 + ON purm.`user_id` = $userId AND purm.`role_id` = s.`role_id` + WHERE x.`content_id` = ? + AND (s.`role_id` IN(" . implode( ',', array_fill( 0, count( $roles ), '?' ) ) . ") OR purm.`user_id` = ?) + ORDER BY x.`item`, x.`xorder`"; + + $historyRows = []; + $result = $this->mDb->query( $sql, $bindVars ); + if( $result ) { + while( $row = $result->fetchRow() ) { + if( $row['type_source'] === 'history' ) { + $historyRows[] = $row; + } else { + $this->mXrefs[] = $row; + } + } + } + return $historyRows; + } +} diff --git a/templates/list_xref.tpl b/templates/list_xref.tpl index 6ffa8c4..21b2608 100644 --- a/templates/list_xref.tpl +++ b/templates/list_xref.tpl @@ -1,21 +1,60 @@ +{assign var=xrefAllowEdit value=$allow_edit|default:true} +{if isset($xrefGroup)} + {* New path: called with a LibertyXrefGroup object *} + {assign var=tabTitle value=$xrefGroup->mTitle} + {assign var=isHistory value=($xrefGroup->mXGroup eq 'history')} + {jstab title="`$tabTitle` ({$xrefGroup->mXrefs|@count})"} + {legend legend=$tabTitle} +
+ + + + + + + {if $xrefAllowEdit} + {if $isHistory}{else}{/if} + + + {/if} + + + + {if $xrefGroup->mXrefs} + {foreach $xrefGroup->mXrefs as $xrefInfo} + + {include file=$gContent->getXrefRecordTemplate($xrefInfo.template)} + + {/foreach} + {else} + + + + {/if} + +
{tr}Type{/tr}{tr}Key{/tr}{tr}Value{/tr}{tr}Ended{/tr}{tr}Started{/tr}{tr}Updated{/tr}{tr}Edit{/tr}
{tr}No {$tabTitle} records found{/tr}
+
+ {if $allow_add && $gContent->isValid() && $gContent->hasUpdatePermission() && !$isHistory} +
+ {smartlink ititle="Add record" ipackage="liberty" ifile="add_xref.php" biticon="list-add" content_id=$gContent->mInfo.content_id group=$xrefGroup->mSortOrder} +
+ {/if} + {/legend} + {/jstab} +{else} + {* Legacy path: called with $source and $source_title (stock, other packages) *} {assign var=xrefcnt value=$gContent->mInfo.$source|default:[]|@count} - {assign var=xrefAllowEdit value=$allow_edit|default:true} {jstab title="$source_title ($xrefcnt)"} {legend legend=$source_title}
- - - - + + + {if $xrefAllowEdit} - {if $source ne 'history'} - - {else} - - {/if} + {if $source ne 'history'}{else}{/if} {/if} @@ -23,13 +62,13 @@ {section name=xref loop=$gContent->mInfo.$source} - {assign var=_rowTpl value=$gContent->mInfo.$source[xref].template} + {assign var=xrefInfo value=$gContent->mInfo.$source[xref]} - {include file=$gContent->getXrefRecordTemplate($_rowTpl)} + {include file=$gContent->getXrefRecordTemplate($xrefInfo.template)} {sectionelse} - + {/section} @@ -42,3 +81,4 @@ {/if} {/legend} {/jstab} +{/if} diff --git a/templates/view_xref_text_item.tpl b/templates/view_xref_text_item.tpl index dbd534a..0c9523a 100644 --- a/templates/view_xref_text_item.tpl +++ b/templates/view_xref_text_item.tpl @@ -1,34 +1,29 @@ {strip} - - - - + + + +{if $xrefAllowEdit|default:false} - + +{/if} {/strip} -- cgit v1.3
{tr}Type{/tr}{tr}Link{/tr}{tr}Key{/tr}{tr}Value{/tr}{tr}Type{/tr}{tr}Key{/tr}{tr}Value{/tr}{tr}Started{/tr}{tr}Ended{/tr}{tr}Started{/tr}{tr}Ended{/tr}{tr}Updated{/tr} {tr}Edit{/tr}
{tr}No {$source_title} records found{/tr}{tr}No {$source_title} records found{/tr}
{$gContent->mInfo.$source[xref].source_title|escape} - {if isset($gContent->mInfo.$source[xref].xref) && $gContent->mInfo.$source[xref].xref > 100} - {$gContent->mInfo.$source[xref].xref|escape} - {else} -   - {/if} -{$gContent->mInfo.$source[xref].xkey|escape} {$gContent->mInfo.$source[xref].xkey_ext|escape}{$gContent->mInfo.$source[xref].data|escape}{$xrefInfo.xref_title|escape}{$xrefInfo.xkey|escape} {$xrefInfo.xkey_ext|escape}{$xrefInfo.data|escape} {if $source ne 'history'} - {$gContent->mInfo.$source[xref].start_date|bit_short_date} + {$xrefInfo.start_date|bit_short_date} {else} - {$gContent->mInfo.$source[xref].end_date|bit_short_date} + {$xrefInfo.end_date|bit_short_date} {/if} {$gContent->mInfo.$source[xref].last_update_date|bit_short_date}{$xrefInfo.last_update_date|bit_short_date} - {if $xrefAllowEdit|default:true && $gContent->hasUpdatePermission() && $source ne 'history'} - {smartlink ititle="Edit" ipackage="liberty" ifile="edit_xref.php" biticon="edit" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id} + {if $gContent->hasUpdatePermission() && $source ne 'history'} + {smartlink ititle="Edit" ipackage="liberty" ifile="edit_xref.php" biticon="edit" content_id=$gContent->mInfo.content_id xref_id=$xrefInfo.xref_id} {/if} - {if $xrefAllowEdit|default:true && $gContent->hasExpungePermission()} + {if $gContent->hasExpungePermission()} {if $source eq 'history'} - {smartlink ititle="Restore" ipackage="liberty" ifile="edit_xref.php" biticon="edit" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id expunge=-1} + {smartlink ititle="Restore" ipackage="liberty" ifile="edit_xref.php" biticon="edit" content_id=$gContent->mInfo.content_id xref_id=$xrefInfo.xref_id expunge=-1} {else} - {smartlink ititle="Delete" ipackage="liberty" ifile="edit_xref.php" biticon="user-trash" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id expunge=1} + {smartlink ititle="Delete" ipackage="liberty" ifile="edit_xref.php" biticon="user-trash" content_id=$gContent->mInfo.content_id xref_id=$xrefInfo.xref_id expunge=1} {/if} {/if}