Example to create calendar objects with PHP

646 views
Skip to first unread message

sabr...@gmail.com

unread,
May 25, 2016, 5:09:41 PM5/25/16
to SabreDAV Discussion
Hey guys,

I'm new here and I try to create calendar objects with PHP. Can someone give me an example how I can create an object?

I tried this example and the Output is correct. But how I can insert it into the database?

My code:
<?php
use Sabre\VObject;

include 'cal/vendor/autoload.php';

$vcalendar = new VObject\Component\VCalendar([
    'VEVENT' => [
        'SUMMARY' => 'My frist Event with sabredav and php',
        'DTSTART' => new \DateTime('2016-05-26 10:00:00'),
        'DTEND'   => new \DateTime('2016-05-26 12:00:00')
    ]
]);

echo $vcalendar->serialize();
?>


The output is shown in the browser but now I don't know how I can insert it into the database and I can't find a tutorial e.g.

Thanks in advance for tips!
Dennis

Evert Pot

unread,
May 25, 2016, 6:08:28 PM5/25/16
to SabreDAV Discussion
Hi Dennis,

If you are using MySQL, you should try to look for a generic PHP and MySQL tutorial or maybe even buy a book.
Your problem is not specific to sabre/vobject, you first need to simply learn how you'd add values from variables to any database.

For that reason this is not a good place to learn this. Once you learn the basics of databases, and you run into specific problems
as they relate to sabre/vobject, I would be happy to help with that.

Evert

sabr...@gmail.com

unread,
May 26, 2016, 4:59:28 AM5/26/16
to SabreDAV Discussion
Hey Evert Pot,

thanks for your reply.

I know how SQL works. I have programmed some applications. But I saw in this forum that SQL direct for events a bad way is.

I've created an SQL Statement that insert a VEVENT to the database. But the event is not shown in my calendar after sync.
I have copied the calendardata and changed the DTSTART and END time and the UID. But the calendar dont sync the manually created event.


Thats the reason why I asked for a PHP Code for that with sabredav.

Any idea or tips?

Sorry for my bad english, I'm from Germany :)

Evert Pot

unread,
May 26, 2016, 2:37:10 PM5/26/16
to SabreDAV Discussion
Hi Dennis,


On Thursday, May 26, 2016 at 4:59:28 AM UTC-4, sabr...@gmail.com wrote:
Hey Evert Pot,

thanks for your reply.

I know how SQL works. I have programmed some applications. But I saw in this forum that SQL direct for events a bad way is.

I've created an SQL Statement that insert a VEVENT to the database. But the event is not shown in my calendar after sync.
I have copied the calendardata and changed the DTSTART and END time and the UID. But the calendar dont sync the manually created event.


It wasn't clear to me that you were inserting into the standard sabre/dav database. We don't really support people doing that, and you really should not do this.
Instead, you should just create an instance of Sabre\CalDAV\Backend\PDO and call the createCalendarObject method with the correct information.

If you're stubborn, you should read the source of that function so you can replicate what it's doing.

Evert

sabr...@gmail.com

unread,
May 27, 2016, 3:56:58 PM5/27/16
to SabreDAV Discussion
Hey,

thanks for your answer. I have found a way to create objects.


Thanks!

Evert Pot

unread,
May 27, 2016, 4:38:55 PM5/27/16
to sabredav...@googlegroups.com
Awesome! 10/10

Reply all
Reply to author
Forward
0 new messages