/** * 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; }
/** * Makes sure that the setters and getters work properly * * @author Chris Tankersley <*****@*****.**> * @since 2015-04-28 */ public function testSettersAndGetters() { $testData = ['email' => '*****@*****.**', 'githubUid' => '1234', 'id' => 1, 'name' => 'Mr. McTest', 'roles' => ['ROLE_USER'], 'timeCreated' => new \DateTime(), 'timezone' => new \DateTimeZone("Europe/London"), 'enabled' => true, 'isMentee' => true, 'isMentor' => false, 'sendNotifications' => true, 'profile' => 'I am interested in learning about PHP.']; $user = new User(); $user->setEmail($testData['email']); $user->setGithubUid($testData['githubUid']); $user->setId($testData['id']); $user->setName($testData['name']); $user->setRoles($testData['roles']); $user->setTimeCreated($testData['timeCreated']); $user->setTimezone($testData['timezone']); $user->setIsEnabled($testData['enabled']); $user->setIsMentee($testData['isMentee']); $user->setIsMentor($testData['isMentor']); $user->setSendNotifications($testData['sendNotifications']); $user->setProfile($testData['profile']); $this->assertEquals($testData['email'], $user->getEmail()); $this->assertEquals($testData['githubUid'], $user->getGithubUid()); $this->assertEquals($testData['id'], $user->getId()); $this->assertEquals($testData['name'], $user->getName()); $this->assertEquals($testData['roles'], $user->getRoles()); $this->assertEquals($testData['timeCreated'], $user->getTimeCreated()); $this->assertEquals($testData['enabled'], $user->isEnabled()); $this->assertEquals($testData['isMentee'], $user->isMentee()); $this->assertEquals($testData['isMentor'], $user->isMentor()); $this->assertEquals($testData['sendNotifications'], $user->hasSendNotifications()); $this->assertEquals($testData['profile'], $user->getProfile()); $this->assertEquals($testData['timezone'], $user->getTimezone()); }
/** * @param User $user * @return Conversation[] */ public function findAllInvolvingUser(User $user) { $convos_data = $this->dbal->fetchAll('SELECT * FROM conversations WHERE (from_user_id = :user_id OR to_user_id = :user_id)', ['user_id' => $user->getId()]); $conversations = []; foreach ($convos_data as $convo_data) { $conversation_id = $convo_data['id']; if (!array_key_exists($conversation_id, $this->in_memory_convos)) { $conversation = $this->hydrateConversation($convo_data); $this->in_memory_convos[$conversation->getId()] = $conversation; } $conversations[] = $this->in_memory_convos[$conversation_id]; } return $conversations; }
public function fetchTermsForUser(User $user, Vocabulary $vocabulary) { $data = $this->dbal->fetchAll('SELECT t.* FROM taxonomyTerms t JOIN userTags u ON t.id=u.term_id WHERE u.user_id = :user_id AND t.vocabulary_id = :vocabulary_id ', ['vocabulary_id' => $vocabulary->getId(), 'user_id' => $user->getId()]); $terms = []; foreach ($data as $termData) { $term = $this->termHydrator->hydrate($termData, new Term()); $term->setVocabulary($vocabulary); $terms[] = $term; } return $terms; }
/** * Makes sure that the setters and getters work properly * * @author Chris Tankersley <*****@*****.**> * @since 2015-04-28 */ public function testSettersAndGetters() { $testData = ['email' => '*****@*****.**', 'githubUid' => '1234', 'id' => 1, 'name' => 'Mr. McTest', 'roles' => ['ROLE_USER'], 'timeCreated' => new \DateTime(), 'enabled' => true, 'isMentee' => true, 'isMentor' => false]; $user = new User(); $user->setEmail($testData['email']); $user->setGithubUid($testData['githubUid']); $user->setId($testData['id']); $user->setName($testData['name']); $user->setRoles($testData['roles']); $user->setTimeCreated($testData['timeCreated']); $user->setIsEnabled($testData['enabled']); $user->setIsMentee($testData['isMentee']); $user->setIsMentor($testData['isMentor']); $this->assertEquals($testData['email'], $user->getEmail()); $this->assertEquals($testData['githubUid'], $user->getGithubUid()); $this->assertEquals($testData['id'], $user->getId()); $this->assertEquals($testData['name'], $user->getName()); $this->assertEquals($testData['roles'], $user->getRoles()); $this->assertEquals($testData['timeCreated'], $user->getTimeCreated()); $this->assertEquals($testData['enabled'], $user->isEnabled()); $this->assertEquals($testData['isMentee'], $user->isMentee()); $this->assertEquals($testData['isMentor'], $user->isMentor()); }
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()]); } }
/** * Given an involved user, it will tell you the other involved user. * * @param User $user * @return User */ public function withUser(User $user) { if ($user === $this->toUser || $this->toUser->getId() && $this->toUser->getId() == $user->getId()) { return $this->fromUser; } return $this->toUser; }
public function isFromUser(User $user) { return $user === $this->fromUser || $user->getId() && $user->getId() == $this->fromUser->getId(); }