forked from Wavyzz/dolibarr
Scrutinizer Auto-Fixes
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
This commit is contained in:
@@ -36,7 +36,7 @@ class CoreObject extends CommonObject
|
||||
/**
|
||||
* @var Array $_fields Fields to synchronize with Database
|
||||
*/
|
||||
protected $fields=array();
|
||||
protected $fields = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -70,8 +70,8 @@ class CoreObject extends CommonObject
|
||||
else $this->{$field} = '';
|
||||
}
|
||||
|
||||
$this->to_delete=false;
|
||||
$this->is_clone=false;
|
||||
$this->to_delete = false;
|
||||
$this->is_clone = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class CoreObject extends CommonObject
|
||||
public function fetch($id, $loadChild = true)
|
||||
{
|
||||
$res = $this->fetchCommon($id);
|
||||
if($res>0) {
|
||||
if ($res > 0) {
|
||||
if ($loadChild) $this->fetchChild();
|
||||
}
|
||||
|
||||
@@ -129,11 +129,11 @@ class CoreObject extends CommonObject
|
||||
*/
|
||||
public function addChild($tabName, $id = 0, $key = 'id', $try_to_load = false)
|
||||
{
|
||||
if(!empty($id))
|
||||
if (!empty($id))
|
||||
{
|
||||
foreach($this->{$tabName} as $k=>&$object)
|
||||
foreach ($this->{$tabName} as $k=>&$object)
|
||||
{
|
||||
if($object->{$key} === $id) return $k;
|
||||
if ($object->{$key} === $id) return $k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ class CoreObject extends CommonObject
|
||||
|
||||
$className = ucfirst($tabName);
|
||||
$this->{$tabName}[$k] = new $className($this->db);
|
||||
if($id>0 && $key==='id' && $try_to_load)
|
||||
if ($id > 0 && $key === 'id' && $try_to_load)
|
||||
{
|
||||
$this->{$tabName}[$k]->fetch($id);
|
||||
}
|
||||
@@ -181,20 +181,20 @@ class CoreObject extends CommonObject
|
||||
{
|
||||
if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
|
||||
{
|
||||
foreach($this->childtables as &$childTable)
|
||||
foreach ($this->childtables as &$childTable)
|
||||
{
|
||||
$className = ucfirst($childTable);
|
||||
|
||||
$this->{$className}=array();
|
||||
$this->{$className} = array();
|
||||
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id;
|
||||
$res = $this->db->query($sql);
|
||||
|
||||
if($res)
|
||||
if ($res)
|
||||
{
|
||||
while($obj = $this->db->fetch_object($res))
|
||||
while ($obj = $this->db->fetch_object($res))
|
||||
{
|
||||
$o=new $className($this->db);
|
||||
$o = new $className($this->db);
|
||||
$o->fetch($obj->rowid);
|
||||
|
||||
$this->{$className}[] = $o;
|
||||
@@ -216,19 +216,19 @@ class CoreObject extends CommonObject
|
||||
*/
|
||||
public function saveChild(User &$user)
|
||||
{
|
||||
if($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
|
||||
if ($this->withChild && !empty($this->childtables) && !empty($this->fk_element))
|
||||
{
|
||||
foreach($this->childtables as &$childTable)
|
||||
foreach ($this->childtables as &$childTable)
|
||||
{
|
||||
$className = ucfirst($childTable);
|
||||
if(!empty($this->{$className}))
|
||||
if (!empty($this->{$className}))
|
||||
{
|
||||
foreach($this->{$className} as $i => &$object)
|
||||
foreach ($this->{$className} as $i => &$object)
|
||||
{
|
||||
$object->{$this->fk_element} = $this->id;
|
||||
|
||||
$object->update($user);
|
||||
if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]);
|
||||
if ($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete == true) unset($this->{$className}[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,7 @@ class CoreObject extends CommonObject
|
||||
public function update(User &$user)
|
||||
{
|
||||
if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed
|
||||
elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user);
|
||||
elseif (isset($this->to_delete) && $this->to_delete == true) return $this->delete($user);
|
||||
|
||||
$error = 0;
|
||||
$this->db->begin();
|
||||
@@ -253,7 +253,7 @@ class CoreObject extends CommonObject
|
||||
$res = $this->updateCommon($user);
|
||||
if ($res)
|
||||
{
|
||||
$result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user);
|
||||
$result = $this->call_trigger(strtoupper($this->element).'_UPDATE', $user);
|
||||
if ($result < 0) $error++;
|
||||
else $this->saveChild($user);
|
||||
}
|
||||
@@ -284,17 +284,17 @@ class CoreObject extends CommonObject
|
||||
*/
|
||||
public function create(User &$user)
|
||||
{
|
||||
if($this->id > 0) return $this->update($user);
|
||||
if ($this->id > 0) return $this->update($user);
|
||||
|
||||
$error = 0;
|
||||
$this->db->begin();
|
||||
|
||||
$res = $this->createCommon($user);
|
||||
if($res)
|
||||
if ($res)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id($this->table_element);
|
||||
|
||||
$result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user);
|
||||
$result = $this->call_trigger(strtoupper($this->element).'_CREATE', $user);
|
||||
if ($result < 0) $error++;
|
||||
else $this->saveChild($user);
|
||||
}
|
||||
@@ -330,20 +330,20 @@ class CoreObject extends CommonObject
|
||||
$error = 0;
|
||||
$this->db->begin();
|
||||
|
||||
$result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user);
|
||||
$result = $this->call_trigger(strtoupper($this->element).'_DELETE', $user);
|
||||
if ($result < 0) $error++;
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$this->deleteCommon($user);
|
||||
if($this->withChild && !empty($this->childtables))
|
||||
if ($this->withChild && !empty($this->childtables))
|
||||
{
|
||||
foreach($this->childtables as &$childTable)
|
||||
foreach ($this->childtables as &$childTable)
|
||||
{
|
||||
$className = ucfirst($childTable);
|
||||
if (!empty($this->{$className}))
|
||||
{
|
||||
foreach($this->{$className} as &$object)
|
||||
foreach ($this->{$className} as &$object)
|
||||
{
|
||||
$object->delete($user);
|
||||
}
|
||||
@@ -376,7 +376,7 @@ class CoreObject extends CommonObject
|
||||
*/
|
||||
public function getDate($field, $format = '')
|
||||
{
|
||||
if(empty($this->{$field})) return '';
|
||||
if (empty($this->{$field})) return '';
|
||||
else
|
||||
{
|
||||
return dol_print_date($this->{$field}, $format);
|
||||
|
||||
Reference in New Issue
Block a user