From cf641112b757d66f340626f6c371ce61e0837da2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 4 Apr 2019 11:16:01 +0200
Subject: [PATCH] :sparkles: feat(management) Allow management classes to hide
 scope checkbox

FAI management has baseMode on but does want a fixed scope, so added a
 way to do that.

issue #5980
---
 ihtml/themes/breezy/management/filter.tpl     |  2 +-
 include/management/class_managementFilter.inc | 27 +++++++++++++------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ihtml/themes/breezy/management/filter.tpl b/ihtml/themes/breezy/management/filter.tpl
index 82e6c3707..ae5116f6e 100644
--- a/ihtml/themes/breezy/management/filter.tpl
+++ b/ihtml/themes/breezy/management/filter.tpl
@@ -29,7 +29,7 @@
 
   <hr/>
 
-  {if $BASEMODE}
+  {if $SHOWSCOPE}
   <label for="SCOPE">
     <input type="checkbox" id="SCOPE" name="SCOPE" value="1"
     {if ($SCOPE == 'sub')}checked="checked"{/if}/>
diff --git a/include/management/class_managementFilter.inc b/include/management/class_managementFilter.inc
index 4a8e9b430..519ff76ab 100644
--- a/include/management/class_managementFilter.inc
+++ b/include/management/class_managementFilter.inc
@@ -1,7 +1,8 @@
 <?php
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
-  Copyright (C) 2017-2018  FusionDirectory
+
+  Copyright (C) 2017-2019  FusionDirectory
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -33,21 +34,19 @@ class managementFilter
 
   protected $filterElements = [];
 
+  protected $fixedScope;
+
   /* The management class */
   public $parent;
 
   public $pid;
 
-  /*
-   * Each objectType has its filters
-   * */
-
   /*!
    * \brief Create a management filter
    *
    * \param string $parent management instance
    */
-  function __construct (management $parent)
+  function __construct (management $parent, bool $fixedScope = NULL)
   {
     global $config;
 
@@ -66,6 +65,8 @@ class managementFilter
     $this->filterElements = [
       new TabFilterElement($this),
     ];
+
+    $this->fixedScope = $fixedScope;
   }
 
   function setScope (string $scope)
@@ -73,6 +74,14 @@ class managementFilter
     $this->scope = $scope;
   }
 
+  protected function showScope (): bool
+  {
+    if ($this->fixedScope !== NULL) {
+      return !$this->fixedScope;
+    }
+    return $this->parent->listing->getBaseMode();
+  }
+
   function addElement (FilterElement $element)
   {
     $this->filterElements[] = $element;
@@ -91,7 +100,9 @@ class managementFilter
 
       $this->showTemplates = isset($_POST['filter_type_TEMPLATE']);
 
-      $this->scope = (isset($_POST['SCOPE']) ? 'sub' : 'one');
+      if ($this->showScope()) {
+        $this->scope = (isset($_POST['SCOPE']) ? 'sub' : 'one');
+      }
 
       $this->search = (isset($_POST['SEARCH']) ? $_POST['SEARCH'] : '');
 
@@ -122,7 +133,7 @@ class managementFilter
     $smarty = get_smarty();
 
     $smarty->assign('SCOPE',      $this->scope);
-    $smarty->assign('BASEMODE',   $this->parent->listing->getBaseMode());
+    $smarty->assign('SHOWSCOPE',  $this->showScope());
     $smarty->assign('FILTER_PID', $this->pid);
     $smarty->assign('SEARCH',     $this->search);
     $smarty->assign('TYPES',      $this->types);
-- 
GitLab