]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/Entity/Document.php
Propose existing types on document form, not only system ones
[galette.git] / galette / lib / Galette / Entity / Document.php
index 1a8f4aacac11b712ad52796139fee8b8cf30d117..ff7c179809fda6a8de442102f7933e6863fc9683 100644 (file)
@@ -495,6 +495,29 @@ class Document implements FileInterface
         return $this->getSystemTypes($translated)[$type] ?? _T($type);
     }
 
+    /**
+     * Get all known types
+     *
+     * @return array<string,string>
+     *
+     * @throws Throwable
+     */
+    public function getTypes(): array
+    {
+        $types = $this->getSystemTypes();
+
+        $select = $this->zdb->select(self::TABLE);
+        $select->quantifier('DISTINCT');
+        $select->where->notIn('type', array_keys($this->getSystemTypes(false)));
+        $results = $this->zdb->execute($select);
+
+        foreach ($results as $r) {
+            $types[$r->type] = $r->type;
+        }
+
+        return $types;
+    }
+
     /**
      * Handle files
      *