Skip to content
Snippets Groups Projects
Commit 54a3d873 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #13679 TIME 0:20 continue refactoring notification scripts

parent e6e469f1
No related branches found
No related tags found
No related merge requests found
...@@ -85,12 +85,12 @@ while ($state != 'END') { ...@@ -85,12 +85,12 @@ while ($state != 'END') {
Bt_writeLog(['level' => 'INFO', 'message' => $nbRecipients.' recipients found, checking active and absences']); Bt_writeLog(['level' => 'INFO', 'message' => $nbRecipients.' recipients found, checking active and absences']);
$parameter = \Parameter\models\ParameterModel::getById(['select' => ['param_value_int'], 'id' => 'user_quota']);
if ($notification['diffusion_type'] === 'dest_entity') { if ($notification['diffusion_type'] === 'dest_entity') {
foreach ($recipients as $key => $recipient) { foreach ($recipients as $key => $recipient) {
$entity_id = $recipient['entity_id']; $entity_id = $recipient['entity_id'];
Bt_writeLog(['level' => 'INFO', 'message' => 'Recipient entity '.$entity_id]); Bt_writeLog(['level' => 'INFO', 'message' => 'Recipient entity '.$entity_id]);
$parameter = \Parameter\models\ParameterModel::getById(['select' => ['param_value_int'], 'id' => 'user_quota']);
if (($recipient['enabled'] == 'N' && (empty($parameter) || $parameter['param_value_int'] == 0)) || $recipient['mail'] == '') { if (($recipient['enabled'] == 'N' && (empty($parameter) || $parameter['param_value_int'] == 0)) || $recipient['mail'] == '') {
Bt_writeLog(['level' => 'INFO', 'message' => $entity_id.' is disabled or mail is invalid, this notification will not be send']); Bt_writeLog(['level' => 'INFO', 'message' => $entity_id.' is disabled or mail is invalid, this notification will not be send']);
unset($recipients[$key]); unset($recipients[$key]);
...@@ -106,8 +106,7 @@ while ($state != 'END') { ...@@ -106,8 +106,7 @@ while ($state != 'END') {
foreach ($recipients as $key => $recipient) { foreach ($recipients as $key => $recipient) {
$user_id = $recipient['user_id']; $user_id = $recipient['user_id'];
Bt_writeLog(['level' => 'INFO', 'message' => 'Recipient '.$user_id]); Bt_writeLog(['level' => 'INFO', 'message' => 'Recipient '.$user_id]);
$parameter = \Parameter\models\ParameterModel::getById(['select' => ['param_value_int'], 'id' => 'user_quota']);
if (($recipient['status'] == 'SPD' && (empty($parameter) || $parameter['param_value_int'] == 0)) || $recipient['status'] == 'DEL') { if (($recipient['status'] == 'SPD' && (empty($parameter) || $parameter['param_value_int'] == 0)) || $recipient['status'] == 'DEL') {
Bt_writeLog(['level' => 'INFO', 'message' => $user_id.' is disabled or deleted, this notification will not be send']); Bt_writeLog(['level' => 'INFO', 'message' => $user_id.' is disabled or deleted, this notification will not be send']);
unset($recipients[$key]); unset($recipients[$key]);
...@@ -181,7 +180,7 @@ while ($state != 'END') { ...@@ -181,7 +180,7 @@ while ($state != 'END') {
$html = str_replace('&', '&', $html); $html = str_replace('&', '&', $html);
$html = str_replace('&', '#and#', $html); $html = str_replace('&', '#and#', $html);
$recipient_mail = $tmpNotif['recipient']['mail']; $recipient_mail = $tmpNotif['recipient']['mail'];
// Attachments // Attachments
$attachments = array(); $attachments = array();
......
...@@ -21,20 +21,20 @@ use User\models\UserModel; ...@@ -21,20 +21,20 @@ use User\models\UserModel;
class DiffusionTypesController class DiffusionTypesController
{ {
public function getRecipients($args = []) public static function getRecipients($args = [])
{ {
$diffusionTypes = NotificationModel::getDiffusionType(); $diffusionTypes = NotificationModel::getDiffusionType();
foreach ($diffusionTypes as $diffusionType) { foreach ($diffusionTypes as $diffusionType) {
if ($diffusionType['id'] == $args['notification']['diffusionType']) { if ($diffusionType['id'] == $args['notification']['diffusion_type']) {
$diffusionInfo = $diffusionType; $function = $diffusionType['function'];
break; break;
} }
} }
$recipients = DiffusionTypesController::$diffusionInfo['function'](['request' => $args['request'], 'notification' => $args['notification']]); $recipients = DiffusionTypesController::$function(['request' => $args['request'], 'notification' => $args['notification']]);
return $recipients; return $recipients;
} }
public function getRecipientsByContact($args = []) public static function getRecipientsByContact($args = [])
{ {
if ($args['request'] == 'recipients') { if ($args['request'] == 'recipients') {
$contactsMatch = DatabaseModel::select([ $contactsMatch = DatabaseModel::select([
...@@ -50,7 +50,7 @@ class DiffusionTypesController ...@@ -50,7 +50,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByCopie($args = []) public static function getRecipientsByCopie($args = [])
{ {
switch ($request) { switch ($request) {
case 'recipients': case 'recipients':
...@@ -171,7 +171,7 @@ class DiffusionTypesController ...@@ -171,7 +171,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByDestEntity($args = []) public static function getRecipientsByDestEntity($args = [])
{ {
switch ($request) { switch ($request) {
case 'recipients': case 'recipients':
...@@ -243,7 +243,7 @@ class DiffusionTypesController ...@@ -243,7 +243,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByDestUserSign($args = []) public static function getRecipientsByDestUserSign($args = [])
{ {
switch ($request) { switch ($request) {
case 'recipients': case 'recipients':
...@@ -355,7 +355,7 @@ class DiffusionTypesController ...@@ -355,7 +355,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByDestUserVisa($args = []) public static function getRecipientsByDestUserVisa($args = [])
{ {
switch ($request) { switch ($request) {
case 'recipients': case 'recipients':
...@@ -467,7 +467,7 @@ class DiffusionTypesController ...@@ -467,7 +467,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByDestUser($args = []) public static function getRecipientsByDestUser($args = [])
{ {
switch ($request) { switch ($request) {
case 'recipients': case 'recipients':
...@@ -577,7 +577,7 @@ class DiffusionTypesController ...@@ -577,7 +577,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByEntity($args = []) public static function getRecipientsByEntity($args = [])
{ {
if ($args['request'] == 'recipients') { if ($args['request'] == 'recipients') {
$aEntities = explode(",", $args['notification']['diffusion_properties']); $aEntities = explode(",", $args['notification']['diffusion_properties']);
...@@ -593,14 +593,14 @@ class DiffusionTypesController ...@@ -593,14 +593,14 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByGroup($args = []) public static function getRecipientsByGroup($args = [])
{ {
if ($args['request'] == 'recipients') { if ($args['request'] == 'recipients') {
$aGroups = explode(",", $args['notification']['diffusion_properties']); $aGroups = explode(",", $args['notification']['diffusion_properties']);
$recipients = DatabaseModel::select([ $recipients = DatabaseModel::select([
'select' => ['us.*'], 'select' => ['us.*'],
'table' => ['usergroup_content ug, users us, usergroups'], 'table' => ['usergroup_content ug, users us, usergroups'],
'where' => ['us.id = ug.user_id', 'ug.group_id = usergroups.group_id', 'usergroups.group_id in (?)', 'us.status != ?'], 'where' => ['us.id = ug.user_id', 'ug.group_id = usergroups.id', 'usergroups.group_id in (?)', 'us.status != ?'],
'data' => [$aGroups, 'DEL'] 'data' => [$aGroups, 'DEL']
]); ]);
return $recipients; return $recipients;
...@@ -609,7 +609,7 @@ class DiffusionTypesController ...@@ -609,7 +609,7 @@ class DiffusionTypesController
} }
} }
public function getRecipientsByUser($args = []) public static function getRecipientsByUser($args = [])
{ {
if ($args['request'] == 'recipients') { if ($args['request'] == 'recipients') {
$aUsers = explode(",", $args['notification']['diffusion_properties']); $aUsers = explode(",", $args['notification']['diffusion_properties']);
......
...@@ -172,13 +172,13 @@ abstract class NotificationModelAbstract ...@@ -172,13 +172,13 @@ abstract class NotificationModelAbstract
'id' => 'group', 'id' => 'group',
'label' => 'Groupe', 'label' => 'Groupe',
'add_attachment' => 'true', 'add_attachment' => 'true',
'function' => 'getRecipientsByContact' 'function' => 'getRecipientsByGroup'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'entity', 'id' => 'entity',
'label' => 'Entité', 'label' => 'Entité',
'add_attachment' => 'true', 'add_attachment' => 'true',
'function' => 'getRecipientsByCopie' 'function' => 'getRecipientsByEntity'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'dest_entity', 'id' => 'dest_entity',
...@@ -190,7 +190,7 @@ abstract class NotificationModelAbstract ...@@ -190,7 +190,7 @@ abstract class NotificationModelAbstract
'id' => 'dest_user', 'id' => 'dest_user',
'label' => 'Liste de diffusion du document', 'label' => 'Liste de diffusion du document',
'add_attachment' => 'false', 'add_attachment' => 'false',
'function' => 'getRecipientsByDestUserSign' 'function' => 'getRecipientsByDestUser'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'dest_user_visa', 'id' => 'dest_user_visa',
...@@ -202,27 +202,27 @@ abstract class NotificationModelAbstract ...@@ -202,27 +202,27 @@ abstract class NotificationModelAbstract
'id' => 'dest_user_sign', 'id' => 'dest_user_sign',
'label' => 'Signataire actuel du document', 'label' => 'Signataire actuel du document',
'add_attachment' => 'true', 'add_attachment' => 'true',
'function' => 'getRecipientsByDestUser' 'function' => 'getRecipientsByDestUserSign'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'user', 'id' => 'user',
'label' => 'Utilisateur désigné', 'label' => 'Utilisateur désigné',
'add_attachment' => 'true', 'add_attachment' => 'true',
'function' => 'getRecipientsByEntity' 'function' => 'getRecipientsByUser'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'copy_list', 'id' => 'copy_list',
'label' => 'Liste de diffusion du document', 'label' => 'Liste de diffusion du document',
'add_attachment' => 'false', 'add_attachment' => 'false',
'function' => 'getRecipientsByGroup' 'function' => 'getRecipientsByCopie'
); );
$diffusionTypes[] = array( $diffusionTypes[] = array(
'id' => 'contact', 'id' => 'contact',
'label' => 'Contact du document', 'label' => 'Contact du document',
'add_attachment' => 'true', 'add_attachment' => 'true',
'function' => 'getRecipientsByUser' 'function' => 'getRecipientsByContact'
); );
return $diffusionTypes; return $diffusionTypes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment