summaryrefslogtreecommitdiff
path: root/list_kitlocker.php
blob: 33a7697140d2105fc1a1be78c3177c96585ea1df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
 * Combined kitlocker listing — assemblies and components filtered by stgrp tag.
 * @package stock
 */

namespace Bitweaver\Stock;

use Bitweaver\KernelTools;
use Bitweaver\Liberty\LibertyContent;

require_once '../kernel/includes/setup_inc.php';

$gBitSystem->verifyPackage( 'stock' );

global $gBitSystem, $gBitSmarty, $gBitDb;

$stgrp = !empty( $_REQUEST['stgrp'] ) ? trim( $_REQUEST['stgrp'] ) : null;

$X        = BIT_DB_PREFIX;
$bindVars = [];
$whereSql = "AND lc.`content_type_guid` IN ('stockassembly','stockcomponent')";

if( $stgrp ) {
	$whereSql .= " AND EXISTS (SELECT 1 FROM `{$X}liberty_xref` sx WHERE sx.`content_id` = lc.`content_id` AND sx.`item` = ?)";
	$bindVars[] = $stgrp;
	$groupTitle = $gBitDb->getOne(
		"SELECT `cross_ref_title` FROM `{$X}liberty_xref_item` WHERE `item` = ? AND `x_group` = 'stgrp'",
		[ $stgrp ]
	);
} else {
	$whereSql .= " AND EXISTS (SELECT 1 FROM `{$X}liberty_xref` sx
		INNER JOIN `{$X}liberty_xref_item` xi ON xi.`item` = sx.`item` AND xi.`x_group` = 'stgrp'
		WHERE sx.`content_id` = lc.`content_id`)";
	$groupTitle = null;
}

$items = $gBitDb->getAll(
	"SELECT lc.`content_id`, lc.`title`, lc.`data`, lc.`format_guid`, lc.`content_type_guid`,
		(SELECT FIRST 1 x.`xkey` FROM `{$X}liberty_xref` x
		 WHERE x.`content_id` = lc.`content_id` AND x.`item` = 'KLID') AS klid,
		(SELECT FIRST 1 x.`xkey` FROM `{$X}liberty_xref` x
		 WHERE x.`content_id` = lc.`content_id` AND x.`item` = 'KLPR') AS klpr
	 FROM `{$X}liberty_content` lc
	 WHERE 1=1 $whereSql
	 ORDER BY lc.`title`",
	$bindVars
);

foreach( $items as &$row ) {
	$parseHash = [ 'data' => $row['data'], 'format_guid' => $row['format_guid'] ?? 'bithtml' ];
	$row['parsed_data'] = LibertyContent::parseDataHash( $parseHash );
}
unset( $row );

$gBitSmarty->assign( 'kitlockerItems', $items );
$gBitSmarty->assign( 'stgrp',          $stgrp );
$gBitSmarty->assign( 'groupTitle',     $groupTitle );

$pageTitle = $groupTitle ?: KernelTools::tra( 'Kitlocker' );
$gBitSystem->setBrowserTitle( $pageTitle );
$gBitSystem->display( 'bitpackage:stock/list_kitlocker.tpl', null, [ 'display_mode' => 'list' ] );