Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $this->manager = $manager;
     $activities = $manager->getRepository("OesteveGrupetaBundle:Activity")->findAll();
     foreach ($activities as $activity) {
         $activity->setSlug(Slug::slugify($activity->getName()));
         $manager->persist($activity);
         $manager->flush();
     }
     $athletes = $manager->getRepository("OesteveGrupetaBundle:Athlete")->findAll();
     foreach ($athletes as $athlete) {
         if ($athlete->getSlug() == null) {
             $i = 1;
             $slug = Slug::slugify($athlete->__toString());
             $exists = $this->manager->getRepository("OesteveGrupetaBundle:Athlete")->findOneBy(array('slug' => $slug));
             while ($exists != null) {
                 $slug = Slug::slugify($athlete->getName() . ' ' . $athlete->getLastName() . ' ' . $i++);
                 $exists = $this->manager->getRepository("OesteveGrupetaBundle:Athlete")->findOneBy(array('slug' => $slug));
             }
             $athlete->setSlug($slug);
             $manager->persist($athlete);
             $manager->flush();
         }
     }
     $clubs = $manager->getRepository("OesteveGrupetaBundle:Club")->findAll();
     foreach ($clubs as $club) {
         if ($club->getSlug() == null) {
             $club->setSlug(Slug::slugify($club->getName()));
             $manager->persist($club);
             $manager->flush();
         }
     }
     $posts = $manager->getRepository("OesteveGrupetaBundle:Post")->findAll();
     foreach ($posts as $post) {
         if ($post->getSlug() == null) {
             $post->setSlug(Slug::slugify($post->getTitle()));
             $manager->persist($post);
             $manager->flush();
         }
         if ($post->getCreated() == null) {
             $post->setCreated(new \DateTime());
             $manager->persist($post);
             $manager->flush();
         }
         if ($post->getGallery() == null) {
             $gallery = new Gallery();
             $gallery->setName($post->getTitle());
             $post->setGallery($gallery);
             $manager->persist($post);
             $manager->flush();
         }
     }
 }
Пример #2
0
 /**
  * Proces post before form handleRequest
  * 
  * @param Post $post
  */
 private function processPost(Post $post)
 {
     // Define slug for this post
     if ($post->getSlug() == null) {
         $em = $this->getDoctrine()->getManager();
         $i = 1;
         $slug = Slug::slugify($post->getTitle());
         $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug));
         while ($exists != null) {
             $slug = Slug::slugify($post->getTitle() . ' ' . $i++);
             $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug));
         }
         $post->setSlug($slug);
     }
     // Check if gallery exists
     if ($post->getGallery() == null) {
         $gallery = new Gallery();
         $gallery->setName($post->getTitle());
         $post->setGallery($gallery);
     }
     return $post;
 }