Fórum

Get All the # of post of User from MessageBoard between Date range

Mukesh Kumar Sharma, modificado 7 Anos atrás.

Get All the # of post of User from MessageBoard between Date range

New Member Postagens: 5 Data de Entrada: 08/07/16 Postagens Recentes
Hi Everyone,
I am newbie in Liferay Framework and I have a requirement like fetch all the user's number of post from MessageBoard between date range.I observed that we don't have column name like messageCount in mbmessage table . We can get Total # of post for individual users from mbstatsuser table but i want # of post between some date range. Some one suggested in community that use below method

long groupId = PortalUtil.getScopeGroupId(request);
long userId = PortalUtil.getUserId(request);
int count = MBMessageLocalServiceUtil.getGroupMessagesCount(groupId, userId, WorkflowConstants.STATUS_APPROVED);


But i am unable to pass my date range value in that method. Then i tried with below Dynamic query but still no luck.

Criterion criterion = null;
long groupId = PortalUtil.getScopeGroupId(request);
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(
MBMessage.class, PortalClassLoaderUtil.getClassLoader());
criterion = RestrictionsFactoryUtil.between("createDate", startDate,endDate);
criterion = RestrictionsFactoryUtil.and(criterion,RestrictionsFactoryUtil.eq("groupId ",groupId));
criterion = RestrictionsFactoryUtil.and(criterion,RestrictionsFactoryUtil.in("userId", userList));
dynamicQuery.add(criterion);
List<MBMessage> mbList1 = null;
try{

mbList1 = MBMessageLocalServiceUtil.dynamicQuery(dynamicQuery);
}
catch(Exception e){
e.getMessage();
}

Please help me out to solve this task.
Mukesh Kumar Sharma, modificado 7 Anos atrás.

RE: Get All the # of post of User from MessageBoard between Date range

New Member Postagens: 5 Data de Entrada: 08/07/16 Postagens Recentes
Hi Guys !
Please reply on above post or provide me some guidance to do that...Please
thumbnail
Jamie Sammons, modificado 7 Anos atrás.

RE: Get All the # of post of User from MessageBoard between Date range (Resposta)

Expert Postagens: 301 Data de Entrada: 05/09/14 Postagens Recentes
Here is how I was able to get it to work.

		ThemeDisplay themeDisplay= (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
		Long companyId = themeDisplay.getLayout().getCompanyId();	
		Long groupId = themeDisplay.getLayout().getGroupId();		
		Calendar startDate = Calendar.getInstance();
		startDate.add(Calendar.MONTH, -5);
		Calendar endDate = Calendar.getInstance();
		endDate.add(Calendar.MONTH, -1);
		
		System.out.println(startDate.getTime());
		System.out.println(endDate.getTime());
		
		DynamicQuery userQuery = DynamicQueryFactoryUtil.forClass(User.class)
				.add(RestrictionsFactoryUtil.eq("companyId", GetterUtil.getLong(companyId)))
				.add(RestrictionsFactoryUtil.ge("loginDate", startDate.getTime()))
				.setProjection(ProjectionFactoryUtil.property("userId"));
		
		List<user> userList = UserLocalServiceUtil.dynamicQuery(userQuery);
		
		DynamicQuery mbQuery = DynamicQueryFactoryUtil.forClass(MBMessage.class)
				.add(RestrictionsFactoryUtil.eq("companyId", GetterUtil.getLong(companyId)))
				.add(RestrictionsFactoryUtil.eq("groupId", GetterUtil.getLong(groupId)))
				.add(RestrictionsFactoryUtil.ne("categoryId", GetterUtil.getLong(-1)))
				.add(RestrictionsFactoryUtil.eq("status", 0))
				.add(RestrictionsFactoryUtil.in("userId", userList))
				.add(RestrictionsFactoryUtil.between("createDate", startDate.getTime(),endDate.getTime()))
				.setProjection(ProjectionFactoryUtil.projectionList().add(ProjectionFactoryUtil.groupProperty("userId"))
						.add(ProjectionFactoryUtil.alias(ProjectionFactoryUtil.rowCount(), "msgCount")));
				
				
		List <object[]> mbList = MBMessageLocalServiceUtil.dynamicQuery(mbQuery);

		for (Object[] message : mbList)
		{
			System.out.println("UserId: " + message[0] + " MBCount: " + message[1]);
		}</object[]></user>


Hope that helps.
Mukesh Kumar Sharma, modificado 7 Anos atrás.

RE: Get All the # of post of User from MessageBoard between Date range

New Member Postagens: 5 Data de Entrada: 08/07/16 Postagens Recentes
Hi Jamie Sammons,
I really appreciate your effort for this great solution and Its working perfect for me.
Thank you so much...