/** * Extracts and returns the user data from the user object * * @param User $object * @return array */ public function extract(User $object) { $data = ['email' => $object->getEmail(), 'id' => $object->getId(), 'name' => $object->getName(), 'roles' => $object->getRoles(), 'timeCreated' => $object->getTimeCreated(), 'isEnabled' => $object->isEnabled(), 'githubUid' => $object->getGithubUid(), 'githubName' => $object->getGithubName(), 'isMentee' => $object->isMentee(), 'isMentor' => $object->isMentor(), 'profile' => $object->getProfile(), 'apprenticeTags' => $object->getApprenticeTags(), 'mentorTags' => $object->getMentorTags(), 'imageUrl' => $object->getProfileImage(), 'timezone' => $object->getTimezone(), 'sendNotifications' => $object->hasSendNotifications()]; if (!is_null($this->termHydrator)) { $apprenticeTags = $data['apprenticeTags']; unset($data['apprenticeTags']); foreach ($apprenticeTags as $key => $tag) { $tag = $this->termHydrator->extract($tag); $apprenticeTags[$key] = $tag; } $data['apprenticeTags'] = $apprenticeTags; $mentorTags = $data['mentorTags']; unset($data['mentorTags']); foreach ($mentorTags as $key => $tag) { $tag = $this->termHydrator->extract($tag); $mentorTags[$key] = $tag; } $data['mentorTags'] = $mentorTags; } if ($data['timeCreated'] instanceof \DateTime) { $data['timeCreated'] = $data['timeCreated']->format(\DateTime::ISO8601); } if ($data['timezone'] instanceof \DateTimeZone) { $data['timezone'] = $data['timezone']->getName(); } return $data; }
public function saveUserTags(User $user) { $this->dbal->delete('userTags', ['user_id' => $user->getId()]); foreach ($user->getMentorTags() as $mentorTag) { echo 'Saving ' . $mentorTag->getName(); $this->dbal->insert('userTags', ['user_id' => $user->getId(), 'term_id' => $mentorTag->getId()]); } foreach ($user->getApprenticeTags() as $apprenticeTag) { echo 'Saving ' . $apprenticeTag->getName(); $this->dbal->insert('userTags', ['user_id' => $user->getId(), 'term_id' => $apprenticeTag->getId()]); } }