Updating or removing fullCalendar events in Symfony

I'm struggling to figure out how to update or delete fullcalendar events in my Symfony project.

When adding a new event, I open a modal window with a form for submitting the event and inserting it into the database.

This is my working controller:

$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);

    /** Creating a new event */
    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'));
    }

To update events, you need to use 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,
    editable: true,
    eventDurationEditable: true,
    events: 'http://localhost/ligne_rh/web/app_dev.php/admin/accueil/calendar',

    eventResize: function(events) {
        console.log("Entering : 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 find this confusing and I'm not sure what my controller should look like for updating events.

Please provide me with an example! I am a beginner and would greatly appreciate your help. Thank you!

Answer №1

It is recommended to utilize the following code snippet for updating an already existing entity:

$em->merge($event);

Similarly, use the following code snippet for removing an entity:

$em->remove($event);

To streamline CRUD operations, consider creating distinct controller actions such as eventDeleteAction and eventCreateAction.

Answer №2

Hello there, I recommend utilizing the CalendarBundle from GitHub at this link: https://github.com/tattali/CalendarBundle. The documentation provides detailed instructions on integrating the calendar with a CRUD system for managing event creation, updates, and deletions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

utilize text offsets to insert tags within strings

I've been facing challenges with using JavaScript string methods and regular expressions. It seems like I might be missing something obvious here. Please forgive me if I'm repeating the question asked by tofutim in more detail, which can be found ...

Developing a personalized loop in handlebars templates

Just starting out with NodeJS and ExpressJS. I'm looking to customize a for loop in order to iterate through data from NodeJS using an index, akin to a non-traditional for loop. Take a look at the code snippet below, extracted from NodeJS, where I re ...

What is special about this element, textarea?

Hey there, I've got this JavaScript code that currently works on all textarea elements on the site. However, I'd like it to only work on one specific element. function limits(obj, limit) { var text = $(obj).val(); var str_length = $(obj) ...

When the mouse drags across the empty space, the force graph continually jumps

I have some questions. I utilized a force graph and added zoom functionality to it. However, when I drag the mouse over the blank area, the force graph keeps jumping erratically. like this Is there a way to prevent the graph from jumping? Thank you. ( ...

Tips on preventing a nested loop's inner ng-repeat from updating when the array undergoes changes

My current challenge involves working with an array of events, each event has teams participating in it. Although these objects are related, they are not properties of each other. I am attempting to loop through every event and display the teams participa ...

Failure to build using the spread operator is unique to the Travis CI environment

I encountered an issue when running the build command npm run build locally for my website. However, on Travis CI, it fails with the following error: > node scripts/build.js /home/travis/build/PatrickDuncan/patrickduncan.github.io/node_modules/@hapi/ho ...

Customizing ESLint configurations for a more productive local development environment

Let's consider an inspiring scenario: I am in the process of coding and need to troubleshoot an issue, so here is a snippet of my code: function foo() { console.log("I'm resorting to printf debugging in 2016"); } However, our build setup in ...

Tips for altering dual data values in Vue

When working with Vue.JS, I encounter the following situation: data() { return { name: 'John', sentence: "Hi, my name is {{ name }}", }; }, In my HTML file, I have the following line: <h2>{{ sentence}}</h2> ...

Having trouble implementing a multi-level sub menu in a popup menu in Vue.js?

data: { menuItems: [{ name: 'Item 1', children: [{ name: 'Subitem 1' }, { name: 'Subitem 2' }, { name: 'Subitem 3' }] }, { ...

Tips on incorporating asynchronous functionality in AngularJS

I am currently utilizing AngularJS version 1.5.8 and have a specific requirement. When the user clicks on the Next button, the text inside the button should change to 'Processing...' before completing the operation. I have implemented the $q serv ...

How to ensure a table in MaterialUI always maintains full width without requiring horizontal scrolling in CSS?

After attempting to allocate each widthPercent value on the TableHeader so they sum up to 100%, I am still experiencing the presence of a scroll bar. I have tried setting fixed widths for each column, but this results in excess space on the right side dep ...

Using the fs module in a React Native application

Currently, I am facing a challenge in importing TinyDB into an expo project. The issue lies with fs, as Expo does not support it due to its third-party file system nature. I attempted using react-native-fs as an alternative but I am unsure about how to pr ...

The next.js code is functioning properly when run in development mode, but encounters issues when attempting

When using the useAddress() function in run dev, it is returning undefined undefined and then the address when console logged. However, in the run build/start, it only returns undefined. What steps should I take to resolve this issue? import { useAddres ...

There seems to be a disconnect between the React Redux store

When attempting to connect my store to a React application, I encountered the following error: TypeError: state is undefined store/index.js (Creating Reducer function) import {createStore} from 'redux'; const counterReducer = (state:{counter:0} ...

What causes jquery height and javascript height to both be returned as 0?

I'm facing an issue with a visible div on my screen - despite being visible, its height always returns as 0. I've attempted various jQuery and JavaScript methods to retrieve the height, but it consistently shows as 0. Here's the structure of ...

retrieve fresh information from the API

Hello! I am attempting to retrieve new data from an API by filtering it with a JSON file. My goal is to filter the data from the API using the JSON file and extract any new information. const jsnf = JSON.stringify(fs.readFileSync("./data.json" ...

Is it possible for a memory leak to occur when a jQuery object is created within a function but never actually used?

As an illustration: function calculateTime(minutes) { var newTime = new Date(); newTime.setHours(0, minutes, 0, 0); return angular.element('<input type="hidden"/>').timepicker('setTime', newTime).val(); } I'm cu ...

Showcasing certain elements as the user scrolls

Looking for a way to display an element (such as a div) when the user scrolls without using JQuery? Here's an example that tries to achieve this: var scroll = document.body.scrollTop; var divLis = document.querySelectorAll("div"); for(let i = 0; i ...

guide to setting up router access using token

I've received a token from the backend axios.post(process.env.VUE_APP_LOGIN, payload) .then(response => { const {access_token, token_type, user} = response.data; this.token = access_token this.$store.commit(&a ...

Error: An unexpected symbol '<' was encountered after the build process in Vue.js

I just finished deploying a MEVN stack application to heroku. While everything is functioning properly locally, I am encountering a blank page and the following errors in the console post-deployment: Uncaught SyntaxError: Unexpected token '<' ...