Page 1 of 1

Need access to central object throughout tree

Posted: Sat Aug 15, 2009 7:25 pm
by Luke
I am back at work on my iCalendar library. One requirement in the format is that if a property specifies a "TZID" parameter, there must be a corresponding VTIMEZONE component in the iCalendar object somewhere. My iCalendar object is a tree. It has nested components, each with properties and parameters (meta-info about properties). Picture something like:

Code: Select all

<?php
// an event that takes place in the park from 10-11am on August 15th, 2009 (US-Eastern time)
$event = new qCal_Component_Vevent(array(
    new qCal_Property_Dtstart('20090815T100000', array('tzid' => 'US-Eastern')),
    new qCal_Property_Dtend('20090815T110000'), array('tzid' => 'US-Eastern')),
    'summary' => 'A picnic',
    'description' => 'A picnic in the park',
    'location' => 'The Park'
));
 
This component will eventually be attached to a qCal_Component_Vcalendar object and be a part of the component tree:

Code: Select all

$cal = new qCal_Component_Vcalendar(array(
    'prodid' => '-//Some Product That Makes iCalendar Files//somehost@host.com',
    'method' => 'PUBLISH'
));
$cal->attach($event);
In order for the event to know how to handle "US-Eastern" time, there must be a qCal_Component_Vtimezone component in the tree somewhere.

Code: Select all

$timezone = new qCal_Component_Vtimezone(array(
    'tzid' => 'US-Eastern',
    // timezone properties here...
));
$cal->attach($timezone);
Components can be nested within other components. For instance, let's add an alarm to our event:

Code: Select all

$alarm = new qCal_Component_Valarm(array(
    new qCal_Property_Trigger('20090815T100000', array('tzid' => 'US-Eastern')),
    'action' => 'audio',
    'attach' => 'http://www.example.com/sounds/alarm.wav',
));
$event->attach($alarm);
My question is, how do I go about ensuring that all tzids specified throughout the tree have associated vtimezone components? It seems that I need some kind of central object that stores this kind of data. What do you guys think?

Re: Need access to central object throughout tree

Posted: Sat Aug 15, 2009 8:23 pm
by Luke
Would it be a bad idea to use something like sqlite with this library as sort of an intermediary storage device? Sometimes icalendar files can be pretty large, and making queries on them would be much faster and easier if I stored them in a database, wouldn't it? I'm really on the fence about it, but it does seem like it would make things easier, no?

Re: Need access to central object throughout tree

Posted: Sat Aug 15, 2009 9:01 pm
by Luke
One of the "appropriate uses for sqlite" listed on the sqlite docs is:
Internal or temporary databases

For programs that have a lot of data that must be sifted and sorted in diverse ways, it is often easier and quicker to load the data into an in-memory SQLite database and use queries with joins and ORDER BY clauses to extract the data in the form and order needed rather than to try to code the same operations manually. Using an SQL database internally in this way also gives the program greater flexibility since new columns and indices can be added without having to recode every query.
Seems like exactly what I need to do...

Re: Need access to central object throughout tree

Posted: Sat Aug 15, 2009 11:34 pm
by Christopher
Luke wrote:My question is, how do I go about ensuring that all tzids specified throughout the tree have associated vtimezone components? It seems that I need some kind of central object that stores this kind of data. What do you guys think?
It seems like qCal_Component_Vcalendar::attach() needs to register some way for these sub-compenents to get the timezone object when they need it, or report that it is not available.

SQLite is excellent for fast read/write where you want a SQL interface. It will limit you to a single server though.

Re: Need access to central object throughout tree

Posted: Sun Aug 16, 2009 4:01 am
by arjan.top
why not something like this?

Code: Select all

 
new qCal_Property_Trigger('20090815T100000', array('tzid' => $timezone))
 

Re: Need access to central object throughout tree

Posted: Thu Aug 20, 2009 12:50 am
by Luke
arborint wrote:
Luke wrote:My question is, how do I go about ensuring that all tzids specified throughout the tree have associated vtimezone components? It seems that I need some kind of central object that stores this kind of data. What do you guys think?
It seems like qCal_Component_Vcalendar::attach() needs to register some way for these sub-compenents to get the timezone object when they need it, or report that it is not available.

SQLite is excellent for fast read/write where you want a SQL interface. It will limit you to a single server though.
I agree, I am just not sure how I should go about it. For now, I suppose, I can use a registry, but I really am not happy with that. I may as well just throw everything into $GLOBALS if I'm going to use a registry for this. It's a hack. Ideally, each component would just be aware of its root object and use that to find all of the available time zone objects. Any ideas?

For now I guess I'll just use a registry and store references to everything in the tree so I can easily find them.

@arjan.top

I don't see how that solves my problem.

Re: Need access to central object throughout tree

Posted: Thu Aug 20, 2009 3:20 pm
by alex.barylski
My question is, how do I go about ensuring that all tzids specified throughout the tree have associated vtimezone components? It seems that I need some kind of central object that stores this kind of data. What do you guys think?
I am not sure I fully understand your problem but it seems to me, that a validator object might simply traverse the 'tree' object and using RTTI check to ensure that associated objects exist?

Re: Need access to central object throughout tree

Posted: Mon Aug 24, 2009 3:47 pm
by Luke
Can you elaborate?

Re: Need access to central object throughout tree

Posted: Mon Aug 24, 2009 10:03 pm
by alex.barylski
Well it sounds like the structure you have is a tree that stores timezones, each node in the tree could be checked by a validator to ensure nodes which had object of type 'TimeZone' had a relevant 'TZID' or whatever the objects are.

RTTI = Runtime type information

Assume an array like

Code: Select all

array
(
  array
  (
    'tzid' => TZID_Object
    'timezone' => 'Chicago/America'
 
  )
)
I'm not sure what your tree structure looks like or what it is your even doing so pardon my attempt...

Basically the validator would traverse the tree assuming it's a series of nested arrays starting at root node, you step through each array and check if leaf nodes have required objects...

Re: Need access to central object throughout tree

Posted: Mon Aug 24, 2009 11:39 pm
by Luke
Oh ok. Yea, that's basically what I've done. It now looks through the tree any time a tzid is attached and makes sure that there is a corresponding vtimezone component. Thanks man.

I still am not 100% satisfied with how it works, but it will at least allow me to go on with my beta release so I can start getting some feedback.

Re: Need access to central object throughout tree

Posted: Tue Aug 25, 2009 5:32 pm
by alex.barylski
I still am not 100% satisfied with how it works, but it will at least allow me to go on with my beta release so I can start getting some feedback.
What are you not satisfied with?

Why are you using a tree and not a linear vector/array?

Re: Need access to central object throughout tree

Posted: Wed Aug 26, 2009 12:35 am
by Luke
Meh, the library is just a little more messy that I'd like. That's OK though, it will get cleaner and cleaner with every release. As for why it's in a tree, it's because it is hierarchal data. Components can be nested within eachother, so a tree is what makes sense.