package controllers;


import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import models.*;
import play.mvc.Controller;

public class EventStream extends Controller{

	public static void page(int size, int page)
	{
		String username = session.get("username");
		
		System.out.println("From EventStream#current username: "+username);
		boolean flag_login = false;
		if (username != null)
		{
			//User user = User.findById(Long.parseLong(userId));
			User user = User.find("byEmail", username).first();
			if (user != null)
			{
				flag_login = true;
				String email = session.get("username");

				// 'size' is the number of elements displayed per page
			    // 'page' is the current page index, starting from 1.
			    int start = (page-1) * size;
				List<Event> posts = Event.find("order by postingDate desc").from(start).fetch(size);

				//render(user, posts);
				render(posts, flag_login, email, size, page);
			}

	
		}
		boolean promote_login = true;
		Application.index(promote_login, false);
	}
}

@@ -387,16 +387,256 @@
  false;%0A
+%09%09// 'size' is the number of elements displayed per page%0A%09    // 'page' is the current page index, starting from 1.%0A%09    int start = (page-1) * size;%0A%09%09List%3CEvent%3E posts = Event.find(%22order by postingDate desc%22).from(start).fetch(size);%0A%09%09%0A
 %09%09if (us
@@ -765,16 +765,21 @@
 first();
+%0A%0A%09%09%09
 %0A%09%09%09if (
@@ -869,254 +869,8 @@
 );%0A%0A
-%09%09%09%09// 'size' is the number of elements displayed per page%0A%09%09%09    // 'page' is the current page index, starting from 1.%0A%09%09%09    int start = (page-1) * size;%0A%09%09%09%09List%3CEvent%3E posts = Event.find(%22order by postingDate desc%22).from(start).fetch(size);%0A%0A
 %09%09%09%09
@@ -956,16 +956,57 @@
 %09%0A%09%09%7D%0A%09%09
+//set true to ask user login firstly%0A%09%09//
 boolean 
@@ -1029,16 +1029,18 @@
 true;%0A%09%09
+//
 Applicat
@@ -1072,13 +1072,56 @@
 false);%0A
+%09%09render(posts, flag_login, size, page);%0A%0A%0A
 %09%7D%0A%7D%0A

enable user to see events withput login