Mutualize code

This commit is contained in:
Laurent Destailleur
2019-10-16 01:36:07 +02:00
parent b0355dd149
commit d3df04c5aa
4 changed files with 168 additions and 89 deletions

View File

@@ -489,6 +489,82 @@ class MyObject extends CommonObject
return $this->deleteLineCommon($user, $idline, $notrigger);
}
/**
* Set draft status
*
* @param User $user Object user that modify
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, >0 if OK
*/
public function setDraft($user, $notrigger = 0)
{
// Protection
if ($this->status <= self::STATUS_DRAFT)
{
return 0;
}
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
{
$this->error='Permission denied';
return -1;
}*/
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'BOM_UNVALIDATE');
}
/**
* Set cancel status
*
* @param User $user Object user that modify
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, 0=Nothing done, >0 if OK
*/
public function cancel($user, $notrigger = 0)
{
// Protection
if ($this->status != self::STATUS_VALIDATED)
{
return 0;
}
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
{
$this->error='Permission denied';
return -1;
}*/
return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'BOM_CLOSE');
}
/**
* Set back to validated status
*
* @param User $user Object user that modify
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int <0 if KO, 0=Nothing done, >0 if OK
*/
public function reopen($user, $notrigger = 0)
{
// Protection
if ($this->status != self::STATUS_CANCELED)
{
return 0;
}
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate))))
{
$this->error='Permission denied';
return -1;
}*/
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'BOM_REOPEN');
}
/**
* Return a link to the object card (with optionaly the picto)
*