diff --git a/build/database/repo/ue.php b/build/database/repo/ue.php index 49d04d4..d9e6e0e 100644 --- a/build/database/repo/ue.php +++ b/build/database/repo/ue.php @@ -69,7 +69,7 @@ class ue extends Repo_i { * @volumeTD [OPT] The UE's new volume of TD * @volumeTP [OPT] The UE's new volume of TP * @disabled [OPT] Whether the UE is disabled - * @defaultFormation [OPT] The default formation foreign key + * @defaultFormation [OPT] The default formation foreign key (-1 to unset) * * @return updated Whether the update have been successful * @@ -86,10 +86,20 @@ class ue extends Repo_i { if( !is_null($volumeTD) ){ $build_rq[] = '`volumeTD` = :volumeTD'; $bind_param[':volumeTD'] = $volumeTD; } if( !is_null($volumeTP) ){ $build_rq[] = '`volumeTP` = :volumeTP'; $bind_param[':volumeTP'] = $volumeTP; } if( !is_null($disabled) ){ $build_rq[] = '`disabled` = :disabled'; $bind_param[':disabled'] = $disabled?1:0; } - if( !is_null($defaultFormation) ){ $build_rq[] = '`Formation_idFormation` = :defaultFormation'; $bind_param[':defaultFormation'] = $defaultFormation; } + + // not null @defaultFormation -> set it + if( !is_null($defaultFormation) ){ + + // if @defaultFormation is (-1) -> unset + if( $defaultFormation < 0 ){ $build_rq[] = '`Formation_idFormation` = NULL'; } + // else -> set to new value + else{ $build_rq[] = '`Formation_idFormation` = :defaultFormation'; $bind_param[':defaultFormation'] = $defaultFormation; } + + } + /* (2) ERROR if no updated field */ - if( count($build_rq) <= 0 || count($bind_param) <= 1 ) + if( count($build_rq) <= 0 ) return FALSE; /* (3) Build request */