/**
  * Handles the upload of a user image.
  *
  * @param \MusicBox\Entity\User $user
  *
  * @param boolean TRUE if a new user image was uploaded, FALSE otherwise.
  */
 protected function handleFileUpload($user)
 {
     // If a temporary file is present, move it to the correct directory
     // and set the filename on the user.
     $file = $user->getFile();
     if ($file) {
         $newFilename = $user->getUsername() . '.' . $file->guessExtension();
         $file->move(SWIM_PUBLIC_ROOT . '/img/users', $newFilename);
         $user->setFile(null);
         $user->setImage($newFilename);
         return TRUE;
     }
     return FALSE;
 }
Esempio n. 2
0
 /**
  * Instantiates a user entity and sets its properties using db data.
  *
  * @param array $userData
  *   The array of db data.
  *
  * @return \MusicBox\Entity\User
  */
 protected function buildUser($userData)
 {
     $user = new User();
     $user->setId($userData['user_id']);
     $user->setUsername($userData['username']);
     $user->setSalt($userData['salt']);
     $user->setPassword($userData['password']);
     $user->setMail($userData['mail']);
     $user->setRole($userData['role']);
     $createdAt = new \DateTime('@' . $userData['created_at']);
     $user->setCreatedAt($createdAt);
     return $user;
 }