]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6571 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 5 Jan 2024 17:32:41 +0000 (18:32 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 5 Jan 2024 17:32:41 +0000 (18:32 +0100)
app/Fields/FluidbookExtranetTask.php

index 03bff017c546681b98ca90dc86a033031badc689..92322a927c629239bf3cc779cde1561aa139daa7 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Fields;
 
+use Cubedesigners\UserDatabase\Permissions;
 use Cubist\Backpack\CubistCrudPanel;
 use Cubist\Backpack\Facades\App;
 use Cubist\Backpack\Magic\Fields\SelectFromArray;
@@ -13,37 +14,51 @@ class FluidbookExtranetTask extends SelectFromArray
     protected static $_projects = null;
     protected static $_projectTasks = null;
 
-    protected static $_taskOptions = null;
+    protected static $_taskOptions = [];
 
     public function getOptions()
     {
-        if (null === static::$_taskOptions) {
-            static::$_taskOptions = [];
-            if (null === static::$_projects) {
-                static::$_projects = static::_getProjects();
-            }
-            if (null === static::$_projectTasks) {
-                static::$_projectTasks = static::_getTasks();
+        $invoicable = "all";
+
+        if ($this->issetCrud()) {
+            /** @var CubistCrudPanel $crud */
+            try {
+                $crud = $this->getCrud();
+                $entry = $crud->getCurrentEntry();
+                if ($entry && $entry->invoicable_company) {
+                    $invoicable = $crud->getCurrentEntry()->invoicable_company;
+                }
+            } catch (\Exception $e) {
+
             }
+        }
+
+        if (null === static::$_projects) {
+            static::$_projects = static::_getProjects();
+        }
+        if (null === static::$_projectTasks) {
+            static::$_projectTasks = static::_getTasks();
+        }
 
+        if (!isset(static::$_taskOptions[$invoicable])) {
+            static::$_taskOptions[$invoicable] = [];
             foreach (static::$_projectTasks as $project => $tasks) {
+
                 if (!isset(static::$_projects[$project])) {
                     continue;
                 }
                 $p = static::$_projects[$project];
+                if ($invoicable !== 'all' && Permissions::getCompanyByUser($p->client) != $invoicable) {
+                    continue;
+                }
+
                 foreach ($tasks as $id => $task) {
-                    static::$_taskOptions[$id] = $p->projet_id . ' | ' . $p->nom . ' > ' . $task->nom;
+                    static::$_taskOptions[$invoicable][$id] = $p->projet_id . ' | ' . $p->nom . ' > ' . $task->nom;
                 }
             }
         }
 
-        if ($this->issetCrud()) {
-            /** @var CubistCrudPanel $crud */
-            $crud=$this->getCrud();
-            $invoicable=$crud->getCurrentEntry()->invoicable_company;
-        }
-
-        return static::$_taskOptions;
+        return static::$_taskOptions[$invoicable];
     }
 
     protected function _postSetCrud()