Last active
August 20, 2018 23:15
-
-
Save esimonetti/6a892fa3ede87f40e85bfdb6edf05d10 to your computer and use it in GitHub Desktop.
Set Case's Teams to the private team of the created by user and of the assigned user. This logic will work only if all users have as default team, their own private team only
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 | |
// Enrico Simonetti | |
// enricosimonetti.com | |
// | |
// 2017-12-19 on Sugar 7.9.2.0 | |
// | |
// Set Case's Teams to the private team of the created by user and of the assigned user. This logic will work only if all users have as default team, their own private team only | |
// file: custom/logichooks/modules/Cases/afterSaveCases.php | |
class afterSaveCases | |
{ | |
public function callAfterSave($bean, $event, $arguments) | |
{ | |
$GLOBALS['log']->debug('afterSaveCases->callAfterSave() for id '.$bean->id); | |
$GLOBALS['log']->debug('afterSaveCases->callAfterSave() with team_set_id '.$bean->team_set_id); | |
$teams_to_replace = array(); | |
$created_by_user = BeanFactory::getBean('Users', $bean->created_by); | |
if(!empty($created_by_user->id)) { | |
$created_by_private_team = $created_by_user->getPrivateTeamID(); | |
if(!empty($created_by_private_team)) { | |
$teams_to_replace[] = $created_by_private_team; | |
$bean->team_id = $created_by_private_team; | |
} | |
} | |
if(!empty($bean->assigned_user_id)) { | |
$assigned_user = BeanFactory::getBean('Users', $bean->assigned_user_id); | |
if(!empty($assigned_user->id)) { | |
$assigned_user_private_team = $created_by_user->getPrivateTeamID(); | |
if(!empty($assigned_user_private_team)) { | |
$teams_to_replace[] = $assigned_user_private_team; | |
} | |
} | |
} | |
if(!empty($teams_to_replace)) { | |
$bean->teams->replace( | |
$teams_to_replace | |
); | |
} | |
$GLOBALS['log']->debug('afterSaveCases->callAfterSave() teams: '.print_r($teams_to_replace, true)); | |
} | |
} |
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 | |
// file: custom/Extension/modules/Cases/Ext/LogicHooks/installer.afterSave.php | |
$hook_array['after_save'][] = array( | |
1, | |
'Cases after save hook', | |
'custom/logichooks/modules/Cases/afterSaveCases.php', | |
'afterSaveCases', | |
'callAfterSave' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment