getId() 공개 메소드

Get id
public getId ( ) : integer
리턴 integer
예제 #1
0
 public function testSendPasswordRestoreToken()
 {
     $this->markTestSkipped();
     // @todo refactor the view dependency
     $this->service->sendPasswordRestoreToken($this->user);
     $this->assertRegExp('#user/' . $this->user->getId() . '/token/[a-z0-9]{40}#i', $this->getEmailBody());
     $this->assertArrayHasKey('Subject', $this->getEmailHeaders());
 }
예제 #2
0
 public function testAuthenticateValid()
 {
     $this->user->setActive();
     $this->em->persist($this->user);
     $this->em->flush();
     $this->service->setUsername(sha1(self::USERNAME))->setEmail(self::EMAIL)->setPassword(self::PASSWORD);
     $result = $this->service->authenticate();
     $this->assertEquals(\Zend_Auth_Result::SUCCESS, $result->getCode());
     $this->assertEquals($this->user->getId(), $result->getIdentity());
 }
예제 #3
0
 public function saveTopicsAction()
 {
     $form = new Application_Form_Topics();
     $topics = $this->_helper->service('topic')->getMultiOptions();
     $form->topics->setMultiOptions($topics);
     $form->selected->setMultiOptions($topics);
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $command = new SaveUserTopicsCommand($form->getValues());
         $command->userId = $this->user->getId();
         $this->_helper->service('user.topic')->saveUserTopics($command);
         $this->_helper->json($command->selected);
     }
     $this->getResponse()->setHttpResponseCode(400);
     $this->_helper->json($form->getMessages());
 }
예제 #4
0
 /**
  * Find topics for user
  *
  * @param Newscoop\Entity\User
  * @return array
  */
 public function findByUser(User $user)
 {
     $em = $this->getEntityManager();
     $query = $em->createQuery('SELECT ut FROM Newscoop\\Entity\\UserTopic ut INNER JOIN ut.topic t WHERE ut.user = :user');
     $query->setParameter('user', $user->getId());
     return $query->getResult();
 }
예제 #5
0
 public function testSave()
 {
     $data = array('email' => '*****@*****.**');
     $this->assertEquals($this->user, $this->service->save($data, $this->user));
     $this->assertGreaterThan(0, $this->user->getId());
     $this->assertEquals('*****@*****.**', $this->user->getEmail());
 }
예제 #6
0
 /**
  * Find results for user and topic
  *
  * @param Newscoop\Entity\User                 $user
  * @param Newscoop\NewscoopBundle\Entity\Topic $topic
  *
  * @return Newscoop\Entity\UserTopic
  */
 public function findByTopicAndUser(User $user, Topic $topic)
 {
     $em = $this->getEntityManager();
     $locale = $em->getRepository("Newscoop\\NewscoopBundle\\Entity\\Topic")->getTranslatableTopicLocale($topic);
     $qb = $em->createQueryBuilder()->select(array('ut'))->from('Newscoop\\Entity\\UserTopic', 'ut')->leftJoin('ut.user', 'u')->leftJoin('ut.topic', 't')->leftJoin('t.translations', 'tt')->where('u.id = :user_id')->andWhere('t.id = :topic_id')->andWhere('tt.locale = :topic_language_id')->setParameters(array('user_id' => $user->getId(), 'topic_id' => $topic->getId(), 'topic_language_id' => $locale));
     return $qb->getQuery()->getResult();
 }
예제 #7
0
 /**
  * Invalidate token
  *
  * @param Newscoop\Entity\User $user
  * @param string $action
  * @return void
  */
 public function invalidateTokens(User $user, $action = 'any')
 {
     $tokens = $this->em->getRepository('Newscoop\\Entity\\UserToken')->findBy(array('user' => $user->getId(), 'action' => $action));
     foreach ($tokens as $token) {
         $this->em->remove($token);
     }
     $this->em->flush();
 }
 public function it_shouldnt_edit_comment(EditorialComment $comment, User $user, User $newUser)
 {
     $comment->getUser()->willReturn($user);
     $comment->setComment(Argument::type('string'))->willReturn(true);
     $newUser->getId()->willReturn(5);
     $newUser->isAdmin()->willReturn(false);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException')->during('edit', array('updated comment', $comment, $newUser));
 }
 public function let(Container $container, EntityManager $entityManager, Request $request, AbstractQuery $query, UserTopicService $userTopicService, UserRepository $userRepository, User $user, Paginator $knpPaginator, PaginatorService $paginator, EntityRepository $repository)
 {
     $container->get('em')->willReturn($entityManager);
     $container->get('user.topic')->willReturn($userTopicService);
     $container->get('newscoop.paginator.paginator_service')->willReturn($paginator);
     $entityManager->persist(Argument::any())->willReturn(true);
     $entityManager->flush(Argument::any())->willReturn(true);
     $entityManager->remove(Argument::any())->willReturn(true);
     $entityManager->getRepository('Newscoop\\Entity\\User')->willReturn($repository);
     $user->getId()->willReturn(1);
     $user->getUsername()->willReturn('admin');
     $user->getEmail()->willReturn('*****@*****.**');
     $this->setContainer($container);
 }
 /**
  * Remove (soft) existing editorial comment
  * @param EditorialComment $comment
  * @param User             $user
  */
 public function remove(EditorialComment $comment, User $user)
 {
     if ($comment->getUser()->getId() == $user->getId() || $user->isAdmin()) {
         $comment->setIsActive(false);
     } else {
         throw new AccessDeniedHttpException("User is not allowed to remove comment");
     }
     $this->em->flush();
     return true;
 }
예제 #11
0
 /**
  * Delete user
  *
  * @param Newscoop\Entity\User $user
  *
  * @return void
  */
 public function delete(User $user)
 {
     if ($this->auth->getIdentity() == $user->getId()) {
         throw new \InvalidArgumentException("You can't delete yourself");
     }
     $this->getRepository()->delete($user);
 }
예제 #12
0
 /**
  * Send password restore token
  *
  * @param Newscoop\Entity\User $user
  * @return void
  */
 public function sendPasswordRestoreToken(User $user)
 {
     $message = $this->view->action('password-restore', 'email', 'default', array('user' => $user->getId(), 'token' => $this->tokenService->generateToken($user, 'password.restore'), 'format' => null));
     $this->send($this->view->placeholder(self::PLACEHOLDER_SUBJECT), $message, $user->getEmail());
 }
예제 #13
0
 /**
  * Get comments count for user
  *
  * @param Newscoop\Entity\User $user
  * @return int
  */
 public function countByUser(User $user)
 {
     return (int) $this->getEntityManager()->createQuery("SELECT COUNT(comment) FROM Newscoop\\Entity\\Comment comment WHERE comment.commenter IN (SELECT commenter.id FROM Newscoop\\Entity\\Comment\\Commenter commenter WHERE commenter.user = :user)")->setParameter('user', $user->getId())->getSingleScalarResult();
 }
예제 #14
0
 /**
  * Remove user attributes
  *
  * @param  Newscoop\Entity\User $user
  * @return void
  */
 private function removeAttributes(User $user)
 {
     $attributes = $this->getEntityManager()->getRepository('Newscoop\\Entity\\UserAttribute')->findBy(array('user' => $user->getId()));
     foreach ($attributes as $attribute) {
         $user->addAttribute($attribute->getName(), null);
         $this->getEntityManager()->remove($attribute);
     }
 }
예제 #15
0
 /**
  * Get user points
  *
  * @param Newscoop\Entity\User $user
  * @return void
  */
 public function getUserPoints(User $user)
 {
     $query = $this->createQueryBuilder('u')->select('u.id, ' . $this->getUserPointsSelect())->where('u.id = :user')->getQuery();
     $query->setParameter('user', $user->getId());
     $result = $query->getSingleResult();
     $user->setPoints($result['comments'] + $result['articles']);
 }
예제 #16
0
 /**
  * Method for saving a banned
  *
  * @param ZendForm $p_form
  * @param Newscoop\Entity\User $p_user
  */
 private function handleBanForm(Admin_Form_BanUser $p_form, $p_user, $p_publication)
 {
     if ($this->getRequest()->isPost() && $p_form->isValid($_POST)) {
         if ($p_form->getSubmit()->isChecked()) {
             $parameters = $p_form->getValues();
             $banValues = array();
             $unbanValues = array();
             if ($parameters['name'] == 1) {
                 $banValues['name'] = $p_user->getName();
             } else {
                 $unbanValues['name'] = $p_user->getName();
             }
             if ($parameters['email'] == 1) {
                 $banValues['email'] = $p_user->getEmail();
             } else {
                 $unbanValues['email'] = $p_user->getEmail();
             }
             $acceptanceRepository = $this->_helper->entity->getRepository('Newscoop\\Entity\\Comment\\Acceptance');
             $acceptanceRepository->ban($p_publication, $banValues);
             $acceptanceRepository->flush();
             $acceptanceRepository->unban($p_publication, $unbanValues);
             $acceptanceRepository->flush();
             $this->_helper->flashMessenger(getGS('Ban for user "$1" saved.', $p_user->getName()));
             if ($parameters['delete_messages'] == 1) {
                 $feedbackRepository = $this->_helper->entity->getRepository('Newscoop\\Entity\\Feedback');
                 $feedbacks = $feedbackRepository->getByUser($p_user->getId());
                 $feedbackRepository->setStatus($feedbacks, 'deleted');
                 $feedbackRepository->flush();
             }
         }
         $this->_helper->redirector->gotoSimple('index', 'feedback');
     }
 }
예제 #17
0
 public function getId()
 {
     $this->__load();
     return parent::getId();
 }
예제 #18
0
 /**
  * Update user topics
  *
  * @param Newscoop\Entity\User $user
  * @param array $topics
  * @return void
  */
 public function updateTopics(User $user, array $topics)
 {
     $repository = $this->em->getRepository('Newscoop\\Entity\\UserTopic');
     foreach ($topics as $topicId => $status) {
         $matches = $repository->findBy(array('user' => $user->getId(), 'topic_id' => $topicId));
         if ($status === 'false' && !empty($matches)) {
             foreach ($matches as $match) {
                 $this->em->remove($match);
             }
         } else {
             if ($status === 'true' && empty($matches)) {
                 $topic = $this->findTopic($topicId);
                 if ($topic) {
                     $this->em->persist(new UserTopic($user, $this->findTopic($topicId)));
                 }
             }
         }
     }
     $this->em->flush();
 }
예제 #19
0
 /**
  * Get comments count for user
  *
  * @param Newscoop\Entity\User $user
  *
  * @return int
  */
 public function countByUser(User $user)
 {
     $em = $this->getEntityManager();
     $qb = $em->createQueryBuilder();
     $qb->select('commenter.id')->from('Newscoop\\Entity\\Comment\\Commenter', 'commenter')->where('commenter.user = :commenterUserId')->setParameter('commenterUserId', $user->getId());
     $commenterId = $qb->getQuery()->getArrayResult();
     if (array_key_exists(0, $commenterId)) {
         $commenterId = $commenterId[0];
     } else {
         return 0;
     }
     if (is_array($commenterId) && array_key_exists('id', $commenterId)) {
         $qb = $em->createQueryBuilder();
         $qb->select('count(comment.id)')->from('Newscoop\\Entity\\Comment', 'comment')->where('comment.commenter = :commenter')->setParameter('commenter', $commenterId['id']);
         return (int) $qb->getQuery()->getSingleScalarResult();
     } else {
         return 0;
     }
 }
예제 #20
0
 /**
  * Get articles count for user if is author.
  *
  * @param Newscoop\Entity\User $user
  *
  * @return int
  */
 public function countByAuthor(User $user)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $qb->select('count(a)')->from('Newscoop\\Entity\\Article', 'a')->from('Newscoop\\Entity\\ArticleAuthor', 'aa')->from('Newscoop\\Entity\\User', 'u')->where('a.number = aa.articleNumber')->andWhere('a.language = aa.languageId')->andWhere('aa.author = u.author')->andwhere('u.id = :user')->andWhere($qb->expr()->in('a.type', array('news', 'blog')))->andWhere('a.workflowStatus = :status')->setParameters(array('user' => $user->getId(), 'status' => Article::STATUS_PUBLISHED));
     $count = $qb->getQuery()->getSingleScalarResult();
     return (int) $count;
 }
예제 #21
0
 /**
  * Get feedbacks count for user
  *
  * @param Newscoop\Entity\User $user
  * @return int
  */
 public function countByUser(User $user)
 {
     return (int) $this->getEntityManager()->createQuery("SELECT COUNT(feedback) FROM Newscoop\\Entity\\Feedback feedback WHERE feedback.user = :user")->setParameter('user', $user->getId())->getSingleScalarResult();
 }