* * 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. */ /** * \file class/actions_idsconnect.class.php * \ingroup idsconnect * \brief Hook-Klasse für IDS Connect (ADL-Buttons auf Produkt-Lieferantenpreisen) */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php'; /** * Hook-Aktionen für IDS Connect */ class ActionsIdsconnect extends CommonHookActions { /** @var DoliDB */ public $db; /** @var string */ public $error = ''; /** @var array */ public $errors = array(); /** @var array */ public $results = array(); /** @var string HTML-Output für Hooks */ public $resprints; /** * Constructor * * @param DoliDB $db Database handler */ public function __construct($db) { $this->db = $db; } /** * Spaltenüberschrift in der Lieferantenpreis-Tabelle * * @param array $parameters Hook-Parameter * @param object $object Produkt-Objekt * @param string $action Aktuelle Aktion * @param HookManager $hookmanager Hook-Manager * @return int 0=weiter */ public function printFieldListTitle($parameters, &$object, &$action, $hookmanager) { if (strpos($parameters['currentcontext'], 'pricesuppliercard') === false) { return 0; } // Spalte nur anzeigen wenn mindestens ein aktiver IDS-Supplier existiert if (!$this->hasActiveIdsSuppliers()) { return 0; } global $langs; $langs->load("idsconnect@idsconnect"); print ''.img_picto($langs->trans("ModuleIdsconnectName"), 'fa-plug').''; return 0; } /** * ADL-Button pro Zeile in der Lieferantenpreis-Tabelle * * @param array $parameters Hook-Parameter (id_pfp, id_fourn, prod_id) * @param object $object Produkt-Objekt * @param string $action Aktuelle Aktion * @param HookManager $hookmanager Hook-Manager * @return int 0=weiter */ public function printFieldListValue($parameters, &$object, &$action, $hookmanager) { if (strpos($parameters['currentcontext'], 'pricesuppliercard') === false) { return 0; } // Keine Spalte wenn keine IDS-Supplier existieren if (!$this->hasActiveIdsSuppliers()) { return 0; } global $user, $langs; $langs->load("idsconnect@idsconnect"); $html = ''; if ($user->hasRight('idsconnect', 'use')) { $id_pfp = $parameters['id_pfp']; $pfpMap = $this->getPfpMap($parameters['prod_id']); $idsMap = $this->getIdsSupplierMap(); if (isset($pfpMap[$id_pfp])) { $fk_soc = $pfpMap[$id_pfp]['fk_soc']; $ref_fourn = $pfpMap[$id_pfp]['ref_fourn']; if (isset($idsMap[$fk_soc]) && !empty($ref_fourn)) { $supplier_id = $idsMap[$fk_soc]; $url = DOL_URL_ROOT.'/custom/idsconnect/launch.php'; $url .= '?supplier_id='.((int) $supplier_id); $url .= '&ids_action=ADL'; $url .= '&artikelnr='.urlencode($ref_fourn); $url .= '&token='.newToken(); $html .= 'trans("IdsconnectShowInShop")).'">'; $html .= img_picto($langs->trans("IdsconnectShowInShop"), 'fa-external-link-alt', 'style="color: #0077b6;"'); $html .= ''; } } } $html .= ''; print $html; return 0; } /** * IDS-Supplier-Map laden (fk_soc => supplier_id), gecacht * * @return array */ private function getIdsSupplierMap() { static $map = null; if ($map !== null) { return $map; } $map = array(); $sql = "SELECT rowid, fk_soc FROM ".$this->db->prefix()."idsconnect_supplier"; $sql .= " WHERE active = 1 AND fk_soc IS NOT NULL AND fk_soc > 0"; $sql .= " AND entity IN (".getEntity('idsconnect').")"; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { $map[$obj->fk_soc] = $obj->rowid; } $this->db->free($resql); } return $map; } /** * Product-Fournisseur-Price-Map laden (pfp_id => {fk_soc, ref_fourn}), gecacht pro Produkt * * @param int $prod_id Produkt-ID * @return array */ private function getPfpMap($prod_id) { static $cache = array(); $prod_id = (int) $prod_id; if (isset($cache[$prod_id])) { return $cache[$prod_id]; } $cache[$prod_id] = array(); $sql = "SELECT rowid, fk_soc, ref_fourn FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_product = ".$prod_id; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { $cache[$prod_id][$obj->rowid] = array( 'fk_soc' => $obj->fk_soc, 'ref_fourn' => $obj->ref_fourn, ); } $this->db->free($resql); } return $cache[$prod_id]; } /** * Prüft ob mindestens ein aktiver IDS-Supplier existiert (gecacht) * * @return bool */ private function hasActiveIdsSuppliers() { return count($this->getIdsSupplierMap()) > 0; } }