Store Event data in the Database

Issue #3 resolved
Helge Sverre Hessevik Liseth repo owner created an issue
  • -On-save serialize event list to JSON and put it in hidden form field-
  • Make sure the information is stored in the database

Must obviously be in first release.

Proposed solutions:

  1. Use WordPress' new settings api to just store the JSON as plain json in the settings table(i presume)
  2. Create a custom table with these fields ( id, page_id, start, end, scheduled_by) parse the submitted JSON and store the relevant info into the DB manually.

Comments (2)

  1. Helge Sverre Hessevik Liseth reporter

    Data is stored in a hidden field as a encodeURIComponent'ed JSON string, this way the JSON string can contain quotes and such without breaking the HTML.

    everytime the events are loaded in we just decode the data and parse the json.

            // Loop through each event object
            for (var i = 0; i < events.length; i++) {
                // Give the data variable only the data we are going to be saving in the DB
                data.push({
                    id: events[i].id,
                    title: events[i].title,
                    pageid: events[i].pageid,
                    start: events[i].start.format("YYYY-MM-DD HH:mm:ss"),
                    end: events[i].end.format("YYYY-MM-DD HH:mm:ss")
                });
            }
    
            // Serialize data to JSON
            var eventData = encodeURIComponent(JSON.stringify(data));
    
  2. Log in to comment