Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • keilo 568 posts 1023 karma points
    Sep 07, 2014 @ 15:22
    keilo
    0

    How to change startdate property name

    I would like to integrate this package with an existing legacy implementation.

    There is a need to change the startDate property name to date, to support the legacy date-folder creation, so my question what would be the simplest way to change the property startDate name 'date' without breaking existing functioanility?

    If you can provide some guidance would be greatly appreciated.

    cheers

  • Ole Martin Bakke 112 posts 624 karma points
    Sep 07, 2014 @ 16:21
    Ole Martin Bakke
    0

    I think I will need some additional information about the legacy implementation.

    The KS.Umbraco7.Calendar is a complex propertytype where all the settings are saved in a single JSON so you are not able to just change the name of the startDate property.

    If the legacy implementation contains a data field with the startdate you could create a script that does this.

    You would then add the KS.Umbraco7.Calendar data type to the existing document type, then the script should loop all the event nodes setting the value of KS.Umbraco7.Calendar data type to: '{ recurrence: "1", weekInterval: "1", monthYearOption: "1", interval: "1", weekDay: "1", month: "1", monthOption: "1", startDate:"oldDate.ToString("yyyy-mm-dd HH:mm:ss")" }';


  • keilo 568 posts 1023 karma points
    Sep 07, 2014 @ 17:09
    keilo
    0

    Sorry for not giving proper details. I have lot of nodes that have date field, where the uDateFoldersy creates the year, month folders automatically on document save.

    uDateFoldersy only checks for a single field, and in the legacy implementation which contains hundreds of pages - various document types, all of them have the date fileld which uDateFoldersy then creates the Year-month folders.

    I would like to incorporate the same, i.e. extend the existing event documenttype with KS.U7.Calendar with recurrence support. I thought if i changed the startDate property name to simple "date" it will work along with other document types and uDateFoldersy will create the Year and month fodlers.

    But from what you mentioned, the property value startDate seems to be in Json, not the document type property name.

    I am not sure how to go about it... I simply would like to have Year and Month folders created automatically when the user selects the dates and save the document.

    For event document type, I can use an alternate approach but Im not sure how to go about it..

    What would you advise, for someone in need of organizing events (lots of em) in year, month folders upon node save where the date selection made within KS.U7.Calendar?

    many thanks!

  • Ole Martin Bakke 112 posts 624 karma points
    Sep 07, 2014 @ 18:50
    Ole Martin Bakke
    0

    I don't think this is something I will include in this package at the moment.

    But what I would have tried to solve this would be to hook onto the saving or save event on the node. (http://our.umbraco.org/documentation/reference/Events-v6/ContentService-Events) and then get the startDate from the KS.U7.Calendar datatype and use that to update the field uDateFoldersy uses to determine the right folder. I'm not sure if this would work, as I don't know when uDateFoldersy interacts with the event, but it looks like it's on saved.

  • keilo 568 posts 1023 karma points
    Sep 07, 2014 @ 19:11
    keilo
    0

    Thank you for the pointer! I figured it would be easy to create a .cs file instead of compiling DLL, and place it under App_Code, something like below;

    But not sure how to parse/get the startDate value from the KSU7Calendar property. Once I figured it out, I will try to see if I can create a folder for Year and Month instead of using uDateFoldersy altogether; Need to find the simplest algorithm to create the Year and Month folders after that...

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Core;
    using Umbraco.Core.Events;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    
    namespace EventhandlingEventsACME.App_Code
    {
        public class eventsManager : ApplicationEventHandler
        {
            static string eventRootAlias = "eventRoot";
    
    
            public eventsManager() {
                ContentService.Saving += ContentService_Saving;
                ContentService.Saved += ContentService_Saved;
            }
    
            void ContentService_Saved(IContentService sender, SaveEventArgs e)
            {
                foreach (IContent node in e.SavedEntities)
                {
                    if(node.ContentType.Alias == eventRoot)
                    {
                        IContent settings = node.Parent();
                        if (settings.Children().Count() > 1)
                        {
    
                if (settings.HasProperty("KSU7Calendar"))
                            {
                                // how to get the KSU7Calendar startDate here?
    
                   // parse the startDate then figure out creating year and month folders (no clue for now) or update the 'date' property hiddent under Properties tab and continue using uDateFoldersy..(is it worth it? or is there a simpler way to do here?
                            }
                        }
                    }
    
                }
            }
    
  • keilo 568 posts 1023 karma points
    Sep 07, 2014 @ 19:15
    keilo
    0

    Sorry.. the parsing you said should be on Saving event

    so the line

    void ContentService_Saved(IContentService sender, SaveEventArgs e)

    should change to

    void ContentService_Saving(IContentService sender, SaveEventArgs e)

     

    i presume? then handle the saving of 'date' property OR creating Year/Month folders within Saved handler.

  • Ole Martin Bakke 112 posts 624 karma points
    Sep 07, 2014 @ 19:53
    Ole Martin Bakke
    0

    I'm not totally sure how to do this, but one way to get the date is:

    using KS.Umbraco7.Calendar.Core;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Umbraco.Core;
    using Umbraco.Core.Services;

    namespace U7EventHandler.Core
    {
    public class SomeHandler : ApplicationEventHandler
    {
    public SomeHandler() {
    ContentService.Saved += ContentService_Saved;
    }

    void ContentService_Saved(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
    {

    foreach (var n in e.SavedEntities) {
    if (n.HasProperty("calendar"))
    {
    var p = n.Properties["calendar"];
    var pv = p.Value.ToString();
    CalendarEvent ce = Newtonsoft.Json.JsonConvert.DeserializeObject <CalendarEvent>(pv);

    var date = ce.startDate;

    }
    }

    }
    }
    }

    If you continue to use uDateFoldersy you should hook on to the saving event and set the value that uDateFoldersy uses to dertermine the root-folder to the startdate.

    If you choose to create something yourself you should hook into the saved event, and then get the year and month part of the date, check if the actual year and month folder exist in the calendar root and set the rigth node as the new parent node, then resave the node without raising the events.

  • keilo 568 posts 1023 karma points
    Sep 07, 2014 @ 20:20
    keilo
    0

    Many thanks for the pointers and insight Martin. Greatly appreciated!

    I will give these a try with a clear mind and will update this post with my findings/progress.

    cheers!

Please Sign in or register to post replies

Write your reply to:

Draft