public function sequenceGridListFilters(&$filters, $items, &$parameters = [])
 {
     if ($allFilter = Application::get_current_page()->FilterAll()) {
         $allTag = $allFilter->Filter;
         $allItemCount = 0;
     } else {
         $allItemCount = $items->count();
         $allTag = '';
     }
     foreach ($filters as $filter) {
         $itemCount = 0;
         $tag = $filter->ModelTag;
         /** @var \DataObject|HasGridListFilters $item */
         foreach ($items as $item) {
             if ($item->hasExtension(HasGridListFilters::class_name())) {
                 if ($item->GridListFilters()->find('ModelTag', $tag)) {
                     $itemCount++;
                 } else {
                     if ($allTag == 'all' || $allTag && $item->GridListFilters()->find('ModelTag', $allTag)) {
                         $allItemCount++;
                     }
                 }
             }
         }
         // don't recount 'all filter' after first pass
         $allTag = false;
         $filter->ItemCount = max($itemCount - 1, 0);
     }
     $parameters[self::AllItemCountKey] = max($allItemCount - 1, 0);
 }
 public function defaultFilter()
 {
     if ($page = Application::get_current_page()) {
         if ($page->hasMethod('DefaultFilter')) {
             return $page->DefaultFilter();
         }
     }
 }
 /**
  * Expects parameters 'start' and 'limit' to be set, limits items by filter to page length
  *
  *
  * @param \SS_LIst $items
  * @param          $filters
  * @param array    $parameters
  */
 public function sequenceGridListItems(&$items, $filters, &$parameters = [])
 {
     $out = new \ArrayList();
     $start = $parameters[Constraints::StartIndexGetVar];
     $limit = $parameters[Constraints::PageLengthGetVar];
     if (!is_null($limit)) {
         $added = 0;
         if ($allFilter = Application::get_current_page()->FilterAll()) {
             // first add 'all filter' items
             if ($allTag = $allFilter->Filter) {
                 $index = 0;
                 $added = 0;
                 foreach ($items as $item) {
                     $index++;
                     if ($index < $start) {
                         continue;
                     }
                     if ($allTag == 'all' || $item->GridListFilters()->find('ModelTag', $allTag)) {
                         // we don't add all, we're just getting the count
                         // $out->push($item);
                         $added++;
                     }
                     if ($added >= $limit) {
                         break;
                     }
                 }
             }
         }
         // initial number of 'all filter' items loaded in page
         $parameters['AllLoadCount'] = $added;
         foreach ($filters as $filter) {
             if ($tag = $filter->ModelTag) {
                 $index = 0;
                 $added = 0;
                 foreach ($items as $item) {
                     $index++;
                     if ($index < $start) {
                         continue;
                     }
                     if ($item->hasExtension(HasGridListFilters::class_name())) {
                         if ($item->GridListFilters()->find('ModelTag', $tag)) {
                             $out->push($item);
                             $added++;
                         }
                     }
                     if ($added >= $limit) {
                         break;
                     }
                 }
                 // initial number of items loaded in page (may be less than page length)
                 $filter->LoadCount = $added;
             }
         }
         $out->removeDuplicates();
         $items = $out;
     }
 }
 /**
  *
  * Use the current page's gridlist_default_mode if set otherwise whatever we had before.
  *
  * @param array $templateData
  * @return array [ 'Mode' => mode e.g. 'grid' or 'list' (or empty if none set)
  */
 public function provideGridListTemplateData($templateData = [])
 {
     $mode = isset($templateData['Mode']) ? $templateData['Mode'] : '';
     // page may be null if it's a new page
     if ($page = Application::get_current_page()) {
         // set to page mode if set, otherwise keep what we have already
         $mode = $page->config()->get('gridlist_default_mode') ?: $mode;
     }
     return ['Mode' => $mode];
 }
 /**
  * Return instance of service that this gridlist is using
  *
  * @return Service
  */
 public static function service()
 {
     /** @var \Page $page */
     $service = '';
     if ($page = Application::get_current_page()) {
         $service = $page->config()->get('gridlist_service');
     }
     $service = $service ?: static::config()->get('gridlist_service');
     return \Injector::inst()->get($service);
 }