Skip to content

Commit

Permalink
pkp/pkp-lib#10328 Refactor Announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Sep 10, 2024
1 parent 03971bf commit 4b63532
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

namespace APP\plugins\generic\announcementFeed;

use APP\facades\Repo;
use APP\template\TemplateManager;
use PKP\announcement\Announcement;
use PKP\core\Core;
use PKP\db\DAORegistry;
use PKP\plugins\GatewayPlugin;
Expand Down Expand Up @@ -128,12 +128,12 @@ public function fetch($args, $request)
}

// Get limit setting, if any
$collector = Repo::announcement()->getCollector()->filterByContextIds([$journal->getId()])->filterByActive();
$announcements = Announcement::withContextIds([$journal->getId()])->withActiveByDate();
$recentItems = (int) $this->_parentPlugin->getSetting($journal->getId(), 'recentItems');
if ($recentItems > 0) {
$collector->limit($recentItems);
$announcements->limit($recentItems);
}
$announcements = $collector->getMany();
$announcements = $announcements->get();

// Get date of most recent announcement
$lastDateUpdated = $this->_parentPlugin->getSetting($journal->getId(), 'dateUpdated');
Expand All @@ -145,7 +145,7 @@ public function fetch($args, $request)
$dateUpdated = $lastDateUpdated;
}
} else {
$dateUpdated = $announcements->first()->getDatetimePosted();
$dateUpdated = $announcements->first()->getAttribute('datePosted');
if (empty($lastDateUpdated) || (strtotime($dateUpdated) > strtotime($lastDateUpdated))) {
$this->_parentPlugin->updateSetting($journal->getId(), 'dateUpdated', $dateUpdated, 'string');
}
Expand Down
14 changes: 7 additions & 7 deletions plugins/generic/announcementFeed/templates/atom.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
{foreach from=$announcements item=announcement}
<entry>
{* required elements *}
<id>{url page="announcement" op="view" path=$announcement->getId()}</id>
<title>{$announcement->getLocalizedTitleFull()|strip|escape:"html"}</title>
<updated>{$announcement->getDatetimePosted()|date_format:"%Y-%m-%dT%T%z"|regex_replace:"/00$/":":00"}</updated>
<id>{url page="announcement" op="view" path=$announcement->getKey()}</id>
<title>{$announcement->getLocalizedData('fullTitle')|strip|escape:"html"}</title>
<updated>{$announcement->getAttribute('datePosted')|date_format:"%Y-%m-%dT%T%z"|regex_replace:"/00$/":":00"}</updated>
<author>
<name>{$journal->getLocalizedName()|strip|escape:"html"}</name>
</author>
<link rel="alternate" href="{url page="announcement" op="view" path=$announcement->getId()}" />
{if $announcement->getLocalizedDescription()}
<summary type="html" xml:base="{url page="announcement" op="view" path=$announcement->getId()}">{$announcement->getLocalizedDescription()|strip|escape:"html"}</summary>
<link rel="alternate" href="{url page="announcement" op="view" path=$announcement->getKey()}" />
{if $announcement->getLocalizedData('description')}
<summary type="html" xml:base="{url page="announcement" op="view" path=$announcement->getKey()}">{$announcement->getLocalizedData('description')|strip|escape:"html"}</summary>
{/if}

{* optional elements *}
{* <category/> *}
{* <contributor/> *}
<published>{$announcement->getDatetimePosted()|date_format:"%Y-%m-%dT%T%z"|regex_replace:"/00$/":":00"}</published>
<published>{$announcement->getAttribute('datePosted')|date_format:"%Y-%m-%dT%T%z"|regex_replace:"/00$/":":00"}</published>
{* <source/> *}
{* <rights/> *}
</entry>
Expand Down
14 changes: 7 additions & 7 deletions plugins/generic/announcementFeed/templates/rss.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
<items>
{foreach from=$announcements item=announcement}
<rdf:Seq>
<rdf:li rdf:resource="{url page="announcement" op="view" path=$announcement->getId()}"/>
<rdf:li rdf:resource="{url page="announcement" op="view" path=$announcement->getKey()}"/>
</rdf:Seq>
{/foreach}
</items>
</channel>

{foreach from=$announcements item=announcement}
<item rdf:about="{url page="announcement" op="view" path=$announcement->getId()}">
<item rdf:about="{url page="announcement" op="view" path=$announcement->getKey()}">
{* required elements *}
<title>{$announcement->getLocalizedTitleFull()|strip|escape:"html"}</title>
<link>{url page="announcement" op="view" path=$announcement->getId()}</link>
<title>{$announcement->getLocalizedData('fullTitle')|strip|escape:"html"}</title>
<link>{url page="announcement" op="view" path=$announcement->getKey()}</link>

{* optional elements *}
{if $announcement->getLocalizedDescription()}
<description>{$announcement->getLocalizedDescription()|strip|escape:"html"}</description>
{if $announcement->getLocalizedData('description')}
<description>{$announcement->getLocalizedData('description')|strip|escape:"html"}</description>
{/if}
<dc:creator>{$journal->getLocalizedName()|strip|escape:"html"}</dc:creator>
<dc:date>{$announcement->getDatePosted()|date_format:"%Y-%m-%d"}</dc:date>
<dc:date>{$announcement->getAttribute('datePosted')|date_format:"%Y-%m-%d"}</dc:date>
</item>
{/foreach}

Expand Down

0 comments on commit 4b63532

Please sign in to comment.