Skip to content

Commit

Permalink
Adding Alarm feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisMorel committed Oct 1, 2013
1 parent 4aab7ed commit cc60305
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
63 changes: 63 additions & 0 deletions Model/Alarm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace BOMO\IcalBundle\Model;

class Alarm
{
/**
* vAlarm object
*/
private $alarm;

public function __construct($param)
{
if (is_array($param)) {
$this->alarm = new \valarm($param);

} elseif ($param instanceOf \valarm) {
$this->alarm = $param;

} else {
throw new InvalidArgumentException('Invalid constructor parameter');

}

}

public function setAction($action)
{
switch($action) {
case 'display':
$this->alarm->setProperty('description', 'Need to be setted');
$this->alarm->setProperty('trigger', '-PT1H', array('VALUE' => 'DURATION'));
break;

default:
throw new \InvalidArgumentException('Only [display] options are available');
break;
}

$this->alarm->setProperty('action', $action);

return $this;
}

public function setDescription($desc)
{
$this->alarm->setProperty('description', $desc);

return $this;
}

public function setTrigger($str)
{
$this->alarm->setProperty('trigger', $str, array('VALUE' => 'DURATION'));

return $this;
}

public function getAlarm()
{
return $this->alarm;
}
}
17 changes: 17 additions & 0 deletions Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ public function setOrganizer($organizer)
return $this;
}

public function newAlarm()
{
return new Alarm($this->event->newComponent('valarm'), $this->event);
}

public function attachAlarm(Alarm $alarm)
{
$this->event->setComponent($alarm->getAlarm());

return $this;
}

public function getProperty($prop)
{
return $this->event->getProperty($prop);
}

public function getEvent()
{
return $this->event;
Expand Down
8 changes: 7 additions & 1 deletion Provider/IcsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


use BOMO\IcalBundle\Model\Calendar,
BOMO\IcalBundle\Model\Event
BOMO\IcalBundle\Model\Event,
BOMO\IcalBundle\Model\Alarm
;

class IcsProvider
Expand Down Expand Up @@ -42,4 +43,9 @@ public function createEvent()
{
return new Event($this->config);
}

public function createAlarm()
{
return new Alarm($this->config);
}
}

0 comments on commit cc60305

Please sign in to comment.