コード例 #1
0
ファイル: UserProvider.php プロジェクト: EllynB/Incipio
 /**
  * @param string|null $type If specified, return the type value. See {@see User::getAllowedTypes()} to see valid
  *                          type names; if is invalid will return en empty array. Otherwise return an array with a
  *                          random of types.
  *
  * @return array Array of user types.
  */
 public function userTypes($type = null)
 {
     $allowedTypes = User::getAllowedTypes();
     if (null === $type) {
         return BaseProvider::randomElements($allowedTypes, BaseProvider::numberBetween(1, count($allowedTypes)));
     }
     return isset($allowedTypes[$type]) ? [$allowedTypes[$type]] : [];
 }
コード例 #2
0
ファイル: UserProviderTest.php プロジェクト: EllynB/Incipio
 /**
  * @testdox Test the UserProvider::userTypes
  *
  * @covers ::userTypes
  */
 public function testUserTypes()
 {
     $allowedTypes = User::getAllowedTypes();
     // Test random generation
     for ($i = 0; $i <= self::N; ++$i) {
         $types = $this->provider->userTypes();
         foreach ($types as $type) {
             $this->assertTrue(in_array($type, $allowedTypes), 'Expected to generate a valid type');
         }
     }
     // Test get specified type
     $this->assertEquals([User::TYPE_CONTRACTOR], $this->provider->userTypes('contractor'));
     $this->assertEquals([User::TYPE_MEMBER], $this->provider->userTypes('member'));
     // Test get invalid type
     $this->assertEquals([], $this->provider->userTypes('unknown'));
 }
コード例 #3
0
ファイル: UserTypeFilter.php プロジェクト: EllynB/Incipio
 /**
  * {@inheritdoc}
  */
 public function applyFilter(ResourceInterface $resource, QueryBuilder $queryBuilder, array $queryValues)
 {
     // ?filter[where][type]=TYPE_CONTRACTOR
     // ?filter[where][type]=contractor
     if (isset($queryValues['type']) && is_string($queryValues['type'])) {
         if (isset(User::getAllowedTypes()[$queryValues['type']])) {
             $type = User::getAllowedTypes()[$queryValues['type']];
         } elseif (in_array($queryValues['type'], User::getAllowedTypes())) {
             $type = $queryValues['type'];
         } else {
             return;
         }
         //TODO: secure parameters
         $queryBuilder->andWhere('o.types LIKE :user_type')->setParameter('user_type', sprintf('%%%s%%', $type));
     }
 }
コード例 #4
0
ファイル: DefaultController.php プロジェクト: Algresh/day
 protected function checkAnotherUserIsBlocked(\ApiBundle\Entity\User $anotherUser)
 {
     $myUser = $this->getUser();
     if ($anotherUser->getUsersWhoBlockedMe()->contains($myUser)) {
         return false;
     }
     return true;
 }
コード例 #5
0
 /**
  *
  * @Route("/profile", name="profile")
  */
 public function profileAction(Request $request)
 {
     $user = new User();
     $user->setUsername('Test');
     $response = $this->render('CuatrovientosArteanBundle:Security:profile.html.twig', array('user' => $user));
 }
コード例 #6
0
ファイル: Helper.php プロジェクト: Algresh/day
 public function getNewResponses(\ApiBundle\Entity\User $employer)
 {
     return $this->em->getRepository('OneDayJobApiBundle:Vacancy')->createQueryBuilder('v')->select('SUM(v.responses)')->where('v.company = :company')->setParameter('company', $employer->getCompany())->getQuery()->getSingleScalarResult();
 }