Question

Is it possible to increment view count of asset entry programically from velocity template?

Thanks for all answers.

Était-ce utile?

La solution

It should be possible, after all its just about updating a liferay entity.

If you can get hold of AssetEntryService then you can call the method incrementViewCounter which would increment the view counter by 1.

So in your template you would have code like this:

#set ($assetEntryService = $serviceLocator.findService('com.liferay.portlet.asset.service.AssetEntryService'))
$assetEntryService.incrementViewCounter(String className, long classPK)

If you want to specify the increment value instead of the default 1, then you would require the instance of AssetEntryLocalService as follows:

#set ($assetEntryLocalService = $serviceLocator.findService('com.liferay.portlet.asset.service.AssetEntryLocalService'))
$assetEntryService.incrementViewCounter(long userId, String className, long classPK, long increment)

increment = to increment the current viewCount by this value.

I hope I have understood what was required.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top