Class EventsFilterHelper

java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.ametys.plugins.calendar.events.EventsFilterHelper
All Implemented Interfaces:
Component, LogEnabled, Serviceable

Helper for events filter
  • Field Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • createEventsFilter

      Create a events filter from the static "events" filter
      Parameters:
      id - the id of filter to create
      Returns:
      the created events filter
    • getTitle

      public String getTitle(ZoneItem zoneItem)
      Get the service title.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the service title.
    • getLink

      public String getLink(ZoneItem zoneItem)
      Get the link.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the link.
    • getLinkTitle

      public String getLinkTitle(ZoneItem zoneItem)
      Get the link title.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the link title.
    • getDefaultRangeType

      public String getDefaultRangeType(ZoneItem zoneItem)
      Get the default range type parameter value.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the default range type.
    • getMaskOrphan

      public boolean getMaskOrphan(ZoneItem zoneItem)
      Mask orphan?
      Parameters:
      zoneItem - the zone item.
      Returns:
      mask orphan.
    • getAccessLimitation

      Get the access limitation policy.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the access limitation policy.
    • getPdfDownload

      protected boolean getPdfDownload(ZoneItem zoneItem)
      Is there a PDF download link on the service?
      Parameters:
      zoneItem - the zone item.
      Returns:
      true if a PDF download link will be present, false otherwise.
    • getIcalDownload

      protected boolean getIcalDownload(ZoneItem zoneItem)
      Is there an iCalendar export link on the service?
      Parameters:
      zoneItem - the zone item.
      Returns:
      true if an iCalendar export link will be present, false otherwise.
    • getContentTypes

      public Set<String> getContentTypes(ZoneItem zoneItem)
      Get the content types through the service parameters.
      Parameters:
      zoneItem - the zone item.
      Returns:
      the content types.
    • getTags

      public Set<String> getTags(ZoneItem zoneItem, List<Map<String,Object>> searchContexts)
      Get the all tags from the search contexts
      Parameters:
      zoneItem - the zone item.
      searchContexts - the search contexts
      Returns:
      the tags.
    • getTagCategories

      public Set<Tag> getTagCategories(ZoneItem zoneItem, List<Map<String,Object>> searchContexts, String currentSiteName)
      Get the all selected tags to be used as categories from the search contexts
      Parameters:
      zoneItem - the zone item.
      searchContexts - the search contexts
      currentSiteName - the current site name.
      Returns:
      the tags categories.
    • getAllTags

      public Set<String> getAllTags(Collection<? extends Tag> tags)
      Get all the descendant tags belonging to a collection of input tags.
      Parameters:
      tags - the collection of input tag.
      Returns:
      an exhaustive set of the tags.
    • getAllTags

      protected Set<Tag> getAllTags(Tag tag)
      Get all the descendant tags belonging to a single tag.
      Parameters:
      tag - the tag.
      Returns:
      an exhaustive set of the tags.
    • getDateRange

      public EventsFilterHelper.DateRange getDateRange(String type, int year, int month, int day, int monthsBefore, int monthsAfter, String rangeType)
      Get the date range from the calendar type and parameters.
      Parameters:
      type - the calendar mode: "calendar", "single-day" or "agenda".
      year - the year.
      month - the month.
      day - the day.
      monthsBefore - get x months before.
      monthsAfter - get x months after.
      rangeType - the range type, "month" or "week".
      Returns:
      the date range.
    • getDateRange

      public EventsFilterHelper.DateRange getDateRange(Date startDate, Date endDate)
      Create a DateRange between 2 dates
      Parameters:
      startDate - stard date
      endDate - end date
      Returns:
      the DateRange between those dates
    • _getDateRange

      protected EventsFilterHelper.DateRange _getDateRange(int monthsBefore, int monthsAfter)
      Get a date range from a period (x months before now and x months after).
      Parameters:
      monthsBefore - the wanted number of months before the current month.
      monthsAfter - the wanted number of months after the current month.
      Returns:
      the date range.
    • _getDateRange

      protected EventsFilterHelper.DateRange _getDateRange(Calendar date, int monthsBefore, int monthsAfter)
      Get a date range from a period, around a given date (x months before and x months after the date).
      Parameters:
      date - the date.
      monthsBefore - the wanted number of months before the current month.
      monthsAfter - the wanted number of months after the current month.
      Returns:
      the date range.
    • _getDateRange

      Get a date range from a date and a range type.
      Parameters:
      date - the date around which the range is to be.
      rangeType - the range type, "month" or "week".
      Returns:
      the date range.
    • _getDate

      protected Calendar _getDate(int year, int month, int day)
      Get a date object from a year-month-day set.
      Parameters:
      year - the year.
      month - the month (1 to 12).
      day - the day (1 to 31).
      Returns:
      the date object.
    • getExpression

      Get the metadata expression from the calendar type and date range.
      Parameters:
      type - the calendar type, may be "calendar", "single-day", "agenda" or "period" (agenda = calendar = period).
      dateRange - the date range. Only the start date is used for "single-day" type.
      Returns:
      the metadata Expression on contents.
    • _getMetadataExpression

      Get a metadata expression from a date range.
      Parameters:
      dateRange - the date range.
      Returns:
      the date range metadata expression.
    • _getMetadataExpression

      Get a metadata expression from a single date.
      Parameters:
      date - the date.
      Returns:
      the date metadata expression.
    • getLastDayOfWeek

      protected int getLastDayOfWeek(Calendar cal)
      Get last day of the week at a given date.
      Parameters:
      cal - the date as a Calendar.
      Returns:
      the last day of the week.
    • getFilteredCategories

      public Set<String> getFilteredCategories(List<Map<String,Object>> searchContexts, String[] requestedCategories, ZoneItem zoneItem, String siteName)
      Filter a list of categories depending on the service parameters (categoriesArray) and request tags (requestedCategoriesArray)
      Parameters:
      searchContexts - the search contexts
      requestedCategories - list of requested categories (can be "all" to get all the categories from the service, or a list of categories)
      zoneItem - zone Item
      siteName - site name
      Returns:
      a set of tags
    • generateEventFilter

      public EventsFilter generateEventFilter(EventsFilterHelper.DateRange dateRange, ZoneItem zoneItem, String view, String type, Set<String> filteredCategories, List<Map<String,Object>> searchContexts)
      Generate the filter
      Parameters:
      dateRange - range of dates to search
      zoneItem - used to get the tags
      view - metadataset used
      type - calendar, agenda, period (same thing) or "single-day" to get a single day
      filteredCategories - list of categories filtered by those requested by the user
      searchContexts - the search contexts
      Returns:
      an EventFilter to match the parameters
    • configureFilter

      public void configureFilter(EventsFilter eventsFilter, Expression expression, Collection<String> contentTypes, List<Map<String,Object>> searchContexts, Set<String> orTags, String view, boolean maskOrphan, WebContentFilter.AccessLimitation accessLimitation)
      Configure the filter to return the wanted contents.
      Parameters:
      eventsFilter - the events filter.
      expression - the metadata Expression, can be null.
      contentTypes - a list of content types that will restrict the scope of the request.
      searchContexts - the input searchContext
      orTags - a list of tags among which only one is required for the content to match.
      view - the view.
      maskOrphan - true to prevent getting orphan contents.
      accessLimitation - The access limitation policy.
    • getSearchContext

      public List<Map<String,Object>> getSearchContext(ZoneItem zoneItem, List<Map<String,Object>> inputSearchContexts)
      Set the search contexts in a filter from a service instance attributes.
      Parameters:
      zoneItem - the service parameters data holder.
      inputSearchContexts - the input search contexts
      Returns:
      a list of search context
    • _setSearchContext

      protected void _setSearchContext(EventsFilter filter, List<Map<String,Object>> searchContextValues, Set<String> orTags)
      Get the search parameters from the search values.
      Parameters:
      filter - the filter to configure.
      searchContextValues - the input searchContext
      orTags - a list of tags among which only one is required for the content to match.