### Select Components by Date Source: https://kigkonsult.se/iCalcreator/index.php Selects calendar components that occur on a specific date, including those with recurrence patterns. It iterates through the selected events to access properties like start time, summary, and description. ```php // select components occurring today // (including components with recurrence pattern) $eventArray = $calendar->selectComponents(); foreach( $eventArray as $year => $yearArray) { foreach( $yearArray as $month => $monthArray ) { foreach( $monthArray as $day => $dailyEventsArray ) { foreach( $dailyEventsArray as $vevent ) { // if event is a member of a recurrence set $currddate = $event->getProperty( Vcalendar::X_CURRENT_DTSTART ); // returns [ // "x-current-dtstart" // , (string) date( // "Y-m-d [H:i:s][timezone/UTC offset]" ) // ] // orig. dtstart $dtstart = $vevent->getDtstart(); $summary = $vevent->getSummary(); $description = $vevent->getDescription(); .. . .. . } } } } ``` -------------------------------- ### Select Components by Property Value Source: https://kigkonsult.se/iCalcreator/index.php Selects calendar components based on specific property values such as CATEGORIES. This allows filtering events that match certain criteria. The example filters for components with 'course1' in their categories. ```php // selects components // based on specific property value(-s) // ATTENDEE, CATEGORIES, CONTACT, // LOCATION, ORGANIZER, // PRIORITY, RESOURCES, STATUS, // SUMMARY, URL, UID $selectSpec = [ Vcalendar::CATEGORIES => "course1" ]; $specComps = $calendar->selectComponents( $selectSpec ); foreach( $specComps as $comp ) { .. . } ``` -------------------------------- ### Edit Calendar Components Source: https://kigkonsult.se/iCalcreator/index.php Iterates through calendar events, retrieves specific properties like UID, start time, and description, and allows for modification or deletion of properties such as attendees. The UID is crucial for updating components. ```php // read events, one by one while( $vevent = $calendar->getComponent( Vcalendar::VEVENT )) { // uid (unique id/key for component), required, one occurrence $uid = $vevent->getUid(); // dtstart required, one occurrence $dtstart = $vevent->getDtstart(); // opt. (first) description if( false !== ( $description = $vevent->getDescription())) { // edit the description // update/replace the (first) description $vevent->setDescription( $description ); } // get optional comments while( $comment = $vevent->getComment()) { .. . } // remove all ATTENDEE properties .. . while( $vevent->deleteAttendee()) { continue; } // update/replace event in calendar // with UID as key $calendar->setComponent ( $vevent, $uid ); } ``` -------------------------------- ### Create an iCalendar Event with iCalcreator Source: https://kigkonsult.se/iCalcreator/index.php This snippet demonstrates how to create a new iCalendar object, set event details like start/end times, location, summary, and description, and add an alarm. It also shows how to create an all-day event with a recurrence rule and parse additional properties from a string. ```php namespace Kigkonsult\Icalcreator; // define time zone $tz = "Europe/Stockholm"; // set Your unique id, // required if any component UID is missing $config = [ Vcalendar::UNIQUE_ID => "kigkonsult.se", // opt. set "calendar" timezone Vcalendar::TZID => $tz ]; // create a new calendar object instance $calendar = new Vcalendar( $config ); // required of some calendar software $calendar->setMethod( "PUBLISH" ); $calendar->setXprop( "x-wr-calname", "Calendar Sample" ); $calendar->setXprop( "X-WR-CALDESC", "Calendar Description" ); $calendar->setXprop( "X-WR-TIMEZONE", $tz ); // create an calendar event component $vevent = $calendar->newVevent(); // set event start $vevent->setDtstart( new DateTime( '2017-04-01 19:00:00' ), new DateTimezone( $tz ) ); // set event end $vevent->setDtend( new DateTime( '2017-04-01 22:30:00'), new DateTimezone( $tz ) ); $vevent->setLocation( "Central Placa" ); $vevent->setSummary( "PHP summit" ); $vevent->setDescription( "This is a description" ); $vevent->setComment( "This is a comment" ); $vevent->setAttendee( "attendee1@icaldomain.net" ); // create an event alarm $valarm = $vevent->newValarm(); $valarm->setAction( Vcalendar::DISPLAY ); // reuse the event description $valarm->setDescription( $vevent->getProperty( Vcalendar::DESCRIPTION )); // create alarm trigger (in UTC datetime) $valarm->setTrigger( new DateTime( "2017-04-01 08:00:00 UTC")); // create another calendar event component $vevent = $calendar->newVevent(); // alt. date format, here for an all-day event $vevent->setDtstart( "20170401", [ Vcalendar::VALUE => Vcalendar::DATE ] ); $vevent->setOrganizer( "boss@icaldomain.com" ); $vevent->setSummary( "ALL-DAY event" ); $vevent->setDescription( "An all-day event" ); $vevent->setResources( "Full attension" ); // weekly, four occasions $vevent->setRRule( [ Vcalendar::FREQ => Vcalendar::WEEKLY, Vcalendar::COUNT => 4 ] ); // supporting parse of strict rfc5545 formatted text $vevent->parse( "LOCATION:1CP Conference Room 4350" ); // all calendar components are described in rfc5545 // a complete iCalcreator function list (ex. setProperty) in // iCalcreator manual $calendarString = $vcalendar // apply appropriate Vtimezone with Standard/DayLight components ->vtimezonePopulate() // and create the (string) calendar ->createCalendar(); ``` -------------------------------- ### Create and Parse iCalendar Data Source: https://kigkonsult.se/iCalcreator/index.php Initializes a new Vcalendar instance, parses iCal content from a file, and sets calendar properties. Ensure the calendar.ics file exists in the correct path. ```php // create a new Vcalendar instance $calendar = new Vcalendar( [ Vcalendar::UNIQUE_ID => "kigkonsult.se" ] ); // get iCal contents from file $iCalContent = file_get_contents( "calendar.ics" ); // parse iCal contents $calendar->parse( $iCalContent ) $calendar->setMethod( Vcalendar::PUBLISH ); $calendar->setXprop( Vcalendar::X_WR_CALNAME, "Calendar Sample" ); $calendar->setXprop( Vcalendar::X_WR_CALDESC, "Calendar Description" ); $calendar->setXprop( Vcalendar::X_WR_TIMEZONE, "Europe/Stockholm" ); ``` -------------------------------- ### Initialize iCalcreator Calendar Instance Source: https://kigkonsult.se/iCalcreator/index.php This snippet shows how to create a new iCalcreator calendar instance, setting a unique ID for the calendar. This is a prerequisite for parsing or manipulating calendar data. ```php // set the (site) unique id, // required if any component UID is missing!! $config = [ Vcalendar::UNIQUE_ID => "kigkonsult.se" ]; // create a new **calendar** instance $calendar = new vcalendar( $config ); ``` -------------------------------- ### Create RFC6321 XML String Source: https://kigkonsult.se/iCalcreator/index.php Generates a well-formed XML string compliant with RFC6321 from a calendar object. This is useful for interoperability with systems that consume XML calendar data. ```php $xmlstr = Kigkonsult\Icalcreator\Util\IcalXMLFactory::iCal2XML( $calendar); ``` -------------------------------- ### Save Calendar to File Source: https://kigkonsult.se/iCalcreator/index.php Saves the generated calendar data to an .ics file. Ensure the file path is writable. ```php $calendarStr = $calendar->createCalendar(); // Save string as file file_put_contents( "calendar.ics", $calendarStr ); ``` -------------------------------- ### Return Calendar to Browser Source: https://kigkonsult.se/iCalcreator/index.php Outputs the generated iCalendar data directly to the browser, typically for downloading as an .ics file. The script execution is then terminated. ```php $calendar->returnCalendar(); exit(); ``` -------------------------------- ### Parse iCal Content from File Source: https://kigkonsult.se/iCalcreator/index.php This code demonstrates how to read iCalendar data from a local file and parse it into an iCalcreator object. This is useful for processing existing .ics files. ```php // get iCal contents from file $iCalContent = file_get_contents( "calendar.ics" ); // parse iCal contents $vcalendar->parse( $iCalContent ); // continue process (edit, parse, select) $calendar ... ``` -------------------------------- ### Create Calendar as String Source: https://kigkonsult.se/iCalcreator/index.php Generates the iCalendar data as a string representation of the current calendar object. This is useful for saving the calendar to a file or sending it via an API. ```php $calendarStr = $calendar->createCalendar(); ``` -------------------------------- ### Parse Remote iCalendar Content Source: https://kigkonsult.se/iCalcreator/index.php Initializes a Vcalendar instance and parses iCal content fetched from a remote URL using UrlRsrc::getContent. This is useful for integrating external calendar feeds. ```php // create a new calendar object instance $calendar = new Vcalendar( [ Vcalendar::UNIQUE_ID => "kigkonsult.se" ] ); // iCalcreator also support remote files $url = "http://www.ical.net/calendars/calendar.ics"; $iCalContent = UrlRsrc::getContent( $url ); $calendar->parse( $iCalContent ); // required of some calendar software $calendar->setMethod( Vcalendar::PUBLISH ); $calendar->setXprop( Vcalendar::X_WR_CALNAME, "Calendar Sample" ); $calendar->setXprop( Vcalendar::X_WR_CALDESC, "Calendar Description" ); $calendar->setXprop( Vcalendar::X_WR_TIMEZONE, "Europe/Stockholm" ); ``` -------------------------------- ### Parse xCal (XML) Content to iCalcreator Object Source: https://kigkonsult.se/iCalcreator/index.php This snippet illustrates how to parse xCal (XML format) data into an iCalcreator object. It includes error handling for XML parsing and requires the IcalXMLFactory utility. ```php use Kigkonsult\Icalcreator\Vcalendar; use Kigkonsult\Icalcreator\Util\IcalXMLFactory; // set Your unique id, // site info for the Vcalendar PRODID property $config = [ Vcalendar::UNIQUE_ID => "kigkonsult.se" ]; // use a local or remote xCal file $filename = "xmlfile.xml"; // get XML contents from file $iCalContent = file_get_contents( $filename ); // parse the XML contents to Vcalendar class instance try { $calendar = IcalXMLFactory::XML2iCal( $iCalContent, $config ); } catch( Exception $e ) { exit( "XML parse error" ); } // continue process (edit, parse, select) $calendar ... ... ``` -------------------------------- ### Create JSON String from Calendar Source: https://kigkonsult.se/iCalcreator/index.php Converts a calendar object to an XML string and then parses it into a JSON string. This allows for easy consumption of calendar data in JavaScript-heavy applications or APIs. ```php $xmlstr = Kigkonsult\Icalcreator\Util\IcalXMLFactory::iCal2XML( $calendar); $json = json_encode( simplexml_load_string( $xmlstr )); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.