OrganizationFixtures.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. namespace App\Tests\Fixture;
  3. use DateTime;
  4. use App\Service\Utils\Uuid;
  5. use App\Entity\Access\Access;
  6. use App\Entity\Booking\Event;
  7. use App\Entity\Person\Person;
  8. use Doctrine\DBAL\Connection;
  9. use App\Entity\Education\Cycle;
  10. use App\Entity\Network\Network;
  11. use App\Enum\Core\TimeZoneEnum;
  12. use App\Entity\Core\ContactPoint;
  13. use App\Enum\Education\CycleEnum;
  14. use App\Entity\Education\Education;
  15. use App\Enum\Booking\VisibilityEnum;
  16. use App\Enum\Organization\LegalEnum;
  17. use App\Entity\Billing\AccessBilling;
  18. use App\Entity\Billing\ResidenceArea;
  19. use App\Entity\Organization\Settings;
  20. use App\Entity\Billing\BillingSetting;
  21. use App\Entity\Organization\Subdomain;
  22. use App\Entity\Organization\Parameters;
  23. use App\Enum\Core\ContactPointTypeEnum;
  24. use App\Enum\Education\PeriodicityEnum;
  25. use Doctrine\Persistence\ObjectManager;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. use App\Entity\Education\EducationTiming;
  28. use App\Entity\Organization\Organization;
  29. use App\Entity\Education\CycleByEducation;
  30. use App\Entity\Education\EducationCategory;
  31. use Doctrine\Bundle\FixturesBundle\Fixture;
  32. use App\Enum\Organization\PrincipalTypeEnum;
  33. use App\Entity\Education\EducationComplement;
  34. use App\Entity\Education\EducationCurriculum;
  35. use App\Entity\Education\EducationStudent;
  36. use App\Enum\Organization\BulletinOutputEnum;
  37. use App\Enum\Organization\BulletinPeriodEnum;
  38. use App\Enum\Organization\SendToBulletinEnum;
  39. use App\Enum\Organization\SettingsProductEnum;
  40. use Doctrine\Common\DataFixtures\Purger\ORMPurger;
  41. use App\Enum\Education\AdvancedEducationNotationTypeEnum;
  42. use App\Enum\Organization\BulletinCriteriaSortEnum;
  43. use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
  44. class OrganizationFixtures extends Fixture
  45. {
  46. protected EntityManagerInterface $em;
  47. private Connection $connection;
  48. public function __construct(EntityManagerInterface $em, Connection $connection)
  49. {
  50. $this->em = $em;
  51. $this->connection = $connection;
  52. }
  53. public static function getGroups(): array
  54. {
  55. return ['poc'];
  56. }
  57. public function purgeDb(): void
  58. {
  59. // Exécutez la requête SQL brute pour effectuer un TRUNCATE FORCE
  60. $tableName = $this->em->getClassMetadata(Organization::class)->getTableName();
  61. $truncateSql = "TRUNCATE TABLE $tableName";
  62. $this->connection->executeQuery($truncateSql);
  63. $accessTable = $this->em->getClassMetadata(Access::class)->getTableName();
  64. $truncateSql = "TRUNCATE TABLE $accessTable";
  65. $this->connection->executeQuery($truncateSql);
  66. }
  67. public function load(ObjectManager $em): void
  68. {
  69. // Purge DB before populating new fixtures
  70. // $this->purgeDb();
  71. // create an organization with a network, legal status accesses, Param , name, id and settings
  72. $network = new Network();
  73. $network->setName('NET');
  74. $em->persist($network);
  75. $contactPoint0 = new ContactPoint();
  76. $contactPoint0->setContactType(ContactPointTypeEnum::PRINCIPAL);
  77. $em->persist($contactPoint0);
  78. // Create the root organization (opentalent)
  79. $root = new Organization();
  80. $root->setName('Root');
  81. $root->setLegalStatus(LegalEnum::ASSOCIATION_LAW_1901);
  82. $root->setPrincipalType(PrincipalTypeEnum::NATIONAL_FEDERATION);
  83. $root->addContactPoint($contactPoint0);
  84. // subdomain fixtures
  85. $subdomain = new Subdomain();
  86. $subdomain->setOrganization($root);
  87. $subdomain->setSubdomain('subdomain');
  88. $subdomain->setActive(true);
  89. $parameters = new Parameters();
  90. $parameters->setFinancialDate(new DateTime());
  91. $parameters->setMusicalDate(new DateTime());
  92. $parameters->setStartCourseDate(new DateTime());
  93. $parameters->setEndCourseDate(new DateTime());
  94. $parameters->setAverage(20);
  95. $parameters->setEditCriteriaNotationByAdminOnly(true);
  96. $parameters->setSmsSenderName('MySender');
  97. $parameters->setLogoDonorsMove(false);
  98. $parameters->setSubDomain('subdomain');
  99. $parameters->setWebsite('https://www.example.com');
  100. $parameters->setOtherWebsite('https://www.otherwebsite.com');
  101. $parameters->setCustomDomain('https://www.customdomain.com');
  102. $parameters->setDesactivateOpentalentSiteWeb(false);
  103. $parameters->setBulletinPeriod(BulletinPeriodEnum::YEAR);
  104. $parameters->setBulletinWithTeacher(false);
  105. $parameters->setBulletinPrintAddress(false);
  106. $parameters->setBulletinSignatureDirector(true);
  107. $parameters->setBulletinDisplayLevelAcquired(true);
  108. $parameters->setBulletinShowEducationWithoutEvaluation(false);
  109. $parameters->setBulletinViewTestResults(false);
  110. $parameters->setBulletinShowAbsences(false);
  111. $parameters->setBulletinShowAverages(true);
  112. $parameters->setBulletinOutput(BulletinOutputEnum::SEND_BY_EMAIL);
  113. $parameters->setBulletinEditWithoutEvaluation(true);
  114. $parameters->setBulletinReceiver(SendToBulletinEnum::STUDENTS_AND_THEIR_GUARDIANS);
  115. $parameters->setBulletinCriteriaSort(BulletinCriteriaSortEnum::ALPHANUM);
  116. $parameters->setUsernameSMS('username');
  117. $parameters->setPasswordSMS('password');
  118. $parameters->setShowAdherentList(true);
  119. $parameters->setStudentsAreAdherents(false);
  120. $parameters->setTimezone(TimeZoneEnum::EUROPE_PARIS);
  121. $parameters->setEducationPeriodicity(PeriodicityEnum::MONTHLY);
  122. $parameters->setAdvancedEducationNotationType(AdvancedEducationNotationTypeEnum::BY_EDUCATION);
  123. $parameters->setSendAttendanceEmail(false);
  124. $parameters->setSendAttendanceSms(false);
  125. $parameters->setGenerateAttendanceReport(true);
  126. $parameters->setConsultPedagogicResult(true);
  127. $parameters->setConsultTeacherListing(true);
  128. $parameters->setPeriodValidation(true);
  129. $parameters->setNotifyAdministrationAbsence(false);
  130. $root->setParameters($parameters);
  131. // settings fixtures
  132. $settings = new Settings();
  133. $settings->setProduct(SettingsProductEnum::SCHOOL);
  134. $settings->setModules(['BillingAdministration']);
  135. $root->setSettings($settings);
  136. //create acesses with orga
  137. $access = new Access();
  138. $access->setOrganization($root);
  139. $access->setRoles(["ROLE_ADMIN","ROLE_ADMIN_CORE","ROLE_SUPER_ADMIN"]);
  140. $teacherAccess = new Access();
  141. $teacherAccess->setOrganization($root);
  142. $teacherAccess->setRoles(["ROLE_TEACHER"]);
  143. // create a person :
  144. $person = new Person();
  145. $person->addAccess($access);
  146. $person->setUsername('username');
  147. $person->setPassword('password');
  148. // create BillingSetting with an organization
  149. $billingSetting = new BillingSetting();
  150. $billingSetting->setOrganization($root);
  151. $em->persist($billingSetting);
  152. // résidence area
  153. $residenceArea = new ResidenceArea();
  154. $residenceArea->setLabel('label');
  155. $residenceArea->setBillingSetting($billingSetting);
  156. //create an AccessBilling with an access
  157. $accessBilling = new AccessBilling();
  158. $accessBilling->setAccess($access);
  159. $accessBilling->setResidenceArea($residenceArea);
  160. // Création de quelques cycles
  161. $cycle1 = new Cycle();
  162. $cycle1->setOrganization($root);
  163. $cycle1->setLabel('Cycle 1');
  164. $cycle1->setCycleEnum(CycleEnum::CYCLE_1);
  165. $cycle2 = new Cycle();
  166. $cycle2->setOrganization($root);
  167. $cycle2->setLabel('Cycle 2');
  168. $cycle2->setCycleEnum(CycleEnum::CYCLE_2);
  169. // Création de l'entité EducationCategory
  170. $educationCategory = new EducationCategory();
  171. $educationCategory->setOrganization($root);
  172. // Création de l'entité EducationComplement
  173. $educationComplement = new EducationComplement();
  174. // Création d'une Education
  175. $education = new Education();
  176. $education->setEducationCategory($educationCategory);
  177. $education->setEducationComplement($educationComplement);
  178. // Création d'un CycleByEducation
  179. $cycleByEducation = new CycleByEducation();
  180. $cycleByEducation->setCycle($cycle1);
  181. $cycleByEducation->setEducation($education);
  182. // Ajout de cycleByEducation à cycle et education
  183. $cycle1->addCycleByEducation($cycleByEducation);
  184. $education->addCycleByEducation($cycleByEducation);
  185. $educationCurriculum = new EducationCurriculum();
  186. $educationTimings= new EducationTiming();
  187. $educationTimings->setTiming(45);
  188. $educationTimings->setOrganization($root);
  189. $educationStudent = new EducationStudent();
  190. $educationTimings->addEducationStudent($educationStudent);
  191. $educationTimings->addEducationCurriculum($educationCurriculum);
  192. $educationCurriculum->setCycle($cycle1);
  193. // // education complément
  194. // $educationComplement = new EducationComplement();
  195. // $education = (new Education());
  196. // $educationCategory = new EducationCategory();
  197. // $educationCategory->setOrganization($root);
  198. // // $educationCurriculum = new EducationCurriculum();
  199. // // $education->setEducationComplement($educationComplement);
  200. // // $educationCategory->setOrganization($root);
  201. // // $educationCategory->addEducation($education);
  202. // $education->setEducationCategory($educationCategory);
  203. // $education->setEducationComplement($educationComplement);
  204. // $cycleByEducation = new CycleByEducation();
  205. // // Cycle
  206. // $cycle = new Cycle();
  207. // $cycle->setOrganization($root);
  208. // $cycle->setCycleEnum(CycleEnum::INITIATION_CYCLE);
  209. // $cycle->setIsSystem(false);
  210. // $cycle->setLabel('toto');
  211. // $cycle->setOrder(1);
  212. // // $cycleByEducation->setEducation();
  213. // $cycle->addCycleByEducation($cycleByEducation);
  214. // $cycle->setIsSystem(false);
  215. // $em->persist($cycle);
  216. // Booking
  217. $now = new \DateTime('now');
  218. $start = $now->add(new \DateInterval('P1M'));
  219. $end = $now->add(new \DateInterval('P1M1D'));
  220. $event = new Event();
  221. $event->setOrganization($root);
  222. $event->setName('My Event');
  223. $event->setDatetimeStart($start);
  224. $event->setDatetimeEnd($end);
  225. $event->setVisibility(VisibilityEnum::PUBLIC_VISIBILITY);
  226. $event->setUuid(Uuid::uuid());
  227. $em->persist($cycle1);
  228. $em->persist($cycle2);
  229. $em->persist($educationCategory);
  230. $em->persist($educationComplement);
  231. $em->persist($education);
  232. $em->persist($cycleByEducation);
  233. // $em->persist($educationComplement);
  234. // $em->persist($educationCurriculum);
  235. // $em->persist($educationCategory);
  236. // $em->persist($education);
  237. // $em->persist($cycleByEducation);
  238. $em->persist($root);
  239. $em->persist($event);
  240. $em->persist($person);
  241. $em->persist($access);
  242. $em->persist($accessBilling);
  243. $em->persist($billingSetting);
  244. $em->persist($residenceArea);
  245. $em->persist($subdomain);
  246. $em->persist($parameters);
  247. $em->flush();
  248. // A circular reference has been detected when serializing the object of
  249. // class \u0022App\\Entity\\Education\\CycleByEducation\u0022
  250. }
  251. }