/** * Returns an array of all allowed product IDs and variant IDs for the current backend user * @return array|bool */ public static function getAllowedIds() { $objUser = \BackendUser::getInstance(); if ($objUser->isAdmin) { $arrProducts = true; } else { $arrNewRecords = $_SESSION['BE_DATA']['new_records']['tl_iso_product']; $arrProductTypes = $objUser->iso_product_types; $arrGroups = array(); // Return false if there are no product types if (!is_array($arrProductTypes) || empty($arrProductTypes)) { return false; } // Find the user groups if (is_array($objUser->iso_groups) && count($objUser->iso_groups) > 0) { $arrGroups = array_merge($arrGroups, $objUser->iso_groups, \Database::getInstance()->getChildRecords($objUser->iso_groups, Group::getTable())); if (in_array('rootPaste', $objUser->iso_groupp)) { $arrGroups[] = 0; } } $objProducts = \Database::getInstance()->execute("\n SELECT id FROM tl_iso_product\n WHERE pid=0\n AND language=''\n " . (empty($arrGroups) ? '' : "AND gid IN (" . implode(',', $arrGroups) . ")") . "\n AND (\n type IN (" . implode(',', $arrProductTypes) . ")" . (is_array($arrNewRecords) && !empty($arrNewRecords) ? " OR id IN (" . implode(',', $arrNewRecords) . ")" : '') . ")\n "); if ($objProducts->numRows == 0) { return array(); } $arrProducts = $objProducts->fetchEach('id'); $arrProducts = array_merge($arrProducts, \Database::getInstance()->getChildRecords($arrProducts, 'tl_iso_product')); } // HOOK: allow extensions to define allowed products if (isset($GLOBALS['ISO_HOOKS']['getAllowedProductIds']) && is_array($GLOBALS['ISO_HOOKS']['getAllowedProductIds'])) { foreach ($GLOBALS['ISO_HOOKS']['getAllowedProductIds'] as $callback) { $objCallback = \System::importStatic($callback[0]); $arrAllowed = $objCallback->{$callback}[1](); if ($arrAllowed === false) { return false; } elseif (is_array($arrAllowed)) { if ($arrProducts === true) { $arrProducts = $arrAllowed; } else { $arrProducts = array_intersect($arrProducts, $arrAllowed); } } } } // If all product are allowed, we don't need to filter if ($arrProducts === true || count($arrProducts) == Product::countAll()) { return true; } return $arrProducts; }