diff --git a/INSTALL.md b/INSTALL.md index d213aec..1256929 100755 --- a/INSTALL.md +++ b/INSTALL.md @@ -10,9 +10,13 @@ Diese Anleitung geht davon aus das du SSH-Zugriff auf deinen Server hast. Wenn du Calcifer auf einem Shared-Hosting-Anbieter installieren willst, so ist dies auch möglich, aber etwas komplizierter und wird irgendwann später beschrieben. - 1. Das [Repo](https://phablab.krautspace.de/diffusion/C/calcifer.git) irgendwo hin clonen - 2. In das calcifer Verzeichnis wechseln. - 3. composer install - 4. Im Verzeichnis app/config die Datei parameters.yml.dist nach parameters.yml kopieren und anpassen. - 5. Dann die Tabellen erstellen: php app/console doctrine:schema:create - 6. Zum Schluss must du noch deinen Webserver [konfigurieren](http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html) und dann ist calcifer auch schon erreichbar. \ No newline at end of file +1. Das [Repo](https://phablab.krautspace.de/diffusion/C/calcifer.git) irgendwo hin clonen +2. In das calcifer Verzeichnis wechseln. +3. Abhängigkeiten installieren + 1. composer herunterladen ```curl -sS https://getcomposer.org/installer | php``` + 2. Installation ausführen: ```php composer.phar install``` +5. Dann die Tabellen erstellen: ```php app/console doctrine:schema:update --force``` +6. Cache löschen ```php app/console cache:clear --env=prod --no-debug``` +7. Assets dumpen ```php app/console assetic:dump --env=prod --no-debug``` +8. Einen täglichen Cronjob anlegen, der die wiederholenden Termine anlegt: ```php app/console calcifer:events:generate``` +6. Zum Schluss must du noch deinen Webserver [konfigurieren](http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html) und dann ist calcifer auch schon erreichbar. diff --git a/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php b/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php new file mode 100755 index 0000000..f697a78 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Command/GenerateEventsCommand.php @@ -0,0 +1,88 @@ +setName('calcifer:events:generate') + ->setDescription('Generate events from repeating events') + ->addOption('duration', 'd', InputOption::VALUE_OPTIONAL, 'The duration you want to generate events into the future. Default is 2 monts','2 months') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $duration = \DateInterval::createFromDateString($input->getOption('duration')); + if ($duration instanceof \DateInterval) { + $now = new \DateTime(); + $end = new \DateTime(); + $end->add($duration); + $output->writeln(sprintf("Generating Dates from %s to %s",$now->format('Y-m-d'),$end->format('Y-m-d'))); + $output->writeln("Fetching repeating events"); + /** @var EntityManager $entityManager */ + $entityManager = $this->getContainer()->get('doctrine')->getManager(); + $repo = $entityManager->getRepository('CalciferBundle:RepeatingEvent'); + $entities = $repo->findAll(); + foreach($entities as $entity) { + /** @var RepeatingEvent $entity */ + $period = new \DatePeriod($entity->nextdate,new \DateInterval($entity->repeating_pattern),$end); + $event = null; + foreach($period as $date) { + /** @var \DateTime $date */ + $output->writeln(sprintf("Creating Event %s for %s",$entity->summary,$date->format('Y-m-d H:i'))); + $event = new Event(); + $event->location = $entity->location; + $event->startdate = $date; + if ($entity->duration > 0) { + $duration = new \DateInterval("PT".$entity->duration.'H'); + /** @var \DateTime $enddate */ + $enddate = clone $date; + $enddate->add($duration); + $entity->enddate = $enddate; + } + $event->summary = $entity->summary; + $event->description = $entity->description; + $event->url = $entity->url; + $entityManager->persist($event); + $entityManager->flush(); + $event->slug = \URLify::filter($event->id . '-' . $event->summary,255,'de'); + $entityManager->persist($event); + $entityManager->flush(); + foreach($entity->getTags() as $tag) { + $event->addTag($tag); + } + $entityManager->persist($event); + $entityManager->flush(); + } + if (!is_null($event)) { + $entity->nextdate = $event->startdate; + $entity->nextdate->add(new \DateInterval($entity->repeating_pattern)); + $entityManager->persist($entity); + $entityManager->flush(); + } + } + } else { + $output->writeln('Invalid duration'); + } + + } +} diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php index 18dd67d..023f6b2 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php @@ -59,76 +59,8 @@ class EventController extends Controller public function createAction(Request $request) { $entity = new Event(); - $entity->setDescription($request->get('description')); - $entity->setSummary($request->get('summary')); - $entity->setUrl($request->get('url')); - $startdate = $request->get('startdate'); - $startdate = new \DateTime($startdate); - $entity->setStartdate($startdate); - $entity->setSlug(\URLify::filter($entity->getSummary(),255,'de')); - $enddate = $request->get('enddate'); - if (strlen($enddate) > 0) { - $enddate = new \DateTime($enddate); - $entity->setenddate($enddate); - } - - $location = $request->get('location'); - $location_lat = $request->get('location_lat'); - $location_lon = $request->get('location_lon'); - if (strlen($location) > 0) { - // check if the location already exists - /** @var EntityManager $em */ - $em = $this->getDoctrine()->getManager(); - $repo = $em->getRepository('CalciferBundle:Location'); - $results = $repo->findBy(['name' => $location]); - if (count($results) > 0) { - $location_obj = $results[0]; - if (strlen($location_lat) > 0) { - $location_obj->setLat($location_lat); - } - if (strlen($location_lon) > 0) { - $location_obj->setLon($location_lon); - } - $em->persist($location_obj); - $em->flush(); - $entity->setLocation($results[0]); - } else { - $location_obj = new Location(); - $location_obj->setName($location); - if (strlen($location_lat) > 0) { - $location_obj->setLat($location_lat); - } - if (strlen($location_lon) > 0) { - $location_obj->setLon($location_lon); - } - $location_obj->setSlug(\URLify::filter($location_obj->getName(),255,'de')); - $em->persist($location_obj); - $em->flush(); - $entity->setLocation($location_obj); - } - } - - $tags = $request->get('tags'); - if (strlen($tags) > 0) { - $tags = explode(',',$tags); - $em = $this->getDoctrine()->getManager(); - $repo = $em->getRepository('CalciferBundle:Tag'); - foreach ($tags as $tag) { - $tag = trim($tag); - $results = $repo->findBy(['name' => $tag]); - if (count($results) > 0) { - $entity->addTag($results[0]); - } else { - $tag_obj = new Tag(); - $tag_obj->setName($tag); - $tag_obj->setSlug(\URLify::filter($tag_obj->getName(),255,'de')); - $em->persist($tag_obj); - $em->flush(); - $entity->addTag($tag_obj); - } - } - } + $em = $this->saveEvent($request, $entity); if ($entity->isValid()) { @@ -136,7 +68,7 @@ class EventController extends Controller $em->persist($entity); $em->flush(); - return $this->redirect($this->generateUrl('_show', array('slug' => $entity->getSlug()))); + return $this->redirect($this->generateUrl('_show', array('slug' => $entity->slug))); } return array( @@ -236,18 +168,42 @@ class EventController extends Controller throw $this->createNotFoundException('Unable to find Event entity.'); } - $entity->setDescription($request->get('description')); - $entity->setSummary($request->get('summary')); - $entity->setUrl($request->get('url')); + $em = $this->saveEvent($request, $entity); + + + if ($entity->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $this->redirect($this->generateUrl('_show', array('slug' => $entity->slug))); + } + + return array( + 'entity' => $entity, + + ); + } + + /** + * @param Request $request + * @param $entity + * @return EntityManager + */ + public function saveEvent(Request $request, Event $entity) + { + $entity->description = $request->get('description'); + $entity->summary = $request->get('summary'); + $entity->url = $request->get('url'); $startdate = $request->get('startdate'); $startdate = new \DateTime($startdate); - $entity->setStartdate($startdate); - $entity->setSlug(\URLify::filter($entity->getSummary(),255,'de')); + $entity->startdate = $startdate; + $entity->slug = \URLify::filter($entity->summary, 255, 'de'); $enddate = $request->get('enddate'); if (strlen($enddate) > 0) { $enddate = new \DateTime($enddate); - $entity->setenddate($enddate); + $entity->enddate = $enddate; } $location = $request->get('location'); @@ -262,24 +218,24 @@ class EventController extends Controller if (count($results) > 0) { $location_obj = $results[0]; if (strlen($location_lat) > 0) { - $location_obj->setLat($location_lat); + $location_obj->lat = $location_lat; } if (strlen($location_lon) > 0) { - $location_obj->setLon($location_lon); + $location_obj->lon = $location_lon; } $em->persist($location_obj); $em->flush(); $entity->setLocation($results[0]); } else { $location_obj = new Location(); - $location_obj->setName($location); + $location_obj->name = $location; if (strlen($location_lat) > 0) { - $location_obj->setLat($location_lat); + $location_obj->lat = $location_lat; } if (strlen($location_lon) > 0) { - $location_obj->setLon($location_lon); + $location_obj->lon = $location_lon; } - $location_obj->setSlug(\URLify::filter($location_obj->getName(),255,'de')); + $location_obj->slug = \URLify::filter($location_obj->name, 255, 'de'); $em->persist($location_obj); $em->flush(); $entity->setLocation($location_obj); @@ -288,9 +244,10 @@ class EventController extends Controller $tags = $request->get('tags'); if (strlen($tags) > 0) { - $tags = explode(',',$tags); + $tags = explode(',', $tags); $em = $this->getDoctrine()->getManager(); $repo = $em->getRepository('CalciferBundle:Tag'); + $entity->clearTags(); foreach ($tags as $tag) { $tag = trim($tag); $results = $repo->findBy(['name' => $tag]); @@ -298,27 +255,15 @@ class EventController extends Controller $entity->addTag($results[0]); } else { $tag_obj = new Tag(); - $tag_obj->setName($tag); - $tag_obj->setSlug(\URLify::filter($tag_obj->getName(),255,'de')); + $tag_obj->name = $tag; + $tag_obj->slug = \URLify::filter($tag_obj->name, 255, 'de'); $em->persist($tag_obj); $em->flush(); $entity->addTag($tag_obj); } } + return $em; } - - - if ($entity->isValid()) { - $em = $this->getDoctrine()->getManager(); - $em->persist($entity); - $em->flush(); - - return $this->redirect($this->generateUrl('_show', array('slug' => $entity->getSlug()))); - } - - return array( - 'entity' => $entity, - - ); + return $em; } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php index 32efe75..3815bfd 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/LocationController.php @@ -2,6 +2,7 @@ namespace Hackspace\Bundle\CalciferBundle\Controller; +use Doctrine\Common\Annotations\Annotation\Required; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; @@ -35,11 +36,11 @@ class LocationController extends Controller /** * Finds and displays a Event entity. * - * @Route("/{slug}(?!\.ics)", name="location_show") + * @Route("/{slug}.{format}", name="location_show", defaults={"format" = "html"}) * @Method("GET") * @Template("CalciferBundle:Event:index.html.twig") */ - public function showAction($slug) + public function showAction($slug,$format) { /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); @@ -67,52 +68,42 @@ class LocationController extends Controller ->andWhere('e.locations_id = :location') ->orderBy('e.startdate') ->setParameter('startdate',$now) - ->setParameter('location',$location->getId()); + ->setParameter('location',$location->id); $entities = $qb->getQuery()->execute(); - return array( - 'entities' => $entities, - 'location' => $location, - ); - } + if ($format == 'ics') { + $calendar = new Calendar(); + $calendar->setProdId('-//My Company//Cool Calendar App//EN'); - /** - * Finds and displays a Event entity. - * - * @Route("/{slug}\.ics", name="location_show_ics") - * @Method("GET") - */ - public function showActionICS($slug) - { - $results = $this->showAction(str_replace('.ics','',$slug)); - $entities = $results['entities']; + foreach ($entities as $entity) { + /** @var Event $entity */ + $event = new CalendarEvent(); + $event->setStart($entity->startdate); + if ($entity->enddate instanceof \DateTime) + $event->setEnd($entity->enddate); + $event->setSummary($entity->summary); + $event->setDescription($entity->description); + $location = new \Jsvrcek\ICS\Model\Description\Location(); + $location->setName($entity->getLocation()->name); + $event->setLocations([$location]); + $calendar->addEvent($event); + } - $calendar = new Calendar(); - $calendar->setProdId('-//My Company//Cool Calendar App//EN'); + $calendarExport = new CalendarExport(new CalendarStream, new Formatter()); + $calendarExport->addCalendar($calendar); - foreach($entities as $entity) { - /** @var Event $entity */ - $event = new CalendarEvent(); - $event->setStart($entity->getStartdate()); - if ($entity->getEnddate() instanceof DateTime) - $event->setEnd($entity->getEnddate()); - $event->setSummary($entity->getSummary()); - $event->setDescription($entity->getDescription()); - $location = new \Jsvrcek\ICS\Model\Description\Location(); - $location->setName($entity->getLocation()->getName()); - $event->setLocations([$location]); - $calendar->addEvent($event); + //output .ics formatted text + $result = $calendarExport->getStream(); + + $response = new Response($result); + $response->headers->set('Content-Type', 'text/calendar'); + + return $response; + } else { + return array( + 'entities' => $entities, + 'location' => $location, + ); } - - $calendarExport = new CalendarExport(new CalendarStream, new Formatter()); - $calendarExport->addCalendar($calendar); - - //output .ics formatted text - $result = $calendarExport->getStream(); - - $response = new Response($result); - $response->headers->set('Content-Type', 'text/calendar'); - - return $response; } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php new file mode 100755 index 0000000..db41dca --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php @@ -0,0 +1,262 @@ +getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + $entities = $repo->findAll(); + + return [ + 'entities' => $entities, + ]; + } + + /** + * Displays a form to create a repeating event + * + * @Route("/neu", name="repeating_event_new") + * @Method("GET") + * @Template() + */ + public function newAction() + { + $entity = new RepeatingEvent(); + + return [ + 'entity' => $entity, + ]; + } + + /** + * Creates a repeating event + * + * @Route("/neu", name="repeating_event_create") + * @Method("POST") + * @Template("CalciferBundle:RepeatingEvent:new.html.twig") + */ + public function createAction(Request $request) + { + $entity = new RepeatingEvent(); + $this->fillEntity($request, $entity); + if ($this->validateRepeatingEvent($entity)) { + $ret = $this->saveRepeatingEvent($request, $entity); + if ($entity->id > 0) { + return $this->redirect($this->generateUrl('repeating_event_show')); + } else { + throw new \Exception('Could not save repeating event?!?'); + } + } + return [ + 'entity' => $entity, + ]; + + } + + /** + * Displays a form to edit a repeating event + * + * @Route("/{slug}/bearbeiten",name="repeating_event_edit") + * @Method("GET") + * @Template() + */ + public function editAction($slug) + { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + /** @var Event $entity */ + $entity = $repo->findOneBy(['slug' => $slug]); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find RepeatingEvent entity.'); + } + + return array( + 'entity' => $entity, + ); + } + + /** + * Updates a repeating event + * + * @Route("/{slug}/bearbeiten",name="repeating_event_update") + * @Method("POST") + * @Template("CalciferBundle:RepeatingEvent:edit.html.twig") + */ + public function updateAction(Request $request, $slug) + { + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + + /** @var EntityRepository $repo */ + $repo = $em->getRepository('CalciferBundle:RepeatingEvent'); + + /** @var Event $entity */ + $entity = $repo->findOneBy(['slug' => $slug]); + + if (!$entity) { + throw $this->createNotFoundException('Unable to find RepeatingEvent entity.'); + } + + $this->fillEntity($request, $entity); + if ($this->validateRepeatingEvent($entity)) { + $ret = $this->saveRepeatingEvent($request, $entity); + if ($entity->id > 0) { + return $this->redirect($this->generateUrl('repeating_event_show')); + } else { + throw new \Exception('Could not save repeating event?!?'); + } + } + return [ + 'entity' => $entity, + ]; + } + + private function fillEntity(Request $request, RepeatingEvent $entity) + { + $fields = [ + 'duration', + 'repeating_pattern', + 'summary', + 'description', + 'url', + ]; + foreach ($fields as $field) { + $entity->$field = $request->get($field); + } + if (strlen($entity->duration) == 0) + $entity->duration = null; + $nextdate = $request->get('nextdate'); + $nextdate = new \DateTime($nextdate); + $entity->nextdate = $nextdate; + + } + + private function validateRepeatingEvent(RepeatingEvent $entity) + { + $fields = [ + 'nextdate', + 'repeating_pattern', + 'summary', + ]; + foreach ($fields as $field) { + if ((is_null($entity->$field)) && (strlen($entity->$field) > 0)) + return false; + } + return true; + } + + private function saveRepeatingEvent(Request $request, RepeatingEvent $entity) + { + $location = $request->get('location'); + $location_lat = $request->get('location_lat'); + $location_lon = $request->get('location_lon'); + if (strlen($location) > 0) { + // check if the location already exists + /** @var EntityManager $em */ + $em = $this->getDoctrine()->getManager(); + $repo = $em->getRepository('CalciferBundle:Location'); + $results = $repo->findBy(['name' => $location]); + if (count($results) > 0) { + $location_obj = $results[0]; + if (strlen($location_lat) > 0) { + $location_obj->lat = $location_lat; + } + if (strlen($location_lon) > 0) { + $location_obj->lon = $location_lon; + } + $em->persist($location_obj); + $em->flush(); + $entity->location = $results[0]; + } else { + $location_obj = new Location(); + $location_obj->name = $location; + if (strlen($location_lat) > 0) { + $location_obj->lat = $location_lat; + } + if (strlen($location_lon) > 0) { + $location_obj->lon = $location_lon; + } + $location_obj->slug = \URLify::filter($location_obj->name, 255, 'de'); + $em->persist($location_obj); + $em->flush(); + $entity->location = $location_obj; + } + } else { + $entity->location = null; + } + + $tags = $request->get('tags'); + if (strlen($tags) > 0) { + $tags = explode(',', $tags); + $em = $this->getDoctrine()->getManager(); + $repo = $em->getRepository('CalciferBundle:Tag'); + $entity->clearTags(); + foreach ($tags as $tag) { + $tag = trim($tag); + $results = $repo->findBy(['name' => $tag]); + if (count($results) > 0) { + $entity->addTag($results[0]); + } else { + $tag_obj = new Tag(); + $tag_obj->name = $tag; + $tag_obj->slug = \URLify::filter($tag_obj->name, 255, 'de'); + $em->persist($tag_obj); + $em->flush(); + $entity->addTag($tag_obj); + } + } + } else { + $entity->clearTags(); + } + + $entity->slug = \URLify::filter($entity->summary,255,'de'); + + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + + return $entity; + + } +} diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php index b6128d9..bcb0a40 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/TagController.php @@ -35,11 +35,11 @@ class TagController extends Controller /** * Finds and displays a Event entity. * - * @Route("/{slug}(?!\.ics)", name="tag_show") + * @Route("/{slug}.{format}", defaults={"format" = "html"}, name="tag_show") * @Method("GET") * @Template("CalciferBundle:Event:index.html.twig") */ - public function showAction($slug) + public function showAction($slug, $format) { /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); @@ -55,60 +55,51 @@ class TagController extends Controller } $now = new \DateTime(); - $now->setTime(0,0,0); + $now->setTime(0, 0, 0); /** @var QueryBuilder $qb */ $qb = $em->createQueryBuilder(); - $qb ->select(array('e')) + $qb->select(array('e')) ->from('CalciferBundle:Event', 'e') - ->join('e.tags', 't', 'WITH', $qb->expr()->in('t.id', $tag->getId())) + ->join('e.tags', 't', 'WITH', $qb->expr()->in('t.id', $tag->id)) ->where('e.startdate >= :startdate') ->orderBy('e.startdate') - ->setParameter('startdate',$now); + ->setParameter('startdate', $now); $entities = $qb->getQuery()->execute(); - return array( - 'entities' => $entities, - 'tag' => $tag, - ); - } + if ($format == 'ics') { + $calendar = new Calendar(); + $calendar->setProdId('-//My Company//Cool Calendar App//EN'); - /** - * Finds and displays a Event entity. - * - * @Route("/{slug}.ics", name="tag_show_ics") - * @Method("GET") - */ - public function showActionICS($slug) - { - $results = $this->showAction(str_replace('.ics','',$slug)); - $entities = $results['entities']; + foreach ($entities as $entity) { + /** @var Event $entity */ + $event = new CalendarEvent(); + $event->setStart($entity->startdate); + if ($entity->enddate instanceof \DateTime) + $event->setEnd($entity->enddate); + $event->setSummary($entity->summary); + $event->setDescription($entity->description); + $location = new \Jsvrcek\ICS\Model\Description\Location(); + $location->setName($entity->location->name); + $event->setLocations([$location]); + $calendar->addEvent($event); + } - $calendar = new Calendar(); - $calendar->setProdId('-//My Company//Cool Calendar App//EN'); + $calendarExport = new CalendarExport(new CalendarStream, new Formatter()); + $calendarExport->addCalendar($calendar); - foreach($entities as $entity) { - /** @var Event $entity */ - $event = new CalendarEvent(); - $event->setStart($entity->getStartdate()); - $event->setEnd($entity->getEnddate()); - $event->setSummary($entity->getSummary()); - $event->setDescription($entity->getDescription()); - $location = new \Jsvrcek\ICS\Model\Description\Location(); - $location->setName($entity->getLocation()->getName()); - $event->setLocations([$location]); - $calendar->addEvent($event); + //output .ics formatted text + $result = $calendarExport->getStream(); + + $response = new Response($result); + $response->headers->set('Content-Type', 'text/calendar'); + + return $response; + } else { + return array( + 'entities' => $entities, + 'tag' => $tag, + ); } - - $calendarExport = new CalendarExport(new CalendarStream, new Formatter()); - $calendarExport->addCalendar($calendar); - - //output .ics formatted text - $result = $calendarExport->getStream(); - - $response = new Response($result); - $response->headers->set('Content-Type', 'text/calendar'); - - return $response; } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php b/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php new file mode 100755 index 0000000..ed3a198 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/BaseEntity.php @@ -0,0 +1,63 @@ +$name; + } else { + throw new \Exception("Property {$name} does not Exists"); + } + } + + public function __set($name,$value) { + if (property_exists($this,$name)) { + $this->$name = $value; + return $this; + } else { + throw new \Exception("Property {$name} does not Exists"); + } + } +} \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php b/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php index 82dfc4e..4e33540 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/Event.php @@ -3,59 +3,59 @@ namespace Hackspace\Bundle\CalciferBundle\Entity; use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\PersistentCollection; /** * Event * + * @property \DateTime $startdate + * @property \DateTime $enddate + * @property string $summary + * @property string $description + * @property Location $location + * @property string $url + * @property array $tags + * * @ORM\Table(name="events") * @ORM\Entity */ -class Event +class Event extends BaseEntity { - /** - * @var integer - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; + use TagTrait; /** * @var \DateTime * * @ORM\Column(name="startdate", type="datetimetz") */ - private $startdate; + protected $startdate; /** * @var \DateTime * * @ORM\Column(name="enddate", type="datetimetz", nullable=true) */ - private $enddate; + protected $enddate; /** * @var string * * @ORM\Column(name="summary", type="string", length=255) */ - private $summary; + protected $summary; /** * @var string * * @ORM\Column(name="description", type="text", nullable=true) */ - private $description; + protected $description; /** * @var string * * @ORM\Column(name="locations_id", type="integer", nullable=true) */ - private $locations_id; + protected $locations_id; /** * @var Location @@ -63,14 +63,14 @@ class Event * @ORM\ManyToOne(targetEntity="Location") * @ORM\JoinColumn(name="locations_id", referencedColumnName="id") */ - private $location; + protected $location; /** * @var string * * @ORM\Column(name="url", type="string", length=255, nullable=true) */ - private $url; + protected $url; /** * @var array @@ -81,179 +81,7 @@ class Event * inverseJoinColumns={@ORM\JoinColumn(name="tags_id", referencedColumnName="id")} * ) */ - private $tags = []; - - /** - * @var string - * - * @ORM\Column(name="slug", type="string", length=255,options={"default" = ""}) - */ - private $slug = ''; - - /** - * @param string $slug - */ - public function setSlug($slug) - { - $this->slug = $slug; - } - - /** - * @return string - */ - public function getSlug() - { - return $this->slug; - } - - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set startdate - * - * @param \DateTime $startdate - * @return Event - */ - public function setStartdate($startdate) - { - $this->startdate = $startdate; - - return $this; - } - - /** - * Get startdate - * - * @return \DateTime - */ - public function getStartdate() - { - return $this->startdate; - } - - /** - * Set enddate - * - * @param \DateTime $enddate - * @return Event - */ - public function setEnddate($enddate) - { - $this->enddate = $enddate; - - return $this; - } - - /** - * Get enddate - * - * @return \DateTime - */ - public function getEnddate() - { - return $this->enddate; - } - - /** - * Set summary - * - * @param string $summary - * @return Event - */ - public function setSummary($summary) - { - $this->summary = $summary; - - return $this; - } - - /** - * Get summary - * - * @return string - */ - public function getSummary() - { - return $this->summary; - } - - /** - * Set description - * - * @param string $description - * @return Event - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - - /** - * Get description - * - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * Set location - * - * @param string $locations_id - * @return Event - */ - public function setLocationsID($locations_id) - { - $this->locations_id = $locations_id; - - return $this; - } - - /** - * Get location - * - * @return string - */ - public function getLocationsID() - { - return $this->locations_id; - } - - /** - * Set url - * - * @param string $url - * @return Event - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * Get url - * - * @return string - */ - public function getUrl() - { - return $this->url; - } + protected $tags = []; /** * @param \Hackspace\Bundle\CalciferBundle\Entity\Location $location @@ -273,41 +101,7 @@ class Event return $this->location; } - public function getTags() { - return $this->tags; - } - - public function hasTag(Tag $tag) { - if ($this->tags instanceof PersistentCollection) { - return $this->tags->contains($tag); - } elseif (is_array($this->tags)) { - return in_array($tag,$this->tags); - } else { - return false; - } - - } - - public function addTag(Tag $tag) { - /** @var PersistentCollection $this->tags */ - if (!$this->hasTag($tag)) { - $this->tags[] = $tag; - } - } - public function isValid() { return true; } - - public function getTagsAsText() { - if (count($this->tags) > 0) { - $tags = []; - foreach ($this->tags as $tag) { - $tags[] = $tag->getName(); - } - return implode(',',$tags); - } else { - return ''; - } - } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php b/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php index 8d3b6a2..af10407 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/Location.php @@ -10,138 +10,28 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="locations") * @ORM\Entity */ -class Location +class Location extends BaseEntity { - /** - * @var integer - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - /** * @var string * * @ORM\Column(name="name", type="string", length=255) */ - private $name; + protected $name; /** * @var float * * @ORM\Column(name="lon", type="float", nullable=true) */ - private $lon; + protected $lon; /** * @var float * * @ORM\Column(name="lat", type="float", nullable=true) */ - private $lat; - - /** - * @var string - * - * @ORM\Column(name="slug", type="string", length=255,options={"default" = ""}) - */ - private $slug = ''; - - /** - * @param string $slug - */ - public function setSlug($slug) - { - $this->slug = $slug; - } - - /** - * @return string - */ - public function getSlug() - { - return $this->slug; - } + protected $lat; - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set name - * - * @param string $name - * @return Location - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Set lon - * - * @param float $lon - * @return Location - */ - public function setLon($lon) - { - $this->lon = $lon; - - return $this; - } - - /** - * Get lon - * - * @return float - */ - public function getLon() - { - return $this->lon; - } - - /** - * Set lat - * - * @param float $lat - * @return Location - */ - public function setLat($lat) - { - $this->lat = $lat; - - return $this; - } - - /** - * Get lat - * - * @return float - */ - public function getLat() - { - return $this->lat; - } } diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php b/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php new file mode 100755 index 0000000..d7a6bcd --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/RepeatingEvent.php @@ -0,0 +1,100 @@ +repeating_pattern) { + case 'P7D': + return 'Wöchentlich'; + case 'P14D': + return 'Alle 2 Wochen'; + case 'P1M': + return 'Monatlich'; + default: + return $this->repeating_pattern; + } + } +} \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/Tag.php b/src/Hackspace/Bundle/CalciferBundle/Entity/Tag.php index ae4ad82..2e296ef 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Entity/Tag.php +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/Tag.php @@ -10,77 +10,12 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="tags") * @ORM\Entity */ -class Tag +class Tag extends BaseEntity { - /** - * @var integer - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - /** * @var string * * @ORM\Column(name="name", type="string", length=255) */ - private $name; - - /** - * @var string - * - * @ORM\Column(name="slug", type="string", length=255,options={"default" = ""}) - */ - private $slug = ''; - - /** - * @param string $slug - */ - public function setSlug($slug) - { - $this->slug = $slug; - } - - /** - * @return string - */ - public function getSlug() - { - return $this->slug; - } - - /** - * Get id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set name - * - * @param string $name - * @return Tag - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name - * - * @return string - */ - public function getName() - { - return $this->name; - } + protected $name; } diff --git a/src/Hackspace/Bundle/CalciferBundle/Entity/TagTrait.php b/src/Hackspace/Bundle/CalciferBundle/Entity/TagTrait.php new file mode 100755 index 0000000..952d990 --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Entity/TagTrait.php @@ -0,0 +1,61 @@ +tags; + } + + public function clearTags() + { + if ($this->tags instanceof PersistentCollection) { + $this->tags->clear(); + } elseif (is_array($this->tags)) { + $this->tags = []; + } + } + + public function hasTag(Tag $tag) + { + if ($this->tags instanceof PersistentCollection) { + return $this->tags->contains($tag); + } elseif (is_array($this->tags)) { + return in_array($tag, $this->tags); + } else { + return false; + } + + } + + public function addTag(Tag $tag) + { + if (!$this->hasTag($tag)) { + $this->tags[] = $tag; + } + } + + public function getTagsAsText() + { + if (count($this->tags) > 0) { + $tags = []; + foreach ($this->tags as $tag) { + $tags[] = $tag->name; + } + return implode(',', $tags); + } else { + return ''; + } + } +} \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js new file mode 100755 index 0000000..3ffdf0e --- /dev/null +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/assets/js/repeating_events.js @@ -0,0 +1,6 @@ +$(document).ready(function(){ + $('.ui.dropdown.selection') + .dropdown() + .dropdown('set value',$('.ui.dropdown.selection input[type=hidden]').val()) + ; +}); diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_box.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_box.html.twig index 1bcb28d..e40664c 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_box.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_box.html.twig @@ -1,25 +1,31 @@
- Bearbeiten + Bearbeiten
- {{ entity.startdate.format('Y-m-d H:i') }} + {{ entity.startdate.format('Y-m-d H:i') }}
{% if entity.location is not null %}- {{ entity.location.name }} + {{ entity.location.name }}
{% endif %} {% if entity.tags|length > 0 %} {% endif %} @@ -37,6 +43,5 @@ {% else %}{{ entity.description|markdown }}
{% endif %} -