combină-profilele.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * File name:
  4. *
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. // Load the list of persons
  26. $xml = new DOMDocument();
  27. $xml->load('../20131013-consilieri.xml');
  28. $xpath = new DOMXpath($xml);
  29. $persons = $xpath->query("/xml/person");
  30. foreach($persons as $person)
  31. {
  32. // Get index name
  33. $comname = $xpath->query("comname", $person)->item(0)->nodeValue;
  34. $surname = $xpath->query("surname", $person)->item(0)->nodeValue;
  35. $iname = $comname.'-'.$surname;
  36. $pmb = new DOMDocument();
  37. $pmb->load('../profile/00-pmb/'.$iname.'.xml');
  38. $liste = new DOMDocument();
  39. $liste->load('../profile/01-liste/'.$iname.'.xml');
  40. $x = $pmb->getElementsByTagName("xml")->item(0);
  41. $a = $pmb->getElementsByTagName("affiliation")->item(0);
  42. $a1 = $liste->getElementsByTagName("affiliation")->item(0);
  43. $x->replaceChild($pmb->importNode($a1->cloneNode(true), true), $a);
  44. $a = $pmb->getElementsByTagName("birthdate")->item(0);
  45. $a1 = $liste->getElementsByTagName("birthdate")->item(0);
  46. $x->replaceChild($pmb->importNode($a1->cloneNode(true), true), $a);
  47. $a = $liste->getElementsByTagName("sex")->item(0);
  48. $x->appendChild($pmb->importNode($a->cloneNode(true), true));
  49. $a = $liste->getElementsByTagName("party")->item(0);
  50. $x->appendChild($pmb->importNode($a->cloneNode(true), true));
  51. $pmb->save('../profile/'.$iname.'.xml');
  52. }
  53. ?>