Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
validation
Commits
7100f01c
Commit
7100f01c
authored
1 year ago
by
Jean-Philippe Metivier
Browse files
Options
Downloads
Patches
Plain Diff
Service
parent
b7585fbb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/UnicaenValidation/Service/ValidationInstance/ValidationInstanceService.php
+34
-7
34 additions, 7 deletions
.../Service/ValidationInstance/ValidationInstanceService.php
with
34 additions
and
7 deletions
src/UnicaenValidation/Service/ValidationInstance/ValidationInstanceService.php
+
34
−
7
View file @
7100f01c
...
...
@@ -2,14 +2,16 @@
namespace
UnicaenValidation\Service\ValidationInstance
;
use
Doctrine\ORM\Exception\NotSupported
;
use
Doctrine\ORM\Exception\ORMException
;
use
Doctrine\ORM\NonUniqueResultException
;
use
Doctrine\ORM\ORMException
;
use
Doctrine\ORM\QueryBuilder
;
use
Laminas\Mvc\Controller\AbstractActionController
;
use
UnicaenApp\Exception\RuntimeException
;
use
UnicaenApp\Service\EntityManagerAwareTrait
;
use
UnicaenUtilisateur\Entity\Db\User
;
use
UnicaenValidation\Entity\Db\ValidationInstance
;
use
UnicaenValidation\Entity\HasValidationsInterface
;
use
UnicaenValidation\Service\ValidationType\ValidationTypeServiceAwareTrait
;
class
ValidationInstanceService
{
...
...
@@ -105,11 +107,14 @@ class ValidationInstanceService {
*/
public
function
createQueryBuilder
()
:
QueryBuilder
{
try
{
$qb
=
$this
->
getEntityManager
()
->
getRepository
(
ValidationInstance
::
class
)
->
createQueryBuilder
(
'vinstance'
)
->
addSelect
(
'createur'
)
->
join
(
'vinstance.histoCreateur'
,
'createur'
)
->
addSelect
(
'modificateur'
)
->
join
(
'vinstance.histoModificateur'
,
'modificateur'
)
->
addSelect
(
'vtype'
)
->
join
(
'vinstance.type'
,
'vtype'
)
;
->
addSelect
(
'vtype'
)
->
join
(
'vinstance.type'
,
'vtype'
);
}
catch
(
NotSupported
$e
)
{
throw
new
RuntimeException
(
"Un problème est survenu lors de la création du QueryBuilder ["
.
ValidationInstance
::
class
.
"]"
,
0
,
$e
);
}
return
$qb
;
}
...
...
@@ -142,7 +147,7 @@ class ValidationInstanceService {
try
{
$result
=
$qb
->
getQuery
()
->
getOneOrNullResult
();
}
catch
(
NonUniqueResultException
$e
)
{
throw
new
RuntimeException
(
"Plusieurs ValidationInstance partagent le même id ["
.
$id
.
"]"
,
0
,
tru
e
);
throw
new
RuntimeException
(
"Plusieurs ValidationInstance partagent le même id ["
.
$id
.
"]"
,
0
,
$
e
);
}
return
$result
;
}
...
...
@@ -205,6 +210,7 @@ class ValidationInstanceService {
/**
* @param string $code
* @param string|null $valeur
* @param string|null $justification
* @return ValidationInstance
*/
public
function
createWithCode
(
string
$code
,
?string
$valeur
=
null
,
?string
$justification
=
null
)
:
ValidationInstance
...
...
@@ -219,4 +225,25 @@ class ValidationInstanceService {
return
$instance
;
}
public
function
setValidationActive
(
HasValidationsInterface
$element
,
string
$code
,
?string
$value
=
null
)
:
HasValidationsInterface
{
//historisation de l'état actif actuel (s'il existe)
$validationActive
=
$element
->
getValidationActiveByTypeCode
(
$code
);
if
(
isset
(
$validationActive
))
{
$this
->
historise
(
$validationActive
);
}
//creation de la nouvelle instance
$validation
=
$this
->
createWithCode
(
$code
,
$value
);
//ajout à l'element et persist
$element
->
addValidation
(
$validation
);
try
{
$this
->
getEntityManager
()
->
persist
(
$element
);
}
catch
(
ORMException
$e
)
{
throw
new
RuntimeException
(
"Un problème est survenu lors de l'ajout de actif de ["
.
get_class
(
$element
)
.
"]"
,
0
,
$e
);
}
return
$element
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment