'entity',
'label' => 'Modifier/Supprimer une entité',
'class' => get_called_class(),
'path' => __FILE__,
'icon' => 'fas fa-database',
'color' => '#ff9f43'
);
if(!isset($key)) return $manifest;
return isset($manifest[$key]) ? $manifest[$key] : '' ;
}
public static function actions($key = null){
$actions = array(
'delete' => array('label' => 'Supprimer'),
'update' => array('label' => 'Modifier')
);
if(!isset($key)) return $actions;
return isset($actions[$key]) ? $actions[$key] : array('label'=>'Non définit');
}
//méthode d'affichage de l'effet
public static function form($item){
$html = '';
$class = get_called_class();
ob_start();
require_once(__DIR__.SLASH.'..'.SLASH.'WorkflowEvent.class.php');
$events = WorkflowEvent::events(null,Workflow::TYPE_LIST);
$randomId = sha1(mt_rand(0,1000).time());
$conditions = !empty($item['effect-conditions']) ? base64_encode(json_encode(filters_set($item['effect-conditions']['advanced']))) : '';
$changes = !empty($item['entity-change']) ? base64_encode(utf8_decode($item['entity-change'])) : '';
?>
toArray();
if(isset($parameters['old'])) $parameters['old'] = $parameters['old']->toArray();
}
$effect->values['entity-entity'] = template($effect->values['entity-entity'],$parameters,true);
//var_dump($effect,$parameters);
$entitySlug = $effect->values['entity-entity'];
$entity = array();
foreach ( WorkflowEvent::events(null,Workflow::TYPE_LIST) as $event) {
if($event['entity']['slug'] == $entitySlug){
$entity = $event['entity'];
break;
}
}
//var_dump($effect);
$filters = array();
foreach($effect->values['effect-conditions']['advanced'] as $filter){
if(isset($filter['value']) && isset($filter['value'][0])) $filter['value'][0] = template($filter['value'][0],$parameters,true);
$filters[] = $filter;
}
$whereQuery = 'SELECT id FROM {{table}} WHERE 1 ';
$queryData = array();
filter_secure_query($filters,array_keys($entity['fields']),$whereQuery,$queryData);
$targetsQuery = $entity['class']::staticQuery($whereQuery,$queryData);
foreach ($targetsQuery->fetchAll() as $line)
$targetsIds[] = $line['id'];
//récuperation de l'entité cible de l'effet
require_once($entity['file']);
switch($effect->values['entity-action']){
case 'update':
$changes = array();
foreach(json_decode($effect->values['entity-change'],true) as $field){
$changes[$field['slug']] = $field['value'];
}
$entity['class']::change($changes,array('id:IN'=>$targetsIds));
break;
case 'delete':
$entity['class']::delete(array('id:IN'=>$targetsIds));
break;
}
$logs .= ' Lancement de "'.self::manifest('label').'"
';
$results = true;
$logs .= 'Résultat '.$results.'
';
return $logs;
}
}
?>