diff --git a/datamodel.combodo-approval-extended.xml b/datamodel.combodo-approval-extended.xml
index 58d2c65..1e3cc62 100755
--- a/datamodel.combodo-approval-extended.xml
+++ b/datamodel.combodo-approval-extended.xml
@@ -87,6 +87,17 @@
true
+
+ bizmodel
+ target_class
+
+ false
+
+
+ target_class_state
+
+ false
+
level1_rule
@@ -200,15 +211,21 @@
-
10
-
-
- 10
-
- -
- 20
-
- -
- 30
-
+ -
+ 10
+
+ -
+ 20
+
+ -
+ 30
+
+ -
+ 40
+
+ -
+ 50
+
@@ -279,9 +296,15 @@
-
20
- -
- 30
-
+ -
+ 30
+
+ -
+ 40
+
+ -
+ 50
+
@@ -342,7 +365,14 @@
-
+
+
+ target_class_state
+ obj_class
+
+ false
+
+
true
@@ -355,32 +385,35 @@
'first_reject' => ApprovalScheme::EXIT_ON_FIRST_REJECT,
'first_approve' => ApprovalScheme::EXIT_ON_FIRST_APPROVE,
);
- if ((get_class($oObject) != 'UserRequest'))
- {
+
+ $aAllowedClasses = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets', ApprovalConfiguration::DEFAULT_TARGET);
+ if (array_key_exists(get_class($oObject), $aAllowedClasses) === false) {
return null;
}
- $sTargetState = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'target_state', 'new');
- if ($sReachingState != $sTargetState)
- {
+
+ $aTargetState = $aAllowedClasses[get_class($oObject)]['target_states'];
+ if (in_array($sReachingState, $aTargetState) === false) {
return null;
}
- $sOQL = 'SELECT ApprovalRule AS ar JOIN ServiceSubcategory AS sc ON sc.approvalrule_id = ar.id WHERE sc.id = :servicesubcategory';
+ $sOQL = 'SELECT ApprovalRule AS ar JOIN ServiceSubcategory AS sc ON sc.approvalrule_id = ar.id WHERE sc.id = :servicesubcategory AND ar.target_class = :target_class AND ar.target_class_state = :target_class_state';
$oApprovalRuleSet = new DBObjectSet(
DBObjectSearch::FromOQL($sOQL),
- array(),
- array('servicesubcategory' => $oObject->Get('servicesubcategory_id'))
- );
+ [],
+ ['servicesubcategory' => $oObject->Get('servicesubcategory_id'), 'target_class' => get_class($oObject), 'target_class_state' => $sReachingState]);
+
if ($oApprovalRuleSet->count() == 0)
{
// No approval rule applies to the current object
return null;
}
- $bReusePreviousAnswers = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'reuse_previous_answers', true);
+ $bReusePreviousAnswers = $aAllowedClasses[get_class($oObject)][ 'reuse_previous_answers'];
$oApprovalRule = $oApprovalRuleSet->fetch();
$oScheme = new ExtendedApprovalScheme();
+ $oScheme->Set('target_class_state', $sReachingState);
+ $oScheme->Set('started_state', $sReachingState);
$bStepAdded = false;
@@ -551,7 +584,9 @@
return false;
}
- $sAllowedProfiles = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'bypass_profiles', 'Administrator, Service Manager');
+ $aAllowedClasses = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets', ApprovalConfiguration::DEFAULT_TARGET);
+
+ $sAllowedProfiles = $aAllowedClasses[$this->Get('obj_class')]['bypass_profiles'];
$aAllowed = array();
foreach (explode(',', $sAllowedProfiles) as $sProfileRaw)
{
diff --git a/main.combodo-approval-extended.php b/main.combodo-approval-extended.php
index 8840ffc..44c7e6e 100755
--- a/main.combodo-approval-extended.php
+++ b/main.combodo-approval-extended.php
@@ -23,7 +23,16 @@
* @author Denis Flaven
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
-
+class ApprovalConfiguration
+{
+ const DEFAULT_TARGET = [
+ 'UserRequest' => [
+ 'target_states' => ['new'],
+ 'bypass_profiles' => 'Service Manager',
+ 'reuse_previous_answers' => true,
+ ]
+ ];
+}
class ApprovalComputeWorkingHours implements iWorkingTimeComputer
{
public static function GetDescription()
@@ -51,17 +60,22 @@ class HideButtonsPlugin implements iApplicationUIExtension
{
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
{
- if ( (get_class($oObject) == 'UserRequest' ) && ( $oObject->IsNew()) )
+ $aAllowedClasses = MetaModel::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets',ApprovalConfiguration::DEFAULT_TARGET);
+ if (array_key_exists(get_class($oObject), $aAllowedClasses) && MetaModel::HasLifecycle(get_class($oObject)))
{
- $oSet = new DBObjectSet(new DBObjectSearch('ApprovalRule'));
- $iCount = $oSet->Count();
- if ($iCount > 0)
- {
- $oPage->add_ready_script(
-<<Get($sStateAttCode);
+
+ if (in_array($sTargetState, $aAllowedClasses[get_class($oObject)][ 'target_states']) ) {
+ $sOQL = 'SELECT ApprovalRule AS ar JOIN ServiceSubcategory AS sc ON sc.approvalrule_id = ar.id WHERE ar.target_class = :target_class AND ar.target_class_state = :target_state';
+ $oApprovalRuleSet = new DBObjectSet( DBObjectSearch::FromOQL($sOQL), [], ['target_class' => get_class($oObject), 'target_state' => $sTargetState]);
+ if ($oApprovalRuleSet->Count() > 0) {
+ $oPage->add_ready_script(
+<< '', // hyperlink to manual setup documentation, if any
'doc.more_information' => '', // hyperlink to more information, if any
- 'settings' => array(
- // Module specific settings go here, if any
- 'target_state' => 'new',
- 'bypass_profiles' => 'Administrator, Service Manager',
- 'reuse_previous_answers' => true
- ),
+ 'settings' =>
+ [
+ 'targets' => [
+ 'UserRequest' =>
+ [
+ 'target_states' => ['new'],
+ 'bypass_profiles' => 'Service Manager',
+ 'reuse_previous_answers' => true,
+ ],
+ ],
+ ],
)
);
@@ -73,7 +78,28 @@ class ApprovalExtendedInstaller extends ModuleInstallerAPI
{
public static function BeforeWritingConfig(Config $oConfiguration)
{
- // If you want to override/force some configuration values, do it here
+ if (empty(utils::GetConfig()->GetModuleSetting('combodo-approval-extended', 'targets', null))
+ && !empty(utils::GetConfig()->GetModuleSetting('combodo-approval-extended', 'target_states', null) )) {
+ // Migration of the old configuration to the new one
+ $newConfiguration = [
+ 'UserRequest' => [
+ 'target_states' => [$oConfiguration->GetModuleSetting('combodo-approval-extended', 'target_states', null) ],
+ 'bypass_profiles' =>$oConfiguration->GetModuleSetting('combodo-approval-extended', 'bypass_profiles', 'Service Manager') ,
+ 'reuse_previous_answers' => $oConfiguration->GetModuleSetting('combodo-approval-extended', 'reuse_previous_answers', true) ,
+ ]
+ ];
+ $oConfiguration->SetModuleSetting('combodo-approval-extended', 'targets', $newConfiguration);
+ }
+ // Replacing old conf parameters value to indicate that it is obsolete
+ $aParamsToRemove = array('target_states', 'bypass_profiles', 'reuse_previous_answers');
+ foreach($aParamsToRemove as $sParamToRemove)
+ {
+ $sParamCurrentValue = $oConfiguration->GetModuleSetting('combodo-approval-extended', $sParamToRemove, null);
+ if(!empty($sParamCurrentValue))
+ {
+ $oConfiguration->SetModuleSetting('combodo-approval-extended', $sParamToRemove, 'No longer used, you can remove this parameter.');
+ }
+ }
return $oConfiguration;
}