From a355f4fc8bb1746d87aa4d6dbee3d27f517d6701 Mon Sep 17 00:00:00 2001 From: kkhelifa Date: Fri, 4 Nov 2022 17:46:32 +0100 Subject: [PATCH] NEW: Add new hooks for actioncomm --- htdocs/comm/action/class/actioncomm.class.php | 13 ++++++++++++ htdocs/core/lib/company.lib.php | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 228ff397607..aa14ba6e696 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1306,8 +1306,17 @@ class ActionComm extends CommonObject dol_syslog(get_class()."::getActions", LOG_DEBUG); + require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($db); + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context + $hookmanager->initHooks(array('agendadao')); + $sql = "SELECT a.id"; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; + // Fields from hook + $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype); + $reshook = $hookmanager->executeHooks('getActionsListFrom', $parameters); // Note that $action and $object may have been modified by hook + if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint; $sql .= " WHERE a.entity IN (".getEntity('agenda').")"; if (!empty($socid)) { $sql .= " AND a.fk_soc = ".((int) $socid); @@ -1326,6 +1335,10 @@ class ActionComm extends CommonObject if (!empty($filter)) { $sql .= $filter; } + // Fields where hook + $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype); + $reshook = $hookmanager->executeHooks('getActionsListWhere', $parameters); // Note that $action and $object may have been modified by hook + if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint; if ($sortorder && $sortfield) { $sql .= $this->db->order($sortfield, $sortorder); } diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 43264ac3d98..3d0cb72e7c9 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1489,6 +1489,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql = ''; if (isModEnabled('agenda')) { + require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($db); + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context + $hookmanager->initHooks(array('agendadao')); + // Recherche histo sur actioncomm if (is_object($objcon) && $objcon->id > 0) { $sql = "SELECT DISTINCT a.id, a.label as label,"; @@ -1528,6 +1533,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } } + // Fields from hook + $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon); + $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook + if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint; + $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id"; @@ -1539,6 +1549,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id); } + // Fields from hook + $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon); + $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook + if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint; + if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid"; } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') { @@ -1639,6 +1654,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin addOtherFilterSQL($sql, $donetodo, $now, $filters); + // Fields from hook + $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module); + $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook + if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint; + if (is_array($actioncode)) { foreach ($actioncode as $code) { $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);