Пример #1
0
 /**
  * Creates a new Tag entity.
  *
  * @Route("/create", name="tag_create")
  */
 public function createAction()
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getEntityManager();
     // usuario
     $session = $this->getRequest()->getSession();
     $user_id = $session->get('id');
     if (!$user_id) {
         return new Response('error');
     }
     // existe tag?
     $title = trim($request->query->get('title'));
     $entity = $em->getRepository('ApplicationTagBundle:Tag')->findOneBy(array('title' => $title));
     if (!$entity) {
         // crear tag
         $entity = new Tag();
         $entity->setUserId($user_id);
         $entity->setTitle($title);
         $entity->setSlug(Util::slugify($title));
         $entity->setDate(new \DateTime("now"));
         //$entity->setUsers(1);
     }
     $em->persist($entity);
     $em->flush();
     // existe vinculo
     $link = $em->getRepository('ApplicationTagBundle:TagUser')->findOneBy(array('tag_id' => $entity->getId(), 'user_id' => $user_id));
     if (!$link) {
         // vincular usuario
         $link = new TagUser();
         $link->setTagId($entity->getId());
         $link->setUserId($user_id);
         $link->setDate(new \DateTime("now"));
         $em->persist($link);
         $em->flush();
         // recalcular total
         $query = "SELECT COUNT(id) AS total FROM TagUser WHERE tag_id = " . $entity->getId();
         $db = $this->get('database_connection');
         $result = $db->query($query)->fetch();
         $total = $result['total'];
         $entity->setUsers($total);
         $em->persist($entity);
         $em->flush();
     }
     //return array('entity' => $entity);
     return new Response('1');
 }
Пример #2
0
 /**
  * Edits an existing Thread entity.
  *
  * @Route("/{id}/update", name="thread_update")
  * @Method("post")
  * @Template("ApplicationForumBundle:Thread:edit.html.twig")
  */
 public function updateAction($id)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $entity = $em->getRepository('ApplicationForumBundle:Thread')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Thread entity.');
     }
     $session = $this->getRequest()->getSession();
     $user_id = $session->get('id');
     $admin = $session->get('admin');
     if ($entity->getUserId() == $user_id || $admin) {
         $editForm = $this->createForm(new ThreadType(), $entity);
         $request = $this->getRequest();
         $editForm->bindRequest($request);
         if ($editForm->isValid()) {
             // limpiar html
             $entity->setTitle(strip_tags($entity->getTitle()));
             $entity->setBody(strip_tags($entity->getBody()));
             $slug = $entity->getTitle();
             $entity->setSlug(Util::slugify($slug));
             $em->persist($entity);
             $em->flush();
             return $this->redirect($this->generateUrl('thread_show', array('id' => $id, 'slug' => $entity->getSlug(), 'forum_id' => $entity->getForumId())));
         }
         return array('entity' => $entity, 'edit_form' => $editForm->createView());
     } else {
         $url = $this->generateUrl('thread_show', array('id' => $entity->getId(), 'slug' => $entity->getSlug(), 'forum_id' => $entity->getForumId()));
         return $this->redirect($url);
     }
 }
Пример #3
0
 /**
  * Get post slugs
  *
  * @Route("/slugs", name="post_slugs")
  */
 public function slugs()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $qb = $em->createQueryBuilder()->add('select', 'p')->add('from', 'ApplicationAnunciosBundle:Post p')->add('orderBy', 'p.id ASC');
     $entities = $qb->getQuery()->getResult();
     $total = count($entities);
     for ($i = 0; $i < $total; $i++) {
         $slug = $entities[$i]->getTitle();
         $city_id = $entities[$i]->getCityId();
         if ($city_id) {
             $city = $em->getRepository('ApplicationCityBundle:City')->find($city_id);
             $slug .= ' ' . $city->getName();
         }
         $company = $entities[$i]->getCompany();
         if ($company) {
             $slug .= ' ' . $company;
         }
         $entities[$i]->setSlug(Util::slugify($slug));
         $em->persist($entities[$i]);
         $em->flush();
     }
     die;
 }
Пример #4
0
 /**
  * Calendar City Event entities.
  *
  * @Route("/slugs", name="event_slugs")
  */
 public function slugs()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $qb = $em->createQueryBuilder()->add('select', 'e')->add('from', 'ApplicationEventBundle:Event e')->add('orderBy', 'e.id ASC');
     $entities = $qb->getQuery()->getResult();
     $total = count($entities);
     for ($i = 0; $i < $total; $i++) {
         $entities[$i]->setSlug(Util::slugify($entities[$i]->getTitle() . ' ' . $entities[$i]->getPrettyDate('%e %B %Y')));
         $em->persist($entities[$i]);
         $em->flush();
     }
     die;
 }
Пример #5
0
 /**
  * Set slug users
  *
  * @Route("/slugs", name="user_slugs")
  */
 public function slugs()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $qb = $em->createQueryBuilder()->add('select', 'u')->add('from', 'ApplicationUserBundle:User u')->add('where', "u.slug = ''")->add('orderBy', 'u.id ASC');
     $entities = $qb->getQuery()->getResult();
     $total = count($entities);
     for ($i = 0; $i < $total; $i++) {
         $entities[$i]->setSlug(Util::slugify($entities[$i]->getName()));
         $em->persist($entities[$i]);
         $em->flush();
     }
     die;
 }