TransformProductCode.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. header('Content-Type: application/json');
  6. $url = realpath("./../server/json/ProductCode.json");
  7. $json = file_get_contents($url);
  8. $json = json_decode($json);
  9. $productcode = str_replace("/", ".", $_GET["ProductCode"]);
  10. $productarray = explode(".", $productcode);
  11. if($_GET["ProductCode"] == ""){
  12. echo json_encode (json_decode ("{}"));
  13. return;
  14. }
  15. if(isset($_GET["Semantic"])){
  16. $fixwerte = 6;
  17. for($i = 0; $i < $fixwerte; ++$i){
  18. if(isset($productarray[$i])){
  19. $asocarray[$json->pattern[$i]->abk] = $productarray[$i];
  20. }
  21. else{
  22. $asocarray[$json->pattern[$i]->abk] = "";
  23. }
  24. }
  25. //Search which abk can be linked to the patternpart
  26. for($i = $fixwerte; $i < count($productarray); ++$i){
  27. foreach($json->pattern as $node){
  28. foreach($node->types as $type){
  29. if($productarray[$i] == $type && $type != "*"){
  30. $asocarray[$node->abk] = $productarray[$i];
  31. }
  32. }
  33. }
  34. }
  35. }
  36. else{
  37. $i = 0;
  38. foreach($json->pattern as $node){
  39. if(isset($productarray[$i])){
  40. $asocarray[$node->abk] = $productarray[$i];
  41. }
  42. ++$i;
  43. }
  44. }
  45. echo json_encode($asocarray);
  46. ?>