[insert_php]
/*
AXA
*/
[/insert_php]
[insert_php]
// ====== CONFIGURATION ============
// URL Filters to fetch the IBP XML
$secureGuid = “33DB475D-9426-442A-9BCF-E7BB6E8DC7A5”; // Broker key
$lang = “FR”; // Langue
$categoryKey = “IBPC-03”; // Information contractuelle produit (cond. gén.)
$subCategoryKey = “IBPSC-11”; // Only documents (PDF, DOC, XLS, …)
// =================================
// ========== FUNCTIONS ============
if (!function_exists(‘compareCompanies’)) { // Needed if we use the Insert PHP WP plugin
// http://stackoverflow.com/questions/2426917/how-do-i-sort-a-multidimensional-array-by-one-of-the-fields-of-the-inner-array-i
// string and strtolower have been added to make a correct sort
function compareCompanies($a, $b) {
if ((string)strtolower($a[“companyName”]) == (string)strtolower($b[“companyName”])) {
return 0;
}
return ((string)strtolower($a[“companyName”]) < (string)strtolower($b["companyName"])) ? -1 : 1;
}
}
if (!function_exists('compareProducts')) {
function compareProducts($a, $b) {
$concatA = $a["productName"] . $a["articleTitle"];
$concatB = $b["productName"] . $b["articleTitle"];
if ((string)strtolower($concatA) == (string)strtolower($concatB)) {
return 0;
}
return ((string)strtolower($concatA) < (string)strtolower($concatB)) ? -1 : 1;
}
}
// =================================
$curl = curl_init();
// URL = http://cat.internetbrokerproject.be/ibpcatalog/Feed/CatalogAtomFeed.svc/DigestedCatalogItems?$filter=SecureGuid%20eq%20%2733DB475D-9426-442A-9BCF-E7BB6E8DC7A5%27%20and%20(Language%20eq%20%27FR%27)%20and%20(CategoryKey%20eq%20%27IBPC-03%27)
// Without subCategoryKey
curl_setopt_array($curl, Array(
CURLOPT_URL => ‘http://cat.internetbrokerproject.be/ibpcatalog/Feed/CatalogAtomFeed.svc/DigestedCatalogItems?$filter=SecureGuid%20eq%20%27′.$secureGuid .’%27%20and%20(Language%20eq%20%27′.$lang.’%27)%20and%20(CategoryKey%20eq%20%27′.$categoryKey.’%27)’,
CURLOPT_USERAGENT => ‘spider’,
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => ‘UTF-8’
));
/*
NB: With subCategoryKey
CURLOPT_URL => ‘http://cat.internetbrokerproject.be/ibpcatalog/Feed/CatalogAtomFeed.svc/DigestedCatalogItems?$filter=SecureGuid%20eq%20%27′.$secureGuid .’%27%20and%20(Language%20eq%20%27′.$lang.’%27)%20and%20(SubCategoryKey%20eq%20%27′.$subCategoryKey.’%27)%20and%20(CategoryKey%20eq%20%27′.$categoryKey.’%27)’,
*/
$data = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($data, ‘SimpleXMLElement’, LIBXML_NOCDATA);
$index = 0;
$companies = array();
foreach ($xml as $item) {
if ($index >= 4) { // Due to the XML structure
// http://stackoverflow.com/questions/1575788/php-library-for-parsing-xml-with-a-colons-in-tag-names
$companyName = $item->content->children(‘m’, true)->properties->children(‘d’, true)->CompanyName;
$companyCode = $item->content->children(‘m’, true)->properties->children(‘d’, true)->CompanyCode;
$articleTitle = $item->title;
$productName = $item->content->children(‘m’, true)->properties->children(‘d’, true)->ProductName;
$urlCondGen = $item->contributor->uri;
$foundCompany = FALSE;
$foundCompanyIndex = 0;
foreach ($companies as $key => $company) {
if ((string)$company[‘companyCode’] == (string)$companyCode) { // (string) is needed otherwise test will always failed
$foundCompany = TRUE;
$foundCompanyIndex = $key;
}
}
if (!$foundCompany) {
// Create a new company with the current product
$company = array(
‘companyName’ => $companyName,
‘companyCode’ => $companyCode
);
$companies[] = $company;
// get last index of companies
end($companies);
$last = key($companies);
$product = array(
‘articleTitle’ => $articleTitle,
‘productName’ => $productName,
‘urlCondGen’ => $urlCondGen
);
$companies[$last][products][] = $product;
}
else {
// Create a new product for this existing company
$product = array(
‘articleTitle’ => $articleTitle,
‘productName’ => $productName,
‘urlCondGen’ => $urlCondGen
);
$companies[$foundCompanyIndex][products][] = $product;
}
}
$index++;
}
usort($companies ,”compareCompanies”);
$count = 0;
foreach ($companies as $company) {
//echo ““.$company[‘companyName’].”
“;
echo ‘
”‘.$company[‘companyName’
usort($company[‘products’] ,”compareProducts”);
foreach ($company[‘products’] as $product) {
$count++;
echo ““;
echo $product[‘productName’];
if ($product[‘articleTitle’] != “”) {
echo ” – “.$product[‘articleTitle’];
}
echo “
“;
}
echo “
“;
}
//echo $count;
[/insert_php]