function surgicalVariablise($variable, $entity) { $varFound = false; global $udvTypes, $udvLibrary, $udvUsage, $bivArray, $usedUdvs; foreach ($udvTypes as $udvTypeKey => $udvTypeVal) { foreach ($udvLibrary[$udvTypeVal] as $udvK => $udvV) { if ($variable === '{{' . $udvV['name'] . '}}') { $variable = '<a href="#udv' . $udvV['variableId'] . '" class="variableDetail" '; $variable = $variable . 'onclick="jQuery(\'.assetList\').hide();jQuery(\'.assetDetail\').hide();jQuery(\'.assetContainer\').hide();jQuery(\'#udvs\').toggle();jQuery(\'#udvType' . $udvTypeVal . '\').next().toggle();jQuery(\'#udvDetail' . $udvV['variableId'] . '\').toggle()">'; $variable = $variable . $udvV['name'] . '</a>'; $varFound = true; $udvUsageIndex = $udvV['variableId']; if (array_key_exists($udvUsageIndex, $udvUsage) === false) { $udvUsage[$udvUsageIndex] = []; $udvUsage[$udvUsageIndex]['tags'] = []; $udvUsage[$udvUsageIndex]['triggers'] = []; $udvUsage[$udvUsageIndex]['variables'] = []; } if (array_key_exists('variableId', $entity) !== false) { if (usageRecorded($udvUsage[$udvUsageIndex]['variables'], $entity, 'variableId', $udvUsageIndex) === false) { array_push($udvUsage[$udvUsageIndex]['variables'], $entity); } } if (array_key_exists('tagId', $entity) !== false) { if (usageRecorded($udvUsage[$udvUsageIndex]['tags'], $entity, 'tagId') === false) { array_push($udvUsage[$udvUsageIndex]['tags'], $entity); } } if (array_key_exists('triggerId', $entity) !== false) { if (usageRecorded($udvUsage[$udvUsageIndex]['triggers'], $entity, 'triggerId') === false) { array_push($udvUsage[$udvUsageIndex]['triggers'], $entity); } } if (array_search('{{' . $udvV['name'] . '}}', $usedUdvs) === false) { array_push($usedUdvs, '{{' . $udvV['name'] . '}}'); } } } } if (!$varFound) { $variable = biVariablise($variable, $bivArray); } return $variable; }
function getUsage($udv) { $uDeets = ''; global $udvUsage, $udvTypes, $udvLibrary; foreach ($udvTypes as $udvTypeIndex => $udvTypeVal) { foreach ($udvLibrary[$udvTypes[$udvTypeIndex]] as $udvIndex => $udvs) { if ($udvLibrary[$udvTypes[$udvTypeIndex]][$udvIndex]['variableId'] !== $udv['variableId'] && strpos(json_encode($udvLibrary[$udvTypes[$udvTypeIndex]][$udvIndex]), $udv['name']) > -1) { if (!array_key_exists($udv['variableId'], $udvUsage)) { $udvUsage[$udv['variableId']] = []; $udvUsage[$udv['variableId']]['tags'] = []; $udvUsage[$udv['variableId']]['triggers'] = []; $udvUsage[$udv['variableId']]['variables'] = []; } if (usageRecorded($udvUsage[$udv['variableId']]['variables'], $udvLibrary[$udvTypes[$udvTypeIndex]][$udvIndex], 'variableId') === false) { array_push($udvUsage[$udv['variableId']]['variables'], $udvLibrary[$udvTypes[$udvTypeIndex]][$udvIndex]); } } } } if (array_key_exists($udv['variableId'], $udvUsage) !== false) { $uDeets = $uDeets . getUsageEntity($udv, 'tags'); $uDeets = $uDeets . getUsageEntity($udv, 'triggers'); $uDeets = $uDeets . getUsageEntity($udv, 'variables'); } else { $uDeets = 'This variable is <b>unused</b>.'; } $uDeets = '<td>' . $uDeets . '</td></tr>'; return $uDeets; }