Пример #1
0
/**
 * Prépare le retour de la fonction renameHandler.
 * On pourrait se servir de prepareMoveReturn étant donné que la structure est similaire, mais en faisant une autre
 * fonction, on peut différencier les indexes, les messages, etc et être mieux préparé à de possibles modifications.
 * @author Alban Truc
 * @param array $options
 * @param bool $operationSuccess
 * @param string|array $error
 * @param array $elementsImpacted
 * @param array $updatedElements
 * @param array $failedToUpdate
 * @return array
 */
function prepareRenameReturn($options, $operationSuccess, $error, $elementsImpacted, $updatedElements, $failedToUpdate)
{
    $return = array();
    $elementManager = new ElementManager();
    $return['operationSuccess'] = $operationSuccess;
    if (!empty($error)) {
        if (is_array($error) && array_key_exists('error', $error)) {
            $return['error'] = $error['error'];
        } else {
            $return['error'] = $error;
        }
    }
    if (is_array($options)) {
        if (array_key_exists('returnImpactedElements', $options) && $options['returnImpactedElements'] == 'TRUE') {
            if (empty($elementsImpacted)) {
                $return['elementsImpacted'] = 'No impacted element or the function had an error before the element(s) got retrieved.';
            } else {
                $return['elementsImpacted'] = $elementManager->convert($elementsImpacted);
            }
        }
        if (array_key_exists('returnUpdatedElements', $options) && $options['returnUpdatedElements'] == 'TRUE') {
            if (empty($updatedElements)) {
                $return['updatedElements'] = 'No updated element or the function had an error before trying to.';
            } else {
                $return['updatedElements'] = $elementManager->convert($updatedElements);
            }
            if (empty($failedToUpdate)) {
                $return['failedToUpdate'] = 'No fail or the function had an error before trying to.';
            } else {
                $return['failedToUpdate'] = $elementManager->convert($failedToUpdate);
            }
        }
    }
    return $return;
}