parent
539616f7b7
commit
807cfa1b55
1 changed files with 64 additions and 13 deletions
|
@ -14,6 +14,15 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||||
use Hackspace\Bundle\CalciferBundle\Entity\Event;
|
use Hackspace\Bundle\CalciferBundle\Entity\Event;
|
||||||
use Hackspace\Bundle\CalciferBundle\Form\EventType;
|
use Hackspace\Bundle\CalciferBundle\Form\EventType;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use
|
||||||
|
Sabre\VObject,
|
||||||
|
Sabre\CalDAV,
|
||||||
|
Sabre\DAV,
|
||||||
|
Sabre\DAVACL,
|
||||||
|
Sabre\DAV\Exception\Forbidden,
|
||||||
|
Hackspace\Bundle\CalciferBundle\libs\CalciferCaldavBackend,
|
||||||
|
Hackspace\Bundle\CalciferBundle\libs\CalciferPrincipalBackend;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event controller.
|
* Event controller.
|
||||||
|
@ -22,6 +31,45 @@ use Hackspace\Bundle\CalciferBundle\Form\EventType;
|
||||||
*/
|
*/
|
||||||
class EventController extends Controller
|
class EventController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Finds and displays a Event entity.
|
||||||
|
*
|
||||||
|
* @Route("/{url}", name="events_caldav", requirements={"url" : "caldav(.+)"})
|
||||||
|
*/
|
||||||
|
public function caldavEntry()
|
||||||
|
{
|
||||||
|
// Backends
|
||||||
|
$calendarBackend = new CalciferCaldavBackend($this);
|
||||||
|
$principalBackend = new CalciferPrincipalBackend();
|
||||||
|
// Directory structure
|
||||||
|
$tree = [
|
||||||
|
new CalDAV\CalendarRootNode($principalBackend, $calendarBackend),
|
||||||
|
];
|
||||||
|
|
||||||
|
$server = new DAV\Server($tree);
|
||||||
|
|
||||||
|
$server->setBaseUri('/caldav');
|
||||||
|
|
||||||
|
/*$aclPlugin = new DAVACL\Plugin();
|
||||||
|
$aclPlugin->allowAccessToNodesWithoutACL = false;
|
||||||
|
$server->addPlugin($aclPlugin);*/
|
||||||
|
|
||||||
|
/* CalDAV support */
|
||||||
|
$caldavPlugin = new CalDAV\Plugin();
|
||||||
|
$server->addPlugin($caldavPlugin);
|
||||||
|
|
||||||
|
/* WebDAV-Sync plugin */
|
||||||
|
$server->addPlugin(new DAV\Sync\Plugin());
|
||||||
|
|
||||||
|
// Support for html frontend
|
||||||
|
$browser = new DAV\Browser\Plugin();
|
||||||
|
$server->addPlugin($browser);
|
||||||
|
|
||||||
|
// And off we go!
|
||||||
|
$server->exec();
|
||||||
|
return new Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all Event entities.
|
* Lists all Event entities.
|
||||||
|
@ -35,20 +83,21 @@ class EventController extends Controller
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
$now = new \DateTime();
|
$now = new \DateTime();
|
||||||
$now->setTime(0,0,0);
|
$now->setTime(0, 0, 0);
|
||||||
/** @var QueryBuilder $qb */
|
/** @var QueryBuilder $qb */
|
||||||
$qb = $em->createQueryBuilder();
|
$qb = $em->createQueryBuilder();
|
||||||
$qb ->select(array('e'))
|
$qb->select(array('e'))
|
||||||
->from('CalciferBundle:Event', 'e')
|
->from('CalciferBundle:Event', 'e')
|
||||||
->where('e.startdate >= :startdate')
|
->where('e.startdate >= :startdate')
|
||||||
->orderBy('e.startdate')
|
->orderBy('e.startdate')
|
||||||
->setParameter('startdate',$now);
|
->setParameter('startdate', $now);
|
||||||
$entities = $qb->getQuery()->execute();
|
$entities = $qb->getQuery()->execute();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'entities' => $entities,
|
'entities' => $entities,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Event entity.
|
* Creates a new Event entity.
|
||||||
*
|
*
|
||||||
|
@ -117,7 +166,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'entity' => $entity
|
'entity' => $entity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +193,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'entity' => $entity,
|
'entity' => $entity,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +256,7 @@ class EventController extends Controller
|
||||||
$startdate = new \DateTime($startdate);
|
$startdate = new \DateTime($startdate);
|
||||||
$entity->startdate = $startdate;
|
$entity->startdate = $startdate;
|
||||||
}
|
}
|
||||||
$entity->slug = $entity->generateSlug($entity->summary,$em);
|
$entity->slug = $entity->generateSlug($entity->summary, $em);
|
||||||
|
|
||||||
$enddate = $request->get('enddate');
|
$enddate = $request->get('enddate');
|
||||||
if (strlen($enddate) > 0) {
|
if (strlen($enddate) > 0) {
|
||||||
|
@ -246,7 +295,7 @@ class EventController extends Controller
|
||||||
if (strlen($location_lon) > 0) {
|
if (strlen($location_lon) > 0) {
|
||||||
$location_obj->lon = $location_lon;
|
$location_obj->lon = $location_lon;
|
||||||
}
|
}
|
||||||
$location_obj->slug = $location_obj->generateSlug($location_obj->name,$em);
|
$location_obj->slug = $location_obj->generateSlug($location_obj->name, $em);
|
||||||
$em->persist($location_obj);
|
$em->persist($location_obj);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$entity->setLocation($location_obj);
|
$entity->setLocation($location_obj);
|
||||||
|
@ -267,7 +316,7 @@ class EventController extends Controller
|
||||||
} else {
|
} else {
|
||||||
$tag_obj = new Tag();
|
$tag_obj = new Tag();
|
||||||
$tag_obj->name = $tag;
|
$tag_obj->name = $tag;
|
||||||
$tag_obj->slug = $tag_obj->generateSlug($tag_obj->name,$em);
|
$tag_obj->slug = $tag_obj->generateSlug($tag_obj->name, $em);
|
||||||
$em->persist($tag_obj);
|
$em->persist($tag_obj);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
$entity->addTag($tag_obj);
|
$entity->addTag($tag_obj);
|
||||||
|
@ -284,7 +333,8 @@ class EventController extends Controller
|
||||||
* @Method({"GET", "POST"})
|
* @Method({"GET", "POST"})
|
||||||
* @Template("CalciferBundle:Event:delete.html.twig")
|
* @Template("CalciferBundle:Event:delete.html.twig")
|
||||||
*/
|
*/
|
||||||
public function deleteAction(Request $request, $slug) {
|
public function deleteAction(Request $request, $slug)
|
||||||
|
{
|
||||||
/** @var EntityManager $em */
|
/** @var EntityManager $em */
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
@ -299,7 +349,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$confirmation = $request->get('confirmation',false);
|
$confirmation = $request->get('confirmation', false);
|
||||||
|
|
||||||
if (($request->getMethod() == 'POST') && ($confirmation)) {
|
if (($request->getMethod() == 'POST') && ($confirmation)) {
|
||||||
$em->remove($entity);
|
$em->remove($entity);
|
||||||
|
@ -309,7 +359,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'entity' => $entity,
|
'entity' => $entity,
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -321,7 +371,8 @@ class EventController extends Controller
|
||||||
* @Method("GET")
|
* @Method("GET")
|
||||||
* @Template("CalciferBundle:Event:edit.html.twig")
|
* @Template("CalciferBundle:Event:edit.html.twig")
|
||||||
*/
|
*/
|
||||||
public function copyAction(Request $request, $slug) {
|
public function copyAction(Request $request, $slug)
|
||||||
|
{
|
||||||
/** @var EntityManager $em */
|
/** @var EntityManager $em */
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
@ -338,7 +389,7 @@ class EventController extends Controller
|
||||||
$entity->id = null;
|
$entity->id = null;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'entity' => $entity,
|
'entity' => $entity,
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue