Пример #1
0
 /**
  * Update the element in the database
  *
  * @return DbUser
  */
 public function update()
 {
     /*
      * Update:
      *      - formation
      *      - niveau
      *      - filiere
      *      - uvs
      *      - semesters history
      */
     $persist = false;
     $user = $this->database;
     $history = $user->addCureentSemesterToHistory();
     $niveau = null;
     $branch = $this->ldap->getNiveau();
     preg_match('/^[^0-9]+/i', $this->ldap->getNiveau(), $match);
     if (isset($match[0])) {
         $branch = $match[0];
         $niveau = str_replace($branch, '', $this->ldap->getNiveau());
     }
     // Updates
     if (ucfirst(strtolower($this->ldap->getFormation())) != $this->database->getFormation()) {
         $persist = true;
         $user->setFormation(ucfirst(strtolower($this->ldap->getFormation())));
     }
     if ($niveau != $this->database->getNiveau()) {
         $persist = true;
         $user->setNiveau($niveau);
     }
     if ($branch != $this->database->getBranch()) {
         $persist = true;
         $user->setBranch($branch);
     }
     if ($this->ldap->getFiliere() != $this->database->getFiliere()) {
         $persist = true;
         $user->setFiliere($this->ldap->getFiliere());
     }
     if (implode('|', $this->ldap->getUvs()) != $this->database->getUvs()) {
         $persist = true;
         $user->setUvs(implode('|', $this->ldap->getUvs()));
     }
     /*
      * Add badges
      */
     if (substr($history['niveau'], 0, 2) == 'TC' && substr($user->getNiveau(), 0, 2) != 'TC') {
         BadgesManager::userAddBadge($user, 'tc_survivor');
         BadgesManager::userPersistBadges($user);
     }
     if ($persist) {
         $this->doctrine->getManager()->persist($user);
     }
     return $persist;
 }