Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $userAdmin = new User();
     $userAdmin->setUsername('admin');
     $userAdmin->setPassword('test');
     $manager->persist($userAdmin);
     $manager->flush();
 }
Ejemplo n.º 2
0
 private function loadUsers(ObjectManager $manager)
 {
     $passwordEncoder = $this->container->get('security.password_encoder');
     $johnUser = new User();
     $johnUser->setUsername('john_user');
     $johnUser->setEmail('*****@*****.**');
     $encodedPassword = $passwordEncoder->encodePassword($johnUser, 'kitten');
     $johnUser->setPassword($encodedPassword);
     $manager->persist($johnUser);
     $annaAdmin = new User();
     $annaAdmin->setUsername('anna_admin');
     $annaAdmin->setEmail('*****@*****.**');
     $annaAdmin->setRoles(array('ROLE_ADMIN'));
     $encodedPassword = $passwordEncoder->encodePassword($annaAdmin, 'kitten');
     $annaAdmin->setPassword($encodedPassword);
     $manager->persist($annaAdmin);
     $manager->flush();
 }
 public function editAction(Request $request)
 {
     $id = $request->get('id');
     $em = $this->getDoctrine()->getManager();
     $user = $em->getRepository('AcmeUserBundle:User')->find($id);
     $products = new \Acme\UserBundle\Entity\User();
     $products->setName('');
     $products->setPrice('');
     $products->setDescription('');
     $products->setImage('');
     $form = $this->createFormBuilder($products)->add('name', 'text')->add('price', 'text')->add('description', 'textarea')->add('image', 'file', array('error_bubbling' => TRUE))->getForm();
     $form->handleRequest($request);
     $validator = $this->get('validator');
     $errors = $validator->validate($products);
     if ($request->getMethod() == 'POST') {
         if (count($errors) > 1) {
             return $this->render('AcmeStoreBundle:Default:edit.html.twig', array('form' => $form->createView(), 'products' => $products, 'product' => $product, 'id' => $id, 'image' => $oldimg));
         } else {
             $a = $request->request->get('form');
             $products = $em->getRepository('AcmeStoreBundle:Product')->find($id);
             if ($_FILES['form']['name']['image'] != NULL) {
                 $products->setImage($_FILES['form']['name']['image']);
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id . '/' . $oldimg)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id . '/' . $oldimg);
                     rmdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $id);
                     $img = $form['image']->getData()->getClientOriginalName();
                     $dir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/products/' . $products->getId();
                     mkdir($dir);
                     $form->get('image')->getData()->move($dir, $img);
                 }
             } else {
                 $products->setImage($oldimg);
             }
             $products->setName($a['name']);
             $products->setPrice($a['price']);
             $products->setDescription($a['description']);
             $products->setStatus('1');
             $em->persist($products);
             $em->flush();
         }
         return $this->redirect($this->generateUrl('acme_store'));
     }
     return $this->render('AcmeStoreBundle:Default:edit.html.twig', array('form' => $form->createView(), 'products' => $products, 'product' => $product, 'id' => $id, 'image' => $oldimg));
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     // your own logic
 }
Ejemplo n.º 5
0
 public function executeSubaction(Subaction $subaction, User $user)
 {
     $em = $this->getEntityManager();
     $userTime = $user->getCurrentDateTime();
     $dayStart = clone $userTime;
     $dayFinish = clone $userTime;
     $dayStart->modify('today midnight');
     $dayFinish->modify('tomorrow midnight');
     $existingSubprogress = $em->getRepository('AcmeEdelaBundle:UserSubactionProgress')->matching(Criteria::create()->where(Criteria::expr()->eq('user', $user))->andWhere(Criteria::expr()->eq('subaction', $subaction))->andWhere(Criteria::expr()->gte('createdAt', $dayStart))->andWhere(Criteria::expr()->lte('createdAt', $dayFinish)));
     if ($existingSubprogress->count()) {
         $em->remove($existingSubprogress->first());
         $progress = false;
     } else {
         $subprogress = new UserSubactionProgress();
         $subprogress->setUser($user)->setSubaction($subaction);
         $em->persist($subprogress);
         $progress = true;
     }
     $em->flush();
     return $progress;
 }
Ejemplo n.º 6
0
 public function getLevel(User $user)
 {
     $conn = $this->getEntityManager()->getConnection();
     $level = $conn->fetchArray('SELECT l.* FROM ed_user_levels l WHERE l.start_exp < :exp ORDER BY l.start_exp DESC LIMIT 1', ['exp' => $user->getExpTotal()]);
     return $level;
 }
Ejemplo n.º 7
0
 /**
  * Is the given User the author of this Post?
  *
  * @param User $user
  *
  * @return bool
  */
 public function isAuthor(User $user = null)
 {
     return $user->getEmail() == $this->getAuthorEmail();
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }