/**
  * Saves the user to the database.
  *
  * @param \MusicBox\Entity\User $user
  */
 public function save($user)
 {
     $userData = array('username' => $user->getUsername(), 'email' => $user->getEmail(), 'role' => $user->getRole(), 'firstname' => $user->getFirstName(), 'lastname' => $user->getLastName(), 'spouse_firstname' => $user->getSpouseFirstName(), 'spouse_lastname' => $user->getSpouseLastName(), 'mobile' => $user->getMobile(), 'home' => $user->getHome());
     // If the password was changed, re-encrypt it.
     if (strlen($user->getPassword()) != 88) {
         $userData['salt'] = uniqid(mt_rand());
         $userData['password'] = $this->encoder->encodePassword($user->getPassword(), $userData['salt']);
     }
     // dump($userData);exit();
     if ($user->getUserId()) {
         // If a new image was uploaded, make sure the filename gets set.
         // $newFile = $this->handleFileUpload($user);
         // if ($newFile) {
         //     $userData['image'] = $user->getImage();
         // }
         try {
             $this->db->update('users', $userData, array('user_id' => $user->getUserId()));
         } catch (\Exception $e) {
             return FALSE;
         }
     } else {
         // The user is new, note the creation timestamp.
         $userData['created_at'] = time();
         try {
             $this->db->insert('users', $userData);
             // Get the id of the newly created user and set it on the entity.
             $user_id = $this->db->lastInsertId();
             $user->setUserId($user_id);
             return $user_id;
         } catch (\Exception $e) {
             dump($e);
             return false;
         }
     }
     // If a new image was uploaded, update the user with the new
     // filename.
     // $newFile = $this->handleFileUpload($user);
     // if ($newFile) {
     //     $newData = array('image' => $user->getImage());
     //     $this->db->update('users', $newData, array('user_id' => $user_id));
     // }
     return TRUE;
 }