<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%
String orderByCol = ParamUtil.getString(request, "orderByCol");
String orderByType = ParamUtil.getString(request, "orderByType");

if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) {
	portalPrefs.setValue(PortletKeys.BOOKMARKS, "entries-order-by-col", orderByCol);
	portalPrefs.setValue(PortletKeys.BOOKMARKS, "entries-order-by-type", orderByType);
}
else {
	orderByCol = portalPrefs.getValue(PortletKeys.BOOKMARKS, "entries-order-by-col", "name");
	orderByType = portalPrefs.getValue(PortletKeys.BOOKMARKS, "entries-order-by-type", "asc");
}

OrderByComparator orderByComparator = BookmarksUtil.getEntriesOrderByComparator(orderByCol, orderByType);
%>

<liferay-ui:search-container
	curParam="cur2"
	delta="<%= entriesPerPage %>"
	deltaConfigurable="<%= false %>"
	emptyResultsMessage="there-are-no-bookmarks-in-this-folder"
	headerNames="<%= StringUtil.merge(entryColumns) %>"
	iteratorURL="<%= portletURL %>"
	orderByCol="<%= orderByCol %>"
	orderByType="<%= orderByType %>"
>
	<liferay-ui:search-container-results>

		<%
		if (useAssetEntryQuery) {

			AssetEntryQuery assetEntryQuery = new AssetEntryQuery(BookmarksEntry.class.getName(), searchContainer);

			assetEntryQuery.setExcludeZeroViewCount(false);

			results = AssetEntryServiceUtil.getEntries(assetEntryQuery);
			total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
		}
		else {
			results = BookmarksEntryLocalServiceUtil.getEntries(scopeGroupId, folderId, searchContainer.getStart(), searchContainer.getEnd(), orderByComparator);
			total = BookmarksEntryLocalServiceUtil.getEntriesCount(scopeGroupId, folderId);
		}

		pageContext.setAttribute("results", results);
		pageContext.setAttribute("total", total);
		%>

	</liferay-ui:search-container-results>

	<liferay-ui:search-container-row
		className="com.liferay.portal.model.BaseModel"
		keyProperty="primaryKeyObj"
		modelVar="result">

		<%@ include file="/html/portlet/bookmarks/cast_result.jspf" %>

		<%
		String rowHREF = null;
		String target = null;

		if (BookmarksEntryPermission.contains(permissionChecker, entry, ActionKeys.VIEW)) {
			PortletURL tempRowURL = renderResponse.createRenderURL();

			tempRowURL.setParameter("struts_action", "/bookmarks/view_entry");
			tempRowURL.setParameter("entryId", String.valueOf(entry.getEntryId()));
			tempRowURL.setParameter("redirect", currentURL);

			rowHREF = tempRowURL.toString();
		}
		else {
			rowHREF = themeDisplay.getPathMain().concat("/bookmarks/open_entry?entryId=").concat(String.valueOf(entry.getEntryId()));

			target = "_blank";
		}
		%>

		<%@ include file="/html/portlet/bookmarks/entry_columns.jspf" %>

	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />
</liferay-ui:search-container>