def get_catalog_page(self, page_number, page_size, search, order_by, sort_order): """Gets a catalog page of the managed collection.""" collection = self.get_all() if search is not None and search != "": """ # NB: if a search filter is provided by the client; then the server side should: # 1. search inside the properties we know should be searched into, and skim the results. # 2. set the total items count as the total of items that respond to the search. # 3. return the full set of items that respect the search criteria. # # As a side note, keep in mind that some properties, like dates and decimal, should be evaluated for their # culture-dependent string representations of values; not their intrinsic values. # Example: a date in UK English can be dd/mm/yyyy; in US English can be mm/dd/yyyy. # A well designed search implementation adapts to the current user's culture. """ collection = ListUtils.search(collection, search, "*") # NB: if an order by is defined; we need to order before paginating results! if order_by is not None and order_by != "": collection = ListUtils.sort_by(collection, order_by, sort_order) # return a paginated result to the client: skip = ((page_number-1)*page_size) if page_number > 0 else 0 # the client needs to know the total items count, in order to build the pagination total_items_count = len(collection) result = ListUtils.sampling(collection, skip, page_size) # return the collection and the count of results: return result, total_items_count