コード例 #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;
 }
コード例 #2
0
 /**
  * @param $type
  * @param User|Organization $user
  */
 private function createSession($type, $user)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $session = new Session($type, $user->getId());
     $session->createName($_SERVER);
     $em->persist($session);
     $em->flush();
     setcookie(md5('etuutt-session-cookie-name'), $session->getToken(), $session->getExpireAt()->format('U'), '/');
 }
コード例 #3
0
 /**
  * Import a user in the database
  *
  * @param Organization $bdeOrga
  * @param bool $flush
  * @return \Etu\Core\UserBundle\Entity\User
  */
 protected function importUser($bdeOrga = null, $flush = false)
 {
     $imagine = new Imagine();
     $webDirectory = __DIR__ . '/../../../../../../../web';
     $avatar = $this->element->getLogin() . '.jpg';
     if (!file_exists($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg')) {
         // Resize photo
         try {
             $image = $imagine->open('http://local-sig.utt.fr/Pub/trombi/individu/' . $this->element->getStudentId() . '.jpg');
             $image->copy()->thumbnail(new Box(200, 200), Image::THUMBNAIL_OUTBOUND)->save($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg');
         } catch (\Exception $e) {
             $avatar = 'default-avatar.png';
         }
     }
     $niveau = null;
     $branch = $this->element->getNiveau();
     preg_match('/^[^0-9]+/i', $this->element->getNiveau(), $match);
     if (isset($match[0])) {
         $branch = $match[0];
         $niveau = str_replace($branch, '', $this->element->getNiveau());
     }
     $user = new \Etu\Core\UserBundle\Entity\User();
     $user->setAvatar($avatar);
     $user->setLogin($this->element->getLogin());
     $user->setFullName($this->element->getFullName());
     $user->setFirstName($this->element->getFirstName());
     $user->setLastName($this->element->getLastName());
     $user->setFiliere($this->element->getFiliere());
     $user->setFormation(ucfirst(strtolower($this->element->getFormation())));
     $user->setNiveau($niveau);
     $user->setBranch($branch);
     $user->setMail($this->element->getMail());
     $user->setPhoneNumber($this->element->getPhoneNumber());
     $user->setRoom($this->element->getRoom());
     $user->setStudentId($this->element->getStudentId());
     $user->setTitle($this->element->getTitle());
     $user->setIsStudent($this->element->getIsStudent());
     $user->setKeepActive(false);
     $user->setUvs(implode('|', $this->element->getUvs()));
     $this->doctrine->getManager()->persist($user);
     // Subscribe to BDE
     if ($bdeOrga) {
         $subscription = new Subscription();
         $subscription->setEntityType('orga')->setEntityId($bdeOrga->getId())->setUser($user);
         $this->doctrine->getManager()->persist($subscription);
     }
     // Subscribe to all events
     $subscription = new Subscription();
     $subscription->setEntityType('event')->setEntityId(0)->setUser($user);
     $this->doctrine->getManager()->persist($subscription);
     // Flush if needed
     if ($flush) {
         $this->doctrine->getManager()->flush();
     }
     return $user;
 }