diff --git a/source/_includes/talk/events.html.twig b/source/_includes/talk/events.html.twig
index c3993f336..a13b6fce2 100644
--- a/source/_includes/talk/events.html.twig
+++ b/source/_includes/talk/events.html.twig
@@ -2,7 +2,7 @@
Events
{% include "talks-table" with {
- talks: { talks: [page], event_data: site.events }|all_talks|reverse,
+ talks: { talks: [page], event_data: site.events }|all_talks,
talk_page: true
} %}
diff --git a/source/_includes/talks-table-row.html.twig b/source/_includes/talks-table-row.html.twig
index 9eac5be3a..f0cfed625 100644
--- a/source/_includes/talks-table-row.html.twig
+++ b/source/_includes/talks-table-row.html.twig
@@ -20,7 +20,11 @@
{% endif %}
- {{ row.event.type|default('Talk') }}
+ {% if row.talk.type %}
+ {{ row.talk.type }}
+ {% else %}
+ {{ row.event.type|default('Talk') }}
+ {% endif %}
{% endif %}
diff --git a/source/_talks/using-laravel-collections-outside-laravel.md b/source/_talks/using-laravel-collections-outside-laravel.md
new file mode 100644
index 000000000..f8b058efb
--- /dev/null
+++ b/source/_talks/using-laravel-collections-outside-laravel.md
@@ -0,0 +1,11 @@
+---
+title: Using Laravel Collections outside Laravel
+slides:
+ url: ~
+ embed: ~
+tags: [nomad-php, lightning-talk, laravel, collections]
+type: Lightning talk
+events:
+ - { event: nomad-php, date: '2017-12-21', 'time': 19:00 CET }
+---
+Laravel Collections are a powerful object-orientated way of interacting with PHP arrays, but did you know that they can be used outside of Laravel, in any PHP project? This short talk shows how we can use Composer to include Laravel Collections within a non-Laravel project and put them to use within your own code.
diff --git a/src/FormatTalksBundle/Twig/FormatTalksExtension.php b/src/FormatTalksBundle/Twig/FormatTalksExtension.php
index 28147a090..effcab786 100644
--- a/src/FormatTalksBundle/Twig/FormatTalksExtension.php
+++ b/src/FormatTalksBundle/Twig/FormatTalksExtension.php
@@ -41,7 +41,7 @@ class FormatTalksExtension extends Twig_Extension
*/
public function getAll(array $data)
{
- return $this->sort($this->format($data));
+ return $this->format($data)->sortBy('event.date');
}
/**
@@ -55,9 +55,9 @@ class FormatTalksExtension extends Twig_Extension
*/
public function getUpcoming(array $data)
{
- return $this->sort($this->format($data)->filter(function ($talk) {
+ return $this->format($data)->filter(function ($talk) {
return $talk['event']['date'] >= $this->today;
- }));
+ })->sortBy('event.date');
}
/**
@@ -71,9 +71,9 @@ class FormatTalksExtension extends Twig_Extension
*/
public function getPast(array $data)
{
- return $this->sort($this->format($data)->filter(function ($talk) {
+ return $this->format($data)->filter(function ($talk) {
return $talk['event']['date'] < $this->today;
- }));
+ })->sortByDesc('event.date');
}
/**
@@ -100,18 +100,6 @@ class FormatTalksExtension extends Twig_Extension
});
}
- /**
- * Sort and return the talks.
- *
- * @param Collection $talks The talk data.
- *
- * @return array
- */
- private function sort(Collection $talks)
- {
- return $talks->sortByDesc('event.date')->all();
- }
-
/**
* {@inheritdoc}
*/
diff --git a/tests/FormatTalksBundle/Twig/FormatTalksTest.php b/tests/FormatTalksBundle/Twig/FormatTalksTest.php
index 386f2bb38..e8d239ee7 100644
--- a/tests/FormatTalksBundle/Twig/FormatTalksTest.php
+++ b/tests/FormatTalksBundle/Twig/FormatTalksTest.php
@@ -4,6 +4,7 @@ namespace FormatTalksBundle\Tests\Twig;
use DateTime;
use FormatTalksBundle\Twig\FormatTalksExtension;
+use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
class FormatTalksTest extends TestCase
@@ -21,6 +22,9 @@ class FormatTalksTest extends TestCase
$this->extension = new FormatTalksExtension();
}
+ /**
+ * @covers FormatTalksExtension::format()
+ */
public function testFormat()
{
$data = [
@@ -79,7 +83,7 @@ class FormatTalksTest extends TestCase
}
/**
- * Test getting all events.
+ * @covers FormatTalksExtension::getAll()
*/
public function testGetAll()
{
@@ -99,16 +103,17 @@ class FormatTalksTest extends TestCase
$this->assertCount(3, $results);
+ // Earliest events should be returned first.
$this->assertEquals(
- [$eventA['date'], $eventC['date'], $eventB['date']],
+ [$eventB['date'], $eventC['date'], $eventA['date']],
$this->extractDates($results)
);
}
/**
- * Test getting only upcoming events.
+ * @covers FormatTalksExtension::getUpcoming()
*/
- public function testUpcomingEventsFilter()
+ public function testGetUpcoming()
{
$eventA = ['date' => (new DateTime('+1 week'))->format('Y-m-d')];
$eventB = ['date' => (new DateTime('-2 weeks'))->format('Y-m-d')];
@@ -128,16 +133,17 @@ class FormatTalksTest extends TestCase
$this->assertCount(3, $results);
+ // Earliest events should be returned first.
$this->assertEquals(
- [$eventE['date'], $eventA['date'], $eventC['date']],
+ [$eventC['date'], $eventA['date'], $eventE['date']],
$this->extractDates($results)
);
}
/**
- * Test getting only past events.
+ * @covers FormatTalksExtension::getPast()
*/
- public function testPastFilter()
+ public function testGetPast()
{
$eventA = ['date' => (new DateTime('+1 week'))->format('Y-m-d')];
$eventB = ['date' => (new DateTime('-2 weeks'))->format('Y-m-d')];
@@ -159,6 +165,7 @@ class FormatTalksTest extends TestCase
$this->assertCount(2, $results);
+ // Latest events should be returned first.
$this->assertEquals(
[$eventB['date'], $eventF['date']],
$this->extractDates($results)
@@ -168,12 +175,12 @@ class FormatTalksTest extends TestCase
/**
* Extract the returned dates from the results.
*
- * @param array $results The results returned from the filter.
+ * @param Collection $results The results returned from the filter.
*
* @return array An array of dates.
*/
- private function extractDates(array $results)
+ private function extractDates(Collection $results)
{
- return collect($results)->pluck('event.date')->all();
+ return $results->pluck('event.date')->all();
}
}