I'm working in a announcement block to display the last 3 announcemnts in the sidebar with a block. I have it working but it's only displayed in the admin sections, like configuration.
The code is based on the 'developed by' plugin adding the getContents to pass the announcemnts data to block.tpl.
Anyone can help me? any indication will be welcome!
thanks a lot!
AnnouncementsBlockPlugin.inc.php:
- Code: Select all
import('lib.pkp.classes.plugins.BlockPlugin');
class AnnouncementsBlockPlugin extends BlockPlugin {
function getEnabled() {
if (!Config::getVar('general', 'installed')) return true;
return parent::getEnabled();
}
function getInstallSitePluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
function getBlockContext() {
if (!Config::getVar('general', 'installed')) return BLOCK_CONTEXT_RIGHT_SIDEBAR;
return parent::getBlockContext();
}
function getSeq() {
if (!Config::getVar('general', 'installed')) return 1;
return parent::getSeq();
}
function getDisplayName() {
return __('plugins.block.Announcements.displayName');
}
function getDescription() {
return __('plugins.block.Announcements.description');
}
function getContents(&$templateMgr) {
$journal =& Request::getJournal();
$limitRecentItems = true;
$recentItems = 3;
$announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
$journalId = $journal->getId();
if ($limitRecentItems && $recentItems > 0) {
import('lib.pkp.classes.db.DBResultRange');
$rangeInfo = new DBResultRange($recentItems, 1);
$announcements =& $announcementDao->getAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journalId, $rangeInfo);
} else {
$announcements =& $announcementDao->getAnnouncementsNotExpiredByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
}
$lastDateUpdated = '';
if ($announcements->wasEmpty()) {
if (empty($lastDateUpdated)) {
$dateUpdated = Core::getCurrentDate();
$announcementBlockPlugin->updateSetting($journal->getId(), 'dateUpdated', $dateUpdated, 'string');
} else {
$dateUpdated = $lastDateUpdated;
}
}
$templateMgr =& TemplateManager::getManager();
$templateMgr->assign_by_ref('announcements', $announcements->toArray());
$templateMgr->assign_by_ref('journal', $journal);
return parent::getContents($templateMgr);
}
}
settings.xml
- Code: Select all
<plugin_settings>
<setting type="bool">
<name>enabled</name>
<value>true</value>
</setting>
<setting type="int">
<name>seq</name>
<value>0</value>
</setting>
<setting type="int">
<name>context</name>
<value>2</value><!-- BLOCK_CONTEXT_RIGHT_SIDEBAR -->
</setting>
</plugin_settings>
block.tpl
- Code: Select all
<div class="block" id="sidebarAnnouncements">
<h2 class="blockTitle" id="announcements">{translate key="plugins.block.Announcements.blockTitle"}</h2>
<ul>
{foreach from=$announcements item=announcement}
<li class="announcementElement"><a href="{url page="announcement" op="view" path=$announcement->getId()}" cass="announcementTitle">
<h3>{$announcement->getLocalizedTitleFull()|strip|escape:"html"}</h3>
{if $announcement->getLocalizedDescription()}
<!--div class="announcementDescription">{$announcement->getLocalizedDescription()|strip|escape:"html"}</div-->
{/if}
</a></li>
{/foreach}
</ul>
</div>
