Loading doc/unicaen/2024-11-migration-organisations-personnes.md +7 −0 Changes for doc/unicaen/2024-11-migration-organisations-personnes.md: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -246,6 +246,13 @@ WHERE AND ladaplogin != ''; ``` > Pour un changement de nom de connecteur (de 'rest' vers 'db'), il faut mettre à jour la table 'organizationperson' (champ origin - valeur rest > db) ```sql UPDATE organizationperson SET origin = 'db' WHERE origin = 'rest'; ``` Enfin, lancer la synchronisation des personnes : ```bash Loading module/Oscar/config/module.config.php +2 −0 Changes for module/Oscar/config/module.config.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ return array( 'index', 'logs', 'messages', 'motscles', 'organizationRole', 'organizationRoleApi', 'organizationType', Loading Loading @@ -307,6 +308,7 @@ return array( 'excel', 'organizationLeader', 'declarant', 'declarant2', 'declarantAPI', 'validationActivity', 'validationActivity2', Loading module/Oscar/config/routes.yml +10 −0 Changes for module/Oscar/config/routes.yml: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,7 @@ timesheet: route: /import-ical defaults: action: importIcal declarant: type: segment options: Loading Loading @@ -2005,6 +2006,15 @@ administration: route: /discipline defaults: action: discipline motscles: type: segment may_terminate: true options: route: /motscles defaults: action: motscles tva: type: segment may_terminate: true Loading module/Oscar/src/Oscar/Controller/ActivityMotsClesController.php +171 −4 Changes for module/Oscar/src/Oscar/Controller/ActivityMotsClesController.php: 171 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ namespace Oscar\Controller; use Laminas\Http\Response; use Laminas\View\Model\JsonModel; use Oscar\Entity\ActivityMotCle; use Oscar\Provider\Privileges; use Oscar\Service\ProjectGrantService; use Oscar\Traits\UseLoggerService; use Oscar\Traits\UseLoggerServiceTrait; use Throwable; Loading @@ -13,19 +15,56 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL { use UseLoggerServiceTrait; /** * @return ProjectGrantService */ public function getActivityService(): ProjectGrantService { return $this->activityService; } /** * @param ProjectGrantService $activityService */ public function setActivityService(ProjectGrantService $activityService): void { $this->activityService = $activityService; } public function apiAction() { try { $activity = NULL; $activityId = $this->params()->fromQuery('activity_id'); if ($activityId) { $activity = $this->getActivityService()->getGrant($activityId); } if ($this->getRequest()->getMethod() == "GET") { return $this->getMotsCles(); $includeActivityCountQueryParam = $this->params()->fromQuery('include_activity_count'); $includeActivityCount = $includeActivityCountQueryParam && $includeActivityCountQueryParam === "true"; return $this->getMotsCles($includeActivityCount, $activity); } if ($this->getRequest()->getMethod() == "POST") { $action_mot_cle_json = json_decode($this->getRequest()->getContent()); if ($action_mot_cle_json->action == "create") { return $this->createMotCle($action_mot_cle_json); return $this->createMotCle($action_mot_cle_json, $activity); } if ($action_mot_cle_json->action == "delete") { return $this->deleteMotCle($action_mot_cle_json); } if ($action_mot_cle_json->action == "update") { return $this->updateMotCle($action_mot_cle_json); } if ($action_mot_cle_json->action == "fusion") { return $this->fusionnerMotsCles($action_mot_cle_json); } } Loading @@ -42,25 +81,49 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL } } private function getMotsCles() { private function getMotsCles($includeCount, $activity) { if ($activity) { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity); } else { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE); } /** @var ActivityMotCleRepository $activityMotCleRepository */ $activityMotCleRepository = $this->getEntityManager()->getRepository(ActivityMotCle::class); $motsCles = []; $tousLesMotsCles = []; if ($includeCount) { foreach ($activityMotCleRepository->getMotsClesCounted() as $motCle) { $motsCles[] = [ 'id' => $motCle['id'], 'label' => $motCle['label'], 'activity_count' => $motCle['activity_count'], ]; } } else { foreach ($activityMotCleRepository->getAll() as $motCle) { $motsCles[] = [ 'id' => $motCle->getId(), 'label' => $motCle->getLabel(), ]; } } $response = new JsonModel(); $response->setVariables(['motscles' => $motsCles]); return $response; } private function createMotCle($action_mot_cle_json) { private function createMotCle($action_mot_cle_json, $activity) { if ($activity) { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity); } else { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE); } $this->getLoggerService()->info("createMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); Loading @@ -75,4 +138,108 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL return $response; } private function deleteMotCle($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("deleteMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $motCle = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $action_mot_cle_json->id)); if (!$motCle) { throw new \Exception("Le mot clé n'existe pas. Veuillez actualiser la page."); } $this->getEntityManager()->remove($motCle); $this->getEntityManager()->flush(); $response = new JsonModel(); $response->setVariables(['id' => $action_mot_cle_json->id]); return $response; } private function updateMotCle($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("updateMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $motCle = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $action_mot_cle_json->id)); if (!$motCle) { throw new \Exception("Le mot clé n'existe pas. Veuillez actualiser la page."); } $motCle->setLabel($action_mot_cle_json->label); $this->getEntityManager()->persist($motCle); $this->getEntityManager()->flush(); $response = new JsonModel(); $response->setVariables(['id' => $motCle->getId(), 'label' => $motCle->getLabel()]); return $response; } private function fusionnerMotsCles($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("fusionMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $targetId = $action_mot_cle_json->targetId; if (!$targetId || !is_numeric($targetId)) { throw new \Exception("Le paramètre targetId doit être un identifiant numérique."); } $motCleCible = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $targetId)); if (!$motCleCible) { throw new \Exception("Le mot clé cible n'existe pas. Veuillez actualiser la page."); } $idsToMerge = $action_mot_cle_json->idsToMerge; if (!$idsToMerge || !is_array($idsToMerge) || count($idsToMerge) < 2) { throw new \Exception("Le paramètre idsToMerge doit être un tableau d'au moins deux identifiants numériques de mots clés."); } $motsClesASupprimer = []; foreach ($idsToMerge as $idToMerge) { if (!is_numeric($idToMerge)) { throw new \Exception("Le paramètre idsToMerge doit contenir des identifiants numériques de mots clés."); } if ($idToMerge == $targetId) { continue; } $motCleASupprimer = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $idToMerge)); if (!$motCleASupprimer) { throw new \Exception("Le mot clé à supprimer n'existe pas. Veuillez actualiser la page."); } $motsClesASupprimer[] = $motCleASupprimer; } foreach ($motsClesASupprimer as $motCleASupprimer) { foreach ($motCleASupprimer->getActivities() as $activity) { if (!$activity->hasMotcle($motCleCible)) { $activity->addMotCle($motCleCible); $this->getEntityManager()->persist($activity); $this->getEntityManager()->flush(); } } } foreach ($motsClesASupprimer as $motCleASupprimer) { $this->getEntityManager()->remove($motCleASupprimer); $this->getEntityManager()->flush(); } $response = new JsonModel(); $response->setVariables([]); return $response; } } module/Oscar/src/Oscar/Controller/ActivityMotsClesControllerFactory.php +2 −0 Changes for module/Oscar/src/Oscar/Controller/ActivityMotsClesControllerFactory.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Factory\FactoryInterface; use Oscar\Service\OscarUserContext; use Oscar\Service\ProjectGrantService; class ActivityMotsClesControllerFactory implements FactoryInterface { Loading @@ -15,6 +16,7 @@ class ActivityMotsClesControllerFactory implements FactoryInterface $c->setEntityManager($container->get(EntityManager::class)); $c->setOscarUserContextService($container->get(OscarUserContext::class)); $c->setLoggerService($container->get('Logger')); $c->setActivityService($container->get(ProjectGrantService::class)); return $c; } } Loading
doc/unicaen/2024-11-migration-organisations-personnes.md +7 −0 Changes for doc/unicaen/2024-11-migration-organisations-personnes.md: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -246,6 +246,13 @@ WHERE AND ladaplogin != ''; ``` > Pour un changement de nom de connecteur (de 'rest' vers 'db'), il faut mettre à jour la table 'organizationperson' (champ origin - valeur rest > db) ```sql UPDATE organizationperson SET origin = 'db' WHERE origin = 'rest'; ``` Enfin, lancer la synchronisation des personnes : ```bash Loading
module/Oscar/config/module.config.php +2 −0 Changes for module/Oscar/config/module.config.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ return array( 'index', 'logs', 'messages', 'motscles', 'organizationRole', 'organizationRoleApi', 'organizationType', Loading Loading @@ -307,6 +308,7 @@ return array( 'excel', 'organizationLeader', 'declarant', 'declarant2', 'declarantAPI', 'validationActivity', 'validationActivity2', Loading
module/Oscar/config/routes.yml +10 −0 Changes for module/Oscar/config/routes.yml: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,7 @@ timesheet: route: /import-ical defaults: action: importIcal declarant: type: segment options: Loading Loading @@ -2005,6 +2006,15 @@ administration: route: /discipline defaults: action: discipline motscles: type: segment may_terminate: true options: route: /motscles defaults: action: motscles tva: type: segment may_terminate: true Loading
module/Oscar/src/Oscar/Controller/ActivityMotsClesController.php +171 −4 Changes for module/Oscar/src/Oscar/Controller/ActivityMotsClesController.php: 171 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ namespace Oscar\Controller; use Laminas\Http\Response; use Laminas\View\Model\JsonModel; use Oscar\Entity\ActivityMotCle; use Oscar\Provider\Privileges; use Oscar\Service\ProjectGrantService; use Oscar\Traits\UseLoggerService; use Oscar\Traits\UseLoggerServiceTrait; use Throwable; Loading @@ -13,19 +15,56 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL { use UseLoggerServiceTrait; /** * @return ProjectGrantService */ public function getActivityService(): ProjectGrantService { return $this->activityService; } /** * @param ProjectGrantService $activityService */ public function setActivityService(ProjectGrantService $activityService): void { $this->activityService = $activityService; } public function apiAction() { try { $activity = NULL; $activityId = $this->params()->fromQuery('activity_id'); if ($activityId) { $activity = $this->getActivityService()->getGrant($activityId); } if ($this->getRequest()->getMethod() == "GET") { return $this->getMotsCles(); $includeActivityCountQueryParam = $this->params()->fromQuery('include_activity_count'); $includeActivityCount = $includeActivityCountQueryParam && $includeActivityCountQueryParam === "true"; return $this->getMotsCles($includeActivityCount, $activity); } if ($this->getRequest()->getMethod() == "POST") { $action_mot_cle_json = json_decode($this->getRequest()->getContent()); if ($action_mot_cle_json->action == "create") { return $this->createMotCle($action_mot_cle_json); return $this->createMotCle($action_mot_cle_json, $activity); } if ($action_mot_cle_json->action == "delete") { return $this->deleteMotCle($action_mot_cle_json); } if ($action_mot_cle_json->action == "update") { return $this->updateMotCle($action_mot_cle_json); } if ($action_mot_cle_json->action == "fusion") { return $this->fusionnerMotsCles($action_mot_cle_json); } } Loading @@ -42,25 +81,49 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL } } private function getMotsCles() { private function getMotsCles($includeCount, $activity) { if ($activity) { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity); } else { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE); } /** @var ActivityMotCleRepository $activityMotCleRepository */ $activityMotCleRepository = $this->getEntityManager()->getRepository(ActivityMotCle::class); $motsCles = []; $tousLesMotsCles = []; if ($includeCount) { foreach ($activityMotCleRepository->getMotsClesCounted() as $motCle) { $motsCles[] = [ 'id' => $motCle['id'], 'label' => $motCle['label'], 'activity_count' => $motCle['activity_count'], ]; } } else { foreach ($activityMotCleRepository->getAll() as $motCle) { $motsCles[] = [ 'id' => $motCle->getId(), 'label' => $motCle->getLabel(), ]; } } $response = new JsonModel(); $response->setVariables(['motscles' => $motsCles]); return $response; } private function createMotCle($action_mot_cle_json) { private function createMotCle($action_mot_cle_json, $activity) { if ($activity) { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_EDIT, $activity); } else { $this->getOscarUserContextService()->check(Privileges::ACTIVITY_CREATE); } $this->getLoggerService()->info("createMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); Loading @@ -75,4 +138,108 @@ class ActivityMotsClesController extends AbstractOscarController implements UseL return $response; } private function deleteMotCle($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("deleteMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $motCle = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $action_mot_cle_json->id)); if (!$motCle) { throw new \Exception("Le mot clé n'existe pas. Veuillez actualiser la page."); } $this->getEntityManager()->remove($motCle); $this->getEntityManager()->flush(); $response = new JsonModel(); $response->setVariables(['id' => $action_mot_cle_json->id]); return $response; } private function updateMotCle($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("updateMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $motCle = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $action_mot_cle_json->id)); if (!$motCle) { throw new \Exception("Le mot clé n'existe pas. Veuillez actualiser la page."); } $motCle->setLabel($action_mot_cle_json->label); $this->getEntityManager()->persist($motCle); $this->getEntityManager()->flush(); $response = new JsonModel(); $response->setVariables(['id' => $motCle->getId(), 'label' => $motCle->getLabel()]); return $response; } private function fusionnerMotsCles($action_mot_cle_json) { $this->getOscarUserContextService()->check(Privileges::MAINTENANCE_DISCIPLINE_MANAGE); $this->getLoggerService()->info("fusionMotCle"); $this->getLoggerService()->info("by: " . $this->getCurrentPerson()); $targetId = $action_mot_cle_json->targetId; if (!$targetId || !is_numeric($targetId)) { throw new \Exception("Le paramètre targetId doit être un identifiant numérique."); } $motCleCible = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $targetId)); if (!$motCleCible) { throw new \Exception("Le mot clé cible n'existe pas. Veuillez actualiser la page."); } $idsToMerge = $action_mot_cle_json->idsToMerge; if (!$idsToMerge || !is_array($idsToMerge) || count($idsToMerge) < 2) { throw new \Exception("Le paramètre idsToMerge doit être un tableau d'au moins deux identifiants numériques de mots clés."); } $motsClesASupprimer = []; foreach ($idsToMerge as $idToMerge) { if (!is_numeric($idToMerge)) { throw new \Exception("Le paramètre idsToMerge doit contenir des identifiants numériques de mots clés."); } if ($idToMerge == $targetId) { continue; } $motCleASupprimer = $this->getEntityManager() ->getRepository(ActivityMotCle::class) ->findOneBy(array('id' => $idToMerge)); if (!$motCleASupprimer) { throw new \Exception("Le mot clé à supprimer n'existe pas. Veuillez actualiser la page."); } $motsClesASupprimer[] = $motCleASupprimer; } foreach ($motsClesASupprimer as $motCleASupprimer) { foreach ($motCleASupprimer->getActivities() as $activity) { if (!$activity->hasMotcle($motCleCible)) { $activity->addMotCle($motCleCible); $this->getEntityManager()->persist($activity); $this->getEntityManager()->flush(); } } } foreach ($motsClesASupprimer as $motCleASupprimer) { $this->getEntityManager()->remove($motCleASupprimer); $this->getEntityManager()->flush(); } $response = new JsonModel(); $response->setVariables([]); return $response; } }
module/Oscar/src/Oscar/Controller/ActivityMotsClesControllerFactory.php +2 −0 Changes for module/Oscar/src/Oscar/Controller/ActivityMotsClesControllerFactory.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Laminas\ServiceManager\Factory\FactoryInterface; use Oscar\Service\OscarUserContext; use Oscar\Service\ProjectGrantService; class ActivityMotsClesControllerFactory implements FactoryInterface { Loading @@ -15,6 +16,7 @@ class ActivityMotsClesControllerFactory implements FactoryInterface $c->setEntityManager($container->get(EntityManager::class)); $c->setOscarUserContextService($container->get(OscarUserContext::class)); $c->setLoggerService($container->get('Logger')); $c->setActivityService($container->get(ProjectGrantService::class)); return $c; } }