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];
 }
 public function blocks(\SS_HTTPRequest $request)
 {
     $page = null;
     /** @var \Page|HasBlocks $page */
     if ($pageID = $request->param('PageID')) {
         $page = \Page::get()->byID($pageID);
     } else {
         if ($path = Application::path_for_request($request)) {
             $page = Application::page_for_path($path);
         }
     }
     if ($page) {
         if ($page->hasExtension(\Modular\Relationships\HasBlocks::class_name())) {
             \Director::set_current_page($page);
             /** @var \GridListBlock $gridList */
             if ($gridListBlock = $page->Blocks()->find('ClassName', 'GridListBlock')) {
                 return $gridListBlock->renderWith("GridListItems");
             }
         }
     }
 }
 /**
  * Try to get page from Director and if in CMS then get it from CMS page, fallback to
  * Controller url via page_for_path.
  *
  * @return \DataObject|\Page|\SiteTree
  */
 public static function get_current_page()
 {
     $page = null;
     if (\Director::is_ajax()) {
         if ($path = self::path_for_request(\Controller::curr()->getRequest())) {
             $page = self::page_for_path($path);
         }
     } else {
         if ($page = \Director::get_current_page()) {
             if ($page instanceof \CMSMain) {
                 $page = $page->currentPage();
             }
         }
         if (!$page && ($controller = Controller::curr())) {
             if ($controller = Controller::curr()) {
                 if ($request = $controller->getRequest()) {
                     $page = Application::page_for_path($request->getURL());
                 }
             }
         }
     }
     return $page;
 }
 /**
  * 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);
 }
 /**
  * Returns a log file path and name relative to the assets folder using config.log_path. If path doesn't exist
  * and is in the assets folder then will try and create it (recursively). If it is outside
  * the assets folder then will not try and create the path.
  *
  * @return string
  * @throws \Modular\Exceptions\Application
  */
 protected function makeLogFileName()
 {
     if ($filePathName = static::config()->get('log_file')) {
         // if no path then dirname returns '.' we don't want that but empty path instead
         $path = trim(dirname($filePathName), '.');
         if (!$path) {
             $path = static::config()->get('log_path');
         }
         $fileName = basename($filePathName, '.log');
     } else {
         $path = static::config()->get('log_path');
         $date = date('Ymd_his');
         $prefix = $this->source ?: "{$date}-";
         $fileName = basename(tempnam($path, "silverstripe-{$prefix}")) . ".log";
     }
     $path = Application::make_safe_path($path, false);
     return "{$path}/{$fileName}.log";
 }