Fix: use hooks for extrafields

This commit is contained in:
Regis Houssin 2011-08-09 17:59:45 +00:00
parent e639bd67e3
commit cf6a902bfe
8 changed files with 467 additions and 321 deletions

View File

@ -0,0 +1,37 @@
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* 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 2 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/adherents/class/actions_adherent.class.php
* \ingroup member
* \brief File for member class
* \version $Id: actions_adherent.class.php,v 1.1 2011/08/09 17:59:48 hregis Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
/**
* \class ActionsAdherent
* \brief Class to manage members objects
*/
class ActionsAdherent extends Adherent
{
}
?>

View File

@ -24,7 +24,7 @@
* \file htdocs/adherents/class/adherent.class.php
* \ingroup member
* \brief File of class to manage members of a foundation
* \version $Id: adherent.class.php,v 1.45 2011/08/03 00:45:44 eldy Exp $
* \version $Id: adherent.class.php,v 1.46 2011/08/09 17:59:46 hregis Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@ -420,12 +420,33 @@ class Adherent extends CommonObject
if ($resql)
{
$nbrowsaffected+=$this->db->affected_rows($resql);
/*
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
*/
// Hook for external modules
if (! empty($this->hooks))
{
foreach($this->hooks as $hook)
{
if ($hook['type'] == 'member_extrafields' && ! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
if (method_exists($module,'insertExtraFields'))
{
$result=$module->insertExtraFields($this);
if ($result < 0) $error++;
}
}
}
}
}
// Update password
if (! $error && $this->pass)

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
* \file htdocs/core/class/commonobject.class.php
* \ingroup core
* \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...)
* \version $Id: commonobject.class.php,v 1.149 2011/08/09 09:13:09 hregis Exp $
* \version $Id: commonobject.class.php,v 1.150 2011/08/09 17:59:45 hregis Exp $
*/
@ -1456,7 +1456,9 @@ class CommonObject
{
if (in_array($type,$hooks))
{
$path = '/'.$module.'/class/';
$path = $module;
if ($module == 'adherent') $path = 'adherents';
$path = '/'.$path.'/class/';
$actionfile = 'actions_'.$module.'.class.php';
$daofile = 'dao_'.$module.'.class.php';
$pathroot = '';
@ -1990,7 +1992,7 @@ class CommonObject
/**
*
*/
function showInputFields($object,$post='',$socid=0)
function showInputFields($object,$post='',$id=0)
{
global $conf;
@ -1999,19 +2001,19 @@ class CommonObject
$extrafields = new ExtraFields($this->db);
$elementtype = $object->element;
if ($object->element = 'societe') $elementtype = 'company';
if ($object->element == 'societe') $elementtype = 'company';
$extralabels=$extrafields->fetch_name_optionals_label($elementtype);
if ($socid)
if ($id)
{
$res=$object->fetch_optionals($socid,$extralabels);
$res=$object->fetch_optionals($id,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }
}
foreach($extrafields->attribute_label as $key=>$label)
{
$value=(isset($post["options_$key"])?$post["options_$key"]:($socid?$object->array_options["options_$key"]:''));
$value=(isset($post["options_$key"])?$post["options_$key"]:($id?$object->array_options["options_$key"]:''));
print "<tr><td>".$label.'</td><td colspan="3">';
print $extrafields->showInputField($key,$value);
print '</td></tr>'."\n";
@ -2021,7 +2023,7 @@ class CommonObject
/**
*
*/
function showOutputFields($object,$socid)
function showOutputFields($object,$id)
{
global $conf;
@ -2030,11 +2032,11 @@ class CommonObject
$extrafields = new ExtraFields($this->db);
$elementtype = $object->element;
if ($object->element = 'societe') $elementtype = 'company';
if ($object->element == 'societe') $elementtype = 'company';
$extralabels=$extrafields->fetch_name_optionals_label($elementtype);
$res=$object->fetch_optionals($socid,$extralabels);
$res=$object->fetch_optionals($id,$extralabels);
if ($res < 0) { dol_print_error($db); exit; }
foreach($extrafields->attribute_label as $key=>$label)
@ -2050,29 +2052,29 @@ class CommonObject
* Add/Update extra fields
* TODO Use also type of field to do manage date fields
*/
function insertExtraFields()
function insertExtraFields($object)
{
if (sizeof($this->array_options) > 0)
if (sizeof($object->array_options) > 0)
{
$this->db->begin();
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del);
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$object->id;
dol_syslog(get_class($object)."::insertExtraFields delete sql=".$sql_del);
$this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
foreach($this->array_options as $key => $value)
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$object->table_element."_extrafields (fk_object";
foreach($object->array_options as $key => $value)
{
// Add field of attribut
$sql.=",".substr($key,8); // Remove 'options_' prefix
}
$sql .= ") VALUES (".$this->id;
foreach($this->array_options as $key => $value)
$sql .= ") VALUES (".$object->id;
foreach($object->array_options as $key => $value)
{
// Add field o fattribut
if ($this->array_options[$key] != '')
if ($object->array_options[$key] != '')
{
$sql.=",'".$this->array_options[$key]."'";
$sql.=",'".$object->array_options[$key]."'";
}
else
{
@ -2081,12 +2083,12 @@ class CommonObject
}
$sql.=")";
dol_syslog(get_class($this)."::insertExtraFields insert sql=".$sql);
dol_syslog(get_class($object)."::insertExtraFields insert sql=".$sql);
$resql = $this->db->query($sql);
if (! $resql)
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
dol_syslog(get_class($object)."::update ".$this->error,LOG_ERR);
$this->db->rollback();
return -1;
}

View File

@ -28,7 +28,7 @@
* \file htdocs/includes/modules/modAdherent.class.php
* \ingroup member
* \brief File descriptor or module Member
* \version $Id: modAdherent.class.php,v 1.87 2011/07/31 23:28:11 eldy Exp $
* \version $Id: modAdherent.class.php,v 1.88 2011/08/09 17:59:51 hregis Exp $
*/
include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php");
@ -74,9 +74,10 @@ class modAdherent extends DolibarrModules
// Constantes
//-----------
$this->const = array();
$this->const[0] = array("MAIN_SEARCHFORM_ADHERENT","yesno","1","Show form for quick member search");
$this->const[1] = array("ADHERENT_MAIL_RESIL","texte","Votre adhésion vient d'être résiliée.\r\nNous espérons vous revoir très bientôt","Mail de résiliation");
$this->const[2] = array("ADHERENT_MAIL_VALID","texte","Votre adhésion vient d'être validée. \r\nVoici le rappel de vos coordonnées (toute information erronée entrainera la non validation de votre inscription) :\r\n\r\n%INFOS%\r\n\r\n","Mail de validation");
$this->const[0] = array("MAIN_MODULE_ADHERENT_HOOKS","chaine",'member_extrafields','',0);
$this->const[2] = array("MAIN_SEARCHFORM_ADHERENT","yesno","1","Show form for quick member search");
$this->const[3] = array("ADHERENT_MAIL_RESIL","texte","Votre adhésion vient d'être résiliée.\r\nNous espérons vous revoir très bientôt","Mail de résiliation");
$this->const[4] = array("ADHERENT_MAIL_VALID","texte","Votre adhésion vient d'être validée. \r\nVoici le rappel de vos coordonnées (toute information erronée entrainera la non validation de votre inscription) :\r\n\r\n%INFOS%\r\n\r\n","Mail de validation");
$this->const[5] = array("ADHERENT_MAIL_VALID_SUBJECT","chaine","Votre adhésion a été validée","Sujet du mail de validation");
$this->const[6] = array("ADHERENT_MAIL_RESIL_SUBJECT","chaine","Résiliation de votre adhésion","Sujet du mail de résiliation");
$this->const[10] = array("ADHERENT_MAILMAN_UNSUB_URL","chaine","http://lists.domain.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&user=%EMAIL%","Url de désinscription aux listes mailman");

View File

@ -22,7 +22,7 @@
/**
* \defgroup societe Module societe
* \brief Module to manage third parties (customers, prospects)
* \version $Id: modSociete.class.php,v 1.120 2011/08/09 09:13:09 hregis Exp $
* \version $Id: modSociete.class.php,v 1.121 2011/08/09 17:59:50 hregis Exp $
*/
/**
@ -108,7 +108,7 @@ class modSociete extends DolibarrModules
$this->const[$r][0] = "MAIN_MODULE_SOCIETE_HOOKS";
$this->const[$r][1] = "chaine";
$this->const[$r][2] = "extrafields";
$this->const[$r][2] = "thirdparty_extrafields";
$this->const[$r][3] = "";
$this->const[$r][4] = 0;
$this->const[$r][4] = 'current';

View File

@ -26,7 +26,7 @@
* \file htdocs/societe/class/societe.class.php
* \ingroup societe
* \brief File for third party class
* \version $Id: societe.class.php,v 1.92 2011/07/31 23:22:58 eldy Exp $
* \version $Id: societe.class.php,v 1.93 2011/08/09 17:59:50 hregis Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@ -533,11 +533,32 @@ class Societe extends CommonObject
// Si le fournisseur est classe on l'ajoute
$this->AddFournisseurInCategory($this->fournisseur_categorie);
/*
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
*/
// Hook for external modules
if (! empty($this->hooks))
{
foreach($this->hooks as $hook)
{
if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
if (method_exists($module,'insertExtraFields'))
{
$result=$module->insertExtraFields($this);
if ($result < 0) $error++;
}
}
}
}
}
if (! $error && $call_trigger)
{

View File

@ -25,7 +25,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
* \version $Id: soc.php,v 1.128 2011/08/09 14:27:38 hregis Exp $
* \version $Id: soc.php,v 1.129 2011/08/09 17:59:52 hregis Exp $
*/
require("../main.inc.php");
@ -78,7 +78,7 @@ else
// Instantiate hooks of thirdparty module. Note that conf->hooks_modules contains array array
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks(array('thirdpartycard','extrafields'));
$object->callHooks(array('thirdpartycard','thirdparty_extrafields'));
}
@ -1040,7 +1040,7 @@ else
{
foreach($object->hooks as $hook)
{
if ($hook['type'] == 'extrafields' && ! empty($hook['modules']))
if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
@ -1483,7 +1483,7 @@ else
{
foreach($object->hooks as $hook)
{
if ($hook['type'] == 'extrafields' && ! empty($hook['modules']))
if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
@ -1839,7 +1839,7 @@ else
{
foreach($object->hooks as $hook)
{
if ($hook['type'] == 'extrafields' && ! empty($hook['modules']))
if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
{
foreach($hook['modules'] as $module)
{
@ -2029,5 +2029,5 @@ else
$db->close();
llxFooter('$Date: 2011/08/09 14:27:38 $ - $Revision: 1.128 $');
llxFooter('$Date: 2011/08/09 17:59:52 $ - $Revision: 1.129 $');
?>