* * 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 * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file subtotaltitle/class/DocumentTypeHelper.class.php * \ingroup subtotaltitle * \brief Helper class für verschiedene Dokumenttypen (Rechnung, Angebot, Auftrag) */ /** * Class DocumentTypeHelper * Hilfsklasse um mit verschiedenen Dokumenttypen zu arbeiten */ class DocumentTypeHelper { /** * Erkennt den Dokumenttyp aus dem Context * * @param string $context Hook-Context (z.B. 'invoicecard', 'propalcard', 'ordercard') * @return string|null Dokumenttyp ('invoice', 'propal', 'order') oder null */ public static function getTypeFromContext($context) { if (strpos($context, 'invoicecard') !== false) { return 'invoice'; } if (strpos($context, 'propalcard') !== false) { return 'propal'; } if (strpos($context, 'ordercard') !== false) { return 'order'; } return null; } /** * Holt den Dokumenttyp aus dem Object * * @param object $object Dolibarr Objekt * @return string|null Dokumenttyp ('invoice', 'propal', 'order') oder null */ public static function getTypeFromObject($object) { if (!is_object($object) || !isset($object->element)) { return null; } if ($object->element == 'facture') { return 'invoice'; } if ($object->element == 'propal') { return 'propal'; } if ($object->element == 'commande') { return 'order'; } return null; } /** * Holt die Tabellennamen für einen Dokumenttyp * * @param string $type Dokumenttyp ('invoice', 'propal', 'order') * @return array Array mit Tabellennamen (parent_table, lines_table, fk_parent, fk_line) */ public static function getTableNames($type) { $tables = array( 'invoice' => array( 'parent_table' => 'facture', 'lines_table' => 'facturedet', 'fk_parent' => 'fk_facture', 'fk_line' => 'fk_facturedet', 'element' => 'facture' ), 'propal' => array( 'parent_table' => 'propal', 'lines_table' => 'propaldet', 'fk_parent' => 'fk_propal', 'fk_line' => 'fk_propaldet', 'element' => 'propal' ), 'order' => array( 'parent_table' => 'commande', 'lines_table' => 'commandedet', 'fk_parent' => 'fk_commande', 'fk_line' => 'fk_commandedet', 'element' => 'commande' ) ); return isset($tables[$type]) ? $tables[$type] : null; } /** * Holt die Hook-Contexts für einen Dokumenttyp * * @param string $type Dokumenttyp ('invoice', 'propal', 'order') * @return string Hook-Context */ public static function getContext($type) { $contexts = array( 'invoice' => 'invoicecard', 'propal' => 'propalcard', 'order' => 'ordercard' ); return isset($contexts[$type]) ? $contexts[$type] : ''; } }