cvs: peardoc /en/package/datetime/calendar faq.xml intro-decorators.xml
| From: | Lorenzo Alberton | Date: | Wed, 23 Jun 2004 22:23:16 +0000 |
| Subject: | cvs: peardoc /en/package/datetime/calendar faq.xml intro-decorators.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-4477@lists.php.net to get a copy of this message | ||
quipo Wed Jun 23 18:23:16 2004 EDT
Modified files:
/peardoc/en/package/datetime/calendar faq.xml intro-decorators.xml
Log:
- wrap sentences when > 80 chars long
- update docs to reflect the latest Calendar version
- start working on bundled decorators description
http://cvs.php.net/diff.php/peardoc/en/package/datetime/calendar/faq.xml?r1=1.7&r2=1.8&ty=u Index: peardoc/en/package/datetime/calendar/faq.xml diff -u peardoc/en/package/datetime/calendar/faq.xml:1.7 peardoc/en/package/datetime/calendar/faq.xml:1.8 --- peardoc/en/package/datetime/calendar/faq.xml:1.7 Wed Mar 24 10:39:00 2004 +++ peardoc/en/package/datetime/calendar/faq.xml Wed Jun 23 18:23:15 2004 @@ -1,4 +1,4 @@ -<!-- $Id: faq.xml,v 1.7 2004/03/24 15:39:00 didou Exp $ --> +<!-- $Id: faq.xml,v 1.8 2004/06/23 22:23:15 quipo Exp $ --> <refentry id="package.datetime.calendar.faq"> <refnamediv> <refname>FAQ</refname> @@ -7,69 +7,98 @@ </refpurpose> </refnamediv> <refsect1> - <title>Why doesn't it generate HTML?</title> + <title>Why doesn't it generate HTML?</title> <para> - What if you want WML, SOAP, PDF, GIF, command line, etc. etc.? PEAR::Calendar can be used to - generate any output format you like (see the examples for SOAP and WML). Tying it to a - particular output content type will limit its use (a problem that every public domain PHP - Calendar library I've looked at suffers from). A PEAR::HTML_Calendar is likely to be developed - using PEAR::Calendar. + What if you want WML, SOAP, PDF, GIF, command line, etc. etc.? + PEAR::<classname>Calendar</classname> can be used to generate any output + format you like (see the examples for SOAP and WML). + Tying it to a particular output content type will limit its use + (a problem that every public domain PHP Calendar library I've + looked at suffers from). + A PEAR::HTML_Calendar is likely to be developed using + PEAR::<classname>Calendar</classname>. </para> </refsect1> <refsect1> - <title>There's too many objects, classes and files. It's bloated!</title> + <title>There are too many objects, classes and files. It's bloated!</title> <para> - Running the examples on Sourceforge's servers (which are always overloaded), example 3.php renders in under 0.1 seconds (usually half that). The code is highly optimized and every "trick in the book" has been applied to make sure PHP only parses / executes the subset of logic you need for your specific problem. If in doubt, use <classname>Cache_Lite</classname> to cache the output HTML. + Running the examples on Sourceforge's servers (which are always overloaded), + example 3.php renders in under 0.1 seconds (usually half that). + The code is highly optimized and every "trick in the book" has been + applied to make sure PHP only parses / executes the subset of logic + you need for your specific problem. + If in doubt, use <classname>Cache_Lite</classname> to cache the output HTML. </para> </refsect1> <refsect1> - <title>You use Unix timestamps to calculate the Calendar, which limits the range of years it can generate. Can this be changed?</title> + <title> + You use Unix timestamps to calculate the Calendar, + which limits the range of years it can generate. Can this be changed? + </title> <para> - All calculations are handled by a class implementing the Calendar_Engine interface. The default implemention is based on PHP's <function>date</function> and <function>mktime</function> functions (so Unix timestamps are required for that engine). A second engine exists which uses PEAR::Date. It's slower but overcomes the limit on the range of Unixstamps. To switch between engines use the constant <constant>CALENDAR_ENGINE</constant> e.g. + All calculations are handled by a class implementing the + <classname>Calendar_Engine</classname> interface. + The default implemention is based on PHP's <function>date</function> + and <function>mktime</function> functions (so Unix timestamps are required + for that engine). + A second engine exists which uses PEAR::<classname>Date</classname>. + It's a bit slower but overcomes the limit on the range of Unixstamps. + To switch between engines use the constant <constant>CALENDAR_ENGINE</constant> e.g. <programlisting role="php"> - <![CDATA[ +<![CDATA[ // The default Unix timestamp engine (this definition is not required) // define('CALENDAR_ENGINE', 'UnixTs'); // Switch to PEAR::Date engine define('CALENDAR_ENGINE', 'PearDate'); - ]]> +]]> </programlisting> - Note that the PEAR::Date engine is based on PEAR Date version 1.3 (version 1.3.1beta is missing a required file and will not work). + Note that the <classname>PearDate</classname> engine is based on + PEAR::<classname>Date</classname> version 1.4 or newer. </para> </refsect1> <refsect1> <title>This examples use the English language for days and months. Can this be changed?</title> <para> - PEAR::Calendar only uses base 10 numbers for calculations - the names of months and days of the week and generated as the calendar is being rendered (by you). You should only need to change PHP's locale with <function>setlocale</function> and use the <function>strftime</function> function e.g.; + PEAR::<classname>Calendar</classname> only uses base 10 numbers for calculations + - the names of months and days of the week and generated as the calendar + is being rendered (by you). + You should only need to change PHP's locale with <function>setlocale</function> + and use the <function>strftime</function> function e.g.: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Day = & new Calendar_Day(2003, 10, 23); setlocale (LC_TIME, 'de_DE'); // German echo strftime('%A %d %B %Y', $Day->getTimeStamp()); - ]]> +]]> </programlisting> Note that <classname>Calendar_Decorator_Textual</classname> provides help in generating month and day of week names in a manner which is independent of the Calendar Engine you are using and can be modified with <function>setlocale</function>. </para> </refsect1> <refsect1> - <title>What are EmptyDays?</title> + <title>What are empty days?</title> <para> - PEAR::Calendar makes it easy to render calendars in tabular format (like humans are used to) such as; + PEAR::<classname>Calendar</classname> makes it easy to render calendars + in tabular format (like humans are used to) such as: <literallayout> +<![CDATA[ October 2003 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -20 21 22 23 24 25 26 +20 2122 23 24 25 26 27 28 29 30 31 +]]> </literallayout> - Notice the top left and botton right of this example - these are "EmptyDays". EmptyDays are generated only by two calendar classes: Calendar_Month_Weekdays and Calendar_Week. For example using Calendar_Month_Weekdays; + Notice the top left and botton right of this example - these are "empty days". + Empty days are generated only by two calendar classes: + <classname>Calendar_Month_Weekdays</classname> and <classname>Calendar_Week</classname>. + For example using <classname>Calendar_Month_Weekdays</classname>; <programlisting role="php"> - <![CDATA[ +<![CDATA[ require_once 'Calendar/Month/Weekdays.php'; $Month = & new Calendar_Month_Weekdays(2003, 10); @@ -87,17 +116,33 @@ if ($Day->isLast()) // Check for the end of a week echo "\n"; } - ]]> +]]> </programlisting> - An empty day can still return values, the date it represents being from the previous or next month in the calendar. You may get empty days for <classname>Calendar_Month_Weekdays</classname> and <classname>Calendar_Week</classname>. Using <classname>Calendar_Week</classname>, you will only build 7 days (use <classname>Calendar_Month_Weeks</classname> to build <classname>Calendar_Week</classname> objects), so the <function>isFirst</function> and <function>isLast</function> methods are not applicable. + An empty day can still return values, the date it represents being from + the previous or next month in the calendar. + You may get empty days for <classname>Calendar_Month_Weekdays</classname> + and <classname>Calendar_Week</classname>. + Using <classname>Calendar_Week</classname>, you will only build 7 days + (use <classname>Calendar_Month_Weeks</classname> to build + <classname>Calendar_Week</classname> objects), so the + <function>isFirst</function> and <function>isLast</function> methods are + not applicable. </para> </refsect1> <refsect1> <title>How do I select some dates?</title> <para> - All calendar objects (except <classname>Calendar_Second</classname>, which has no "children") have the method <function>build</function> to build the "children" of that object. For example <classname>Calendar_Year</classname>::<function>build</function> builds <classname>Calendar_Month</classname> objects while <classname>Calendar_Hour</classname>::<function>build</function> builds <classname>Calendar_Minute</classname> objects. You have the option of passing this method an indexed array of Calendar objects which will be used to "select" the matching built children. For example; + All calendar objects (except <classname>Calendar_Second</classname>, + which has no "children") have the method <function>build</function> + to build the "children" of that object. + For example <classname>Calendar_Year</classname>::<function>build</function> + builds <classname>Calendar_Month</classname> objects while + <classname>Calendar_Hour</classname>::<function>build</function> builds + <classname>Calendar_Minute</classname> objects. + You have the option of passing this method an indexed array of Calendar objects + which will be used to "select" the matching built children. For example: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Calendar_Month(2003, 10); // Oct 2003 $SelectedDay1 = & new Calendar_Day(2003, 10, 5); Oct 5th 2003 @@ -112,23 +157,46 @@ if ($Day->isSelected()) echo $Day->thisYear().' '.$Day->thisMonth().' '.$Day->thisDay().' is selected'."\n"; } - ]]> +]]> </programlisting> - <emphasis>Note:</emphasis> date objects you pass to a <function>build</function> method replace the corresponding built date objects, allowing you to do things like attach your own subclass of <classname>Calendar_Decorator</classname> to them, then access the decorating functionality inside the loop which renders the calendar. You might display the contents from an "events database table" using this approach. + <emphasis>Note:</emphasis> the date objects you pass to a + <function>build</function> method replace the corresponding built + date objects, allowing you to do things like attach your own subclass + of <classname>Calendar_Decorator</classname> to them, then access + the decorating functionality inside the loop which renders the calendar. + You might display the contents from an "events database table" using this + approach. </para> </refsect1> <refsect1> - <title>Why do I have to call build() explicitly. Why can't children be built automatically?</title> + <title> + Why do I have to call build() explicitly. Why can't children be + built automatically? + </title> <para> - First and foremost, for performance. Building the children has a performance cost and you won't always need to have the children, so it should be called explicitly, otherwise you might have $Year->build(), expecting to get just months but behind the scenes, months built days, which built hours, which build minutes etc. Also calling <function>build</function> yourself give you a chance to "select" some of the children. + First and foremost, for performance. Building the children has a + performance cost and you won't always need to have the children, + so it should be called explicitly, otherwise you might have $Year->build(), + expecting to get just months but behind the scenes, months built days, + which built hours, which build minutes etc. + Also calling <function>build</function> yourself give you a chance to + "select" some of the children. </para> </refsect1> <refsect1> <title>How do I validate a date?</title> <para> - Validity is determined by the Caalendar_Engine being used as well as the time the date object you're working with represents (e.g. $Month = & new Month(2003, 2, 29); is invalid, because Feb 2003 was not a leap year). For quick validation, you can call the method <function>isValid</function> on any date object, which will return FALSE if there's a problem. For more information of more detailed validation, you can call the method <function>getValidator</function> on any date object, which returns an instance of the class <classname>Calendar_Validator</classname>. For example; + Validity is determined by the Caalendar_Engine being used as well as + the time the date object you're working with represents (e.g. + $Month = & new Month(2003, 2, 29); is invalid, because Feb 2003 was + not a leap year). For quick validation, you can call the method + <function>isValid</function> on any date object, which will return &false; + if there's a problem. For more information of more detailed validation, + you can call the method <function>getValidator</function> on any date object, + which returns an instance of the class <classname>Calendar_Validator</classname>. + For example; <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Month(2003, 2, 29); // 29th Feb 2003 (?!?) if (!$Month->isValid()) { $Validator = & $Month->getValidator(); @@ -136,23 +204,41 @@ echo $Error->toString(); } } - ]]> +]]> </programlisting> - You can also begin validation by calling <function>getValidator</function> then either <function>isValidYear</function>, <function>isValidMonth</function>, <function>isValidDay</function>, <function>isValidHour</function>, <function>isValidMinute</function> and <function>isValidSecond</function> (or just <function>isValid</function> which calls all of the isValidxxx methods). + You can also begin validation by calling <function>getValidator</function> + then either <function>isValidYear</function>, <function>isValidMonth</function>, + <function>isValidDay</function>, <function>isValidHour</function>, + <function>isValidMinute</function> and <function>isValidSecond</function> + (or just <function>isValid</function> which calls all of the isValidxxx methods). </para> </refsect1> <refsect1> <title>Can I adjust invalid dates?</title> <para> - If you're allowing end users to navigate your calendar via the URL, were they to modify the URL to something like calendar.php?year=2003&month=13, instead of throwing a validation error at them, you could call the <classname>Calendar</classname>::<function>adjust</function> method on the calendar object you create with that URL. You should then end up with January 2004 (in this example). This behaviour is possible thanks to <function>mktime</function> for the Unix Timestamp engine, while being built into the PEAR Date engine for you. + If you're allowing end users to navigate your calendar via the URL, + were they to modify the URL to something like calendar.php?year=2003&month=13, + instead of throwing a validation error at them, you could call the + <classname>Calendar</classname>::<function>adjust</function> method on the + calendar object you create with that URL. You should then end up with + January 2004 (in this example). This behaviour is possible thanks to + <function>mktime</function> for the Unix Timestamp engine, while being built + into the <classname>PearDate</classname> engine for you. </para> </refsect1> <refsect1> - <title>After calling build(), I just want to get a single child date object with looping through the lot. How?</title> + <title> + After calling <function>build</function>, I just want to get a single + child date object with looping through the lot. How? + </title> <para> - The method <function>fetchAll</function> can be called on any date object to get an indexed array of all the children which have been built, allowing you to reference them directly. Be careful with the first index of this array - in some cases it will be [1] not [0], depending on the type of date object built. For example; + The method <function>fetchAll</function> can be called on any date object + to get an indexed array of all the children which have been built, + allowing you to reference them directly. Be careful with the first index + of this array - in some cases it will be [1] not [0], depending on the + type of date object built. For example; <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Calendar_Month(2003, 10); $Month->build(); @@ -164,20 +250,38 @@ $hours = & $Hour->fetchAll(); // Now all in array echo $hours[0]->thisHour(); // The first hour has index 0 - ]]> +]]> </programlisting> - The following classes are always built to have the first index as 1: <classname>Calendar_Month</classname>, <classname>Calendar_Month_Weekdays</classname>, <classname>Calendar_Month_Weeks</classname>, <classname>Calendar_Week</classname> and <classname>Calendar_Day</classname> - The following classes are always built to have the first index as 0: <classname>Calendar_Hour</classname>, <classname>Calendar_Minute</classname> and <classname>Calendar_Second</classname> - - Note also the method <function>size</function> can be called on any date object, after <function>build</function> has been called, to get the number of children. + The following classes are always built to have the first index as 1: + <classname>Calendar_Month</classname>, + <classname>Calendar_Month_Weekdays</classname>, + <classname>Calendar_Month_Weeks</classname>, + <classname>Calendar_Week</classname> and + <classname>Calendar_Day</classname> + The following classes are always built to have the first index as 0: + <classname>Calendar_Hour</classname>, + <classname>Calendar_Minute</classname> and + <classname>Calendar_Second</classname> + + Note also the method <function>size</function> can be called on any + date object, after <function>build</function> has been called, + to get the number of children. </para> </refsect1> <refsect1> - <title>What does a week actually represent in PEAR::Calendar?</title> + <title>What does a week actually represent in PEAR::<classname>Calendar</classname>?</title> <para> - Weeks are "pseudo" dates. They're useful for formatting the user interface for end users. Weeks are instantiated with a year, a month and a day of the month. You can then have the week tell you its timestamp (which will be the same as the timestamp for the first day in the week), its numeric position within the <emphasis>tabular</emphasis> month (see Empty Days above), its numeric position within the year (this is an ISO-8601 week number of year, weeks starting on Monday) or an array containing the numeric year, month and the first day of the week (as a number within the month). For example; + Weeks are "pseudo" dates. They're useful for formatting the user + interface for end users. Weeks are instantiated with a year, a month + and a day of the month. You can then have the week tell you its timestamp + (which will be the same as the timestamp for the first day in the week), + its numeric position within the <emphasis>tabular</emphasis> month (see + empty days above), its numeric position within the year (this is an ISO-8601 + week number of year, weeks starting on Monday) or an array containing the + numeric year, month and the first day of the week (as a number within the month). + For example: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Week = & new Calendar_Week(2003, 10, 15); $Week = new Calendar_Week(2003, 10, 15); @@ -191,23 +295,35 @@ // (YYYY-MM-DD HH:MM:SS), depending on the engine. print_r $Week->thisWeek('array'); // [year] => 2003 [month] => 10 [day] => 12 - ]]> +]]> </programlisting> </para> </refsect1> <refsect1> - <title>How do I get a Calendar_Year to build Calendar_Month_Weekdays or Calendar_Month_Weeks, instead of the default Calendar_Month objects?</title> + <title> + How do I get a Calendar_Year to build Calendar_Month_Weekdays or + Calendar_Month_Weeks, instead of the default Calendar_Month objects? + </title> <para> - When working with a <classname>Calendar_Year</classname>, the constants <constant>CALENDAR_MONTH_STATE</constant> controls what type of month object is built. You can define <constant>CALENDAR_MONTH_STATE</constant> to <constant>CALENDAR_USE_MONTH_WEEKDAYS</constant> or <constant>CALENDAR_USE_MONTH_WEEKS</constant> for the Calendar_Month_Weekdays and <classname>Calendar_Month_Week</classname> classes, respectively. - </para> + When working with a <classname>Calendar_Year</classname>, the constants + <constant>CALENDAR_MONTH_STATE</constant> controls what type of month + object is built. You can define <constant>CALENDAR_MONTH_STATE</constant> + to <constant>CALENDAR_USE_MONTH_WEEKDAYS</constant> or + <constant>CALENDAR_USE_MONTH_WEEKS</constant> for the + <classname>Calendar_Month_Weekdays</classname> and + <classname>Calendar_Month_Week</classname> classes, respectively. + </para> </refsect1> <refsect1> <title>You use Monday as the start of the week. Can I change that?</title> <para> - Yes. For the classes which are concerned with the notion of a "week", you can can pass a value which defines the first day of the week. For the default timestamp based Calendar engine, this is a number from 0 to 6, 0 being Sunday through to 6 being Saturday. + Yes. For the classes which are concerned with the notion of a "week", + you can can pass a value which defines the first day of the week. + For the default timestamp based Calendar engine, this is a number + from 0 to 6, 0 being Sunday through to 6 being Saturday. This value can be passed to the following: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Year = new Calendar_Year(2003); $selection = array(); $Year->build($selection, 0); // the second argument is the first day of the week (Sunday) @@ -217,7 +333,7 @@ $MonthWeeks = new Calendar_Month_Weekdays(2003, 10, 2); // Third argument - Tuesday $Week = new Calendar_Week(2003, 10, 15, 5) // Fourth argument - Friday - ]]> +]]> </programlisting> </para> </refsect1> http://cvs.php.net/diff.php/peardoc/en/package/datetime/calendar/intro-decorators.xml?r1=1.6&r2=1.7&ty=u Index: peardoc/en/package/datetime/calendar/intro-decorators.xml diff -u peardoc/en/package/datetime/calendar/intro-decorators.xml:1.6 peardoc/en/package/datetime/calendar/intro-decorators.xml:1.7 --- peardoc/en/package/datetime/calendar/intro-decorators.xml:1.6 Wed Mar 24 10:39:00 2004 +++ peardoc/en/package/datetime/calendar/intro-decorators.xml Wed Jun 23 18:23:15 2004 @@ -1,4 +1,4 @@ -<!-- $Id: intro-decorators.xml,v 1.6 2004/03/24 15:39:00 didou Exp $ --> +<!-- $Id: intro-decorators.xml,v 1.7 2004/06/23 22:23:15 quipo Exp $ --> <refentry id="package.datetime.calendar.intro-decorators"> <refnamediv> <refname>Calendar Decorators</refname> @@ -9,14 +9,23 @@ <refsect1> <title>Calendar Decorators</title> <para> - The <classname>Calendar_Decorator</classname> is provided to allow you to attach - functionality to existing Calendar objects without needing to subclass them. This - helps in a number of situations, such as allowing results from, say, a database - query to be rendered in the calendar or to modify the values returned from Calendar - methods (perhaps converting a numeric month into its textual name).</para> - <para>Some concrete decorators are provided with PEAR::Calendar, to address what may be common problems you encounter in using the library. These are not designed to suit everyone but instead focus on solving a more narrow problem domain. They will only be parsed by the PHP engine should you explicitly include them in your code. An example of why decorators can be useful; + The <classname>Calendar_Decorator</classname> is provided to allow you + to attach functionality to existing Calendar objects without needing + to subclass them. + This helps in a number of situations, such as allowing results from, + say, a database query to be rendered in the calendar or to modify the + values returned from Calendar methods (perhaps converting a numeric month + into its textual name). + </para> + <para> + Some concrete decorators are provided with PEAR::<classname>Calendar</classname>, + to address what may be common problems you encounter in using the library. + These are not designed to suit everyone but instead focus on solving + a more narrow problem domain. + They will only be parsed by the PHP engine should you explicitly include them + in your code. An example of why decorators can be useful: <programlisting role="php"> - <![CDATA[ +<![CDATA[ require_once 'Calendar/Day.php'; require_once 'Calendar/Decorator.php'; @@ -27,17 +36,17 @@ // Overides the default fetch method of the calendar object function fetch() { - if ( $Hour = parent::fetch() ) { + if ($Hour = parent::fetch()) { // Recursive fetch, return only hours between 8am and 6pm - if ( $Hour->thisHour() < 8 || $Hour->thisHour() > 18 ) { + if ($Hour->thisHour() < 8 || $Hour->thisHour() > 18) { return $this->fetch(); } else { return $Hour; } } else { // Make sure to return FALSE when the real fetch returned nothing - // or you'll get an infinite loop + // or you will get an infinite loop return FALSE; } } @@ -51,30 +60,223 @@ $WorkingDay = new WorkingDay($Day); // Only hours in a working day are displayed... -while ( $Hour = $WorkingDay->fetch() ) { - echo ( $Hour->thisHour().'<br>' ); +while ($Hour = $WorkingDay->fetch()) { + echo $Hour->thisHour().'<br />'; } - ]]> +]]> </programlisting> </para> </refsect1> <refsect1> <title>The base Calendar_Decorator</title> <para> - The base class <classname>Calendar_Decorator</classname> "mirrors" the combined - API of all the subclasses of <classname>Calendar</classname>. It accepts a Calendar - object to its constructor then "takes over" the API allowing you to make calls through - it rather than directly to the original calendar object. The - <classname>Calendar_Decorator</classname> simply routes calls through to the calendar - object it is decorating and returns values where appropriate. + The base class <classname>Calendar_Decorator</classname> "mirrors" the + combined API of all the subclasses of <classname>Calendar</classname>. + It accepts a Calendar object to its constructor then "takes over" + the API allowing you to make calls through it rather than directly + to the original calendar object. + The <classname>Calendar_Decorator</classname> simply routes calls + through to the calendar object it is decorating and returns values + where appropriate. </para> </refsect1> <refsect1> <title>Decorators and Date Selection</title> <para> - One important use of decorators is to help "inject" data into the loop which renders the calendar. This helps with fetching data from some sort of "event" table in a database. When passing a selection array to any <function>build</function> method, the selected date objects will replace the default built objects, allowing you to get them back as inside the <function>fetch</function> loop, using the <function>isSelected</function> method. You'll find an example of this in the PEAR::Calendar download. It should always be possible to fetch the event data you need with a single database query... + One important use of decorators is to help "inject" data into the loop + which renders the calendar. This helps with fetching data from some sort + of "event" table in a database. When passing a selection array to any + <function>build</function> method, the selected date objects will replace + the default built objects, allowing you to get them back as inside the + <function>fetch</function> loop, using the <function>isSelected</function> + method. + You'll find an example of this in the PEAR::<classname>Calendar</classname> + download. It should always be possible to fetch the event data you need + with a single database query... </para> </refsect1> + <refsect1> + <title>The bundled Decorators</title> + <para> + PEAR::<classname>Calendar</classname> already provides a few decorators: + <itemizedlist> + <listitem> + <para><classname>Calendar_Decorator_Textual</classname></para> + <para> + Decorator to help with fetching textual representations of months and + days of the week. It has + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Uri</classname></para> + <para> + Decorator to help with building HTML links for navigating the calendar. + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Weekday</classname></para> + <para> + Decorator for fetching the day of the week. + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Wrapper</classname></para> + <para> + Decorator to help with wrapping built children in another decorator. + </para> + </listitem> + </itemizedlist> + </para> + </refsect1> + <refsect1> + <title>Calendar_Decorator_Textual example</title> + <para> + This decorator defines a few methods that can be useful to handle + month and day names: + <itemizedlist> + <listitem> + <para>monthNames(<parameter>$format</parameter>='long')</para> + <para> + Returns an array with month names; the format of returned months + depends on the <parameter>format</parameter> parameter + (one, two, short or long) + </para> + </listitem> + <listitem> + <para>weekdayNames(<parameter>$format</parameter>='long')</para> + <para> + Returns an array with day names; the format of returned days + depends on the <parameter>format</parameter> parameter + (one, two, short or long) + </para> + </listitem> + <listitem> + <para>prevMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the previous month of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>thisMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the month of the decorated calendar object + </para> + </listitem> + <listitem> + <para>nextMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the next month of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>prevDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the previous day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>thisDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>nextDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the next day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>orderedWeekdays(<parameter>$format</parameter>='long')</para> + <para> + Returns the days of the week using the order defined in the decorated + calendar object. Only useful for <classname>Calendar_Month_Weekdays</classname>, + <classname>Calendar_Month_Weeks</classname> and <classname>Calendar_Week</classname>. + Otherwise the returned array will begin on Sunday. + </para> + </listitem> + + </itemizedlist> + </para> + </refsect1> + <refsect1> + <title>Calendar_Decorator_Uri example</title> + <para> + Methods defined by this decorator: + <itemizedlist> + <listitem> + <para>setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null)</para> + <para> + Set the names of the URI vars for each date element + </para> + </listitem> + <listitem> + <para>setSeparator(<parameter>$separator</parameter>)</para> + <para> + Set the fragments separator, for instance '/' (default: &). + </para> + </listitem> + <listitem> + <para>setScalar(boolean <parameter>$state</parameter>=&true;)</para> + <para> + Puts Uri decorator into "scalar mode" - URI variable names are not returned + </para> + </listitem> + <listitem> + <para>prev(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the previous calendar unit (year, month, week or day etc) + </para> + </listitem> + <listitem> + <para>this(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the current calendar unit (year, month, week or day etc) + </para> + </listitem> + <listitem> + <para>next(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the next calendar unit (year, month, week or day etc) + </para> + </listitem> + </itemizedlist> + </para> + + <para> + A simple usage example: + <programlisting role="php"> +<![CDATA[ +$Day = new Calendar_Day(2003, 10, 23); +$Uri = & new Calendar_Decorator_Uri($Day); +$Uri->setFragments('year', 'month', 'day'); +echo $Uri->getPrev(); +// Displays year=2003&month=10&day=22 +]]> + </programlisting> + </para> + </refsect1> + + <refsect1> + <title>Calendar_Decorator_Uri example</title> + <para> + + </para> + </refsect1> + + <refsect1> + <title>Calendar_Decorator_Wrapper example</title> + <para> + + </para> + </refsect1> + + </refentry> <!-- Keep this comment at the end of the file Local variables:
http://cvs.php.net/diff.php/peardoc/en/package/datetime/calendar/faq.xml?r1=1.7&r2=1.8&ty=u Index: peardoc/en/package/datetime/calendar/faq.xml diff -u peardoc/en/package/datetime/calendar/faq.xml:1.7 peardoc/en/package/datetime/calendar/faq.xml:1.8 --- peardoc/en/package/datetime/calendar/faq.xml:1.7 Wed Mar 24 10:39:00 2004 +++ peardoc/en/package/datetime/calendar/faq.xml Wed Jun 23 18:23:15 2004 @@ -1,4 +1,4 @@ -<!-- $Id: faq.xml,v 1.7 2004/03/24 15:39:00 didou Exp $ --> +<!-- $Id: faq.xml,v 1.8 2004/06/23 22:23:15 quipo Exp $ --> <refentry id="package.datetime.calendar.faq"> <refnamediv> <refname>FAQ</refname> @@ -7,69 +7,98 @@ </refpurpose> </refnamediv> <refsect1> - <title>Why doesn't it generate HTML?</title> + <title>Why doesn't it generate HTML?</title> <para> - What if you want WML, SOAP, PDF, GIF, command line, etc. etc.? PEAR::Calendar can be used to - generate any output format you like (see the examples for SOAP and WML). Tying it to a - particular output content type will limit its use (a problem that every public domain PHP - Calendar library I've looked at suffers from). A PEAR::HTML_Calendar is likely to be developed - using PEAR::Calendar. + What if you want WML, SOAP, PDF, GIF, command line, etc. etc.? + PEAR::<classname>Calendar</classname> can be used to generate any output + format you like (see the examples for SOAP and WML). + Tying it to a particular output content type will limit its use + (a problem that every public domain PHP Calendar library I've + looked at suffers from). + A PEAR::HTML_Calendar is likely to be developed using + PEAR::<classname>Calendar</classname>. </para> </refsect1> <refsect1> - <title>There's too many objects, classes and files. It's bloated!</title> + <title>There are too many objects, classes and files. It's bloated!</title> <para> - Running the examples on Sourceforge's servers (which are always overloaded), example 3.php renders in under 0.1 seconds (usually half that). The code is highly optimized and every "trick in the book" has been applied to make sure PHP only parses / executes the subset of logic you need for your specific problem. If in doubt, use <classname>Cache_Lite</classname> to cache the output HTML. + Running the examples on Sourceforge's servers (which are always overloaded), + example 3.php renders in under 0.1 seconds (usually half that). + The code is highly optimized and every "trick in the book" has been + applied to make sure PHP only parses / executes the subset of logic + you need for your specific problem. + If in doubt, use <classname>Cache_Lite</classname> to cache the output HTML. </para> </refsect1> <refsect1> - <title>You use Unix timestamps to calculate the Calendar, which limits the range of years it can generate. Can this be changed?</title> + <title> + You use Unix timestamps to calculate the Calendar, + which limits the range of years it can generate. Can this be changed? + </title> <para> - All calculations are handled by a class implementing the Calendar_Engine interface. The default implemention is based on PHP's <function>date</function> and <function>mktime</function> functions (so Unix timestamps are required for that engine). A second engine exists which uses PEAR::Date. It's slower but overcomes the limit on the range of Unixstamps. To switch between engines use the constant <constant>CALENDAR_ENGINE</constant> e.g. + All calculations are handled by a class implementing the + <classname>Calendar_Engine</classname> interface. + The default implemention is based on PHP's <function>date</function> + and <function>mktime</function> functions (so Unix timestamps are required + for that engine). + A second engine exists which uses PEAR::<classname>Date</classname>. + It's a bit slower but overcomes the limit on the range of Unixstamps. + To switch between engines use the constant <constant>CALENDAR_ENGINE</constant> e.g. <programlisting role="php"> - <![CDATA[ +<![CDATA[ // The default Unix timestamp engine (this definition is not required) // define('CALENDAR_ENGINE', 'UnixTs'); // Switch to PEAR::Date engine define('CALENDAR_ENGINE', 'PearDate'); - ]]> +]]> </programlisting> - Note that the PEAR::Date engine is based on PEAR Date version 1.3 (version 1.3.1beta is missing a required file and will not work). + Note that the <classname>PearDate</classname> engine is based on + PEAR::<classname>Date</classname> version 1.4 or newer. </para> </refsect1> <refsect1> <title>This examples use the English language for days and months. Can this be changed?</title> <para> - PEAR::Calendar only uses base 10 numbers for calculations - the names of months and days of the week and generated as the calendar is being rendered (by you). You should only need to change PHP's locale with <function>setlocale</function> and use the <function>strftime</function> function e.g.; + PEAR::<classname>Calendar</classname> only uses base 10 numbers for calculations + - the names of months and days of the week and generated as the calendar + is being rendered (by you). + You should only need to change PHP's locale with <function>setlocale</function> + and use the <function>strftime</function> function e.g.: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Day = & new Calendar_Day(2003, 10, 23); setlocale (LC_TIME, 'de_DE'); // German echo strftime('%A %d %B %Y', $Day->getTimeStamp()); - ]]> +]]> </programlisting> Note that <classname>Calendar_Decorator_Textual</classname> provides help in generating month and day of week names in a manner which is independent of the Calendar Engine you are using and can be modified with <function>setlocale</function>. </para> </refsect1> <refsect1> - <title>What are EmptyDays?</title> + <title>What are empty days?</title> <para> - PEAR::Calendar makes it easy to render calendars in tabular format (like humans are used to) such as; + PEAR::<classname>Calendar</classname> makes it easy to render calendars + in tabular format (like humans are used to) such as: <literallayout> +<![CDATA[ October 2003 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -20 21 22 23 24 25 26 +20 2122 23 24 25 26 27 28 29 30 31 +]]> </literallayout> - Notice the top left and botton right of this example - these are "EmptyDays". EmptyDays are generated only by two calendar classes: Calendar_Month_Weekdays and Calendar_Week. For example using Calendar_Month_Weekdays; + Notice the top left and botton right of this example - these are "empty days". + Empty days are generated only by two calendar classes: + <classname>Calendar_Month_Weekdays</classname> and <classname>Calendar_Week</classname>. + For example using <classname>Calendar_Month_Weekdays</classname>; <programlisting role="php"> - <![CDATA[ +<![CDATA[ require_once 'Calendar/Month/Weekdays.php'; $Month = & new Calendar_Month_Weekdays(2003, 10); @@ -87,17 +116,33 @@ if ($Day->isLast()) // Check for the end of a week echo "\n"; } - ]]> +]]> </programlisting> - An empty day can still return values, the date it represents being from the previous or next month in the calendar. You may get empty days for <classname>Calendar_Month_Weekdays</classname> and <classname>Calendar_Week</classname>. Using <classname>Calendar_Week</classname>, you will only build 7 days (use <classname>Calendar_Month_Weeks</classname> to build <classname>Calendar_Week</classname> objects), so the <function>isFirst</function> and <function>isLast</function> methods are not applicable. + An empty day can still return values, the date it represents being from + the previous or next month in the calendar. + You may get empty days for <classname>Calendar_Month_Weekdays</classname> + and <classname>Calendar_Week</classname>. + Using <classname>Calendar_Week</classname>, you will only build 7 days + (use <classname>Calendar_Month_Weeks</classname> to build + <classname>Calendar_Week</classname> objects), so the + <function>isFirst</function> and <function>isLast</function> methods are + not applicable. </para> </refsect1> <refsect1> <title>How do I select some dates?</title> <para> - All calendar objects (except <classname>Calendar_Second</classname>, which has no "children") have the method <function>build</function> to build the "children" of that object. For example <classname>Calendar_Year</classname>::<function>build</function> builds <classname>Calendar_Month</classname> objects while <classname>Calendar_Hour</classname>::<function>build</function> builds <classname>Calendar_Minute</classname> objects. You have the option of passing this method an indexed array of Calendar objects which will be used to "select" the matching built children. For example; + All calendar objects (except <classname>Calendar_Second</classname>, + which has no "children") have the method <function>build</function> + to build the "children" of that object. + For example <classname>Calendar_Year</classname>::<function>build</function> + builds <classname>Calendar_Month</classname> objects while + <classname>Calendar_Hour</classname>::<function>build</function> builds + <classname>Calendar_Minute</classname> objects. + You have the option of passing this method an indexed array of Calendar objects + which will be used to "select" the matching built children. For example: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Calendar_Month(2003, 10); // Oct 2003 $SelectedDay1 = & new Calendar_Day(2003, 10, 5); Oct 5th 2003 @@ -112,23 +157,46 @@ if ($Day->isSelected()) echo $Day->thisYear().' '.$Day->thisMonth().' '.$Day->thisDay().' is selected'."\n"; } - ]]> +]]> </programlisting> - <emphasis>Note:</emphasis> date objects you pass to a <function>build</function> method replace the corresponding built date objects, allowing you to do things like attach your own subclass of <classname>Calendar_Decorator</classname> to them, then access the decorating functionality inside the loop which renders the calendar. You might display the contents from an "events database table" using this approach. + <emphasis>Note:</emphasis> the date objects you pass to a + <function>build</function> method replace the corresponding built + date objects, allowing you to do things like attach your own subclass + of <classname>Calendar_Decorator</classname> to them, then access + the decorating functionality inside the loop which renders the calendar. + You might display the contents from an "events database table" using this + approach. </para> </refsect1> <refsect1> - <title>Why do I have to call build() explicitly. Why can't children be built automatically?</title> + <title> + Why do I have to call build() explicitly. Why can't children be + built automatically? + </title> <para> - First and foremost, for performance. Building the children has a performance cost and you won't always need to have the children, so it should be called explicitly, otherwise you might have $Year->build(), expecting to get just months but behind the scenes, months built days, which built hours, which build minutes etc. Also calling <function>build</function> yourself give you a chance to "select" some of the children. + First and foremost, for performance. Building the children has a + performance cost and you won't always need to have the children, + so it should be called explicitly, otherwise you might have $Year->build(), + expecting to get just months but behind the scenes, months built days, + which built hours, which build minutes etc. + Also calling <function>build</function> yourself give you a chance to + "select" some of the children. </para> </refsect1> <refsect1> <title>How do I validate a date?</title> <para> - Validity is determined by the Caalendar_Engine being used as well as the time the date object you're working with represents (e.g. $Month = & new Month(2003, 2, 29); is invalid, because Feb 2003 was not a leap year). For quick validation, you can call the method <function>isValid</function> on any date object, which will return FALSE if there's a problem. For more information of more detailed validation, you can call the method <function>getValidator</function> on any date object, which returns an instance of the class <classname>Calendar_Validator</classname>. For example; + Validity is determined by the Caalendar_Engine being used as well as + the time the date object you're working with represents (e.g. + $Month = & new Month(2003, 2, 29); is invalid, because Feb 2003 was + not a leap year). For quick validation, you can call the method + <function>isValid</function> on any date object, which will return &false; + if there's a problem. For more information of more detailed validation, + you can call the method <function>getValidator</function> on any date object, + which returns an instance of the class <classname>Calendar_Validator</classname>. + For example; <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Month(2003, 2, 29); // 29th Feb 2003 (?!?) if (!$Month->isValid()) { $Validator = & $Month->getValidator(); @@ -136,23 +204,41 @@ echo $Error->toString(); } } - ]]> +]]> </programlisting> - You can also begin validation by calling <function>getValidator</function> then either <function>isValidYear</function>, <function>isValidMonth</function>, <function>isValidDay</function>, <function>isValidHour</function>, <function>isValidMinute</function> and <function>isValidSecond</function> (or just <function>isValid</function> which calls all of the isValidxxx methods). + You can also begin validation by calling <function>getValidator</function> + then either <function>isValidYear</function>, <function>isValidMonth</function>, + <function>isValidDay</function>, <function>isValidHour</function>, + <function>isValidMinute</function> and <function>isValidSecond</function> + (or just <function>isValid</function> which calls all of the isValidxxx methods). </para> </refsect1> <refsect1> <title>Can I adjust invalid dates?</title> <para> - If you're allowing end users to navigate your calendar via the URL, were they to modify the URL to something like calendar.php?year=2003&month=13, instead of throwing a validation error at them, you could call the <classname>Calendar</classname>::<function>adjust</function> method on the calendar object you create with that URL. You should then end up with January 2004 (in this example). This behaviour is possible thanks to <function>mktime</function> for the Unix Timestamp engine, while being built into the PEAR Date engine for you. + If you're allowing end users to navigate your calendar via the URL, + were they to modify the URL to something like calendar.php?year=2003&month=13, + instead of throwing a validation error at them, you could call the + <classname>Calendar</classname>::<function>adjust</function> method on the + calendar object you create with that URL. You should then end up with + January 2004 (in this example). This behaviour is possible thanks to + <function>mktime</function> for the Unix Timestamp engine, while being built + into the <classname>PearDate</classname> engine for you. </para> </refsect1> <refsect1> - <title>After calling build(), I just want to get a single child date object with looping through the lot. How?</title> + <title> + After calling <function>build</function>, I just want to get a single + child date object with looping through the lot. How? + </title> <para> - The method <function>fetchAll</function> can be called on any date object to get an indexed array of all the children which have been built, allowing you to reference them directly. Be careful with the first index of this array - in some cases it will be [1] not [0], depending on the type of date object built. For example; + The method <function>fetchAll</function> can be called on any date object + to get an indexed array of all the children which have been built, + allowing you to reference them directly. Be careful with the first index + of this array - in some cases it will be [1] not [0], depending on the + type of date object built. For example; <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Month = & new Calendar_Month(2003, 10); $Month->build(); @@ -164,20 +250,38 @@ $hours = & $Hour->fetchAll(); // Now all in array echo $hours[0]->thisHour(); // The first hour has index 0 - ]]> +]]> </programlisting> - The following classes are always built to have the first index as 1: <classname>Calendar_Month</classname>, <classname>Calendar_Month_Weekdays</classname>, <classname>Calendar_Month_Weeks</classname>, <classname>Calendar_Week</classname> and <classname>Calendar_Day</classname> - The following classes are always built to have the first index as 0: <classname>Calendar_Hour</classname>, <classname>Calendar_Minute</classname> and <classname>Calendar_Second</classname> - - Note also the method <function>size</function> can be called on any date object, after <function>build</function> has been called, to get the number of children. + The following classes are always built to have the first index as 1: + <classname>Calendar_Month</classname>, + <classname>Calendar_Month_Weekdays</classname>, + <classname>Calendar_Month_Weeks</classname>, + <classname>Calendar_Week</classname> and + <classname>Calendar_Day</classname> + The following classes are always built to have the first index as 0: + <classname>Calendar_Hour</classname>, + <classname>Calendar_Minute</classname> and + <classname>Calendar_Second</classname> + + Note also the method <function>size</function> can be called on any + date object, after <function>build</function> has been called, + to get the number of children. </para> </refsect1> <refsect1> - <title>What does a week actually represent in PEAR::Calendar?</title> + <title>What does a week actually represent in PEAR::<classname>Calendar</classname>?</title> <para> - Weeks are "pseudo" dates. They're useful for formatting the user interface for end users. Weeks are instantiated with a year, a month and a day of the month. You can then have the week tell you its timestamp (which will be the same as the timestamp for the first day in the week), its numeric position within the <emphasis>tabular</emphasis> month (see Empty Days above), its numeric position within the year (this is an ISO-8601 week number of year, weeks starting on Monday) or an array containing the numeric year, month and the first day of the week (as a number within the month). For example; + Weeks are "pseudo" dates. They're useful for formatting the user + interface for end users. Weeks are instantiated with a year, a month + and a day of the month. You can then have the week tell you its timestamp + (which will be the same as the timestamp for the first day in the week), + its numeric position within the <emphasis>tabular</emphasis> month (see + empty days above), its numeric position within the year (this is an ISO-8601 + week number of year, weeks starting on Monday) or an array containing the + numeric year, month and the first day of the week (as a number within the month). + For example: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Week = & new Calendar_Week(2003, 10, 15); $Week = new Calendar_Week(2003, 10, 15); @@ -191,23 +295,35 @@ // (YYYY-MM-DD HH:MM:SS), depending on the engine. print_r $Week->thisWeek('array'); // [year] => 2003 [month] => 10 [day] => 12 - ]]> +]]> </programlisting> </para> </refsect1> <refsect1> - <title>How do I get a Calendar_Year to build Calendar_Month_Weekdays or Calendar_Month_Weeks, instead of the default Calendar_Month objects?</title> + <title> + How do I get a Calendar_Year to build Calendar_Month_Weekdays or + Calendar_Month_Weeks, instead of the default Calendar_Month objects? + </title> <para> - When working with a <classname>Calendar_Year</classname>, the constants <constant>CALENDAR_MONTH_STATE</constant> controls what type of month object is built. You can define <constant>CALENDAR_MONTH_STATE</constant> to <constant>CALENDAR_USE_MONTH_WEEKDAYS</constant> or <constant>CALENDAR_USE_MONTH_WEEKS</constant> for the Calendar_Month_Weekdays and <classname>Calendar_Month_Week</classname> classes, respectively. - </para> + When working with a <classname>Calendar_Year</classname>, the constants + <constant>CALENDAR_MONTH_STATE</constant> controls what type of month + object is built. You can define <constant>CALENDAR_MONTH_STATE</constant> + to <constant>CALENDAR_USE_MONTH_WEEKDAYS</constant> or + <constant>CALENDAR_USE_MONTH_WEEKS</constant> for the + <classname>Calendar_Month_Weekdays</classname> and + <classname>Calendar_Month_Week</classname> classes, respectively. + </para> </refsect1> <refsect1> <title>You use Monday as the start of the week. Can I change that?</title> <para> - Yes. For the classes which are concerned with the notion of a "week", you can can pass a value which defines the first day of the week. For the default timestamp based Calendar engine, this is a number from 0 to 6, 0 being Sunday through to 6 being Saturday. + Yes. For the classes which are concerned with the notion of a "week", + you can can pass a value which defines the first day of the week. + For the default timestamp based Calendar engine, this is a number + from 0 to 6, 0 being Sunday through to 6 being Saturday. This value can be passed to the following: <programlisting role="php"> - <![CDATA[ +<![CDATA[ $Year = new Calendar_Year(2003); $selection = array(); $Year->build($selection, 0); // the second argument is the first day of the week (Sunday) @@ -217,7 +333,7 @@ $MonthWeeks = new Calendar_Month_Weekdays(2003, 10, 2); // Third argument - Tuesday $Week = new Calendar_Week(2003, 10, 15, 5) // Fourth argument - Friday - ]]> +]]> </programlisting> </para> </refsect1> http://cvs.php.net/diff.php/peardoc/en/package/datetime/calendar/intro-decorators.xml?r1=1.6&r2=1.7&ty=u Index: peardoc/en/package/datetime/calendar/intro-decorators.xml diff -u peardoc/en/package/datetime/calendar/intro-decorators.xml:1.6 peardoc/en/package/datetime/calendar/intro-decorators.xml:1.7 --- peardoc/en/package/datetime/calendar/intro-decorators.xml:1.6 Wed Mar 24 10:39:00 2004 +++ peardoc/en/package/datetime/calendar/intro-decorators.xml Wed Jun 23 18:23:15 2004 @@ -1,4 +1,4 @@ -<!-- $Id: intro-decorators.xml,v 1.6 2004/03/24 15:39:00 didou Exp $ --> +<!-- $Id: intro-decorators.xml,v 1.7 2004/06/23 22:23:15 quipo Exp $ --> <refentry id="package.datetime.calendar.intro-decorators"> <refnamediv> <refname>Calendar Decorators</refname> @@ -9,14 +9,23 @@ <refsect1> <title>Calendar Decorators</title> <para> - The <classname>Calendar_Decorator</classname> is provided to allow you to attach - functionality to existing Calendar objects without needing to subclass them. This - helps in a number of situations, such as allowing results from, say, a database - query to be rendered in the calendar or to modify the values returned from Calendar - methods (perhaps converting a numeric month into its textual name).</para> - <para>Some concrete decorators are provided with PEAR::Calendar, to address what may be common problems you encounter in using the library. These are not designed to suit everyone but instead focus on solving a more narrow problem domain. They will only be parsed by the PHP engine should you explicitly include them in your code. An example of why decorators can be useful; + The <classname>Calendar_Decorator</classname> is provided to allow you + to attach functionality to existing Calendar objects without needing + to subclass them. + This helps in a number of situations, such as allowing results from, + say, a database query to be rendered in the calendar or to modify the + values returned from Calendar methods (perhaps converting a numeric month + into its textual name). + </para> + <para> + Some concrete decorators are provided with PEAR::<classname>Calendar</classname>, + to address what may be common problems you encounter in using the library. + These are not designed to suit everyone but instead focus on solving + a more narrow problem domain. + They will only be parsed by the PHP engine should you explicitly include them + in your code. An example of why decorators can be useful: <programlisting role="php"> - <![CDATA[ +<![CDATA[ require_once 'Calendar/Day.php'; require_once 'Calendar/Decorator.php'; @@ -27,17 +36,17 @@ // Overides the default fetch method of the calendar object function fetch() { - if ( $Hour = parent::fetch() ) { + if ($Hour = parent::fetch()) { // Recursive fetch, return only hours between 8am and 6pm - if ( $Hour->thisHour() < 8 || $Hour->thisHour() > 18 ) { + if ($Hour->thisHour() < 8 || $Hour->thisHour() > 18) { return $this->fetch(); } else { return $Hour; } } else { // Make sure to return FALSE when the real fetch returned nothing - // or you'll get an infinite loop + // or you will get an infinite loop return FALSE; } } @@ -51,30 +60,223 @@ $WorkingDay = new WorkingDay($Day); // Only hours in a working day are displayed... -while ( $Hour = $WorkingDay->fetch() ) { - echo ( $Hour->thisHour().'<br>' ); +while ($Hour = $WorkingDay->fetch()) { + echo $Hour->thisHour().'<br />'; } - ]]> +]]> </programlisting> </para> </refsect1> <refsect1> <title>The base Calendar_Decorator</title> <para> - The base class <classname>Calendar_Decorator</classname> "mirrors" the combined - API of all the subclasses of <classname>Calendar</classname>. It accepts a Calendar - object to its constructor then "takes over" the API allowing you to make calls through - it rather than directly to the original calendar object. The - <classname>Calendar_Decorator</classname> simply routes calls through to the calendar - object it is decorating and returns values where appropriate. + The base class <classname>Calendar_Decorator</classname> "mirrors" the + combined API of all the subclasses of <classname>Calendar</classname>. + It accepts a Calendar object to its constructor then "takes over" + the API allowing you to make calls through it rather than directly + to the original calendar object. + The <classname>Calendar_Decorator</classname> simply routes calls + through to the calendar object it is decorating and returns values + where appropriate. </para> </refsect1> <refsect1> <title>Decorators and Date Selection</title> <para> - One important use of decorators is to help "inject" data into the loop which renders the calendar. This helps with fetching data from some sort of "event" table in a database. When passing a selection array to any <function>build</function> method, the selected date objects will replace the default built objects, allowing you to get them back as inside the <function>fetch</function> loop, using the <function>isSelected</function> method. You'll find an example of this in the PEAR::Calendar download. It should always be possible to fetch the event data you need with a single database query... + One important use of decorators is to help "inject" data into the loop + which renders the calendar. This helps with fetching data from some sort + of "event" table in a database. When passing a selection array to any + <function>build</function> method, the selected date objects will replace + the default built objects, allowing you to get them back as inside the + <function>fetch</function> loop, using the <function>isSelected</function> + method. + You'll find an example of this in the PEAR::<classname>Calendar</classname> + download. It should always be possible to fetch the event data you need + with a single database query... </para> </refsect1> + <refsect1> + <title>The bundled Decorators</title> + <para> + PEAR::<classname>Calendar</classname> already provides a few decorators: + <itemizedlist> + <listitem> + <para><classname>Calendar_Decorator_Textual</classname></para> + <para> + Decorator to help with fetching textual representations of months and + days of the week. It has + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Uri</classname></para> + <para> + Decorator to help with building HTML links for navigating the calendar. + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Weekday</classname></para> + <para> + Decorator for fetching the day of the week. + </para> + </listitem> + <listitem> + <para><classname>Calendar_Decorator_Wrapper</classname></para> + <para> + Decorator to help with wrapping built children in another decorator. + </para> + </listitem> + </itemizedlist> + </para> + </refsect1> + <refsect1> + <title>Calendar_Decorator_Textual example</title> + <para> + This decorator defines a few methods that can be useful to handle + month and day names: + <itemizedlist> + <listitem> + <para>monthNames(<parameter>$format</parameter>='long')</para> + <para> + Returns an array with month names; the format of returned months + depends on the <parameter>format</parameter> parameter + (one, two, short or long) + </para> + </listitem> + <listitem> + <para>weekdayNames(<parameter>$format</parameter>='long')</para> + <para> + Returns an array with day names; the format of returned days + depends on the <parameter>format</parameter> parameter + (one, two, short or long) + </para> + </listitem> + <listitem> + <para>prevMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the previous month of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>thisMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the month of the decorated calendar object + </para> + </listitem> + <listitem> + <para>nextMonthName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the next month of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>prevDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the previous day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>thisDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>nextDayName(<parameter>$format</parameter>='long')</para> + <para> + Returns textual representation of the next day of the decorated + calendar object + </para> + </listitem> + <listitem> + <para>orderedWeekdays(<parameter>$format</parameter>='long')</para> + <para> + Returns the days of the week using the order defined in the decorated + calendar object. Only useful for <classname>Calendar_Month_Weekdays</classname>, + <classname>Calendar_Month_Weeks</classname> and <classname>Calendar_Week</classname>. + Otherwise the returned array will begin on Sunday. + </para> + </listitem> + + </itemizedlist> + </para> + </refsect1> + <refsect1> + <title>Calendar_Decorator_Uri example</title> + <para> + Methods defined by this decorator: + <itemizedlist> + <listitem> + <para>setFragments($y, $m=null, $d=null, $h=null, $i=null, $s=null)</para> + <para> + Set the names of the URI vars for each date element + </para> + </listitem> + <listitem> + <para>setSeparator(<parameter>$separator</parameter>)</para> + <para> + Set the fragments separator, for instance '/' (default: &). + </para> + </listitem> + <listitem> + <para>setScalar(boolean <parameter>$state</parameter>=&true;)</para> + <para> + Puts Uri decorator into "scalar mode" - URI variable names are not returned + </para> + </listitem> + <listitem> + <para>prev(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the previous calendar unit (year, month, week or day etc) + </para> + </listitem> + <listitem> + <para>this(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the current calendar unit (year, month, week or day etc) + </para> + </listitem> + <listitem> + <para>next(<parameter>$method</parameter>)</para> + <para> + Gets the URI string for the next calendar unit (year, month, week or day etc) + </para> + </listitem> + </itemizedlist> + </para> + + <para> + A simple usage example: + <programlisting role="php"> +<![CDATA[ +$Day = new Calendar_Day(2003, 10, 23); +$Uri = & new Calendar_Decorator_Uri($Day); +$Uri->setFragments('year', 'month', 'day'); +echo $Uri->getPrev(); +// Displays year=2003&month=10&day=22 +]]> + </programlisting> + </para> + </refsect1> + + <refsect1> + <title>Calendar_Decorator_Uri example</title> + <para> + + </para> + </refsect1> + + <refsect1> + <title>Calendar_Decorator_Wrapper example</title> + <para> + + </para> + </refsect1> + + </refentry> <!-- Keep this comment at the end of the file Local variables: