forked from Wavyzz/dolibarr
Update adherent_type.class.php
This commit is contained in:
@@ -89,6 +89,8 @@ class AdherentType extends CommonObject
|
||||
/** @var array Array of members */
|
||||
public $members=array();
|
||||
|
||||
public $multilangs=array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -101,6 +103,185 @@ class AdherentType extends CommonObject
|
||||
$this->statut = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load array this->multilangs
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function getMultiLangs()
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$current_lang = $langs->getDefaultLang();
|
||||
|
||||
$sql = "SELECT lang, label, description, email";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql.= " WHERE fk_type=".$this->id;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
while ($obj = $this->db->fetch_object($result))
|
||||
{
|
||||
//print 'lang='.$obj->lang.' current='.$current_lang.'<br>';
|
||||
if ($obj->lang == $current_lang) // si on a les traduct. dans la langue courante on les charge en infos principales.
|
||||
{
|
||||
$this->label = $obj->label;
|
||||
$this->description = $obj->description;
|
||||
$this->email = $obj->email;
|
||||
}
|
||||
$this->multilangs["$obj->lang"]["label"] = $obj->label;
|
||||
$this->multilangs["$obj->lang"]["description"] = $obj->description;
|
||||
$this->multilangs["$obj->lang"]["email"] = $obj->email;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error: ".$this->db->lasterror()." - ".$sql;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update or add a translation for a product
|
||||
*
|
||||
* @param User $user Object user making update
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function setMultiLangs($user)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
|
||||
$current_lang = $langs->getDefaultLang();
|
||||
|
||||
foreach ($langs_available as $key => $value)
|
||||
{
|
||||
if ($key == $current_lang) {
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql.= " WHERE fk_type=".$this->id;
|
||||
$sql.= " AND lang='".$key."'";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($this->db->num_rows($result)) // if there is already a description line for this language
|
||||
{
|
||||
$sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql2.= " SET ";
|
||||
$sql2.= " label='".$this->db->escape($this->label)."',";
|
||||
$sql2.= " description='".$this->db->escape($this->description)."'";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", email='".$this->db->escape($this->other)."'";
|
||||
}
|
||||
$sql2.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.=", email";
|
||||
}
|
||||
$sql2.= ")";
|
||||
$sql2.= " VALUES(".$this->id.",'".$this->db->escape($key)."','". $this->db->escape($this->label)."',";
|
||||
$sql2.= " '".$this->db->escape($this->description)."'";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", '".$this->db->escape($this->other)."'";
|
||||
}
|
||||
$sql2.= ")";
|
||||
}
|
||||
dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key);
|
||||
if (! $this->db->query($sql2)) {
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
elseif (isset($this->multilangs[$key])) {
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql.= " WHERE fk_type=".$this->id;
|
||||
$sql.= " AND lang='".$key."'";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
if ($this->db->num_rows($result)) // if there is already a description line for this language
|
||||
{
|
||||
$sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql2.= " SET ";
|
||||
$sql2.= " label='".$this->db->escape($this->multilangs["$key"]["label"])."',";
|
||||
$sql2.= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", email='".$this->db->escape($this->multilangs["$key"]["other"])."'";
|
||||
}
|
||||
$sql2.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.=", email";
|
||||
}
|
||||
$sql2.= ")";
|
||||
$sql2.= " VALUES(".$this->id.",'".$this->db->escape($key)."','". $this->db->escape($this->multilangs["$key"]["label"])."',";
|
||||
$sql2.= " '".$this->db->escape($this->multilangs["$key"]["description"])."'";
|
||||
if (! empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2.= ", '".$this->db->escape($this->multilangs["$key"]["other"])."'";
|
||||
}
|
||||
$sql2.= ")";
|
||||
}
|
||||
|
||||
// We do not save if main fields are empty
|
||||
if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) {
|
||||
if (! $this->db->query($sql2)) {
|
||||
$this->error=$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// language is not current language and we didn't provide a multilang description for this language
|
||||
}
|
||||
}
|
||||
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user);
|
||||
if ($result < 0) {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
// End call triggers
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a language for this product
|
||||
*
|
||||
* @param string $langtodelete Language code to delete
|
||||
* @param User $user Object user making delete
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function delMultiLangs($langtodelete, $user)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang";
|
||||
$sql.= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($langtodelete)."'";
|
||||
|
||||
dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('ADHERENT_TYPE_DEL_MULTILANGS', $user);
|
||||
if ($result < 0) {
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
// End call triggers
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fonction qui permet de creer le status de l'adherent
|
||||
@@ -111,7 +292,7 @@ class AdherentType extends CommonObject
|
||||
*/
|
||||
public function create($user, $notrigger = 0)
|
||||
{
|
||||
global $conf;
|
||||
global $langs, $conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
@@ -180,7 +361,7 @@ class AdherentType extends CommonObject
|
||||
*/
|
||||
public function update($user, $notrigger = 0)
|
||||
{
|
||||
global $conf, $hookmanager;
|
||||
global $langs, $conf, $hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
@@ -202,6 +383,17 @@ class AdherentType extends CommonObject
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
|
||||
$this->description = $this->db->escape($this->note);
|
||||
|
||||
// Multilangs
|
||||
if (! empty($conf->global->MAIN_MULTILANGS)) {
|
||||
if ($this->setMultiLangs($user) < 0) {
|
||||
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
$action='update';
|
||||
|
||||
// Actions on extra fields
|
||||
@@ -283,6 +475,8 @@ class AdherentType extends CommonObject
|
||||
*/
|
||||
public function fetch($rowid)
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut, d.subscription, d.mail_valid, d.note, d.vote";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
|
||||
$sql .= " WHERE d.rowid = ".(int) $rowid;
|
||||
@@ -299,12 +493,18 @@ class AdherentType extends CommonObject
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->rowid;
|
||||
$this->label = $obj->label;
|
||||
$this->morphy = $obj->morphy;
|
||||
$this->morphy = $obj->morphy;
|
||||
$this->statut = $obj->statut;
|
||||
$this->subscription = $obj->subscription;
|
||||
$this->mail_valid = $obj->mail_valid;
|
||||
$this->note = $obj->note;
|
||||
$this->vote = $obj->vote;
|
||||
|
||||
// multilangs
|
||||
if (! empty($conf->global->MAIN_MULTILANGS)) {
|
||||
$this->getMultiLangs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user