getId() public method

public getId ( )
Ejemplo n.º 1
0
 /**
  * @param User $user
  * @return array
  */
 public function getNotifications(User $user)
 {
     $qb = $this->createQueryBuilder('n');
     $qb->select('n.id, a.articleId, a.heading as article_heading, a.createdAt, u.username, img.path, v.heading as video_heading, v.videoId, l.linkId, l.heading as link_heading');
     $qb->leftJoin('n.article', 'a')->leftJoin('n.user', 'u')->leftJoin('u.profileImg', 'img')->leftJoin('n.video', 'v')->leftJoin('n.link', 'l')->where('a.userId = ' . $user->getId())->orWhere('v.userId = ' . $user->getId())->orWhere('l.userId = ' . $user->getId())->andWhere('n.seen = 0');
     return $qb->getQuery()->getResult();
 }
Ejemplo n.º 2
0
 /**
  * @param User $user
  * @return Token
  */
 public function createToken(User $user) : Token
 {
     $issued = Carbon::now();
     $expire = Carbon::now()->addSeconds((int) $this->config['expire']);
     $notBefore = Carbon::now()->addSeconds((int) $this->config['notbefore']);
     return $this->tokenBuilder->setIssuer($this->config['issuer'])->setAudience($this->config['audience'])->setId($this->config['appid'], true)->setIssuedAt($issued->getTimestamp())->setNotBefore($notBefore->getTimestamp())->setExpiration($expire->getTimestamp())->set('data', ["uid" => $user->getId(), "uidentifier" => $user->getUsername()])->sign($this->signer, $this->secret)->getToken();
 }
Ejemplo n.º 3
0
 /**
  * @param User $user
  * @param PageAnimal $pageAnimal
  * @throws HistoryException
  * @throws ValidationException
  */
 public function commit(User $user, PageAnimal $pageAnimal)
 {
     /** @var PageAnimalBranch $pageAnimalBranch */
     $pageAnimalBranch = $this->pageAnimalBranchRepository->find($pageAnimal->getId());
     if ($pageAnimalBranch == null) {
         throw new HistoryException(HistoryException::BRANCHE_INCONNUE);
     }
     if ($user->getId() !== $pageAnimalBranch->getOwner()->getId()) {
         throw new HistoryException(HistoryException::DROIT_REFUSE);
     }
     /** @var PageAnimalCommit $clientHead */
     $clientHead = $this->pageAnimalCommitRepository->find($pageAnimal->getHead());
     if ($clientHead->getId() !== $pageAnimalBranch->getCommit()->getId()) {
         throw new HistoryException(HistoryException::NON_FAST_FORWARD);
     }
     if (empty($pageAnimal->getNom())) {
         throw new ValidationException(ValidationException::EMPTY_NOM);
     }
     if (empty($pageAnimal->getDateNaissance())) {
         throw new ValidationException(ValidationException::EMPTY_DATE_NAISSANCE);
     }
     $commit = new PageAnimalCommit($clientHead, $pageAnimal->getNom(), $pageAnimal->getDateNaissance(), $pageAnimal->getDescription(), $pageAnimal->getStatut(), $pageAnimal->getSexe(), $pageAnimal->getPhotos());
     $this->doctrine->persist($commit);
     $pageAnimalBranch->setCommit($commit);
     $this->doctrine->flush([$commit, $pageAnimalBranch]);
     $pageAnimal->setHead($commit->getId());
 }
Ejemplo n.º 4
0
 protected function getRecentFrequent(User $user, array $criteria = null, $limit = 10)
 {
     $sql = '
         SELECT text, MAX(createdAt) AS recency, COUNT(*) AS frequency
         FROM stress_log_factors
         JOIN stress_logs ON stress_log_id = stress_logs.id
         WHERE user_id = ?
     ';
     $params = array($user->getId());
     if (is_array($criteria)) {
         foreach ($criteria as $key => $val) {
             $op = '=';
             if (is_array($val)) {
                 reset($val);
                 $op = key($val);
                 $val = current($val);
             }
             $sql .= 'AND `' . $key . '` ' . $op . ' ? ';
             $params[] = $val;
         }
     }
     $sql .= 'GROUP BY text ';
     $sql .= 'ORDER BY recency DESC, frequency DESC ';
     $sql .= 'LIMIT ' . (int) $limit;
     $result = $this->conn->fetchAll($sql, $params);
     return array_column($result, 'text');
 }
Ejemplo n.º 5
0
 public function getQueryBuilderFindTodoBy(User $user)
 {
     $sub = $this->_em->createQueryBuilder();
     $sub->select('identity(v.proposal)')->from('AppBundle:Vote', 'v')->where($sub->expr()->eq('v.user', $user->getId()));
     $qb = $this->_em->createQueryBuilder();
     $proposals = $qb->select('p')->from('AppBundle:Proposal', 'p')->where($qb->expr()->notIn('p', $sub->getDQL()));
     return $proposals;
 }
 /**
  * @return int
  */
 public function delete(User $user, Post $post)
 {
     $conn = $this->_em->getConnection();
     $statement = $conn->prepare('DELETE FROM post_vote WHERE user_id = :user_id AND post_id = :post_id');
     $statement->bindValue('user_id', $user->getId());
     $statement->bindValue('post_id', $post->getId());
     return $statement->execute();
 }
Ejemplo n.º 7
0
 protected function stopActiveLogEntriesByUser(User $user)
 {
     $activeLogEntries = $this->logEntryRepository->getNonCompletedLogEntriesByUser($user->getId());
     foreach ($activeLogEntries as $activeEntry) {
         $activeEntry->setTo(new \DateTime());
         $this->logEntryRepository->save($activeEntry);
     }
 }
Ejemplo n.º 8
0
 public function getUserLiveGames(User $user)
 {
     $query = $this->getEntityManager()->createQuery('SELECT g FROM AppBundle:Game g JOIN g.players p JOIN p.user u WHERE u.id =:userId AND g.gameState =:state');
     $query->setParameter('userId', $user->getId());
     $query->setParameter('state', Game::STATE_HAS_PLAYERS_BUT_NOT_READY);
     $result = $query->getResult();
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Sets task as users default task
  *
  * @param Task $task
  * @param User $user
  */
 public function setTaskAsDefault(Task $task, User $user)
 {
     $this->em->beginTransaction();
     $defaultTask = $this->taskRepository->findUserDefaultTask($user->getId());
     $defaultTask->setDefault(false);
     $task->setDefault(true);
     $this->taskRepository->update($task);
     $this->em->flush();
     $this->em->commit();
 }
Ejemplo n.º 10
0
 public function getConversation(User $mainUser, User $secendaryUser, $order = 'DESC')
 {
     $queryBuilder = $this->createQueryBuilder('m');
     $queryBuilder->where($queryBuilder->expr()->andX($queryBuilder->expr()->eq('m.sender', ':mainUser'), $queryBuilder->expr()->eq('m.receiver', ':secendaryUser')))->orWhere($queryBuilder->expr()->andX($queryBuilder->expr()->eq('m.sender', ':secendaryUser'), $queryBuilder->expr()->eq('m.receiver', ':mainUser')))->setParameter('mainUser', $mainUser->getId())->setParameter('secendaryUser', $secendaryUser->getId());
     if (!in_array(strtoupper($order), array('ASC', 'DESC'))) {
         $order = 'DESC';
     }
     $queryBuilder->orderBy('m.createdAt', $order);
     return $queryBuilder->getQuery()->getResult();
 }
Ejemplo n.º 11
0
 /**
  * @param User $user
  * @param $request
  * @throws
  * @return User
  */
 public function addCustomer(User $user, $request)
 {
     $result = BraintreeCustomer::create(['id' => 'userid-' . $user->getId(), 'email' => $user->getEmail(), "creditCard" => ["number" => $request->request->get("number"), "cvv" => $request->request->get("cvv"), "expirationMonth" => $request->request->get("month"), "expirationYear" => $request->request->get("year")]]);
     if ($result->success === true) {
         $user->setBraintreeCustomerId($result->customer->id);
     } else {
         throw new Exception("Braintree create customer failed");
     }
     return $result->success;
 }
Ejemplo n.º 12
0
 /**
  * Test an empty User entity
  */
 public function testEmptyUser()
 {
     $user = new User();
     $this->assertEquals('New User', $user->__toString());
     $this->assertNull($user->getId());
     $this->assertNull($user->getFullName());
     $this->assertNull($user->getFacebookAccessToken());
     $this->assertNull($user->getFacebookId());
     $this->assertEquals(0, $user->getItems()->count());
 }
Ejemplo n.º 13
0
 /**
  * Test creation of new entity
  */
 public function testCreateNewEntity()
 {
     $user = new User();
     $this->assertNull($user->getId());
     $this->assertFalse($user->isEnabled());
     $this->assertNull($user->getCreatedAt());
     $this->assertNull($user->getUpdatedAt());
     $this->assertNull($user->getFullName());
     $this->assertNull($user->getPhone());
 }
Ejemplo n.º 14
0
 /**
  * @param User $user
  * @param $request
  * @throws Exception
  * @return User
  */
 public function addCustomer(User $user, $request)
 {
     $stripeToken = $request->request->get('token');
     //register stripe customer if necessary
     $customer = StripeCustomer::create(["description" => sprintf("UserId %s email %s", $user->getId(), $user->getEmail()), "source" => $stripeToken, "email" => $user->getEmail()]);
     if (!$customer->id) {
         throw new Exception("stripe create customer failed");
     }
     $user->setStripeCustomerId($customer->id);
     return true;
 }
Ejemplo n.º 15
0
 /**
  * Deletes a User entity.
  *
  * @Route("/{id}", name="user_delete")
  * @Method("DELETE")
  */
 public function deleteAction(Request $request, User $user)
 {
     $form = $this->createFormDelete($user->getId());
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->remove($user);
         $em->flush();
     }
     return $this->redirectToRoute('user_show');
 }
Ejemplo n.º 16
0
 public function unsubscribe(User $user, Subscription $subscription)
 {
     $query = $this->getEntityManager()->createNativeQuery('DELETE FROM xdb__user_subscription_relation WHERE subscription_id=? AND user_id=?', new ResultSetMapping());
     $query->setParameter(1, $subscription->getId());
     $query->setParameter(2, $user->getId());
     try {
         $query->getResult();
     } catch (\PDOException $e) {
         // this is thrown, but nothing went wrong (seems like)
     }
 }
Ejemplo n.º 17
0
 /**
  * @param $id
  * @param User $user
  * @return bool
  * This function check if the Id passed in first parameter is equal to the id of the second
  * Admin is an exception
  */
 public function sameUser($id, $user)
 {
     if ($user->hasRole('ROLE_ADMIN')) {
         return true;
     } else {
         if ($id == $user->getId()) {
             return true;
         } else {
             throw new HttpException(403, 'forbidden !');
         }
     }
 }
Ejemplo n.º 18
0
 /**
  * Transform a Model User to its representation.
  *
  * @param User|null $user
  *
  * @return UserRepresentation|null
  */
 public function transform($user)
 {
     if (!$user) {
         return;
     }
     $representation = new UserRepresentation();
     $representation->setId($user->getId());
     $representation->setUsername($user->getUsername());
     $representation->setEmail($user->getEmail());
     $representation->setFirstname($user->getFirstName());
     return $representation;
 }
Ejemplo n.º 19
0
 public function __construct(User $user)
 {
     $this->id = $user->getId();
     $this->firstname = $user->getFirstname();
     $this->lastname = $user->getLastname();
     $this->email = $user->getEmail();
     $this->positionLong = $user->getPositionLong();
     $this->positionLat = $user->getPositionLat();
     $this->positionCity = $user->getPositionCity();
     $this->positionDep = $user->getPositionDep();
     $this->positionCountry = $user->getPositionCountry();
     $this->photo = $user->getPhoto();
 }
Ejemplo n.º 20
0
 /**
  * UserModel constructor.
  * @param User $user
  */
 public function __construct(User $user)
 {
     $this->setId($user->getId());
     $this->setUsername($user->getUsername());
     $this->setUserFirstName($user->getUserFirstName());
     $this->setUserLastName($user->getUserLastName());
     $this->setEmail($user->getEmail());
     $this->setPassword($user->getPassword());
     $this->setApiKey($user->getApiKey());
     $role = $this->determineTheBiggestRole($user);
     if ($role) {
         $this->setRole(new RoleModel($role));
     }
 }
Ejemplo n.º 21
0
 public function getActiveEvents(User $user)
 {
     $temp_user = $user->getId();
     $today = Date("Y-m-d H:i:s");
     $PDO = $this->getEntityManager()->getConnection()->prepare('SELECT id FROM event WHERE user_id = :user AND startTime <= Now() AND Now() <= startTime + INTERVAL eventLength HOUR');
     $PDO->bindParam(':user', $temp_user);
     $PDO->execute();
     $result = $PDO->fetchAll();
     $activeevents = [];
     foreach ($result as $value) {
         $event = $this->findOneBy(array('id' => $value));
         $activeevents[] = $event;
     }
     return $activeevents;
 }
Ejemplo n.º 22
0
 public function save(User $user)
 {
     $new = !$user->getId();
     $generatedPassword = $user->getPlainPassword();
     //TODO - permission?
     try {
         $this->entityManager->persist($user);
         $this->entityManager->flush();
     } catch (DBALException $e) {
         throw new UserException('Uživatel s tímto e-mailem již existuje');
     }
     if ($new) {
         $this->userCreate->send($user, $generatedPassword);
     }
 }
 public function findByUserAndTags(User $user, $tags = null)
 {
     $filterQuery = new Query\Filtered();
     $searchFilter = new Filter\Bool();
     $searchFilter->addMust(new Filter\Term(array('user' => $user->getId())));
     if (!empty($tags)) {
         $tagFilter = new Filter\Terms('tags', explode('+', $tags));
         $tagFilter->setExecution('and');
         $searchFilter->addMust($tagFilter);
     }
     $filterQuery->setFilter($searchFilter);
     $searchQuery = new Query($filterQuery);
     $searchQuery->addSort(array('createdAt' => 'desc'));
     $agg = new Aggregation\Terms('tags');
     $agg->setField('tags')->setOrder('_count', 'desc')->setSize(100);
     $searchQuery->addAggregation($agg);
     return $searchQuery;
 }
 /**
  * Test is the given response is valid.
  *
  * @param Response $response
  * @param User     $user
  */
 private function assertIsValidV2Response(Response $response, User $user)
 {
     // Response is OK
     $this->assertEquals(200, $response->getStatusCode());
     $result = $response->getContent();
     $content = json_decode($result, true);
     // All key are presents
     $keys = array('id', 'username', 'email', 'firstname');
     foreach ($keys as $key) {
         $this->assertArrayHasKey($key, $content);
     }
     // There is no extra key
     foreach ($content as $key => $value) {
         $this->assertContains($key, $keys);
     }
     // all values are valid
     $this->assertEquals($user->getId(), $content['id']);
     $this->assertEquals($user->getUsername(), $content['username']);
     $this->assertEquals($user->getEmail(), $content['email']);
     $this->assertEquals($user->getFirstName(), $content['firstname']);
 }
Ejemplo n.º 25
0
 public function test_create_token()
 {
     $user = new User();
     $user->setId(1);
     $user->setUsername('user1');
     $signer = new Sha256();
     $secret = 'test_sign_secret';
     $config = ['issuer' => 'me', 'audience' => 'me', 'appid' => 10, 'expire' => 60, 'notbefore' => 5];
     $issued = Carbon::now();
     $expire = Carbon::now()->addSeconds((int) $config['expire']);
     $notBefore = Carbon::now()->addSeconds((int) $config['notbefore']);
     $builder = $this->prophesize(Builder::class);
     $builder->setIssuer('me')->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->setAudience('me')->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->setId(10, true)->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->setIssuedAt($issued->getTimestamp())->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->setNotBefore($notBefore->getTimestamp())->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->setExpiration($expire->getTimestamp())->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->set('data', ["uid" => $user->getId(), "uidentifier" => $user->getUsername()])->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->sign($signer, $secret)->shouldBeCalledTimes(1)->willReturn($builder->reveal());
     $builder->getToken()->shouldBeCalledTimes(1)->willReturn(new Token());
     $generator = new TokenGenerator($builder->reveal(), $signer, $secret, $config);
     $generator->createToken($user);
 }
Ejemplo n.º 26
0
 /**
  * @param User $user
  * @return ApiToken[]
  */
 public function findAllForUser(User $user)
 {
     return $this->findBy(array('user' => $user->getId()));
 }
 /**
  * @Route("/new/{id}", requirements={"id": "\d+"}, name="new_private_message")
  * @ParamConverter("recipient", class="AppBundle:User")
  * @Method("GET")
  * @Template("AppBundle:shop/PrivateMessage:form.html.twig")
  * @param User $recipient
  * @return array
  */
 public function newAction(User $recipient)
 {
     $privateMessage = new PrivateMessage();
     $form = $this->createForm(PrivateMessageType::class, $privateMessage, ['action' => $this->generateUrl('create_private_message', ['id' => $recipient->getId()]), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'private_message.send']);
     return ['form' => $form->createView(), 'recipient' => $recipient];
 }
Ejemplo n.º 28
0
 /**
  * @param User $user
  * @param PageEleveur $commitingPageEleveur
  * @return PageEleveur
  * @throws HistoryException
  */
 public function commit(User $user, PageEleveur $commitingPageEleveur)
 {
     /** @var PageEleveurCommit $clientHead */
     $clientHead = $this->pageEleveurCommitRepository->find($commitingPageEleveur->getHead());
     /** @var PageEleveurBranch $pageEleveurBranch */
     $pageEleveurBranch = $this->pageEleveurBranchRepository->find($commitingPageEleveur->getId());
     if (!$pageEleveurBranch || !$clientHead) {
         throw new HistoryException(HistoryException::BRANCHE_INCONNUE);
     }
     if ($pageEleveurBranch->getOwner()->getId() !== $user->getId()) {
         throw new HistoryException(HistoryException::DROIT_REFUSE);
     }
     if ($clientHead->getId() !== $pageEleveurBranch->getCommit()->getId()) {
         throw new HistoryException(HistoryException::NON_FAST_FORWARD);
     }
     $managedActialites = [];
     if ($commitingPageEleveur->getActualites() !== null) {
         foreach ($commitingPageEleveur->getActualites() as $actualite) {
             if ($actualite->hashCode() !== $actualite->getId()) {
                 // l'actualité a été modifiée, on doit persister la nouvelle version
                 $this->doctrine->persist($actualite);
             } else {
                 // L'actualité n'a pas changé
                 $actualite = $this->doctrine->merge($actualite);
             }
             array_push($managedActialites, $actualite);
         }
     }
     $newCommit = new PageEleveurCommit($clientHead, $commitingPageEleveur->getNom(), $commitingPageEleveur->getDescription(), $commitingPageEleveur->getEspeces(), $commitingPageEleveur->getRaces(), $commitingPageEleveur->getLieu(), $commitingPageEleveur->getAnimaux() !== null ? array_map(function (PageAnimal $pageAnimal) use($user) {
         if ($pageAnimal->getOwner()->getId() !== $user->getId()) {
             throw new HistoryException(HistoryException::DROIT_REFUSE);
         }
         return $this->pageAnimalBranchRepository->find($pageAnimal->getId());
     }, $commitingPageEleveur->getAnimaux()) : [], $managedActialites);
     $this->doctrine->persist($newCommit);
     $pageEleveurBranch->setCommit($newCommit);
     $this->doctrine->flush([$newCommit, $pageEleveurBranch]);
     $pageEleveur = $this->fromBranch($this->findAtCommit($commitingPageEleveur->getId(), $newCommit->getId()));
     return $pageEleveur;
 }
Ejemplo n.º 29
0
 /**
  * @return bool
  */
 public function myPostsDelete($id, User $user)
 {
     $post = $this->repository->find($id);
     if (!$post || $post->getUser()->getId() != $user->getId()) {
         return false;
     }
     return $this->repository->delete($post);
 }
Ejemplo n.º 30
0
 public function totalCount(User $user)
 {
     $qb = $this->rep->createQueryBuilder('a');
     return intval($qb->select('count(a.id)')->where($qb->expr()->eq('a.user', ':user'))->setParameter('user', $user->getId())->getQuery()->getSingleScalarResult());
 }