* @version $Revision: 18172 $
*/
class NewItemsModule extends GalleryModule {
function NewItemsModule() {
global $gallery;
$this->setId('newitems');
$this->setName($gallery->i18n('New Items'));
$this->setDescription($gallery->i18n('Highlight new/updated Gallery items'));
$this->setVersion('1.0.8');
$this->_templateVersion = 1;
$this->setGroup('display', $gallery->i18n('Display'));
$this->setCallbacks('getSiteAdminViews|getItemSummaries');
$this->setRequiredCoreApi(array(7, 27));
$this->setRequiredModuleApi(array(3, 6));
}
/**
* @see GalleryModule::upgrade
*/
function upgrade($currentVersion) {
if (!isset($currentVersion)) {
foreach (array('days.new' => '7',
'days.updated' => '7' )
as $key => $value) {
$ret = $this->setParameter($key, $value);
if ($ret) {
return $ret;
}
}
}
return null;
}
/**
* @see GalleryModule::performFactoryRegistrations
*/
function performFactoryRegistrations() {
$ret = GalleryCoreApi::registerFactoryImplementation(
'GallerySortInterface_1_2', 'NewItemsSortOrder', 'NewItems',
'modules/newitems/classes/NewItemsSortOrder.class', 'newitems', null);
if ($ret) {
return $ret;
}
return null;
}
/**
* @see GalleryModule::getSiteAdminViews
*/
function getSiteAdminViews() {
return array(null,
array(array('name' => $this->translate('New Items'),
'view' => 'newitems.NewItemsSiteAdmin')));
}
/**
* @see GalleryModule::getItemSummaries
*/
function getItemSummaries($items, $permissions, &$template) {
list ($ret, $param) = GalleryCoreApi::fetchAllPluginParameters('module', 'newitems');
if ($ret) {
return array($ret, null);
}
$time = time();
$newTime = $time - $param['days.new'] * 86400;
$updatedTime = $time - $param['days.updated'] * 86400;
$newString = $this->translate('New');
$updatedString = $this->translate('Updated');
$summaries = array();
foreach ($items as $item) {
if ($param['days.new'] > 0 && $item->getCreationTimestamp() > $newTime) {
$summaries[$item->getId()] = ''
. $newString . '';
} else if ($param['days.updated'] > 0
&& $item->getModificationTimestamp() > $updatedTime) {
$summaries[$item->getId()] = ''
. $updatedString . '';
}
}
return array(null, $summaries);
}
/**
* @see GalleryModule::uninstall
*/
function uninstall() {
$ret = GalleryCoreApi::deleteSortOrder('NewItems');
if ($ret) {
return $ret;
}
return parent::uninstall();
}
}
?>