PerfMigrate.api.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. abstract class PerfApiMigration extends XMLMigration {
  3. public function __construct(){
  4. parent::__construct(MigrateGroup::getInstance('PerfMigrate'));
  5. }
  6. public function getTextsAuthors($xml, $attr, $l){
  7. $values = array();
  8. $authors = array();
  9. $language = array();
  10. foreach ($xml as $xml_value) {
  11. $values = array_merge( $values, array( $this->getAttribute($xml_value, $attr), $this->getAttribute($xml_value, 'TRADUCTION')) );
  12. $auteur_nom = $this->getAttribute($xml_value, 'NOM_AUTEUR');
  13. $auteur_prenom = $this->getAttribute($xml_value, 'PRENOM_AUTEUR');
  14. $auteur = $auteur_nom != '' || $auteur_prenom != '' ? trim($auteur_prenom .' '. $auteur_nom) : '';
  15. $authors = array_merge($authors, array($auteur,$auteur));
  16. $language = array_merge($language, $l);
  17. }
  18. return array(
  19. 'values'=>$values,
  20. 'authors'=>$authors,
  21. 'language'=>$language,
  22. );
  23. }
  24. public function getAttribute($object, $attr){
  25. $attr_objects = $object->xpath('@'.$attr);
  26. return isset($attr_objects[0]) ? (string) $attr_objects[0] : '';
  27. }
  28. public function getPersonne($object, $suffix = ''){
  29. $nom = $this->getAttribute($object, 'NOM'.$suffix);
  30. $prenom = $this->getAttribute($object, 'PRENOM'.$suffix);
  31. return $nom != '' || $prenom != '' ? trim($prenom .' '. $nom) : '';
  32. }
  33. public function getDate($o, $moment){
  34. $date = $this->getAttribute($o, 'ANNEE_'.$moment)
  35. .'/'. $this->getAttribute($o, 'MOIS_'.$moment)
  36. .'/'. $this->getAttribute($o, 'JOUR_'.$moment)
  37. .'-'. $this->getAttribute($o, 'HEURE_'.$moment)
  38. .':'. $this->getAttribute($o, 'MINUTE_'.$moment);
  39. do {
  40. $date = preg_replace('/(\/+|:+|-+)$/', '', $date, 1, $count);
  41. } while ($count);
  42. return $date;
  43. }
  44. public function recordGroup(&$node, $field, $xml, $attr){
  45. foreach ($xml->xpath('GROUPE_ARTISTES[@'.$attr.'="oui"]') as $xml_group){
  46. # group d'artiste
  47. $gname = trim($this->getAttribute($xml_group, 'NOM'));
  48. // drush_log(dt('recordGroup !name', array('!name'=>$gname)), 'status');
  49. $gts = taxonomy_get_term_by_name($gname);
  50. //
  51. // drush_log(dt('group_term : !gt', array('!gt'=>print_r($gt, true))));
  52. if(!count($gts)){
  53. $gt = new stdClass();
  54. $gt->name = $gname;
  55. $gt->vid = 7;
  56. taxonomy_term_save($gt);
  57. }else{
  58. // print_r($gts);
  59. foreach ($gts as $tid => $t) {
  60. $gt = $t;
  61. break;
  62. }
  63. }
  64. // drush_log(dt('term group !name, tid : !tid', array('!name'=>$gt->name,'!tid'=>$gt->tid)), 'status');
  65. $node->{$field}['und'][] = array('tid'=>$gt->tid);
  66. # personne dans le group d'artist
  67. //!\\ ici ça ne boucle pas
  68. foreach ($xml->xpath('GROUPE_ARTISTES[@NOM="'.$gname.'"]/PERSONNE[@'.$attr.'="oui"]') as $xml_p){
  69. $term_name = trim($this->getPersonne($xml_p));
  70. // drush_log(dt('recordGroup :: personne : !p', array('!p'=>$term_name)), 'status');
  71. $tbn = taxonomy_get_term_by_name($term_name);
  72. if(!count($tbn)){
  73. $t = new stdClass();
  74. $t->name = $term_name;
  75. $t->vid = 7;
  76. taxonomy_term_save($t);
  77. }else{
  78. foreach ($tbn as $tid => $tt) {
  79. $t = $tt;
  80. break;
  81. }
  82. }
  83. $parents = taxonomy_get_parents($t->tid);
  84. $t->parent = array();
  85. foreach ($parents as $tid => $parent_term) {
  86. $t->parent[] = $tid;
  87. }
  88. if(!in_array($gt->tid, $t->parent)){
  89. $t->parent[] = $gt->tid;
  90. }
  91. $nom = trim($this->getAttribute($xml_p, 'NOM'));
  92. $prenom = trim($this->getAttribute($xml_p, 'PRENOM'));
  93. $t->field_nom = array(
  94. 'und'=>array(
  95. array(
  96. 'value' => $nom,
  97. 'format' => null,
  98. 'safe_value' => $nom,
  99. )
  100. )
  101. );
  102. $t->field_prenom = array(
  103. 'und'=>array(
  104. array(
  105. 'value' => $prenom,
  106. 'format' => null,
  107. 'safe_value' => $prenom,
  108. )
  109. )
  110. );
  111. taxonomy_term_save($t);
  112. // drush_log(dt('term personne !name, tid : !tid', array('!name'=>$t->name,'!tid'=>$t->tid)), 'status');
  113. $node->{$field}['und'][] = array('tid'=>$t->tid);
  114. }
  115. }
  116. }
  117. public function updatePersonneTerms($xml){
  118. foreach ($xml->xpath('PERSONNE') as $xml_concepteur){
  119. $nom = trim($this->getAttribute($xml_concepteur, 'NOM'));
  120. $prenom = trim($this->getAttribute($xml_concepteur, 'PRENOM'));
  121. $term_name = $nom != '' || $prenom != '' ? trim($prenom .' '. $nom) : '';
  122. $tbn = taxonomy_get_term_by_name($term_name);
  123. // if(!count($tbn)){
  124. // $t = new stdClass();
  125. // $t->name = $term_name;
  126. // $t->vid = 7;
  127. // taxonomy_term_save($t);
  128. // }else{
  129. foreach ($tbn as $tid => $tt) {
  130. $term = $tt;
  131. break;
  132. }
  133. // }
  134. $term->field_nom = array(
  135. 'und'=>array(
  136. array(
  137. 'value' => $nom,
  138. 'format' => null,
  139. 'safe_value' => $nom,
  140. )
  141. )
  142. );
  143. $term->field_prenom = array(
  144. 'und'=>array(
  145. array(
  146. 'value' => $prenom,
  147. 'format' => null,
  148. 'safe_value' => $prenom,
  149. )
  150. )
  151. );
  152. taxonomy_term_save($term);
  153. }
  154. }
  155. }