Example #1
0
 public function load(ObjectManager $manager)
 {
     $listNames = array('RĂ©mi', 'Axel', 'Batman');
     foreach ($listNames as $name) {
         $user = new User();
         $user->setUsername($name);
         $user->setPassword($name);
         $manager->persist($user);
     }
     $manager->flush();
 }
Example #2
0
 public function getActiveArticlesByAuthor(User $author, $limit = null)
 {
     $articleClass = $this->_entityName;
     $query = "SELECT a FROM {$articleClass} a\n                  INNER JOIN a.author u\n                  WHERE a.status= :published AND a.publishedAt <= :cur\n                  AND a.author = :author_id\n                  ORDER BY a.publishedAt DESC";
     $query = $this->getEntityManager()->createQuery($query)->setParameter("published", Article::STATUS_PUBLISHED)->setParameter('cur', new \DateTime())->setParameter('author_id', $author->getId());
     if ($limit) {
         $query->setMaxResults($limit);
     }
     $articles = $query->useQueryCache(true)->setQueryCacheLifetime(60)->getResult();
     return $articles;
 }
Example #3
0
 public function getDefaultBlogRole(User $user)
 {
     $role = "ROLE_BLOG_CONTRIBUTOR";
     if ($user->hasRole('ROLE_BLOG_ADMIN')) {
         return 'ROLE_BLOG_ADMIN';
     } elseif ($user->hasRole('ROLE_BLOG_EDITOR')) {
         return 'ROLE_BLOG_EDITOR';
     } elseif ($user->hasRole('ROLE_BLOG_AUTHOR')) {
         return 'ROLE_BLOG_AUTHOR';
     }
     return $role;
 }
Example #4
0
 public function load(ObjectManager $em)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $johnUser = new User();
     $johnUser->setUsername('john_user');
     $johnUser->setEmail('*****@*****.**');
     #$johnUser->setPassword('kitten');
     $encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten');
     $johnUser->setPassword($encodedPassword);
     $johnUser->setRoles(array('ROLE_USER'));
     $annaAdmin = new User();
     $annaAdmin->setUsername('anna_admin');
     $annaAdmin->setEmail('*****@*****.**');
     #$annaAdmin->setPassword('kitten');
     $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
     $annaAdmin->setPassword($encodedPassword);
     $annaAdmin->setRoles(array('ROLE_ADMIN'));
     $annaAdmin->setIsActive(true);
     $em->persist($johnUser);
     $em->persist($annaAdmin);
     $em->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }