How to update or delete fullCalendar Event with Symfony - javascript

I dont know how update or delete fullcalendar events on my symfony project.
To add a new event, i open a modal window with a form to submit a new event and insert it in my database.
This is my controler(it work fine):
$datas = array();
$form = $this->createFormBuilder($datas)
->add('title', TextType::class)
->add('startDate', TextType::class, array(
'attr'=> array('class' => 'dateTimePicker')))
->add('endDate', TextType::class, array(
'attr'=> array('class' => 'dateTimePicker')))
->add('backgroundColor', ChoiceType::class, array('choices' => $color ))
->getForm();
$form->handleRequest($request);
/** Création d'un nouvel évenement */
if ($form->isSubmitted() && $form->isValid()) {
$title = $form->get('title')->getData();
$start = new \DateTime($form->get('startDate')->getData());
$end = new \DateTime($form->get('endDate')->getData());
$backgroundColor = $form->get('backgroundColor')->getData();
$event = new CalendarEvent();
$event->setTitle($title);
$event->setStartDate($start);
$event->setEndDate($end);
$event->setBackgroundColor($backgroundColor);
$em = $this->getDoctrine()->getManager();
$em->persist($event);
$em->flush();
return $this->redirect($this->generateUrl('ma_lrm_accueil'));
}
I know that to update events, i have to have a javascript like this:
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev, next',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
timezone: ('Europe/London'),
businessHours: {
start: '09:00',
end: '18:30',
dow: [1, 2, 3, 4, 5]
},
allDaySlot: true,
defaultView: 'agendaWeek',
lazyFetching: true,
firstDay: 1,
selectable: true,
/*timeFormat: {
agenda: 'h:mmt',
'': 'h:mmt'
},*/
editable: true,
eventDurationEditable: true,
events: 'http://localhost/ligne_rh/web/app_dev.php/admin/accueil/calendar',
eventResize: function(events) {
console.log("Entrée dans : eventResize");
var start1 = events.start.format('Y-m-d\TH:i:s');
var end1 = events.end.format('Y-m-d\TH:i:s');
var xhr = $.ajax({
type: "POST",
url: 'http://localhost/.../calendar/event/update',
data: 'title=' + events.title + '&start=' + start1 + '&end=' + end1 + '&id=' + events.id,
dataType: 'html',
success: function(data) {
window.location.reload(true);
},
error: function() {
alert("...");
},
});
},
});
I dont understand any of it and i have no idea what my controler should look like.
Please HELP ME with an example!! I am novice!! thank you!!!!

You should use
$em->merge($event);
for updating already existing entity and
$em->remove($event);
for removing entity.
Also maybe you should try to create different controller actions(eventDeleteAction, eventCreateAction) to make CRUD operations.

Hi you can use https://github.com/tattali/CalendarBundle the documentation explain how to link the calendar to a CRUD to allow create, update and delete events

Related

load Events from database on fullcalendar v6

I'm using FC 6 (upgrading from FC 3). I'm trying to load my events from my MS SQL Server database and JSON file but I don't understand why it's not working.
This is the call I made in my calendar.js:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
/*CODE*/
events: [{
url: '../script/apps/calendar/load.php',
method: 'POST',
},
{
url: '../../resource/various/vacation.json'
},
{
id: "weekend",
rrule: {
freq: 'weekly',
byweekday: [ 'sa', 'su' ],
dtstart: '2022-01-01',
},
allDay: true,
display:"background",
backgroundColor: "#90ee90"
}
],
But I'm not understanding why I cannot see any events on my calendar.
This is my load.php:
<?php
require_once "../../connection.php";
$data = array();
$query= sqlrsv_query($conn,"SELECT * FROM gestioneOre ORDER BY idAssenza");
while($result = sqlrsv_fetch_array($query)){
$data[] = array(
'idAssenza' => $result['idAssenza'],
'title' => $result['ename'],
'start' => $result['starts'],
'end' => $result['ends'],
'nomeUtente'=> $result['nomeUtente'],
'pausaPranzo'=> $result['pausaPranzo']
);
}
echo json_encode($data);
?>
I change by myself the JSON with an old one I had and now it's working again; but now i'ts not loading the weekends and the one from the database.
JSON send it from my database ->

How to add remove event option with cross sign in fullcalendar.io ? asp.net mvc core

I am going to add remove cross sign with each event of calendar which are getting from database. But how to add this and i want when click on cross sign(delete) then specific url will be triggered and i want to delete event from database. Please let me know how can i do this? How to add delete event with cross sign.
call-init.js
!function($) {
"use strict";
var CalendarApp = function() {
this.$body = $("body")
this.$calendar = $('#calendar'),
this.$event = ('#calendar-events div.calendar-events'),
this.$categoryForm = $('#add-new-event form'),
this.$extEvents = $('#calendar-events'),
this.$modal = $('#my-event'),
this.$saveCategoryBtn = $('.save-category'),
this.$calendarObj = null
};
/* Initializing */
CalendarApp.prototype.init = function() {
this.enableDrag();
/* Initialize the calendar */
var events = [];
$.ajax({
type: 'POST',
async: false,
url: '/Booking/GetBookings',
success: function (mems) {
//states contains the JSON formatted list
//of states passed from the controller
$.each(mems, function (_, member) {
debugger;
events.push({
title: member.guestname,
start: new Date(member.checkindatetime),
end: new Date(member.checkoutdatetime),
allDay: true,
url: '/Booking/Booking/' + member.encryptedId,
className: member.classnamecolor
});
});
},
error: function (ex) {
alert('Buchungen konnten nicht geladen werden.');
}
});
var $this = this;
$this.$calendarObj = $this.$calendar.fullCalendar({
defaultView: 'month',
handleWindowResize: true,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
navLinks: false, // can click day/week names to navigate views
events: events
//eventStartEditable: false // disable drag&drop of events
});
},
//init CalendarApp
$.CalendarApp = new CalendarApp, $.CalendarApp.Constructor = CalendarApp
}(window.jQuery),
//initializing CalendarApp
function($) {
"use strict";
$.CalendarApp.init()
}(window.jQuery);
other calendar view is
#model FewoVerwaltung.Models.Booking.BookingListModel
<div id="calendar"></div>
<!-- Calendar JavaScript -->
<script src="~/plugins/calendar/dist/locale/de.js"></script>
<script src="~/plugins/calendar/dist/fullcalendar.min.js"></script>
<script src="~/plugins/calendar/dist/cal-init.js"></script>

Pass another parameter to Fulcalendar

Here is the code, the "events: url," part of the code is coming through into my fullcalendar.js file and adds the events however I also want to add a list of users from json data like so users:'urlusers'
Will I have to edit the fullcalendar.js file and if so where can I add another parameter for the users.
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
defaultView: 'agendaWeek',
minTime: "08:00:00",
maxTime: "20:00:00",
editable:false,
header:{
left:'prev,next today',
center:'title',
},
events: 'https://events.com/eventsjson',
users:'https://events.com/usersjson',
selectable:true,
selectHelper:true,
select: function(start, end, allDay)
{
var titlestart = $.fullCalendar.formatDate(start, "DD-MM-Y HH:mm:ss");
var r = confirm("Request Time " + titlestart);
if (r == true) {
event.preventDefault();
//Open dialog
var subject = 'Booking '+titlestart;
var emailBody = 'Create booking for '+titlestart
showDialog(titlestart);
} else {
}
},
});
});
Not the solution I was thinking of but got the result.
on the events: 'https://events.com/eventsjson', I needed to add more data to the JSON then the fullcalendar sorted the rest out for me
foreach($result as $row)
{
$data[] = array(
'id' => $row["user_id"],
'start' => $row["startevent"],
'end' => $row["endevent"],
'backgroundColor' => $row["backgroundColor"],
'borderColor' => $row["borderColor"]
);
}

FullCalendar not showing extraParams

I am having some problems retrieving these from my string
here is my script, taken from the website..
events: {
url: '/CalendarManager/Findall',
method: 'GET',
extraParams: {
custom_param1: 'customerName',
custom_param2: 'description'
},
failure: function () {
alert('there was an error while fetching events!');
},
eventRender: function (event, element) {
element.qtip({
content: event.custom_param1,
content: event.custom_param2
});
}
},
UPDATE: 12/24/2020
To answer questions below.. I am using 5.3.2 version. I can use this as well and it will bring back everything but the custom parameters.
events: '/CalendarManager/Findall',
I am using Json pulling from DB - Below is the code..
public ActionResult FindAll()
{
return Json(db.GetEvents.AsEnumerable().Select(e => new
{
id = e.CompanyId,
companyName = e.CompanyName,
title = e.Title,
description = e.Description,
allDay = e.AllDay,
start = e.StartDate.ToString("yyyy-MM-ddTHH:mm:ss"),
end = e.EndDate.ToString("yyyy-MM-ddTHH:mm:ss"),
color = e.Color
}).ToList(), JsonRequestBehavior.AllowGet);
}
I changed the version I was using and that is when the extras did not show up. So I added what I thought the documentation said to use.
Adding the extra Params after the url did not work..
UPDATE:
I read through the suggested. I guess I am still not understanding or maybe not getting "Where I am supposed to put the code".
I believe I need to use eventContent. I also did use the console.log(info.event.extendedProps.companyName); Which is great, it does show up in the console window, However i need it on the calendar not in the console window. FullCalendar's examples could be a little better!
Here is what I did but still does not show on the calendar.
eventDidMount: function (info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
console.log(info.event.extendedProps.companyName);
},
eventSources: [{
url: '/CalendarManager/Findall',
failure: function () {
alert('there was an error while fetching events!');
},
}],
eventContent: function (arg) {
html: arg.event.extendedProps.companyName
}
I did add some stuff in there to produce just a bubble when hovered over with this info but it does not work either.
Thank You!
UPDATE: 12/27/2020 Working Code
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prevYear,prev,next,nextYear today',
center: 'title',
right: 'dayGridMonth,dayGridWeek,dayGridDay,listWeek'
},
initialView: 'dayGridMonth',
navLinks: true, // can click day/week names to navigate views
editable: true,
dayMaxEvents: true, // allow "more" link when too many events
themeSystem: 'bootstrap',
selectable: true,
selectMirror: true,
//Random default events
//events: '/CalendarManager/Findall',
eventDidMount: function (info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
console.log(info.event.extendedProps.companyName);
},
events: {
url: '/CalendarManager/Findall',
failure: function () {
alert('there was an error while fetching events!');
},
},
eventContent: function (arg) {
return { html: arg.event.title + '<br>' + arg.event.extendedProps.companyName + '<br>' + arg.event.extendedProps.description };
}
});
calendar.render();
Thank you for all your help!
First, let me know what kind of version of fullcalendar you are using.
fullcalendar v5.5 doesn't provide eventRender.
And extraParams is not what you want to show. It is the query params which attach after the request url, like http://example.com/CalendarManager/Findall?custom_param1=customerName&....
If you want to use extend event props then you should parse them as extendProps.
And you should use Event Render Hooks rather than eventRender if you are using the latest version.
How to fix:
Anyway, you should use function, not an object.
You can use events (as a function)
function( fetchInfo, successCallback, failureCallback ) { }
You can also use events (as a json feed)
var calendar = new Calendar(calendarEl, {
events: '/myfeed.php'
});
If you are going to use object rather than function, then you can use eventSources
And if you want to handle the success response, then use eventSourceSuccess function
Here is an example (using fullcalendar v5.5):
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'listWeek',
loading: function(bool) {
if (bool) {
$("#dashboard-calendar-column .pre-loader").show();
} else {
$("#dashboard-calendar-column .pre-loader").hide();
}
},
// get all events from the source
eventSources: [{
url: '/CalendarManager/Findall',
method: 'GET',
failure: function() {
document.getElementById('script-warning').style.display = 'block'
}
}],
// convert the response to the fullcalendar events
eventSourceSuccess: function(content, xhr) {
var events = [];
content.events.value.map(event => {
events.push({
id: event.id,
allDay: event.isAllDay,
title: event.subject,
start:event.start.dateTime,
end: event.end.dateTime,
// The followings are what you want to add as extended
custom_param1: 'customerName',
custom_param2: 'description',
// Or you could add them to the extendedProps object
extendedProps: {
custom_param1: 'customerName',
custom_param2: 'description',
description: event.bodyPreview,
...
},
// You can check fullcalendar event parsing
...
})
})
return events;
},
eventDidMount: function (arg) {
// remove dot between the event titles
$(arg.el).find('.fc-list-event-graphic').remove();
// You can select the extended props like arg.event.custom_param1 or arg.event.extendProps.custom_param1
...
},
});
calendar.render();
})
Hope this would help you.
You can use extraParams using eventSources if you are using fullcalendar v5.
eventSources: [{
url: '/CalendarManager/Findall',
method: 'POST',
extraParams: {
custom_param1: 'customerName',
custom_param2: 'description'
}
...
}]
You should use POST rather use GET, then it will work.

Fullcalander.js Delete an event with google a.p.i calendar

I am using FullCalendar library to load events in my calendar from Google Calendars. And the Calendar does display the events, but now I want to be able to delete/remove an event that sync with the google calendar. I am looking couple of days now how to do it, but can’t find the answer.
(I know there a couple of people who had the same problem but it doesn’t work for me)
I hope someone can help me find the solution.
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list', 'bootstrap', 'googleCalendar'],
customButtons: {
myCustomButton: {
text: 'custom!',
click: function() {
alert('clicked the custom button!');
}
}
},
header: { right: 'prev,next today,list,dayGridDay,timeGridWeek,dayGridMonth', left: 'prev,next today myCustomButton' }, // buttons for switching between views
defaultView: 'timeGridWeek',
themeSystem: 'bootstrap',
editable: true,
eventLimit: true,
eventRender: function(eventObj, el) {
},
// Showing events
events: {!! json_encode($events) !!},
});
calendar.render();
});
This is how I load the events:
$request->validate([ 'calendar_id' => 'required', ]);
$gclient = new Gclient; $client = $gclient->client();
$cal = Calendar::find($request['calendar_id']);
$client->setAccessToken($cal->gmail->token);
$gcal_id = isset($cal->calendar_id) ? $cal->calendar_id : env('GOOGLE_DEFAULT');
$g_cal = new \Google_Service_Calendar($client);
$eventlist = $g_cal->events->listEvents($gcal_id)->getItems();
$events = [];
foreach ($eventlist as $event) {
if ($event->summary == NULL ) {
if ($event->location == NULL ) {
$title = 'default';
}
else {
$title = $event->location;
}
}
else {
$title = $event->summary;
}
$events[] = [
'title' => $title,
'start' => $event->start->dateTime,
'end' => $event->end->dateTime,
'id' => $event->id
];
}

Categories