Skip to content

Commit

Permalink
Merge pull request #9533 from frederic34/trimParameters
Browse files Browse the repository at this point in the history
trimParameters function
  • Loading branch information
eldy committed Sep 18, 2018
2 parents 1c13fbb + f935701 commit 61f5a2e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
70 changes: 23 additions & 47 deletions htdocs/compta/sociales/class/cchargesociales.class.php
Expand Up @@ -77,31 +77,18 @@ public function create(User $user, $notrigger = false)

$error = 0;

// Clean parameters

if (isset($this->libelle)) {
$this->libelle = trim($this->libelle);
}
if (isset($this->deductible)) {
$this->deductible = trim($this->deductible);
}
if (isset($this->active)) {
$this->active = trim($this->active);
}
if (isset($this->code)) {
$this->code = trim($this->code);
}
if (isset($this->fk_pays)) {
$this->fk_pays = trim($this->fk_pays);
}
if (isset($this->module)) {
$this->module = trim($this->module);
}
if (isset($this->accountancy_code)) {
$this->accountancy_code = trim($this->accountancy_code);
}


// Clean parameters
$this->trimParameters(
array(
'libelle',
'deductible',
'active',
'code',
'fk_pays',
'module',
'accountancy_code',
)
);

// Check parameters
// Put here code to add control on parameters values
Expand Down Expand Up @@ -243,28 +230,17 @@ public function update(User $user, $notrigger = false)

// Clean parameters

if (isset($this->libelle)) {
$this->libelle = trim($this->libelle);
}
if (isset($this->deductible)) {
$this->deductible = trim($this->deductible);
}
if (isset($this->active)) {
$this->active = trim($this->active);
}
if (isset($this->code)) {
$this->code = trim($this->code);
}
if (isset($this->fk_pays)) {
$this->fk_pays = trim($this->fk_pays);
}
if (isset($this->module)) {
$this->module = trim($this->module);
}
if (isset($this->accountancy_code)) {
$this->accountancy_code = trim($this->accountancy_code);
}

$this->trimParameters(
array(
'libelle',
'deductible',
'active',
'code',
'fk_pays',
'module',
'accountancy_code',
)
);


// Check parameters
Expand Down
18 changes: 17 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -7324,7 +7324,7 @@ public function fetchComments()
$comment = new Comment($this->db);
$result=$comment->fetchAllFor($this->element, $this->id);
if ($result<0) {
$this->errors=array_merge($this->errors,$comment->errors);
$this->errors=array_merge($this->errors, $comment->errors);
return -1;
} else {
$this->comments = $comment->comments;
Expand All @@ -7341,4 +7341,20 @@ public function getNbComments()
{
return count($this->comments);
}

/**
* Trim object parameters
* @param string[] $parameters array of parameters to trim
*
* @return void
*/
public function trimParameters($parameters)
{
if (!is_array($parameters)) return;
foreach ($parameters as $parameter) {
if (isset($this->$parameter)) {
$this->$parameter = trim($this->$parameter);
}
}
}
}

0 comments on commit 61f5a2e

Please sign in to comment.