Re: [SMARTY] calendars and smarty

From: Date: Tue, 15 Jun 2004 18:18:15 +0000
Subject: Re: [SMARTY] calendars and smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11460@lists.php.net to get a copy of this message
Hi Sarah (and Jochem), I actually decided to use PEAR calendar (for better or worse). I had to access the classes in a strange way to allow flexibility in displaying "selected" days in a month calendar. Since the PEAR concept (including Calendar) is built around objects, you need to be very careful to use $smarty->assign_by_ref() instead of the normal assign() method. PEAR calendar lets you store stuff inside its objects (which is nice), but you have to build a so-called "Decorator" class to extend it to support data payloads that can come along with those objects. Calendar only supports isSelected() method out-of-the-box, so there is no way to show what event happened on the day you've selected. Here's an example PEAR_Calendar extension class I wrote to implement a simple data repository. This lets me use the data in smarty templates by calling for example, {$var_that_holds_calendar_object->getData('index')} //------------------------------------------- // CREATED: DEC 20040401 // MODIFIED: DEC 20040401 // DESCRIPTION: CLASS to attach data to PEAR calendar objects // Decorator to "attach" functionality to selected days // allows data payload to exist with the date // class DataEvent extends Calendar_Decorator { var $entry; function DataEvent($calendar) { Calendar_Decorator::Calendar_Decorator($calendar); } // store the data in assoc array function setData($entry, $key) { $this->entry[$key][] = $entry; } function getData() { return $this->entry; } } Call it like so: // $ts is a variable that holds a unix timestamp // build regular calendar days that will hold the data $day = & new Calendar_Day(date("Y",$ts), date("n",$ts), date("j",$ts)); // Create the decorator by reference, passing it the regular day $DataEvent = & new DataEvent($day); // Attach the payload (the index) to the decorated day $DataEvent->setData($index, 'index'); // Add the decorator to the selection // to send later to the month build() method $selection[] =& $DataEvent; In smarty template you grab it something like this: {assign var=payload value=$day->getData()} {section name=data loop=$payload.index} <a href="?id={$payload.index[data]}"> {$payload.index[data]} </a><br> {/section} I put up a wiki page to describe my foray into using PEAR::Calendar and Smarty. There you can find the full source code and template file to make a monthly calendar. http://smarty.incutio.com/?page=PEARCalendarExploration Further, in order to extend with a decorator you have to apply it specifically to the day object with the event. You can't use the "wrapper" functionality because it wraps all day objects with the same data regardless. There are some other things that I had to thrash through to get it to work, but I've repressed those memories. Finally, the example I made at the wiki shows using fetchAll() method rather than the built-in fetch() iterator. I use fetchAll() to be able to handle the weeks. It may be possible to use {$pear_calendar_object->fetch()} inside smarty templates but it didn't occur to me at the time. In any case, this technique, though cumbersome, works. Please feel free to refine it and add to the wiki page. Cheers, dan On 6/15/04 11:23 AM, "Sarah Gray" <sarah@fabled.net> wrote: > I have played with the smarty plugin below and also with PEAR::Calendar, > deciding between the two for usage. They are both nice, but > the thing that is special about PEAR is that it allows you to pass an > array of selected items (like day objects) when you build your calendar, > so that you can take output from a database (for an event calendar, say) > and have the calendar draw itself accordingly (days with events a diff > color, have a diff behaviour when clicked, etc). I didn't see similar > functionality in the smarty calendar plugin. Is there something like > this that I missed in the smarty one? And if you wanted this > functionality would you agree that using the PEAR class makes more sense > -- or not? thanks, > > s. > > Jochem Maas wrote: >> >> what do you want it to do? >> >> there is a nice/simple output calendar plugin which you can find in the >> smarty wiki (of which I have an extended version which allows showing of >> multiple months and choosing which day is 1st-day-of-week - mail me if >> you want it or check the archives for the download link, there is an >> exmaple included) >> >> I also use to show a client side calendar: >> http://dynarch.com/mishoo/calendar.epl >> >> Daniel Cummings wrote: >> >>> IYHO... which calendar lib works nicely with smarty? I'm currently looking >>> at PEAR::Calendar and finding it a little abstract. Is there something more >>> tuned to smarty ken? >>> >>> dan >>> >> >> -- >> Smarty General Mailing List (http://smarty.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#11460) next »