Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°3366 - Multiple target state on approbal-extended #7

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
81 changes: 58 additions & 23 deletions datamodel.combodo-approval-extended.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
<default_value/>
<is_null_allowed>true</is_null_allowed>
</field>
<field id="target_class" xsi:type="AttributeClass">
<class_category>bizmodel</class_category>
<sql>target_class</sql>
<default_value/>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="target_class_state" xsi:type="AttributeString">
<sql>target_class_state</sql>
<default_value/>
<is_null_allowed>false</is_null_allowed>
</field>
<field id="level1_rule" xsi:type="AttributeOQL">
<sql>level1_rule</sql>
<default_value/>
Expand Down Expand Up @@ -200,15 +211,21 @@
<item id="fieldset:ApprovalRule:baseinfo">
<rank>10</rank>
<items>
<item id="name">
<rank>10</rank>
</item>
<item id="description">
<rank>20</rank>
</item>
<item id="coveragewindow_id">
<rank>30</rank>
</item>
<item id="name">
<rank>10</rank>
</item>
<item id="description">
<rank>20</rank>
</item>
<item id="target_class">
<rank>30</rank>
</item>
<item id="target_class_state">
<rank>40</rank>
</item>
<item id="coveragewindow_id">
<rank>50</rank>
</item>
</items>
</item>
</items>
Expand Down Expand Up @@ -279,9 +296,15 @@
<item id="description">
<rank>20</rank>
</item>
<item id="coveragewindow_id">
<rank>30</rank>
</item>
<item id="target_class">
<rank>30</rank>
</item>
<item id="target_class_state">
<rank>40</rank>
</item>
<item id="coveragewindow_id">
<rank>50</rank>
</item>
</items>
</search>
<list>
Expand Down Expand Up @@ -342,7 +365,14 @@
</attributes>
</reconciliation>
</properties>
<fields/>
<fields>
<field id="target_class_state" xsi:type="AttributeString">
<sql>target_class_state</sql>
<class_field>obj_class</class_field>
<default_value/>
<is_null_allowed>false</is_null_allowed>
</field>
</fields>
<methods>
<method id="GetApprovalScheme">
<static>true</static>
Expand All @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
34 changes: 24 additions & 10 deletions main.combodo-approval-extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
* @author Denis Flaven <[email protected]>
* @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()
Expand Down Expand Up @@ -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(
<<<EOF
$('button.action[name="next_action"]').hide();
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($oObject));
$sTargetState = $oObject->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(
<<<EOF
$('button.action[name="next_action"]').hide();
EOF
);
);
}
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions module.combodo-approval-extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@
'doc.manual_setup' => '', // 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,assigned',
'bypass_profiles' => 'Service Manager',
'reuse_previous_answers' => true,
],
],
],
)
);

Expand Down