Skip to content

Commit

Permalink
Merge pull request #43 from wa7eedem/laravel-4-edit
Browse files Browse the repository at this point in the history
Add options to laravel-4
  • Loading branch information
maddhatter authored Nov 1, 2016
2 parents 6987364 + b1491a0 commit 94b331b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.phar
composer.lock
.DS_Store
.idea/
8 changes: 5 additions & 3 deletions src/MaddHatter/LaravelFullcalendar/Calendar.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace MaddHatter\LaravelFullcalendar;

use ArrayAccess;
use DateTime;
use Illuminate\View\Factory;

Expand Down Expand Up @@ -66,11 +67,13 @@ public function __construct(Factory $view, EventCollection $eventCollection)
* @param string $isAllDay
* @param string|DateTime $start If string, must be valid datetime format: http://bit.ly/1z7QWbg
* @param string|DateTime $end If string, must be valid datetime format: http://bit.ly/1z7QWbg
* @param string $id event Id
* @param array $options
* @return SimpleEvent
*/
public static function event($title, $isAllDay, $start, $end)
public static function event($title, $isAllDay, $start, $end, $id = null, $options = [])
{
return new SimpleEvent($title, $isAllDay, $start, $end);
return new SimpleEvent($title, $isAllDay, $start, $end, $id, $options);
}

/**
Expand Down Expand Up @@ -224,7 +227,6 @@ protected function getOptionsJson()
}

return $json;

}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/MaddHatter/LaravelFullcalendar/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,25 @@ public function toArray()

private function convertToArray(Event $event, array $customAttributes = [])
{
return array_merge([
$eventArray = [
'id' => $this->getEventId($event),
'title' => $event->getTitle(),
'allDay' => $event->isAllDay(),
'start' => $event->getStart()->format('c'),
'end' => $event->getEnd()->format('c'),
], $customAttributes);
];

$eventOptions = method_exists($event, 'getEventOptions') ? $event->getEventOptions() : [];

return array_merge($eventArray, $eventOptions, $customAttributes);
}

private function getEventId(Event $event)
{
if ($event instanceof IdentifiableEvent) {
return $event->getId();
}
return null;
}

}
36 changes: 35 additions & 1 deletion src/MaddHatter/LaravelFullcalendar/SimpleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
class SimpleEvent implements Event
{

/**
* @var string|int|null
*/
public $id;

/**
* @var
*/
Expand All @@ -32,18 +37,37 @@ class SimpleEvent implements Event
*/
public $end;

/**
* @var array
*/
private $options;

/**
* @param string $title
* @param bool $isAllDay
* @param string|DateTime $start If string, must be valid datetime format: http://bit.ly/1z7QWbg
* @param string|DateTime $end If string, must be valid datetime format: http://bit.ly/1z7QWbg
* @param int|string|null $id
* @param array $options
*/
public function __construct($title, $isAllDay, $start, $end)
public function __construct($title, $isAllDay, $start, $end, $id = null, $options = [])
{
$this->title = $title;
$this->isAllDay = $isAllDay;
$this->start = $start instanceof DateTime ? $start : new DateTime($start);
$this->end = $start instanceof DateTime ? $end : new DateTime($end);
$this->id = $id;
$this->options = $options;
}

/**
* Get the event's id number
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
Expand Down Expand Up @@ -85,4 +109,14 @@ public function getEnd()
{
return $this->end;
}

/**
* Get the optional event options
*
* @return array
*/
public function getEventOptions()
{
return $this->options;
}
}

0 comments on commit 94b331b

Please sign in to comment.