/** * @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()]); } }
protected function sendEmail(User $to, $subject, $template, $vars) { $body = $this->twig->render($template, array_merge(['to_name' => $to->getName(), 'to_email' => $to->getEmail()], $vars)); $message = \Swift_Message::newInstance()->setSubject($subject)->addTo($to->getEmail())->addFrom($this->getDefaultFromEmail())->setBody($body); $this->mailer->send($message); }
/** * Hydrates a user object with the data * * @param array $data * @param User $object * * @return User */ public function hydrate(array $data, User $object) { $object->setEmail($data['email']); $object->setName($data['name']); $object->setSendNotifications($data['sendNotifications']); if (isset($data['timezone'])) { if (!$data['timezone'] instanceof \DateTimeZone) { $object->setTimezone(new \DateTimeZone($data['timezone'])); } else { $object->setTimezone($data['timezone']); } } $object->setIsMentee($data['isMentee']); $object->setIsMentor($data['isMentor']); if (isset($data['isEnabled'])) { $object->setIsEnabled($data['isEnabled']); } if (isset($data['githubUid'])) { $object->setGithubUid($data['githubUid']); } if (isset($data['githubName'])) { $object->setGithubName($data['githubName']); } if (isset($data['timeCreated'])) { if (!$data['timeCreated'] instanceof \DateTime) { $createdTime = new \DateTime($data['timeCreated']); $object->setTimeCreated($createdTime); } else { $object->setTimeCreated($data['timeCreated']); } } if (isset($data['id'])) { $object->setId($data['id']); } if (isset($data['roles'])) { if (is_array($data['roles'])) { $object->setRoles($data['roles']); } else { $object->setRoles(unserialize($data['roles'])); } } if (isset($data['profile'])) { $object->setProfile($data['profile']); } $mentoringTerm = $this->taxonomyService->fetchVocabularyByName('mentor'); $apprenticeTerm = $this->taxonomyService->fetchVocabularyByName('apprentice'); $object->setMentorTags($this->taxonomyService->fetchTermsForUser($object, $mentoringTerm)); $object->setApprenticeTags($this->taxonomyService->fetchTermsForUser($object, $apprenticeTerm)); return $object; }
protected function getTestUser() { $testData = $this->getTestData(); $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['isEnabled']); $user->setIsMentee($testData['isMentee']); $user->setIsMentor($testData['isMentor']); $user->setProfile($testData['profile']); $user->setSendNotifications($testData['sendNotifications']); return $user; }
/** * 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()); }
/** * 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(); }