<?php

if (!is_array($item_ids) || count($item_ids) <= 0) {
	include_once 'itemsearch.class.php';

	$ItemsClass = new ItemSearch($this->base_object);
	//$result = $ItemsClass->searchItems($search['search_item'], true);

	$item_ids = $result['data'];
}

if (is_array($item_ids) && count($item_ids) > 0) {
	$sql = "
		SELECT
			wg.id,
			count(wg.id) AS found_items
		FROM
			structure wg
		LEFT JOIN
			item_structure_assign isa
		ON
			wg.id = isa.structure_id
		WHERE
			isa.item_id IN (
				" . implode(',', $item_ids) . "
			)
		AND
			wg.active=1
		GROUP BY
			wg.id
	";
}