N°653 Portal: Lifecycle: Flags on transitions part 2

SVN:trunk[4767]
This commit is contained in:
Guillaume Lajarige
2017-06-22 13:38:45 +00:00
parent 43b8522b85
commit 71ec3da4ac
4 changed files with 29 additions and 20 deletions

View File

@@ -2944,10 +2944,10 @@ EOF
* Updates the object from a flat array of values
* @param $aAttList array $aAttList array of attcode
* @param $aErrors array Returns information about slave attributes
* @param $sTargetState string Target state for which to evaluate the writeable attributes (=current state is empty)
* @param $aAttFlags array Attribute codes => Flags to use instead of those from the MetaModel
* @return array of attcodes that can be used for writing on the current object
*/
public function GetWriteableAttList($aAttList, &$aErrors, $sTargetState = '')
public function GetWriteableAttList($aAttList, &$aErrors, $aAttFlags = array())
{
if (!is_array($aAttList))
{
@@ -2956,14 +2956,19 @@ EOF
// WARNING: if you change this also check the functions DisplayModifyForm and DisplayCaseLog
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef)
{
if ($this->IsNew())
if(array_key_exists($sAttCode, $aAttFlags))
{
$iFlags = $aAttFlags[$sAttCode];
}
elseif ($this->IsNew())
{
$iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
}
else
{
$aVoid = array();
$iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState);
$iFlags = $this->GetAttributeFlags($sAttCode, $aVoid);
}
if ($oAttDef instanceof AttributeCaseLog)
{
@@ -2979,15 +2984,19 @@ EOF
foreach($aAttList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if ($this->IsNew())
if(array_key_exists($sAttCode, $aAttFlags))
{
$iFlags = $aAttFlags[$sAttCode];
}
elseif ($this->IsNew())
{
$iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
}
else
{
$aVoid = array();
$iFlags = $this->GetAttributeFlags($sAttCode, $aVoid, $sTargetState);
$iFlags = $this->GetAttributeFlags($sAttCode, $aVoid);
}
if ($oAttDef->IsWritable())
{
@@ -3172,7 +3181,7 @@ EOF
/**
* Updates the object from the POSTed parameters (form)
*/
public function UpdateObjectFromPostedForm($sFormPrefix = '', $aAttList = null, $sTargetState = '')
public function UpdateObjectFromPostedForm($sFormPrefix = '', $aAttList = null, $aAttFlags = array())
{
if (is_null($aAttList))
{
@@ -3280,7 +3289,7 @@ EOF
$aErrors = array();
$aFinalValues = array();
foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $sTargetState) as $sAttCode => $oAttDef)
foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $aAttFlags) as $sAttCode => $oAttDef)
{
$aFinalValues[$sAttCode] = $aValues[$sAttCode];
}
@@ -3302,7 +3311,7 @@ EOF
/**
* Updates the object from a given page argument
*/
public function UpdateObjectFromArg($sArgName, $aAttList = null, $sTargetState = '')
public function UpdateObjectFromArg($sArgName, $aAttList = null, $aAttFlags = array())
{
if (is_null($aAttList))
{
@@ -3320,7 +3329,7 @@ EOF
$aErrors = array();
$aFinalValues = array();
foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $sTargetState) as $sAttCode => $oAttDef)
foreach($this->GetWriteableAttList(array_keys($aValues), $aErrors, $aAttFlags) as $sAttCode => $oAttDef)
{
$aFinalValues[$sAttCode] = $aValues[$sAttCode];
}

View File

@@ -816,7 +816,7 @@ EOF
$sClass = get_class($oObj);
$sStimulus = trim(utils::ReadPostedParam('apply_stimulus', ''));
$sTargetState = '';
$aExpectedAttributes = array();
if (!empty($sStimulus))
{
// Compute the target state
@@ -826,10 +826,10 @@ EOF
{
throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
}
$sTargetState = $aTransitions[$sStimulus]['target_state'];
}
$aExpectedAttributes = $oObj->GetTransitionAttributes($sStimulus /*, current state*/);
}
$oObj->UpdateObjectFromPostedForm('' /* form prefix */, $aAttList, $sTargetState);
$oObj->UpdateObjectFromPostedForm('' /* form prefix */, $aAttList, $aExpectedAttributes);
// Optional: apply a stimulus
//

View File

@@ -1375,7 +1375,7 @@ EOF
}
}
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $aExpectedAttributes);
if (count($aErrors) == 0)
{
@@ -1496,7 +1496,7 @@ EOF
}
}
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $aExpectedAttributes);
if (count($aErrors) == 0)
{
@@ -1513,7 +1513,7 @@ EOF
{
// Rollback to the previous state... by reloading the object from the database and applying the modifications again
$oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey());
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
$oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $aExpectedAttributes);
$sIssues = $e->getMessage();
}
}

View File

@@ -514,9 +514,9 @@ EOF
return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
}
public function UpdateObjectFromPostedForm($sFormPrefix = '', $sAttList = null, $sTargetState = '')
public function UpdateObjectFromPostedForm($sFormPrefix = '', $sAttList = null, $aAttFlags = array())
{
parent::UpdateObjectFromPostedForm($sFormPrefix, $sAttList, $sTargetState);
parent::UpdateObjectFromPostedForm($sFormPrefix, $sAttList, $aAttFlags);
// And now read the other post parameters...
$oAttributeSet = $this->Get('attribute_list');
$aAttributes = array();