Guest User

Untitled

a guest
Jul 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. //Ajout & Modif de motsclés (sujets)
  4. $existing = $this->sujets->getPrimaryKeys();
  5. $values = array_filter(explode('|', trim($request->getParameter('infolettres[motscles_liste]'))));
  6.  
  7. if (!is_array($values)) { $values = array(); }
  8.  
  9. $values_pas_effacer = array();
  10.  
  11. foreach ($values as $value) {
  12. $s = Doctrine_Query::create()
  13. ->from('ProfilSujet')
  14. ->where('profil_id =?', $this->id)
  15. ->andWhere("valeur LIKE '".$value."'")
  16. ->limit(1)
  17. ->fetchOne();
  18.  
  19. if ((is_object($s)) and (strlen($s->id) > 0)) {
  20. array_push($values_pas_effacer, $s->valeur);
  21. } else {
  22. if (strlen($value) > 0) {
  23. array_push($values_pas_effacer, $value);
  24. $sujet_nouveau = new ProfilSujet();
  25. $sujet_nouveau->profil_id = $this->id;
  26. $sujet_nouveau->valeur = $value;
  27. $sujet_nouveau->save();
  28. }
  29. }
  30. }
  31.  
  32. foreach ($existing as $key => $existe_deja) {
  33. if (!is_numeric(array_search($value, $values_pas_effacer))) {
  34. $s = Doctrine_Query::create()
  35. ->from('ProfilSujet')
  36. ->where('profil_id =?', $this->id)
  37. ->andWhere('valeur =?', $value)
  38. ->execute();
  39.  
  40. $s->delete();
  41. }
  42. }
Add Comment
Please, Sign In to add comment