Created
March 21, 2020 01:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var modX $modx */ | |
switch ($modx->event->name) { | |
case 'OnDocFormSave': | |
/** @var Ticket $resource */ | |
if ($resource->class_key == "Ticket") { | |
//$modx->log(1, "TicketsResGroup ".print_r($resource->toArray(),1)); | |
if(!empty($resource->res_groups)){ | |
$resGroups = $resource->getMany('ResourceGroupResources'); | |
$res_groups = $resource->res_groups; | |
foreach($resGroups as $old_rg){ | |
$isset_group = false; | |
foreach($res_groups as $k=>$rg){ | |
if($rg == 0) unset($res_groups[$k]); | |
if ($old_rg->document_group == $rg) { | |
unset($res_groups[$k]); | |
//$isset_groups = true; | |
$isset_group = true; | |
} | |
} | |
if(!$isset_group) $old_rg->remove(); | |
} | |
if(!empty($res_groups)){ //add group | |
foreach($res_groups as $k=>$rg){ | |
if($rg == 0) continue; | |
$resource->joinGroup((int)$rg); | |
} | |
} | |
}else{ | |
$resGroups = $resource->getMany('ResourceGroupResources'); | |
foreach($resGroups as $old_rg){ | |
$old_rg->remove(); | |
} | |
} | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment