Skip to content

Commit c5e1ece

Browse files
committed
Add method phpweb\News\NewsHandler::getConferences()
1 parent 3896dc1 commit c5e1ece

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

conferences/index.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,9 @@
1313
]);
1414

1515
$content = "<div class='home-content'>";
16-
$frontpage = [];
17-
foreach ((new NewsHandler())->getPregeneratedNews() as $entry) {
18-
foreach ($entry["category"] as $category) {
19-
if ($category["term"] == "cfp") {
20-
$frontpage[] = $entry;
21-
break;
22-
}
23-
if ($category["term"] == "conferences") {
24-
$frontpage[] = $entry;
25-
break;
26-
}
27-
}
28-
}
2916
$panels = '<p class="prepend"><a href="https://wiki.php.net/conferences">Want to see your conference appear here?</a></p>';
3017

31-
foreach ($frontpage as $entry) {
18+
foreach ((new NewsHandler())->getConferences() as $entry) {
3219
$link = preg_replace('~^(http://php.net/|https://www.php.net/)~', '', $entry["id"]);
3320
$id = parse_url($entry["id"], PHP_URL_FRAGMENT);
3421
$date = date_format(date_create($entry["updated"]), 'Y-m-d');

src/News/NewsHandler.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ public function getFrontPageNews(): array
4040
return $frontPage;
4141
}
4242

43+
/** @return list<array> */
44+
public function getConferences(): array
45+
{
46+
$conferences = [];
47+
foreach ($this->getPregeneratedNews() as $entry) {
48+
foreach ($entry['category'] as $category) {
49+
if ($category['term'] !== 'cfp' && $category['term'] !== 'conferences') {
50+
continue;
51+
}
52+
53+
$conferences[] = $entry;
54+
break;
55+
}
56+
}
57+
58+
return $conferences;
59+
}
60+
4361
public function getPregeneratedNews(): array
4462
{
4563
$NEWS_ENTRIES = null;

tests/Unit/News/NewsHandlerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ public function testGetLastestNews(): void
1919
self::assertSame($news[0], $newsHandler->getLastestNews());
2020
}
2121

22+
public function testGetConferences(): void
23+
{
24+
$conferences = (new NewsHandler())->getConferences();
25+
self::assertNotEmpty($conferences);
26+
foreach ($conferences as $conference) {
27+
$isConference = false;
28+
foreach ($conference['category'] as $category) {
29+
if ($category['term'] === 'cfp' || $category['term'] === 'conferences') {
30+
$isConference = true;
31+
break;
32+
}
33+
}
34+
35+
self::assertTrue($isConference);
36+
}
37+
}
38+
2239
public function testGetFrontPageNews(): void
2340
{
2441
$frontPage = (new NewsHandler())->getFrontPageNews();

0 commit comments

Comments
 (0)