ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilICalParser Class Reference
+ Collaboration diagram for ilICalParser:

Public Member Functions

 __construct ($a_ical, $a_type)
 Constructor.
 setCategoryId ($a_id)
 set category id
 parse ()
 Parse input.

Data Fields

const INPUT_STRING = 1
const INPUT_FILE = 2

Protected Member Functions

 getContainer ()
 get container
 setContainer ($a_container)
 set container
 dropContainer ()
 pop la
 pushContainer ($a_container)
 push container
 parseLine ($line)
 parse a line
 storeItems ($a_param_part, $a_value_part)
 store items
 splitLine ($a_line)
 parse parameters
 tokenize ($a_string, $a_tokenizer)
 tokenize string
 getTZ ($a_timezone)
 get timezone
 switchTZ (ilTimeZone $timezone)
 Switch timezone.
 restoreTZ ()
 restore time
 writeEvent ()
 write a new event
 purgeString ($a_string)
 purge string

Protected Attributes

 $log = null
 $category = null
 $ical = ''
 $file = ''
 $default_timezone = null
 $container = array()

Detailed Description

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

/

Definition at line 43 of file class.ilICalParser.php.

Constructor & Destructor Documentation

ilICalParser::__construct (   $a_ical,
  $a_type 
)

Constructor.

public

Parameters
stringical string

Definition at line 65 of file class.ilICalParser.php.

References $ilLog.

{
global $ilLog;
if($a_type == self::INPUT_STRING)
{
$this->ical = $a_ical;
}
elseif($a_type == self::INPUT_FILE)
{
$this->file = $a_ical;
$this->ical = file_get_contents($a_ical);
}
$this->log = $ilLog;
}

Member Function Documentation

ilICalParser::dropContainer ( )
protected

pop la

protected

Definition at line 152 of file class.ilICalParser.php.

Referenced by parseLine(), and storeItems().

{
return array_pop($this->container);
}

+ Here is the caller graph for this function:

ilICalParser::getContainer ( )
protected

get container

protected

Definition at line 131 of file class.ilICalParser.php.

Referenced by parseLine(), storeItems(), and writeEvent().

{
return $this->container[count($this->container) - 1];
}

+ Here is the caller graph for this function:

ilICalParser::getTZ (   $a_timezone)
protected

get timezone

protected

Definition at line 356 of file class.ilICalParser.php.

References $default_timezone, and ilTimeZone\_getInstance().

Referenced by parseLine(), and writeEvent().

{
$parts = explode('/',$a_timezone);
$tz = array_pop($parts);
$continent = array_pop($parts);
if(isset($continent) and $continent)
{
$timezone = $continent.'/'.$tz;
}
else
{
$timezone = $a_timezone;
}
try
{
if($this->default_timezone->getIdentifier() == $timezone)
{
}
else
{
$this->log->write(__METHOD__.': Found new timezone: '.$timezone);
return ilTimeZone::_getInstance($timezone);
}
}
{
$this->log->write(__METHOD__.': Found invalid timezone: '.$timezone);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilICalParser::parse ( )

Parse input.

public

Definition at line 100 of file class.ilICalParser.php.

References ilTimeZone\_getInstance(), ilICalUtils\ICAL_EOL, ilICalUtils\ICAL_SPACE, ilICalUtils\ICAL_TAB, parseLine(), and tokenize().

{
$this->default_timezone = ilTimeZone::_getInstance();
$lines = $this->tokenize($this->ical,ilICalUtils::ICAL_EOL);
for($i = 0; $i < count($lines); $i++)
{
$line = $lines[$i];
// Check for next multilines (they start with a space)
$offset = 1;
while(isset($lines[$i + $offset]) and
(strpos($lines[$i + $offset],ilICalUtils::ICAL_SPACE) === 0) or
(strpos($lines[$i + $offset],ilICalUtils::ICAL_TAB) === 0))
{
$lines[$i + $offset] = str_replace(ilICalUtils::ICAL_EOL,'',$lines[$i + $offset]);
$line = $line.substr($lines[$i + $offset],1);
$offset++;
}
$i += ($offset - 1);
// Parse this line
$this->parseLine($line);
}
}

+ Here is the call graph for this function:

ilICalParser::parseLine (   $line)
protected

parse a line

protected

Definition at line 174 of file class.ilICalParser.php.

References $container, dropContainer(), getContainer(), getTZ(), pushContainer(), setContainer(), splitLine(), storeItems(), and writeEvent().

Referenced by parse().

{
switch(trim($line))
{
case 'BEGIN:VCALENDAR':
$this->log->write(__METHOD__.': BEGIN VCALENDAR');
$this->setContainer(new ilICalComponent('VCALENDAR'));
break;
case 'END:VCALENDAR':
$this->log->write(__METHOD__.': END VCALENDAR');
break;
case 'BEGIN:VEVENT':
$this->log->write(__METHOD__.': BEGIN VEVENT');
$this->pushContainer(new ilICalComponent('VEVENT'));
break;
case 'END:VEVENT':
$this->log->write(__METHOD__.': END VEVENT');
$this->writeEvent();
$this->dropContainer();
break;
case 'BEGIN:VTIMEZONE':
$this->log->write(__METHOD__.': BEGIN VTIMEZONE');
$container = new ilICalComponent('VTIMEZONE');
break;
case 'END:VTIMEZONE':
$this->log->write(__METHOD__.': END VTIMEZONE');
if($tzid = $this->getContainer()->getItemsByName('TZID'))
{
$this->default_timezone = $this->getTZ($tzid[0]->getValue());
}
$this->dropContainer();
break;
default:
if(strpos(trim($line),'BEGIN') === 0)
{
$this->log->write(__METHOD__.': Do not handling line:'.$line);
continue;
}
list($params,$values) = $this->splitLine($line);
$this->storeItems($params,$values);
break;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilICalParser::purgeString (   $a_string)
protected

purge string

protected

Definition at line 610 of file class.ilICalParser.php.

References ilUtil\stripSlashes().

Referenced by writeEvent().

{
$a_string = str_replace("\;",";",$a_string);
$a_string = str_replace("\,",",",$a_string);
$a_string = str_replace("\:",":",$a_string);
return ilUtil::stripSlashes($a_string);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilICalParser::pushContainer (   $a_container)
protected

push container

protected

Parameters
ilICalItem

Definition at line 163 of file class.ilICalParser.php.

Referenced by parseLine(), and storeItems().

{
$this->container[] = $a_container;
}

+ Here is the caller graph for this function:

ilICalParser::restoreTZ ( )
protected

restore time

protected

Definition at line 414 of file class.ilICalParser.php.

{
$this->default_timezone->restoreTZ();
}
ilICalParser::setCategoryId (   $a_id)

set category id

public

Parameters
intcategory id
Returns

Definition at line 88 of file class.ilICalParser.php.

{
include_once('./Services/Calendar/classes/class.ilCalendarCategory.php');
$this->category = new ilCalendarCategory($a_id);
}
ilICalParser::setContainer (   $a_container)
protected

set container

protected

Parameters
ilICalItem

Definition at line 142 of file class.ilICalParser.php.

Referenced by parseLine().

{
$this->container = array($a_container);
}

+ Here is the caller graph for this function:

ilICalParser::splitLine (   $a_line)
protected

parse parameters

protected

Parameters
stringa line

Definition at line 325 of file class.ilICalParser.php.

Referenced by parseLine().

{
$matches = array();
if(preg_match('/([^:]+):(.*)/',$a_line,$matches))
{
return array($matches[1],$matches[2]);
}
else
{
$this->log->write(__METHOD__.': Found invalid parameter: '.$a_line);
}
return array('','');
}

+ Here is the caller graph for this function:

ilICalParser::storeItems (   $a_param_part,
  $a_value_part 
)
protected

store items

protected

Definition at line 234 of file class.ilICalParser.php.

References dropContainer(), getContainer(), and pushContainer().

Referenced by parseLine().

{
// Check for a semicolon in param part and split it.
$items = array();
if($splitted_param = explode(';',$a_param_part))
{
$counter = 0;
foreach($splitted_param as $param)
{
if(!$counter)
{
$items[$counter]['param'] = $param;
$items[$counter]['value'] = $a_value_part;
}
else
{
// Split by '='
if($splitted_param_values = explode('=',$param))
{
$items[$counter]['param'] = $splitted_param_values[0];
$items[$counter]['value'] = $splitted_param_values[1];
}
}
++$counter;
}
}
// Split value part
$substituted_values = str_replace('\;','',$a_value_part);
$values = array();
if($splitted_values = explode(';',$substituted_values))
{
$counter = 0;
foreach($splitted_values as $value)
{
// Split by '='
if($splitted_value_values = explode('=',$value))
{
$values[$counter]['param'] = $splitted_value_values[0];
$values[$counter]['value'] = $splitted_value_values[1];
}
++$counter;
}
}
// Return if there are no values
if(!count($items))
{
$this->log->write(__METHOD__.': Cannot parse parameter: '.$a_param_part.', value: '.$a_value_part);
return false;
}
$counter = 0;
foreach($items as $item)
{
if(!$counter)
{
// First is ical-Parameter
$parameter = new ilICalProperty($item['param'],$item['value']);
$this->getContainer()->addItem($parameter);
$this->pushContainer($parameter);
if(count($values) > 1)
{
foreach($values as $value)
{
$value = new ilICalValue($value['param'],$value['value']);
$this->getContainer()->addItem($value);
}
}
}
else
{
$value = new ilICalParameter($item['param'],$item['value']);
$this->getContainer()->addItem($value);
}
++$counter;
}
$this->dropContainer();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilICalParser::switchTZ ( ilTimeZone  $timezone)
protected

Switch timezone.

protected

Definition at line 396 of file class.ilICalParser.php.

References ilTimeZone\switchTZ().

{
try
{
$timezone->switchTZ();
}
{
$this->log->write(__METHOD__.': Found invalid timezone: '.$timezone);
return false;
}
}

+ Here is the call graph for this function:

ilICalParser::tokenize (   $a_string,
  $a_tokenizer 
)
protected

tokenize string

protected

Definition at line 346 of file class.ilICalParser.php.

Referenced by parse().

{
return explode($a_tokenizer,$a_string);
}

+ Here is the caller graph for this function:

ilICalParser::writeEvent ( )
protected

write a new event

protected

Definition at line 424 of file class.ilICalParser.php.

References $default_timezone, ilCalendarCategoryAssignments\addAssignment(), getContainer(), getTZ(), IL_CAL_DATE, IL_CAL_DATETIME, and purgeString().

Referenced by parseLine().

{
$entry = new ilCalendarEntry();
// Search for summary
foreach($this->getContainer()->getItemsByName('SUMMARY',false) as $item)
{
if(is_a($item,'ilICalProperty'))
{
$entry->setTitle($this->purgeString($item->getValue()));
break;
}
}
// Search description
foreach($this->getContainer()->getItemsByName('DESCRIPTION',false) as $item)
{
if(is_a($item,'ilICalProperty'))
{
$entry->setDescription($this->purgeString($item->getValue()));
break;
}
}
// Search location
foreach($this->getContainer()->getItemsByName('LOCATION',false) as $item)
{
if(is_a($item,'ilICalProperty'))
{
$entry->setLocation($this->purgeString($item->getValue()));
break;
}
}
foreach($this->getContainer()->getItemsByName('DTSTART') as $start)
{
$fullday = false;
foreach($start->getItemsByName('VALUE') as $type)
{
if($type->getValue() == 'DATE')
{
$fullday = true;
}
}
foreach($start->getItemsByName('TZID') as $param)
{
$start_tz = $this->getTZ($param->getValue());
}
if($fullday)
{
$start = new ilDate($start->getValue(),
}
else
{
$start = new ilDateTime($start->getValue(),
$start_tz->getIdentifier());
}
$entry->setStart($start);
$entry->setFullday($fullday);
}
foreach($this->getContainer()->getItemsByName('DTEND') as $end)
{
$fullday = false;
foreach($end->getItemsByName('VALUE') as $type)
{
if($type->getValue() == 'DATE')
{
$fullday = true;
}
}
foreach($end->getItemsByName('TZID') as $param)
{
$end_tz = $this->getTZ($param->getValue());
}
if($fullday)
{
$end = new ilDate($end->getValue(),
}
else
{
$end = new ilDateTime($end->getValue(),
$end_tz->getIdentifier());
}
$entry->setEnd($end);
$entry->setFullday($fullday);
}
// save calendar event
$entry->save();
include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
$ass = new ilCalendarCategoryAssignments($entry->getEntryId());
$ass->addAssignment($this->category->getCategoryID());
// Recurrences
foreach($this->getContainer()->getItemsByName('RRULE') as $recurrence)
{
#var_dump("<pre>",$recurrence,"</pre>");
include_once('./Services/Calendar/classes/class.ilCalendarRecurrence.php');
$rec = new ilCalendarRecurrence();
$rec->setEntryId($entry->getEntryId());
foreach($recurrence->getItemsByName('FREQ') as $freq)
{
switch($freq->getValue())
{
case 'DAILY':
case 'WEEKLY':
case 'MONTHLY':
case 'YEARLY':
$rec->setFrequenceType($freq->getValue());
break;
default:
$this->log->write(__METHOD__.': Cannot handle recurring event of type: '.$freq->getValue());
break 3;
}
}
foreach($recurrence->getItemsByName('COUNT') as $value)
{
$rec->setFrequenceUntilCount($value->getValue());
break;
}
foreach($recurrence->getItemsByName('UNTIL') as $until)
{
$rec->setFrequenceUntilDate(new ilDate($until->getValue(),IL_CAL_DATE));
break;
}
foreach($recurrence->getItemsByName('INTERVAL') as $value)
{
$rec->setInterval($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYDAY') as $value)
{
$rec->setBYDAY($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYWEEKNO') as $value)
{
$rec->setBYWEEKNO($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYMONTH') as $value)
{
$rec->setBYMONTH($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYMONTHDAY') as $value)
{
$rec->setBYMONTHDAY($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYYEARDAY') as $value)
{
$rec->setBYYEARDAY($value->getValue());
break;
}
foreach($recurrence->getItemsByName('BYSETPOS') as $value)
{
$rec->setBYSETPOS($value->getValue());
break;
}
foreach($recurrence->getItemsByName('WKST') as $value)
{
$rec->setWeekstart($value->getValue());
break;
}
$rec->save();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilICalParser::$category = null
protected

Definition at line 50 of file class.ilICalParser.php.

ilICalParser::$container = array()
protected

Definition at line 56 of file class.ilICalParser.php.

Referenced by parseLine().

ilICalParser::$default_timezone = null
protected

Definition at line 54 of file class.ilICalParser.php.

Referenced by getTZ(), and writeEvent().

ilICalParser::$file = ''
protected

Definition at line 53 of file class.ilICalParser.php.

ilICalParser::$ical = ''
protected

Definition at line 52 of file class.ilICalParser.php.

ilICalParser::$log = null
protected

Definition at line 48 of file class.ilICalParser.php.

const ilICalParser::INPUT_FILE = 2

Definition at line 46 of file class.ilICalParser.php.

const ilICalParser::INPUT_STRING = 1

Definition at line 45 of file class.ilICalParser.php.


The documentation for this class was generated from the following file: