Nibble

UI-O-Matic Event Model

The most recent version of UI-O-Matic (1.4.0 at this moment) introduces a couple of events that allow you to do some interesting stuff. The events are all placed on the PetaPocoObjectController (that’s the controller responsable for handling the crud operations).

Following the Umbraco convention there are before and after events.

BuildingQuery and BuildedQuery

These execute when UI-O-Matic builds the sql query for fetching the list view data. By default UI-O-Matic will fetch all the data from the table but using these events you can limit that by still having control over the query before it is executed.

CreatingObject and CreatedObject

These will execute when UI-O-Matic is inserting an object, so you can use these events to set values.

UpdatingObject and UpdatedObject

These will execute when UI-O-Matic is updating an object

Examples

1 public class EventHandlerscs: ApplicationEventHandler 2 { 3 protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) 4 { 5 UIOMatic.Controllers.PetaPocoObjectController.CreatingObject += PetaPocoObjectController_CreatingObject; 6 UIOMatic.Controllers.PetaPocoObjectController.BuildingQuery += PetaPocoObjectController_BuildingQuery; 7 } 8 9 void PetaPocoObjectController_CreatingObject(object sender, UIOMatic.ObjectEventArgs e) 10 { 11 if (e.Object.GetType() == typeof (ccpEvent)) 12 { 13 ccpEvent ob = (ccpEvent) e.Object; 14 ob.IsApproved = true; 15 } 16 } 17 18 void PetaPocoObjectController_BuildingQuery(object sender, UIOMatic.QueryEventArgs e) 19 { 20 if (e.TableName == ccpEvent) 21 e.Query.Where(AREAID = @0, 2); 22 } 23 }

7 Comments so far

  1. Robert on February 17th, 2016

    Hi Tim,

    Is there any way to represent one to many relationships with a joining table in UI-O-Matic? For example, I have a list of physicians with multiple languages I need to attach to them.

  2. Tim Geyssens on February 18th, 2016

    @Robert haven’t done that would need to take a deeper look but in theory it should be possible with a custom field type (but might need some core updates)

  3. Robert on February 23rd, 2016

    Ok, just an idea. It’s a great feature in DEWD, but unfortunately they have not moved forward with a v7 version.

  4. Ben on July 7th, 2016

    Hi Tim,

    I’ve got this running on 7.4.3 and connected to an external sql express database, and it can delete and read the table data, but is not writing to it, even though the ui is giving successful messages. Any thing come to mind? Should I post any of my code?

    Thanks!! Love the package!

  5. Tim Geyssens on July 8th, 2016

    @Ben yeah maybe post the details on the forum? Glad you like the package :)

  6. AnnettSmall on February 27th, 2018

    I have checked your page and i’ve found some duplicate content, that’s why you don’t rank high in google’s search results,
    but there is a tool that can help you to create 100% unique articles,
    search for; Boorfe’s tips unlimited content

  7. GaleChief on March 7th, 2018

    I have checked your blog and i have found some duplicate content, that’s why you don’t rank
    high in google’s search results, but there is a tool that can help
    you to create 100% unique articles, search for: Best article rewritwer Ercannou’s essential tools

Leave a Reply