mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 17:28:23 +00:00 
			
		
		
		
	Compare commits
	
		
			1272 Commits
		
	
	
		
			feature-ad
			...
			fixtures/f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 609deba325 | |||
| c7c62dc10b | |||
| fbc7cf3954 | |||
| 958cacd61f | |||
| 58bb471d32 | |||
| 4cf676858e | |||
| b87046dcd6 | |||
| 259d0b5668 | |||
| 5224a26e57 | |||
| 76eea2a4eb | |||
| afb2a92997 | |||
| 7ba3e0287a | |||
| 54ac122863 | |||
| 1a37910fb1 | |||
| 8a8ec31163 | |||
| b88c01365d | |||
| 71c22b9c06 | |||
| 160383e3a3 | |||
| cdc6cf211a | |||
|  | f12dc97d57 | ||
|  | a58bdb466c | ||
|  | 23366d5582 | ||
|  | f58be46466 | ||
| 65e72b05c5 | |||
|  | 069b3d1839 | ||
|  | cbdf976885 | ||
|  | 8df4c93c97 | ||
|  | 5ce6d37a69 | ||
|  | 7dc501cbda | ||
|  | 8207db4b45 | ||
| f5c5038fda | |||
| 436d583f65 | |||
| 533865c41a | |||
| 14c0c9763f | |||
| a54e70f9e0 | |||
| 63b820784f | |||
| 71b54622e2 | |||
| 190549180b | |||
| 375326fc32 | |||
| a1435314a0 | |||
| 8d98a144fd | |||
| d0fa28db2a | |||
| 9ac14ff5e3 | |||
| d67483fd9a | |||
| 3156706c2b | |||
| 44e85361e6 | |||
| 320f16a121 | |||
| 5635d19252 | |||
| 6544566c34 | |||
| 9f7c0dcd09 | |||
| 0e2e7155fb | |||
| 8a962a4f1c | |||
| 2f699d32b0 | |||
| 72a1ac02eb | |||
| c420d2bfd7 | |||
| 8d2b1fbe13 | |||
| a3a5d5cfd0 | |||
| 3302d69373 | |||
| f188cc2d27 | |||
| 8f9c8bc1a6 | |||
| 43f9e50100 | |||
| aa0ff37479 | |||
| 20cdec20d2 | |||
| 0abb4983f7 | |||
| 5a716a3523 | |||
| 29b5e700f6 | |||
| e8e2607076 | |||
| 107699ec31 | |||
| 25465b1121 | |||
|  | 8834f200df | ||
|  | cc84c067c5 | ||
|  | d8ee42b0a5 | ||
|  | a948d9e2da | ||
|  | c9a5d0548c | ||
|  | c37ba5db6a | ||
| 54c4524b27 | |||
| 966292cdd5 | |||
| 9d1166d8fc | |||
| 1b3904f8e3 | |||
| 2d2bb117ca | |||
| 17dd52c3dc | |||
| d6e41e5ac7 | |||
| b0187d0594 | |||
| ea691d9b32 | |||
| 1d2cbc4f62 | |||
| 5e0c930087 | |||
| f535e794a7 | |||
| 2f28e02f65 | |||
| 1600d3d271 | |||
| 4b69f97e2f | |||
| 64433b420d | |||
| 8f9d4a1765 | |||
| c302452e01 | |||
| 205c48f58a | |||
| 368bbcf9b2 | |||
| 76a4b24aa1 | |||
| f6376118a0 | |||
| a6001c195a | |||
| 8829d234ec | |||
| 6ee0acfa0f | |||
| 7d97889cbf | |||
| fc6a9ad64f | |||
| 4c7129a3b2 | |||
| bbb69bcfe0 | |||
| a1ed0d3ce4 | |||
| fb43980a2a | |||
| da98b42c8c | |||
| 840ffe42a6 | |||
| 1f8c343a89 | |||
| f6a02e157d | |||
| 21957846b0 | |||
| 1c7e1b55f8 | |||
| ea391d18e9 | |||
| 72cd9f452e | |||
| 44313b507a | |||
| 46bd70881e | |||
| fbf343dd19 | |||
| 028af50dbc | |||
| 0075fed9a5 | |||
| 62dc94bb14 | |||
| c075ff199d | |||
| e178183cef | |||
| 63fbf4b249 | |||
| 9f77b84e48 | |||
| fae196d3eb | |||
| ca4d542604 | |||
| 75be8aa557 | |||
| 9e94cea9d5 | |||
| 6d58bf152b | |||
| 47d704b521 | |||
| cdbd97e595 | |||
| 24714227b8 | |||
| da09e10fb1 | |||
| b74f9cf5dc | |||
| b62597426c | |||
| 6c0ab6f25e | |||
| 9f3ceb94f0 | |||
|  | 6b4e27a531 | ||
|  | 3be024bf6b | ||
|  | 88847cb19c | ||
|  | ad5eed4c26 | ||
|  | 25eee88693 | ||
|  | c32ca59c76 | ||
|  | 94b0432bb9 | ||
| 9ee140a7d8 | |||
| 5d598bf46b | |||
| 8649d49d98 | |||
| d67b99b269 | |||
| 01cc230136 | |||
| ac999a4f17 | |||
| 794c7d0c4a | |||
| 07ffc86ced | |||
| 718933af75 | |||
| 884de5c19e | |||
| d948ba0cd5 | |||
| 0072f4c676 | |||
| 72b43e9a99 | |||
| 7a56ff7d29 | |||
| 51f4d2ab0e | |||
| 4716ab3e3c | |||
| 3d630eeedf | |||
| 61d8e06975 | |||
| eec913375e | |||
| 7f3b266209 | |||
| 85b7e4add8 | |||
| fadf2d62b0 | |||
| 3e498c34e5 | |||
| 81de17594d | |||
| e42a5217be | |||
| a0154331de | |||
| 3d2cc340a6 | |||
| 82841f47c8 | |||
| b571620e6c | |||
| 357b87dadb | |||
| a5948259d9 | |||
| 0bc894836f | |||
| 23bc71a38c | |||
| 3082634323 | |||
| 4cd2dc63c5 | |||
| ff58816ee0 | |||
| 7b8a067002 | |||
| c13f63b3ba | |||
| 94d743c5b6 | |||
| 2290da6f3b | |||
| f9195aa881 | |||
| 84dc5bd881 | |||
| 1edcb399c4 | |||
| 9ac31d2d8b | |||
| ccf5b90951 | |||
| ee8e9f1ebc | |||
| 4fa1820d8d | |||
| e72a8fe5a0 | |||
|  | 9b756ffb2f | ||
| 7ee91afae2 | |||
| 7665181d44 | |||
| a8047fd89b | |||
| 61f6e95281 | |||
| ad55cc0477 | |||
| 714d8b841c | |||
| e2e38a9ce8 | |||
| d916b575da | |||
| 982c704f6c | |||
| 9f5086e9c1 | |||
| ee819e7767 | |||
| d34a00b2c0 | |||
| a096266ca5 | |||
| 96e979f92d | |||
| 48873d15c9 | |||
| 4be4cd7279 | |||
| c4a8b85be5 | |||
| 4c47105de1 | |||
| 1c404e5cb3 | |||
| 6dae4785e6 | |||
| 360322bdbf | |||
| 8c06014ea5 | |||
| 98dd31dffc | |||
| 1325355ca7 | |||
| 9764ee1794 | |||
| a48d7f5e94 | |||
| 949366cf7b | |||
| 65fe9ab784 | |||
| 532d4aa164 | |||
| 02bea40cc4 | |||
| 51216b90c5 | |||
| f9735823c7 | |||
| b683e60cf7 | |||
| e8e4dbef1f | |||
| 7e4afc826b | |||
| 31c5c8b52a | |||
| f734210db5 | |||
| 014fe19b45 | |||
| 08cd6c81f2 | |||
| 175d6892ec | |||
| 4cac5f9a4a | |||
| 6dac130844 | |||
| 886924a7e5 | |||
| 55ac730c18 | |||
| 87a7e0de00 | |||
| 39f6f14467 | |||
| 5ef5b65d90 | |||
| ad3fe7cf91 | |||
| 4e9916534f | |||
| 3637ae6aee | |||
| 2893b9c726 | |||
| 42784cf584 | |||
| 3169da20ad | |||
| 81752befcf | |||
| 3c7b67604c | |||
| 4e8dd3b189 | |||
| 50e9a06e49 | |||
| 57a8b49f49 | |||
| df3d32c653 | |||
| 4cca148f69 | |||
| 34f22d237e | |||
|  | d0b51f3573 | ||
|  | 53d3a0921b | ||
|  | cc824faf54 | ||
|  | b33cb4946c | ||
|  | ef6c5870b5 | ||
|  | e1f8aa5a5e | ||
|  | d208a79764 | ||
|  | b41b1346e5 | ||
|  | d50d3e0e4b | ||
|  | 401659748c | ||
|  | c25c302466 | ||
|  | c37b98cecd | ||
|  | 979ea5841d | ||
|  | 9e9a459a20 | ||
| 89dfea74b3 | |||
| 4b3f4edcc1 | |||
| 376d8df55e | |||
| a6266c5317 | |||
| b0ef9b6612 | |||
| 8384508c1a | |||
| d20a3cf9d4 | |||
| e0dbe9cf9d | |||
|  | 5c2c509805 | ||
|  | 9d478c0f01 | ||
|  | 4646795c2c | ||
| d8d66aeeb6 | |||
| 7ac61002b0 | |||
| c9562ebdf7 | |||
|  | 18369a6c0a | ||
|  | 0fd9485de5 | ||
| c8f139528a | |||
| 8030792eb6 | |||
|  | 50a4df3d0f | ||
|  | 0907ae1602 | ||
|  | 673a4761e9 | ||
|  | 282db51f06 | ||
|  | bdf691a063 | ||
|  | 18ab10dd45 | ||
| 0cd9dc6028 | |||
| 65198937c0 | |||
| 2699d48533 | |||
| d81f5bafe3 | |||
| c6a3f59d87 | |||
| ff671ded9c | |||
| 678c7d18b4 | |||
| f73f515fb3 | |||
| afd4ac27ea | |||
| ea734e2a9e | |||
| 8462538123 | |||
| 645252fd85 | |||
| 08e396195c | |||
| ab0863a275 | |||
| 82c79a17dd | |||
| d35553a1e2 | |||
| 030e71d276 | |||
| 4fc3d813c4 | |||
| 5f012165d1 | |||
| 61bd5d8ae8 | |||
| 07c464c112 | |||
| 70a4c34865 | |||
| 5a47ebed42 | |||
| 80eb5519bc | |||
| 50f3ec9064 | |||
| bdf0ec63d2 | |||
| 15f439b43d | |||
| 30af99f4f0 | |||
| c413166866 | |||
| 3c4c5e29a3 | |||
| 0224224744 | |||
| a9a59895b4 | |||
| 8a859f7885 | |||
| 2244c58ec2 | |||
| c1ede921ff | |||
| 17ff80c39c | |||
| f4f747d8d1 | |||
| a740ad29ea | |||
| ccee105efb | |||
| b10012f4da | |||
| 4937fd00fc | |||
| 0b329a9c9b | |||
| 4cfc43aaa6 | |||
| 1c45770929 | |||
| 198c815052 | |||
| a995adcf0d | |||
| bccda15307 | |||
| 75c3df50e0 | |||
| ce8207ea65 | |||
| 0f6ad3670a | |||
| 02a752f20b | |||
| 1bbce2bb81 | |||
| ca43933163 | |||
| 1392365257 | |||
| 3653d7e0b8 | |||
| 3970bb2644 | |||
| ea2d6eac7b | |||
| 9a1272d350 | |||
| e7c76734a6 | |||
| 8389afb4a8 | |||
| 36419cf5f0 | |||
| fc074c2f1a | |||
| eff1d6e797 | |||
| 10de2d7966 | |||
| c96f407e6a | |||
| 690688f5e1 | |||
| 4668f657ab | |||
| 49253abfb8 | |||
| c2122d62c6 | |||
| ca17ca4984 | |||
| a5d749b882 | |||
| 53c021b06e | |||
| b6e8c64211 | |||
| 342fd3e297 | |||
| 05a1f7d041 | |||
| 2e2eeae4f2 | |||
| c27268443c | |||
|  | 842dfcc69f | ||
|  | 67c31e781d | ||
| f32ffc572d | |||
| a44b26da6c | |||
| d016f9be86 | |||
| c36aa22ab2 | |||
| e77c886e3f | |||
| 4ca1618480 | |||
| 8e8cdfce0a | |||
| 3694eb5bf2 | |||
| e44342ab87 | |||
| a236873919 | |||
| a13766e7d7 | |||
| bc240a6754 | |||
| 50727fc4b0 | |||
| b327a3fbfa | |||
| 2916babe1c | |||
| fe2f107ddc | |||
| 3da8f89d3c | |||
| 19326ee750 | |||
| e0ae5d56f0 | |||
| 0878767c17 | |||
| f0232228a3 | |||
| fc63955205 | |||
| a78de0f96c | |||
| 270c0accc5 | |||
| fd94f27eee | |||
| f7e3be38a7 | |||
| 5861a86289 | |||
| 68c0f9b7d7 | |||
| 52288f7260 | |||
|  | 0b5daa6c33 | ||
| 2fe1605385 | |||
| d8256b0ac5 | |||
| b5760e82ea | |||
| d3ac8d8ceb | |||
| 196f709065 | |||
| 6a8c96cdae | |||
| 3e83891744 | |||
| 662e5f967c | |||
| 802125edc6 | |||
| 028c3e0c31 | |||
| e4adafafc8 | |||
| 54316d148c | |||
| 3c5a2a65df | |||
| 741ef7b40d | |||
| e7384343b2 | |||
| 1e2a920200 | |||
| b5a78fa341 | |||
| d9c1f52894 | |||
|  | f05f7415bd | ||
|  | 5553c7314c | ||
| 7dc70baf57 | |||
|  | 34af401a98 | ||
| 5bae8dc5bf | |||
| 6e277e99ae | |||
| 2688c0f0ce | |||
|  | 0135f5184e | ||
| fd698419e8 | |||
| 4a864a0b14 | |||
| 55dc0d3f9f | |||
| 85835c8b0d | |||
|  | ab1edee9fb | ||
| 6154e0912b | |||
| 0388428c6f | |||
| 7ac55275c2 | |||
| 1119e20a49 | |||
| ea2870eef8 | |||
|  | 93a44d8303 | ||
|  | 8109415e05 | ||
|  | 514fe6163a | ||
| 9d9be7f831 | |||
|  | 4cf3cc8353 | ||
| 2a974e1269 | |||
| beca41774e | |||
| dd991e3572 | |||
| 0640631821 | |||
| e845d9ba90 | |||
|  | 6f8231f6f6 | ||
|  | 048161e300 | ||
| b705c5910f | |||
| 6f1209eaf5 | |||
| 020759180b | |||
| 3748b4fbf4 | |||
|  | 4f49292178 | ||
| 6eaffcae49 | |||
|  | f92d710a26 | ||
|  | bc6ba88acd | ||
| 61c2934d64 | |||
| 28b4d9562c | |||
| e06aded1ec | |||
| 3a81124e04 | |||
|  | b72d45d9db | ||
| 2a1f5cbad1 | |||
| e8566fd006 | |||
| cd6b5c9a39 | |||
| 9aa3974071 | |||
| a8bf478ee8 | |||
| a35f3363b2 | |||
| 0b117e5158 | |||
| 7cae9e1769 | |||
| a43e6c12a0 | |||
| abe012de60 | |||
| aaa9a1ec7b | |||
| 25f2d17097 | |||
| 4fd43310c0 | |||
| c85ca894b8 | |||
| fe22e6c7dc | |||
| cb67605bd2 | |||
| d26e08324c | |||
| e55a2691b7 | |||
|  | aa5c7f333e | ||
| 0afe277b04 | |||
| 981b9299ad | |||
|  | 36eb247995 | ||
|  | d71c3f310e | ||
|  | 4a2ada784a | ||
|  | 3b5ef53b9b | ||
| 2cda6ceebf | |||
|  | 18d0ad67d6 | ||
|  | ea1c12da64 | ||
| 1ceabec400 | |||
|  | 91c5cd74f7 | ||
|  | b7f2e189dc | ||
|  | ab8deb036b | ||
|  | ac47a75a75 | ||
|  | 4e6454d7de | ||
| 92a95d4186 | |||
|  | 141aabcddc | ||
|  | c23ada3533 | ||
|  | 6e37e7feac | ||
|  | df1f44d814 | ||
|  | dc26ca7e77 | ||
|  | 2667867bd0 | ||
|  | 5ddc0e7a53 | ||
| b72b1bd4c7 | |||
| ca9ae3874c | |||
| 7fb4616aa6 | |||
| ac4cf43753 | |||
| 5a4a0a3617 | |||
| 2cc1274ee0 | |||
| 154fa4719d | |||
| 193e7b4c7e | |||
| 80c2bd285f | |||
| 133c0ac1ac | |||
| c8d5c2c67b | |||
| 0754d20622 | |||
| 99d6e030ca | |||
| 5d38d193e2 | |||
| 86f7b116a9 | |||
| bcab5a1211 | |||
| 65a6607112 | |||
| 1cd376bf86 | |||
| 84f6f9b44d | |||
| b53f6af8d8 | |||
| 34d6452286 | |||
| c04ccef4cd | |||
|  | d8afbc4a40 | ||
| 95edbc673c | |||
| 07ffdfab86 | |||
| 50be29308d | |||
| d1e0d997ac | |||
|  | 504b2efacf | ||
| 4c3c67344a | |||
| 40fcb09082 | |||
| aa4a9e874a | |||
| 3abfdbf6fd | |||
| 07cc394abd | |||
| 99337c4aa6 | |||
| 04ccca092b | |||
|  | b3792f6714 | ||
| e1f01a47f8 | |||
| dc79e1a02d | |||
| 7a6117a264 | |||
|  | 1a204312f3 | ||
| 1b1a25edc4 | |||
| 5ab7f7a37b | |||
| b174397823 | |||
| 9d35e4efbb | |||
| 0e9933ca41 | |||
|  | 3d14f00cac | ||
| 0add757230 | |||
| 2bf65dfadb | |||
| a7ecd08d78 | |||
|  | bccaf5ad6e | ||
| 585a19e803 | |||
| b801b75eb9 | |||
| f1120af59e | |||
| 9d58356b90 | |||
| a7131653c9 | |||
| 9f3cd943cb | |||
|  | 970635dfad | ||
|  | c8297b2230 | ||
| 994cce41e5 | |||
| 86e41fb877 | |||
| f8b97b96f4 | |||
| 27907e7558 | |||
|  | 38712de462 | ||
| fd7c7388d9 | |||
| ef55d2cf7f | |||
|  | 8406c30c8e | ||
|  | 901ae47ce6 | ||
|  | 951160982d | ||
|  | e2633a2a79 | ||
|  | 1cfc29caf7 | ||
|  | 5b72eeb147 | ||
|  | 1b9d8fab61 | ||
|  | 801af209a1 | ||
|  | 06daf35e96 | ||
| 38bff2e42f | |||
| e68a5405a1 | |||
| 8bd20c9c78 | |||
| 54997e5893 | |||
|  | 35d35c9f40 | ||
|  | 49d022ef55 | ||
| 78ca61c82e | |||
| b68de1f2e9 | |||
| 68ecff253a | |||
|  | db545f9fe6 | ||
|  | 86d764c097 | ||
|  | cf8b9ec172 | ||
|  | 23528e7a5c | ||
|  | a258905c59 | ||
|  | 84913553e8 | ||
|  | 916209e402 | ||
|  | 3ec212df93 | ||
| e95d8fbc7a | |||
|  | ce88fe158f | ||
| efdfd10e49 | |||
|  | 000ae6c2cb | ||
|  | 7c26f0a56c | ||
| f827e50431 | |||
| 41617295c1 | |||
| b2c1d75fc5 | |||
| 17c3ecbabe | |||
| de024b405f | |||
| 51399b21b9 | |||
| c40019da8f | |||
| 1df759e970 | |||
|  | 92b4adc113 | ||
| 807d3674fc | |||
| af740fd87d | |||
| 45dc8ed661 | |||
| ecc8b929ca | |||
|  | c378f59f5a | ||
| 4fd6d38187 | |||
|  | f3a7556bca | ||
|  | 14db7265fe | ||
|  | f22461af1b | ||
|  | 1b709d39a4 | ||
|  | 81e8a4562b | ||
|  | 1e72247546 | ||
|  | 670ba1713a | ||
|  | 5daf5cbe84 | ||
|  | 331cdf13ca | ||
| f25365f651 | |||
| cbadcb4980 | |||
| b2ce5fca38 | |||
| 38c06977ca | |||
|  | 1551ea796d | ||
| 3e39dd9a1e | |||
| 89734c680c | |||
|  | 4c025184b4 | ||
| 6fed008ff2 | |||
| 057bdf6a6a | |||
|  | 6f2c219e3b | ||
|  | 550aaacaab | ||
| f9758eff5b | |||
| abc79249a2 | |||
| f7bb9ac327 | |||
| 3c727d1c65 | |||
| ac211337d6 | |||
| 30668ca67f | |||
| 5da0be24ff | |||
|  | dd78e9759c | ||
|  | 1b36d9b1ab | ||
| 7fddf1d5e0 | |||
| 315fc7f63a | |||
| 3c889db41a | |||
| 71f794c4d9 | |||
| e135b98072 | |||
| e14205ae1d | |||
|  | e14a125bf3 | ||
| 8a5650a705 | |||
| 18217f53e8 | |||
| 79ec182ca3 | |||
| 1433af8e95 | |||
| e91596ae12 | |||
|  | 9375c2cf86 | ||
|  | db77224b9f | ||
| 1c42bf6400 | |||
| c9da72fa0d | |||
| 3b3855089c | |||
| 265ace0b4c | |||
| 0e1bbbfee9 | |||
| ebf896ac74 | |||
| 31befaa339 | |||
| 780c14cfbe | |||
| 8183c028f8 | |||
| 97bba861c9 | |||
| 8d7d170f11 | |||
| c126f680ae | |||
|  | 6a42edd460 | ||
| 0aa909f060 | |||
| f27957e91b | |||
| ed891b224f | |||
|  | 76d945f2a7 | ||
|  | 7d13bc7cfe | ||
|  | 66b54bad31 | ||
|  | 9d32ccbcad | ||
| 4dc82bc207 | |||
| 2384281532 | |||
| 7c94824c20 | |||
| a922e397f8 | |||
| be13f8f65b | |||
| 12f83abccc | |||
|  | 63c3b5a970 | ||
| 1967d6ea4c | |||
| 5cb076495a | |||
|  | 03a7ec389b | ||
| 604e78f35e | |||
|  | f39fe05dd5 | ||
| eeffa3191e | |||
|  | 6c126b0581 | ||
| 84d5fb936e | |||
|  | 5ee824d1c2 | ||
| 7933aaed1c | |||
|  | 6d20476b81 | ||
|  | 2b5ed5e5a3 | ||
| 0fe70d00ec | |||
| e5905902cc | |||
| 48e5809008 | |||
| a947634f30 | |||
| 3e3c9dc894 | |||
| 574b5dcbd0 | |||
| c1ba892811 | |||
|  | 6f68349f57 | ||
|  | d513be2fce | ||
|  | 7a33c37b51 | ||
|  | a6c4b4eb55 | ||
|  | 160c7f2c31 | ||
|  | aff140230c | ||
|  | 31468aeae0 | ||
| 3e57ff3ffa | |||
| 6cbbce03c4 | |||
|  | e52c94aabd | ||
| ef98111a2f | |||
| 55fa16ce56 | |||
|  | 7e1b7b7e9f | ||
|  | 39dca2a9ca | ||
| 80ccb76794 | |||
|  | 878ee5d9c7 | ||
|  | 541fe8f1ad | ||
|  | bb71b9f908 | ||
|  | 7b67ef5db2 | ||
| 330234981c | |||
| a323e84357 | |||
| c33f577f5a | |||
|  | 0ce814cf52 | ||
|  | d806a074a7 | ||
|  | 14a9d9c739 | ||
| 502a629dc8 | |||
| 4ace2fef99 | |||
|  | 4a1ebc1c4c | ||
|  | 4553051271 | ||
|  | 743d6cd0bf | ||
|  | 0f635ca51a | ||
| 987815471c | |||
| d9a3e117b2 | |||
|  | f6d4d32ce4 | ||
| 937be1af3a | |||
| 32b3d74a1b | |||
|  | 43fb020272 | ||
|  | f26fafb2f2 | ||
|  | e1e3051d00 | ||
|  | a659263af6 | ||
|  | 9333b6d2df | ||
| 4d0cfbb396 | |||
| e9caa7b4b8 | |||
| 261acdfd24 | |||
| 17481798fb | |||
| edb8aa1dfe | |||
| 93a67c9ab9 | |||
| 980a305456 | |||
| 0158c6f2ed | |||
| ff5b0bc258 | |||
| a133f56dce | |||
|  | c4e226d0bd | ||
| fa556bbba1 | |||
| e8f3c499ee | |||
| cfd9f1bab1 | |||
| c6949490a4 | |||
|  | 8011293b28 | ||
|  | 7992f09aea | ||
| abede56d68 | |||
| 9ab032c943 | |||
| 4562ed46db | |||
| cd52f7e6e8 | |||
| 126ffc55bf | |||
| f49c54d51f | |||
| 1410213258 | |||
| 35e0b98687 | |||
| 8f1091b8a3 | |||
| c269bfe278 | |||
| 041b1dfc51 | |||
| 718d6c2375 | |||
| 158b572879 | |||
| 68059a9938 | |||
| 543f6b20dd | |||
| e95d756e71 | |||
| 992734bb72 | |||
| 741ed84918 | |||
| 5822736f19 | |||
| 66776eed01 | |||
| ace3b1969e | |||
| edc86af659 | |||
| e123ee5d03 | |||
| 87ba68971c | |||
| 94bcbac06a | |||
| 74520330b1 | |||
| 666c1e7ae7 | |||
|  | 935006eae3 | ||
| 622c254cc4 | |||
| a19fd51600 | |||
|  | 165012b302 | ||
|  | 057db09847 | ||
| 56242f9b5a | |||
| 549f3a4c78 | |||
| 9ec2a62fb6 | |||
| 65ac9a47b4 | |||
| b1d7e543fc | |||
| b89cffce68 | |||
|  | 063076d0cb | ||
|  | bcf2b9d834 | ||
| 968e6914b2 | |||
| 52ee8c5a9a | |||
|  | 64d28106c8 | ||
| 0a5d20b16f | |||
| 85dda8b680 | |||
| 2c49afe549 | |||
| 2e1201418a | |||
| a9fb916843 | |||
| 6631e853b4 | |||
| e26e3ac67b | |||
| 562c72f7bb | |||
| 6602e1b286 | |||
| b69aaeafd9 | |||
| aa473b5f70 | |||
| 124e36b9d4 | |||
| b88765c344 | |||
| f3427d6754 | |||
| df00ac66f5 | |||
| 2b12e61fbd | |||
| 151e8deaeb | |||
| acbe93f9cf | |||
| 358410cde1 | |||
| 06c74ed5ed | |||
| 25c986cc61 | |||
| cad8174333 | |||
| 6c8f1f77ff | |||
| 75c586fbf8 | |||
| 2cb9dfc250 | |||
| 3b2d4142c1 | |||
| 9a6bab7ba2 | |||
| c2bbee299c | |||
| f4db9be557 | |||
| 5449efdd97 | |||
| 7896d288e7 | |||
| b98d6fa505 | |||
| e4d1b951a3 | |||
| ae8e5bc2e3 | |||
| 9b66f7a83f | |||
|  | 13d5b7078e | ||
| 37996651c4 | |||
|  | 679665d9db | ||
|  | 1d4edd5b7b | ||
|  | f1c77277f3 | ||
| 6264171c0c | |||
| 902d8b52d3 | |||
| caeb75ce13 | |||
| 2f27674e05 | |||
| ce9070e641 | |||
| 5350a09951 | |||
| 31252461c9 | |||
| 73790db700 | |||
|  | 72795be040 | ||
| fc2a2da75f | |||
|  | e88e9b1a6f | ||
|  | f7dea7f041 | ||
|  | 57a35f88be | ||
|  | 1b1eb45d15 | ||
|  | 65859f62f3 | ||
|  | 4cc308c936 | ||
|  | 2f28cb16ef | ||
|  | 73ee77b8b2 | ||
|  | 830cda64e0 | ||
|  | 3bc510d116 | ||
|  | 5f8a506c84 | ||
|  | bbb9dc2561 | ||
|  | b51575fc49 | ||
|  | fee37b5af3 | ||
|  | 0afcf3d79e | ||
|  | 743b456030 | ||
| 0dbd42ba5b | |||
| 7efbf2fce8 | |||
| 9b1a66c992 | |||
|  | cb897cfef1 | ||
|  | bafbc2dd74 | ||
| 74541f360b | |||
| 20a14c9ff4 | |||
| cdade50d76 | |||
| d4f96ee25f | |||
| ca33580831 | |||
| 64e37c5235 | |||
| bf576e171c | |||
| 3f2fe6a138 | |||
| f18ccce814 | |||
| 2386a35eb7 | |||
| 1fbda740a7 | |||
| d35e1fe21e | |||
| 771b9eb616 | |||
| 4261ddcde4 | |||
| 6ee03b7ebb | |||
| 1217578202 | |||
| c7b6788288 | |||
| 02f1d2ff8a | |||
| bb677152c9 | |||
| ad6519fb87 | |||
| d08f2e0e11 | |||
| 73aeca0916 | |||
| 080a54231f | |||
| b403569b16 | |||
| 3abfb02962 | |||
| 11a6d08023 | |||
| 69ecc42055 | |||
| 5f74c5297a | |||
| 34fcefa1bd | |||
| c9e6935f15 | |||
| 21cc0007fb | |||
| ebe3bc5f7b | |||
| 132f11298e | |||
| 21f75c8a63 | |||
| c1e1f65715 | |||
|  | 5cc5e6a1f7 | ||
|  | 1f4735caac | ||
|  | d672a29dda | ||
| 68ebd60bc8 | |||
| 4d12796289 | |||
| 857298b8b8 | |||
| 220f1ea0eb | |||
| a88acd34fd | |||
| 8ae113c872 | |||
| 098a2ea620 | |||
| 6a62b46dec | |||
|  | 2bae684df9 | ||
| 8bd75429c1 | |||
|  | 8fe00b4c2b | ||
| 199e5a73d8 | |||
| 54d03275cf | |||
| 8683f8faf3 | |||
| 821b67723c | |||
| ae1146c79c | |||
| 050c325195 | |||
| 5e0d869d9b | |||
|  | c59cf3f0df | ||
|  | 890b8db5dd | ||
| 32b8de8997 | |||
| 9f1f7ad3f7 | |||
| 9da4c1ebeb | |||
| 9b7a52064a | |||
| faad3f5f47 | |||
|  | 7595d70ada | ||
|  | 484259c8ab | ||
|  | a6e0b16032 | ||
|  | 9d34968b88 | ||
| f548121312 | |||
| 1ecb1abc80 | |||
| 28a45992c6 | |||
| c39097f164 | |||
| 30b127bc88 | |||
| 25d7fc36a4 | |||
| 03bd1674e1 | |||
| b018a50a7e | |||
| 4440cf8a24 | |||
| 6bd7a0105d | |||
|  | 51c2408878 | ||
| 242c77a30c | |||
| 22aa4afc02 | |||
| 04e9e30972 | |||
| d536da3581 | |||
| 27f49b2aa3 | |||
| 912a8d53af | |||
| 9ef397e935 | |||
| eca8172c6d | |||
| f3802e36b3 | |||
| 2f9c7c38b5 | |||
|  | d73fd697dd | ||
| f35889339d | |||
| 8e95166c24 | |||
| 30c53b17f7 | |||
| 2610730219 | |||
| 5dd99d201b | |||
| d327dae9fa | |||
| 2bdbb20154 | |||
| 14bd211a5f | |||
| 35627203e6 | |||
| f978636d57 | |||
| e095cac7e0 | |||
| c5b0d6e2bd | |||
|  | 905cb66011 | ||
| eaac97221f | |||
|  | 893c38fba4 | ||
|  | f867f4985d | ||
|  | aebeefcf80 | ||
|  | 3fc6c0c479 | ||
|  | ce854cb58f | ||
|  | ed4f1344c2 | ||
|  | 86dbe527d8 | ||
|  | 69a56fb433 | ||
|  | a7fad0ca1b | ||
|  | 9b8c34a9be | ||
| 5acc78507e | |||
| 1722cf721e | |||
| 75ba07f181 | |||
| 5b635fbe58 | |||
| e0dc0a8fdb | |||
| 2aa13dceff | |||
| ea477a9842 | |||
| 73653744d7 | |||
| 55264da092 | |||
| 38f5854c6d | |||
| 3c6d3f30d2 | |||
| a6d6a962cd | |||
| 6256d6a19e | |||
| 8841af8d2b | |||
| 0a9b8ba0b0 | |||
| 9710f8be63 | |||
| d872bf65dd | |||
| c3ef8d112c | |||
| f2a4347de7 | |||
| 51a4880fdb | |||
| a4d22b0fcb | |||
| 8d051800a4 | |||
|  | c0b59162a1 | ||
| 0e53a081c7 | |||
| d76f6d716f | |||
| f1d5d9840e | |||
| f3eb418409 | |||
| 3e85529468 | |||
| 05798688d0 | |||
| 01f35eed04 | |||
| aef97cca32 | |||
| 87e2ac9386 | |||
| 4a04628d5b | |||
| 0af78f814c | |||
| 929d40ff6e | |||
| 68f6642ff2 | |||
| 91e4d585ff | |||
| eac42581a6 | |||
|  | 4e50d0ace9 | ||
|  | 0b54adeb59 | ||
|  | 5d23de4862 | ||
|  | eda454cb9d | ||
| 6da8f1c107 | |||
| 4fb487dcef | |||
| 0d6a339b53 | |||
| c6525be444 | |||
| cb846891d6 | |||
| 2aed37757e | |||
| 444159b52a | |||
| 7aed8e83ea | |||
| f7a807473d | |||
| f8e91c325d | |||
| a448405ce5 | |||
| a4989f99d6 | |||
| 3f64db3b3a | |||
|  | 7ee5ca0753 | ||
| 41254db72f | |||
|  | 15e301b889 | ||
| 061a7dd537 | |||
|  | c3926991ac | ||
|  | ea0b2407df | ||
| 569679238c | |||
| ed17f78da5 | |||
| dfd9230541 | |||
| 65b751642f | |||
| d6fd827f8b | |||
| 162b0099b2 | |||
| e0b689174a | |||
| edf4430fb1 | |||
| 040884a039 | |||
| f7c08f02c2 | |||
|  | 2fe38945d2 | ||
| cece152c0b | |||
| 4e31b3e424 | |||
| 109bf5ec5d | |||
| 4f3f16d9b0 | |||
|  | fe5745831c | ||
| 3447117742 | |||
| 143f8f43fa | |||
| 36326a2a70 | |||
| 52637c2919 | |||
| f3a8552829 | |||
| bfdfd19711 | |||
|  | efb9bc938a | ||
| dcd1856ebb | |||
| 43f3270171 | |||
| b7fcac8f39 | |||
| e521d06702 | |||
| a260274549 | |||
| b37a7d2690 | |||
| 242c2b31a3 | |||
| 57c420e9dd | |||
| ac67f56b09 | |||
| b24eb93c57 | |||
| 0f59be04a7 | |||
| 54eb15ea35 | |||
| a85f170e2d | |||
| 226f71ab2b | |||
| a887326611 | |||
| 8ed2e7585d | |||
| 7a1ad24f0e | |||
|  | b934c2eeaf | ||
| de0e3f7dfd | |||
| 44c9a65505 | |||
| 038d7ad2e1 | |||
|  | c1b727b1c8 | ||
| a63c38b6aa | |||
| 8915c42008 | |||
| 503293a359 | |||
| 7bdf71315a | |||
| 6f5d457122 | |||
| b4274264a7 | |||
| 8002725c87 | |||
| 2c9edf3741 | |||
| 3f562449e1 | |||
| 1cce39bcb5 | |||
| c93d5ceb16 | |||
| ad690db886 | |||
|  | 1b8462b40d | ||
|  | 8c98f2cf6e | ||
| f3260f57a4 | |||
| b4ad0128e4 | |||
| e1c8278f71 | |||
|  | ed3f46ce7f | ||
|  | 1f838d9c5a | ||
| 33457d3cbc | |||
| 6df8e6dec8 | |||
| f9b8f13dd6 | |||
| e919b4322e | |||
| 7503c845df | |||
|  | c6cd785262 | ||
|  | e453e24203 | ||
| 3686a294d3 | |||
|  | 115a14fcba | ||
|  | fc172fdb1f | ||
| b6131379f9 | |||
| e1fcc41ace | |||
| f2a04cebe6 | |||
| c693002ddb | |||
| ee77c8540a | |||
| a536d2780e | |||
| f880598052 | |||
| e7985ea52f | |||
| f56dc65021 | |||
|  | 4770758aee | ||
| 90fe484d81 | |||
| 2b8bbe019d | |||
|  | 1f1b9c594f | ||
| 9e1c151402 | |||
| 088e522292 | |||
|  | f836114d84 | ||
| b8e6e98a74 | |||
|  | 4fd13440c6 | ||
|  | 4d8afd53ad | ||
| 2db847ada2 | |||
| 07e0692783 | |||
| e78d53064b | |||
| e6fcb5ff22 | |||
| f02e33fda7 | |||
| 1bbec9efae | |||
| 3b53c4451c | |||
| 30f490959b | |||
|  | 0a894b0db1 | ||
| c20e9507d5 | |||
| f89c690f1b | |||
|  | 7819c1204c | ||
|  | f61af9d02a | ||
|  | e470a6a97e | ||
|  | cd8c47449b | ||
| 120e7cade5 | |||
| ac550e05e8 | |||
| d6e7fadb4f | |||
|  | 2be1c08c44 | ||
|  | 86c177bbbb | ||
|  | d426d28ba0 | ||
|  | 72e69fc0b3 | ||
| cc8de353d4 | |||
| 4495a5d33b | |||
| 9dffe30aad | |||
| d393e74896 | |||
| daf083dc88 | |||
|  | ce859697b5 | ||
|  | 1587c762f8 | ||
|  | 17c01d9b46 | ||
| a1bb9ea352 | |||
|  | a1895ec65f | ||
|  | c5faa0b99d | ||
|  | e9d142f3e8 | ||
|  | 91860afd80 | ||
|  | bec0700d39 | ||
|  | 05d3d7f5c7 | ||
|  | ebff36d257 | ||
|  | a709b3afb6 | ||
|  | 69a3c6a9b2 | ||
|  | 8c33d876e8 | ||
|  | 1ec2fbcc16 | ||
|  | bc4e29141b | ||
|  | e90ea31683 | ||
|  | 7c99f0b3e0 | ||
|  | c089960707 | ||
|  | 0b2f29f1e8 | ||
|  | 9a4f50472a | ||
|  | 7d1a1c4004 | ||
|  | ebd58d4229 | ||
|  | dd48795f64 | ||
| 3d45b6687f | |||
| 35e6d36ce0 | |||
| 4900c81c11 | |||
| 52472b0ec3 | |||
| ec68e6f761 | |||
|  | 82d8556f24 | ||
| 25bd170f6b | |||
| 6939b4a313 | |||
| d18922ed98 | |||
| e8bf242c42 | |||
| 2050460bb3 | |||
|  | 4add30e895 | ||
| e1dbfdafd7 | |||
| 75becb2294 | |||
| 94e494361f | |||
| cab3b1059d | |||
|  | d27bdf68fb | ||
|  | 82b82920e1 | ||
| 4bb3eadf91 | |||
| 4c82e65c1f | |||
| cf4d7df7ad | |||
| 86d13410c3 | |||
| 19fdf2a503 | |||
| 3a0c25c871 | |||
| 083338da8d | |||
| 37e5c9ceaa | |||
|  | 5448238697 | ||
|  | c5250a1059 | ||
| b2c1a7b8de | |||
| 49c6915c0a | |||
| b4583fc6dc | |||
| f7c508939c | |||
| 4cf77a9b0e | |||
| a2160bef7d | |||
|  | c2a4a95eba | ||
| 8641d6bdce | |||
| 5f4d513aa6 | |||
| f47b15de39 | |||
| 7426dc02cf | |||
| a570160aed | |||
| 6e81ef0065 | |||
| e3cc76c689 | |||
| b43f43fa0b | |||
| 7596bd5a06 | |||
| f02d6df262 | |||
| e4e2138765 | |||
| 395735e6f7 | |||
| 2c96c02261 | |||
| 53813f8f29 | |||
|  | b8ef0d28f5 | ||
|  | e973c4013f | ||
| 01f9d03b14 | |||
|  | 0f9a395dfc | ||
|  | 38ac3badef | ||
|  | cda32fb925 | ||
|  | 58cb34f39b | ||
| 66426f5102 | |||
|  | 45671bda52 | ||
|  | 934eef4db4 | ||
|  | 31e8dea965 | ||
|  | 05ebdefd47 | ||
|  | c233c481b6 | ||
|  | 68d9778c00 | ||
|  | 8acd852070 | ||
|  | a9420f0339 | ||
|  | 207e5bf01d | ||
|  | cb5cf5763e | ||
|  | ff450215c6 | ||
|  | dad8fd5378 | ||
|  | 37b395ee52 | ||
|  | 03243605da | ||
|  | 48e2d2ceab | ||
|  | 777fb25860 | ||
|  | 03601b9707 | ||
|  | 580dc71218 | ||
|  | 24a7d7b34b | ||
| c205bbddd3 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -19,3 +19,4 @@ docs/build/ | ||||
| /phpunit.xml | ||||
| .phpunit.result.cache | ||||
| ###< phpunit/phpunit ### | ||||
|  | ||||
|   | ||||
| @@ -5,20 +5,23 @@ image: registry.gitlab.com/chill-projet/chill-app/php-base-image:7.4 | ||||
| cache: | ||||
|   paths: | ||||
|     - tests/app/vendor/ | ||||
|     - .composer | ||||
|  | ||||
| before_script: | ||||
|   # add extensions to postgres | ||||
|   - PGPASSWORD=$POSTGRES_PASSWORD psql -U $POSTGRES_USER -h db -c "CREATE EXTENSION IF NOT EXISTS unaccent; CREATE EXTENSION IF NOT EXISTS pg_trgm;" | ||||
|   # Install and run Composer | ||||
|   - mkdir -p $COMPOSER_HOME | ||||
|   - curl -sS https://getcomposer.org/installer | php | ||||
|   - php composer.phar install | ||||
|   - php -d memory_limit=2G composer.phar install | ||||
|   - php tests/app/bin/console doctrine:migrations:migrate -n | ||||
|   - php tests/app/bin/console doctrine:fixtures:load -n | ||||
|   - php -d memory_limit=2G tests/app/bin/console doctrine:fixtures:load -n | ||||
|   - echo "before_script finished" | ||||
|  | ||||
| # Bring in any services we need http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service | ||||
| # See http://docs.gitlab.com/ee/ci/services/README.html for examples. | ||||
| services: | ||||
|   - name: postgres:12 | ||||
|   - name: postgis/postgis:12-3.1-alpine | ||||
|     alias: db | ||||
|   - name: redis | ||||
|     alias: redis | ||||
| @@ -30,8 +33,16 @@ variables: | ||||
|   POSTGRES_PASSWORD: postgres | ||||
|   # fetch the chill-app using git submodules | ||||
|   GIT_SUBMODULE_STRATEGY: recursive | ||||
|   REDIS_HOST: redis | ||||
|   REDIS_PORT: 6379 | ||||
|   REDIS_URL: redis://redis:6379 | ||||
|   # change vendor dir to make the app install into tests/apps | ||||
|   COMPOSER_VENDOR_DIR: tests/app/vendor | ||||
|   # cache some composer data | ||||
|   COMPOSER_HOME: .composer | ||||
|  | ||||
|  | ||||
| # Run our tests | ||||
| test: | ||||
|   script: | ||||
|     - bin/phpunit --colors=never | ||||
|     - php -d memory_limit=3G bin/phpunit --colors=never | ||||
|   | ||||
							
								
								
									
										25
									
								
								.php_cs.dist
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								.php_cs.dist
									
									
									
									
									
								
							| @@ -1,25 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| $config = require __DIR__ . '/vendor/drupol/php-conventions/config/php73/php_cs_fixer.config.php'; | ||||
|  | ||||
| $config | ||||
|     ->getFinder() | ||||
|     ->ignoreDotFiles(false) | ||||
|     ->name(['.php_cs.dist']); | ||||
|  | ||||
| $rules = $config->getRules(); | ||||
|  | ||||
| $rules['header_comment']['header'] = trim(file_get_contents(__DIR__ . '/resource/header.txt')); | ||||
|  | ||||
| return $config->setRules($rules); | ||||
							
								
								
									
										8
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -629,12 +629,12 @@ to attach them to the start of each source file to most effectively | ||||
| state the exclusion of warranty; and each file should have at least | ||||
| the "copyright" line and a pointer to where the full notice is found. | ||||
|  | ||||
|     <one line to give the program's name and a brief idea of what it does.> | ||||
|     Copyright (C) <year>  <name of author> | ||||
|     chill-bundles | ||||
|     Copyright (C) 2021  Chill Project | ||||
|  | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU Affero General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     it under the terms of the GNU Affero General Public License as published | ||||
|     by the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
|  | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|   | ||||
							
								
								
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Chill framework | ||||
|  | ||||
| Documentation of the Chill software. | ||||
|  | ||||
| The online documentation can be found at http://docs.chill.social | ||||
|  | ||||
| See the [`docs`][1] directory for more. | ||||
|  | ||||
| [1]: docs/README.md | ||||
| @@ -3,7 +3,10 @@ | ||||
|     "license": "AGPL-3.0-only", | ||||
|     "type": "library", | ||||
|     "description": "Most used bundles for chill-project", | ||||
|     "keywords": ["chill", "social worker"], | ||||
|     "keywords": [ | ||||
|         "chill", | ||||
|         "social worker" | ||||
|     ], | ||||
|     "autoload": { | ||||
|         "psr-4": { | ||||
|             "Chill\\ActivityBundle\\": "src/Bundle/ChillActivityBundle", | ||||
| @@ -16,12 +19,14 @@ | ||||
|             "Chill\\PersonBundle\\": "src/Bundle/ChillPersonBundle", | ||||
|             "Chill\\ReportBundle\\": "src/Bundle/ChillReportBundle", | ||||
|             "Chill\\TaskBundle\\": "src/Bundle/ChillTaskBundle", | ||||
|             "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle" | ||||
|             "Chill\\ThirdPartyBundle\\": "src/Bundle/ChillThirdPartyBundle", | ||||
|             "Chill\\AsideActivityBundle\\": "src/Bundle/ChillAsideActivityBundle/src", | ||||
|             "Chill\\DocGeneratorBundle\\": "src/Bundle/ChillDocGeneratorBundle" | ||||
|         } | ||||
|     }, | ||||
|     "autoload-dev": { | ||||
|         "psr-4": { | ||||
|           "App\\": "tests/app/src/" | ||||
|             "App\\": "tests/app/src/" | ||||
|         } | ||||
|     }, | ||||
|     "require": { | ||||
| @@ -52,19 +57,19 @@ | ||||
|         "knplabs/knp-time-bundle": "^1.12", | ||||
|         "symfony/intl": "4.*", | ||||
|         "symfony/swiftmailer-bundle": "^3.5", | ||||
|         "league/csv": "^9.6", | ||||
|         "league/csv": "^9.7.1", | ||||
|         "phpoffice/phpspreadsheet": "^1.16", | ||||
|         "symfony/browser-kit": "^5.2", | ||||
|         "symfony/css-selector": "^5.2", | ||||
|         "twig/markdown-extra": "^3.3", | ||||
|         "erusev/parsedown": "^1.7", | ||||
|         "symfony/serializer": "^5.2" | ||||
|         "symfony/serializer": "^5.2", | ||||
|         "symfony/webpack-encore-bundle": "^1.11" | ||||
|     }, | ||||
|     "conflict": { | ||||
|         "symfony/symfony": "*" | ||||
|     }, | ||||
|     "require-dev": { | ||||
|         "drupol/php-conventions": "4.*", | ||||
|         "fakerphp/faker": "^1.13", | ||||
|         "phpunit/phpunit": "^7.0", | ||||
|         "symfony/dotenv": "^5.1", | ||||
| @@ -74,7 +79,8 @@ | ||||
|         "symfony/web-profiler-bundle": "^5.0", | ||||
|         "symfony/var-dumper": "4.*", | ||||
|         "symfony/debug-bundle": "^5.1", | ||||
|         "symfony/phpunit-bridge": "^5.2" | ||||
|         "symfony/phpunit-bridge": "^5.2", | ||||
|         "nelmio/alice": "^3.8" | ||||
|     }, | ||||
|     "scripts": { | ||||
|         "auto-scripts": { | ||||
| @@ -83,6 +89,6 @@ | ||||
|         } | ||||
|     }, | ||||
|     "config": { | ||||
|       "bin-dir": "bin" | ||||
|         "bin-dir": "bin" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,128 +1,123 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\PersonBundle\Export\Filter; | ||||
|  | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\MainBundle\Export\FilterInterface; | ||||
| use DateTime; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
| use Symfony\Component\Validator\Constraints; | ||||
| use Symfony\Component\Form\FormEvent; | ||||
| use Symfony\Component\Form\FormEvents; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Chill\MainBundle\Form\Type\Export\FilterType; | ||||
| use Symfony\Component\Form\FormError; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
|  | ||||
| class BirthdateFilter implements ExportElementValidatedInterface, FilterInterface | ||||
| class BirthdateFilter implements FilterInterface, ExportElementValidatedInterface | ||||
| { | ||||
|     // add specific role for this filter | ||||
|     // add specific role for this filter     | ||||
|     public function addRole() | ||||
|     { | ||||
|         // we do not need any new role for this filter, so we return null | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     // here, we alter the query created by Export | ||||
|     public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) | ||||
|     { | ||||
|         $where = $qb->getDQLPart('where'); | ||||
|         // we create the clause here | ||||
|         $clause = $qb->expr()->between( | ||||
|             'person.birthdate', | ||||
|             ':date_from', | ||||
|             ':date_to' | ||||
|         ); | ||||
|  | ||||
|         // we have to take care **not to** remove previous clauses... | ||||
|         if ($where instanceof Expr\Andx) { | ||||
|             $where->add($clause); | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|  | ||||
|         $qb->add('where', $where); | ||||
|         // we add parameters from $data. $data contains the parameters from the form | ||||
|         $qb->setParameter('date_from', $data['date_from']); | ||||
|         $qb->setParameter('date_to', $data['date_to']); | ||||
|     } | ||||
|  | ||||
|     // we give information on which type of export this filter applies | ||||
|     public function applyOn() | ||||
|     { | ||||
|         return 'person'; | ||||
|     } | ||||
|  | ||||
|     // we build a form to collect some parameters from the users | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('date_from', DateType::class, [ | ||||
|             'label' => 'Born after this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('date_to', DateType::class, [ | ||||
|             'label' => 'Born before this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     // here, we create a simple string which will describe the action of | ||||
|     // the filter in the Response | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         return ['Filtered by person\'s birtdate: ' | ||||
|             . 'between %date_from% and %date_to%', [ | ||||
|                 '%date_from%' => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%' => $data['date_to']->format('d-m-Y'), | ||||
|             ], ]; | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Filter by person\'s birthdate'; | ||||
|     } | ||||
|  | ||||
|     // we build a form to collect some parameters from the users | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('date_from', DateType::class, array( | ||||
|             'label' => "Born after this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         )); | ||||
|          | ||||
|         $builder->add('date_to', DateType::class, array( | ||||
|             'label' => "Born before this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         )); | ||||
|          | ||||
|     } | ||||
|     | ||||
|     // the form created above must be validated. The process of validation | ||||
|     // is executed here. This function is added by the interface | ||||
|     // `ExportElementValidatedInterface`, and can be ignore if there is | ||||
|     // is executed here. This function is added by the interface  | ||||
|     // `ExportElementValidatedInterface`, and can be ignore if there is  | ||||
|     // no need for a validation | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|     {  | ||||
|         $date_from = $data['date_from']; | ||||
|         $date_to = $data['date_to']; | ||||
|  | ||||
|         if (null === $date_from) { | ||||
|         $date_to   = $data['date_to']; | ||||
|          | ||||
|         if ($date_from === null) { | ||||
|             $context->buildViolation('The "date from" should not be empty') | ||||
|                 //->atPath('date_from') | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|  | ||||
|         if (null === $date_to) { | ||||
|          | ||||
|         if ($date_to === null) { | ||||
|             $context->buildViolation('The "date to" should not be empty') | ||||
|                 //->atPath('date_to') | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         if ( | ||||
|             (null !== $date_from && null !== $date_to) | ||||
|             && $date_from >= $date_to | ||||
|             ($date_from !== null && $date_to !== null) | ||||
|             && | ||||
|             $date_from >= $date_to | ||||
|         ) { | ||||
|             $context->buildViolation('The date "date to" should be after the ' | ||||
|                 . 'date given in "date from" field') | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
|     // here, we alter the query created by Export | ||||
|     public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) | ||||
|     { | ||||
|         $where = $qb->getDQLPart('where'); | ||||
|         // we create the clause here | ||||
|         $clause = $qb->expr()->between('person.birthdate', ':date_from',  | ||||
|             ':date_to'); | ||||
|  | ||||
|         // we have to take care **not to** remove previous clauses... | ||||
|         if ($where instanceof Expr\Andx) { | ||||
|             $where->add($clause); | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|          | ||||
|         $qb->add('where', $where); | ||||
|         // we add parameters from $data. $data contains the parameters from the form | ||||
|         $qb->setParameter('date_from', $data['date_from']); | ||||
|         $qb->setParameter('date_to', $data['date_to']); | ||||
|     } | ||||
|  | ||||
|     // here, we create a simple string which will describe the action of | ||||
|     // the filter in the Response | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         return array('Filtered by person\'s birtdate: ' | ||||
|             . 'between %date_from% and %date_to%', array( | ||||
|                 '%date_from%' => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%'   => $data['date_to']->format('d-m-Y') | ||||
|             )); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,121 +1,118 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\PersonBundle\Export\Export; | ||||
|  | ||||
| use Chill\MainBundle\Export\ExportInterface; | ||||
| use Chill\MainBundle\Export\FormatterInterface; | ||||
| use Chill\PersonBundle\Export\Declarations; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\Query; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Doctrine\ORM\Query; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\PersonBundle\Export\Declarations; | ||||
| use Chill\MainBundle\Export\FormatterInterface; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class CountPerson implements ExportInterface | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         EntityManagerInterface $em | ||||
|     ) { | ||||
|             EntityManagerInterface $em | ||||
|             ) | ||||
|     { | ||||
|         $this->entityManager = $em; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(FormBuilderInterface $builder) | ||||
|     { | ||||
|         // this export does not add any form | ||||
|     } | ||||
|  | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return [FormatterInterface::TYPE_TABULAR]; | ||||
|     } | ||||
|  | ||||
|     public function getDescription() | ||||
|     { | ||||
|         return 'Count peoples by various parameters.'; | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         // the Closure which will be executed by the formatter. | ||||
|         return function ($value) { | ||||
|             switch ($value) { | ||||
|                 case '_header': | ||||
|                   // we have to process specifically the '_header' string, | ||||
|                   // which will be used by the formatter to show a column title | ||||
|                     return $this->getTitle(); | ||||
|  | ||||
|                 default: | ||||
|                   // for all value, we do not process them and return them | ||||
|                   // immediatly | ||||
|                     return $value; | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         // this array match the result keys in the query. We have only | ||||
|         // one column. | ||||
|         return ['export_result']; | ||||
|     } | ||||
|  | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Count peoples'; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function getType() | ||||
|     { | ||||
|         return Declarations::PERSON_TYPE; | ||||
|     } | ||||
|  | ||||
|     public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) | ||||
|      | ||||
|     public function getDescription() | ||||
|     { | ||||
|         // we gather all center the user choose. | ||||
|         $centers = array_map(static function ($el) { | ||||
|             return $el['center']; | ||||
|         }, $acl); | ||||
|  | ||||
|         $qb = $this->entityManager->createQueryBuilder(); | ||||
|  | ||||
|         $qb->select('COUNT(person.id) AS export_result') | ||||
|             ->from('ChillPersonBundle:Person', 'person') | ||||
|             ->join('person.center', 'center') | ||||
|             ->andWhere('center IN (:authorized_centers)') | ||||
|             ->setParameter('authorized_centers', $centers); | ||||
|  | ||||
|         return $qb; | ||||
|         return "Count peoples by various parameters."; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return "Count peoples"; | ||||
|     } | ||||
|      | ||||
|     public function requiredRole() | ||||
|     { | ||||
|         return new Role(PersonVoter::STATS); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function initiateQuery(array $requiredModifiers,  array $acl, array $data = array()) | ||||
|     { | ||||
|         // we gather all center the user choose. | ||||
|         $centers = array_map(function($el) { return $el['center']; }, $acl); | ||||
|          | ||||
|         $qb = $this->entityManager->createQueryBuilder(); | ||||
|          | ||||
|         $qb->select('COUNT(person.id) AS export_result') | ||||
|                 ->from('ChillPersonBundle:Person', 'person') | ||||
|                 ->join('person.center', 'center') | ||||
|                 ->andWhere('center IN (:authorized_centers)') | ||||
|                 ->setParameter('authorized_centers', $centers); | ||||
|                 ; | ||||
|          | ||||
|          | ||||
|         return $qb; | ||||
|     } | ||||
|      | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|     } | ||||
|      | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         // this array match the result keys in the query. We have only | ||||
|         // one column. | ||||
|         return array('export_result'); | ||||
|     } | ||||
|      | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|          | ||||
|         // the Closure which will be executed by the formatter.  | ||||
|         return function($value) { | ||||
|             switch($value) { | ||||
|                 case '_header': | ||||
|                   // we have to process specifically the '_header' string,  | ||||
|                   // which will be used by the formatter to show a column title | ||||
|                   return $this->getTitle(); | ||||
|                 default: | ||||
|                   // for all value, we do not process them and return them | ||||
|                   // immediatly | ||||
|                   return $value; | ||||
|         }; | ||||
|     } | ||||
|      | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return array(FormatterInterface::TYPE_TABULAR); | ||||
|     } | ||||
|      | ||||
|     public function buildForm(FormBuilderInterface $builder) { | ||||
|         // this export does not add any form | ||||
|     } | ||||
|      | ||||
|     public function supportsModifiers() | ||||
|     { | ||||
|         // explain the export manager which formatters and filters are allowed | ||||
|         return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN]; | ||||
|         return array(Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN); | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
							
								
								
									
										747
									
								
								docs/source/development/api.rst
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										747
									
								
								docs/source/development/api.rst
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,747 @@ | ||||
| .. Copyright (C)  2014 Champs Libres Cooperative SCRLFS | ||||
|    Permission is granted to copy, distribute and/or modify this document | ||||
|    under the terms of the GNU Free Documentation License, Version 1.3 | ||||
|    or any later version published by the Free Software Foundation; | ||||
|    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. | ||||
|    A copy of the license is included in the section entitled "GNU | ||||
|    Free Documentation License". | ||||
|  | ||||
| .. _api: | ||||
|  | ||||
| API | ||||
| ### | ||||
|  | ||||
| Chill provides a basic framework to build REST api. | ||||
|  | ||||
| Basic configuration | ||||
| ******************* | ||||
|  | ||||
| Configure a route | ||||
| ================= | ||||
|  | ||||
| Follow those steps to build a REST api: | ||||
|  | ||||
| 1. Create your model; | ||||
| 2. Configure the API; | ||||
|  | ||||
| You can also: | ||||
|  | ||||
| * hook into the controller to customize some steps; | ||||
| * add more route and steps | ||||
|  | ||||
| .. note:: | ||||
|  | ||||
|     Useful links: | ||||
|  | ||||
|     * `How to use annotation to configure serialization <https://symfony.com/doc/current/serializer.html>`_ | ||||
|     * `How to create your custom normalizer <https://symfony.com/doc/current/serializer/custom_normalizer.html>`_ | ||||
|  | ||||
| Auto-loading the routes | ||||
| ======================= | ||||
|  | ||||
| Ensure that those lines are present in your file `app/config/routing.yml`: | ||||
|  | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    chill_cruds: | ||||
|        resource: 'chill_main_crud_route_loader:load' | ||||
|        type: service | ||||
|  | ||||
|  | ||||
| Create your model | ||||
| ================= | ||||
|  | ||||
| Create your model on the usual way: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
|  | ||||
|    use Chill\PersonBundle\Entity\AccompanyingPeriod\OriginRepository; | ||||
|    use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
|    /** | ||||
|     * @ORM\Entity(repositoryClass=OriginRepository::class) | ||||
|     * @ORM\Table(name="chill_person_accompanying_period_origin") | ||||
|     */ | ||||
|    class Origin | ||||
|    { | ||||
|        /** | ||||
|         * @ORM\Id | ||||
|         * @ORM\GeneratedValue | ||||
|         * @ORM\Column(type="integer") | ||||
|         */ | ||||
|        private $id; | ||||
|  | ||||
|        /** | ||||
|         * @ORM\Column(type="json") | ||||
|         */ | ||||
|        private $label; | ||||
|  | ||||
|        /** | ||||
|         * @ORM\Column(type="date_immutable", nullable=true) | ||||
|         */ | ||||
|        private $noActiveAfter; | ||||
|  | ||||
|        // .. getters and setters | ||||
|  | ||||
|    } | ||||
|  | ||||
|  | ||||
| Configure api | ||||
| ============= | ||||
|  | ||||
| Configure the api using Yaml (see the full configuration: :ref:`api_full_configuration`): | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    # config/packages/chill_main.yaml | ||||
|    chill_main: | ||||
|        apis: | ||||
|            accompanying_period_origin: | ||||
|                base_path: '/api/1.0/person/accompanying-period/origin' | ||||
|                class: 'Chill\PersonBundle\Entity\AccompanyingPeriod\Origin' | ||||
|                name: accompanying_period_origin | ||||
|                base_role: 'ROLE_USER' | ||||
|                actions: | ||||
|                    _index: | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|                    _entity: | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|  | ||||
| .. note:: | ||||
|  | ||||
|    If you are working on a shared bundle (aka "The chill bundles"), you should define your configuration inside the class :code:`ChillXXXXBundleExtension`, using the "prependConfig" feature: | ||||
|  | ||||
|    .. code-block:: php | ||||
|  | ||||
|       namespace Chill\PersonBundle\DependencyInjection; | ||||
|  | ||||
|       use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
|       use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
|       use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
|       /** | ||||
|        * Class ChillPersonExtension | ||||
|        * Loads and manages your bundle configuration | ||||
|        * | ||||
|        * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||||
|        * @package Chill\PersonBundle\DependencyInjection | ||||
|        */ | ||||
|       class ChillPersonExtension extends Extension implements PrependExtensionInterface | ||||
|       { | ||||
|           public function prepend(ContainerBuilder $container) | ||||
|           { | ||||
|               $this->prependCruds($container); | ||||
|           } | ||||
|  | ||||
|           /** | ||||
|            * @param ContainerBuilder $container | ||||
|            */ | ||||
|           protected function prependCruds(ContainerBuilder $container) | ||||
|           { | ||||
|               $container->prependExtensionConfig('chill_main', [ | ||||
|                   'apis' => [ | ||||
|                       [ | ||||
|                           'class' => \Chill\PersonBundle\Entity\AccompanyingPeriod\Origin::class, | ||||
|                           'name' => 'accompanying_period_origin', | ||||
|                           'base_path' => '/api/1.0/person/accompanying-period/origin', | ||||
|                           'controller' => \Chill\PersonBundle\Controller\OpeningApiController::class, | ||||
|                           'base_role' => 'ROLE_USER', | ||||
|                           'actions' => [ | ||||
|                               '_index' => [ | ||||
|                                   'methods' => [  | ||||
|                                       Request::METHOD_GET => true, | ||||
|                                       Request::METHOD_HEAD => true | ||||
|                                   ], | ||||
|                               ], | ||||
|                               '_entity' => [ | ||||
|                                   'methods' => [  | ||||
|                                       Request::METHOD_GET => true, | ||||
|                                       Request::METHOD_HEAD => true | ||||
|                                   ] | ||||
|                               ], | ||||
|                           ] | ||||
|                       ] | ||||
|                   ] | ||||
|               ]); | ||||
|           } | ||||
|       } | ||||
|  | ||||
| The :code:`_index` and :code:`_entity` action | ||||
| ********************************************* | ||||
|  | ||||
| The :code:`_index` and :code:`_entity` action are default actions: | ||||
|  | ||||
| * they will call a specific method in the default controller; | ||||
| * they will generate defined routes: | ||||
|  | ||||
| Index: | ||||
|    Name: :code:`chill_api_single_accompanying_period_origin__index` | ||||
|  | ||||
|    Path: :code:`/api/1.0/person/accompanying-period/origin.{_format}` | ||||
|  | ||||
| Entity: | ||||
|    Name: :code:`chill_api_single_accompanying_period_origin__entity` | ||||
|  | ||||
|    Path: :code:`/api/1.0/person/accompanying-period/origin/{id}.{_format}` | ||||
|  | ||||
| Role | ||||
| **** | ||||
|  | ||||
| By default, the key `base_role` is used to check ACL. Take care of creating the :code:`Voter` required to take that into account. | ||||
|  | ||||
| For index action, the role will be called with :code:`NULL` as :code:`$subject`. The retrieved entity will be the subject for single queries. | ||||
|  | ||||
| You can also define a role for each method. In this case, this role is used for the given method, and, if any, the base role is taken into account. | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    # config/packages/chill_main.yaml | ||||
|    chill_main: | ||||
|        apis: | ||||
|            accompanying_period_origin: | ||||
|                base_path: '/api/1.0/person/bla/bla' | ||||
|                class: 'Chill\PersonBundle\Entity\Blah' | ||||
|                name: bla | ||||
|                actions: | ||||
|                    _entity: | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|                        roles: | ||||
|                            GET: MY_ROLE_SEE | ||||
|                            HEAD: MY ROLE_SEE | ||||
|  | ||||
| Customize the controller | ||||
| ************************ | ||||
|  | ||||
| You can customize the controller by hooking into the default actions. Take care of extending :code:`Chill\MainBundle\CRUD\Controller\ApiController`. | ||||
|  | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|  | ||||
|    namespace Chill\PersonBundle\Controller; | ||||
|  | ||||
|    use Chill\MainBundle\CRUD\Controller\ApiController; | ||||
|    use Symfony\Component\HttpFoundation\Request; | ||||
|    use Symfony\Component\HttpFoundation\Response; | ||||
|  | ||||
|    class OpeningApiController extends ApiController | ||||
|    { | ||||
|        protected function customizeQuery(string $action, Request $request, $qb): void | ||||
|        { | ||||
|            $qb->where($qb->expr()->gt('e.noActiveAfter', ':now')) | ||||
|                ->orWhere($qb->expr()->isNull('e.noActiveAfter')); | ||||
|            $qb->setParameter('now', new \DateTime('now')); | ||||
|        }      | ||||
|    } | ||||
|  | ||||
| And set your controller in configuration: | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    chill_main: | ||||
|        apis: | ||||
|            accompanying_period_origin: | ||||
|                base_path: '/api/1.0/person/accompanying-period/origin' | ||||
|                class: 'Chill\PersonBundle\Entity\AccompanyingPeriod\Origin' | ||||
|                name: accompanying_period_origin | ||||
|                # add a controller | ||||
|                controller: 'Chill\PersonBundle\Controller\OpeningApiController' | ||||
|                base_role: 'ROLE_USER' | ||||
|                actions: | ||||
|                    _index: | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|                    _entity: | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|  | ||||
| Create your own actions | ||||
| *********************** | ||||
|  | ||||
| You can add your own actions: | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    chill_main: | ||||
|        apis: | ||||
|            - | ||||
|                class: Chill\PersonBundle\Entity\AccompanyingPeriod | ||||
|                name: accompanying_course | ||||
|                base_path: /api/1.0/person/accompanying-course | ||||
|                controller: Chill\PersonBundle\Controller\AccompanyingCourseApiController | ||||
|                actions: | ||||
|                    # add a custom participation: | ||||
|                    participation: | ||||
|                        methods: | ||||
|                            POST: true | ||||
|                            DELETE: true | ||||
|                            GET: false | ||||
|                            HEAD: false | ||||
|                            PUT: false | ||||
|                        roles: | ||||
|                            POST: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            DELETE: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            GET: null | ||||
|                            HEAD: null | ||||
|                            PUT: null | ||||
|                        single-collection: single | ||||
|  | ||||
| The key :code:`single-collection` with value :code:`single` will add a :code:`/{id}/ + "action name"` (in this example, :code:`/{id}/participation`) into the path, after the base path. If the value is :code:`collection`, no id will be set, but the action name will be append to the path. | ||||
|  | ||||
| Then, create the corresponding action into your controller: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Controller; | ||||
|  | ||||
|    use Chill\MainBundle\CRUD\Controller\ApiController; | ||||
|    use Symfony\Component\HttpFoundation\Request; | ||||
|    use Symfony\Component\HttpFoundation\Response; | ||||
|    use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
|    use Symfony\Component\HttpFoundation\Exception\BadRequestException; | ||||
|    use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
|    use Symfony\Component\Validator\Validator\ValidatorInterface; | ||||
|    use Chill\PersonBundle\Privacy\AccompanyingPeriodPrivacyEvent; | ||||
|    use Chill\PersonBundle\Entity\Person; | ||||
|  | ||||
|    class AccompanyingCourseApiController extends ApiController | ||||
|    { | ||||
|        protected EventDispatcherInterface $eventDispatcher; | ||||
|  | ||||
|        protected ValidatorInterface $validator; | ||||
|  | ||||
|        public function __construct(EventDispatcherInterface $eventDispatcher, $validator) | ||||
|        { | ||||
|            $this->eventDispatcher = $eventDispatcher; | ||||
|            $this->validator = $validator; | ||||
|        } | ||||
|         | ||||
|        public function participationApi($id, Request $request, $_format) | ||||
|        { | ||||
|            /** @var AccompanyingPeriod $accompanyingPeriod */  | ||||
|            $accompanyingPeriod = $this->getEntity('participation', $id, $request); | ||||
|            $person = $this->getSerializer() | ||||
|                ->deserialize($request->getContent(), Person::class, $_format, []); | ||||
|  | ||||
|            if (NULL === $person) { | ||||
|                throw new BadRequestException('person id not found'); | ||||
|            } | ||||
|  | ||||
|            $this->onPostCheckACL('participation', $request, $accompanyingPeriod, $_format); | ||||
|  | ||||
|            switch ($request->getMethod()) { | ||||
|                case Request::METHOD_POST: | ||||
|                    $participation = $accompanyingPeriod->addPerson($person); | ||||
|                    break; | ||||
|                case Request::METHOD_DELETE: | ||||
|                    $participation = $accompanyingPeriod->removePerson($person); | ||||
|                    break; | ||||
|                default: | ||||
|                    throw new BadRequestException("This method is not supported"); | ||||
|            } | ||||
|  | ||||
|            $errors = $this->validator->validate($accompanyingPeriod); | ||||
|  | ||||
|            if ($errors->count() > 0) { | ||||
|                // only format accepted | ||||
|                return $this->json($errors); | ||||
|            } | ||||
|  | ||||
|            $this->getDoctrine()->getManager()->flush(); | ||||
|  | ||||
|            return $this->json($participation); | ||||
|        } | ||||
|    } | ||||
|  | ||||
| Managing association | ||||
| ******************** | ||||
|  | ||||
| ManyToOne association | ||||
| ===================== | ||||
|  | ||||
| In ManyToOne association, you can add associated entities using the :code:`PATCH` request. By default, the serializer deserialize entities only with their id and discriminator type, if any. | ||||
|  | ||||
| Example: | ||||
|  | ||||
| .. code-block:: bash | ||||
|  | ||||
|    curl -X 'PATCH' \ | ||||
|      'http://localhost:8001/api/1.0/person/accompanying-course/2668.json' \ | ||||
|      -H 'accept: */*' \ | ||||
|      -H 'Content-Type: application/json' \ | ||||
|       # see the data sent to the server: \ | ||||
|      -d '{ | ||||
|      "type": "accompanying_period", | ||||
|      "id": 2668, | ||||
|      "origin": { "id": 11 } | ||||
|    }' | ||||
|  | ||||
| ManyToMany associations | ||||
| ======================= | ||||
|  | ||||
| In OneToMany association, you can easily create route for adding and removing entities, using :code:`POST` and :code:`DELETE` requests. | ||||
|  | ||||
| Prepare your entity, creating the methods :code:`addYourEntity` and :code:`removeYourEntity`: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Entity; | ||||
|  | ||||
|    use Chill\MainBundle\Entity\Scope; | ||||
|    use Doctrine\Common\Collections\ArrayCollection; | ||||
|    use Doctrine\Common\Collections\Collection; | ||||
|    use Doctrine\ORM\Mapping as ORM; | ||||
|    use Symfony\Component\Serializer\Annotation\Groups; | ||||
|    use Symfony\Component\Serializer\Annotation\DiscriminatorMap; | ||||
|  | ||||
|    /** | ||||
|     * AccompanyingPeriod Class | ||||
|     * | ||||
|     * @ORM\Entity | ||||
|     * @ORM\Table(name="chill_person_accompanying_period") | ||||
|     * @DiscriminatorMap(typeProperty="type", mapping={ | ||||
|     *  "accompanying_period"=AccompanyingPeriod::class | ||||
|     *  }) | ||||
|     */ | ||||
|    class AccompanyingPeriod | ||||
|    { | ||||
|        /** | ||||
|         * @var Collection | ||||
|         * @ORM\ManyToMany( | ||||
|         *     targetEntity=Scope::class, | ||||
|         *     cascade={} | ||||
|         *     ) | ||||
|         * @Groups({"read"}) | ||||
|         */ | ||||
|        private $scopes; | ||||
|  | ||||
|        public function addScope(Scope $scope): self | ||||
|        { | ||||
|            $this->scopes[] = $scope; | ||||
|  | ||||
|            return $this; | ||||
|        } | ||||
|  | ||||
|        public function removeScope(Scope $scope): void | ||||
|        { | ||||
|            $this->scopes->removeElement($scope); | ||||
|        } | ||||
|  | ||||
|  | ||||
| Create your route into the configuration: | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|    chill_main: | ||||
|        apis: | ||||
|            - | ||||
|                class: Chill\PersonBundle\Entity\AccompanyingPeriod | ||||
|                name: accompanying_course | ||||
|                base_path: /api/1.0/person/accompanying-course | ||||
|                controller: Chill\PersonBundle\Controller\AccompanyingCourseApiController | ||||
|                actions: | ||||
|                    scope: | ||||
|                        methods: | ||||
|                            POST: true | ||||
|                            DELETE: true | ||||
|                            GET: false | ||||
|                            HEAD: false | ||||
|                            PUT: false | ||||
|                            PATCH: false | ||||
|                        roles: | ||||
|                            POST: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            DELETE: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            GET: null | ||||
|                            HEAD: null | ||||
|                            PUT: null | ||||
|                            PATCH: null | ||||
|                        controller_action: null | ||||
|                        path: null | ||||
|                        single-collection: single | ||||
|  | ||||
| This will create a new route, which will accept two methods: DELETE and POST: | ||||
|  | ||||
| .. code-block:: raw | ||||
|  | ||||
|    +--------------+---------------------------------------------------------------------------------------+ | ||||
|    | Property     | Value                                                                                 | | ||||
|    +--------------+---------------------------------------------------------------------------------------+ | ||||
|    | Route Name   | chill_api_single_accompanying_course_scope                                            | | ||||
|    | Path         | /api/1.0/person/accompanying-course/{id}/scope.{_format}                              | | ||||
|    | Path Regex   | {^/api/1\.0/person/accompanying\-course/(?P<id>[^/]++)/scope\.(?P<_format>[^/]++)$}sD | | ||||
|    | Host         | ANY                                                                                   | | ||||
|    | Host Regex   |                                                                                       | | ||||
|    | Scheme       | ANY                                                                                   | | ||||
|    | Method       | POST|DELETE                                                                           | | ||||
|    | Requirements | {id}: \d+                                                                             | | ||||
|    | Class        | Symfony\Component\Routing\Route                                                       | | ||||
|    | Defaults     | _controller: csapi_accompanying_course_controller:scopeApi                            | | ||||
|    | Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                               | | ||||
|    +--------------+---------------------------------------------------------------------------------------+ | ||||
|  | ||||
|  | ||||
|  | ||||
| Then, create the controller action. Call the method: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Controller; | ||||
|  | ||||
|    use Chill\MainBundle\CRUD\Controller\ApiController; | ||||
|    use Symfony\Component\HttpFoundation\Request; | ||||
|    use Symfony\Component\HttpFoundation\Response; | ||||
|    use Chill\MainBundle\Entity\Scope; | ||||
|  | ||||
|    class MyController extends ApiController | ||||
|    { | ||||
|        public function scopeApi($id, Request $request, string $_format): Response | ||||
|        { | ||||
|            return $this->addRemoveSomething('scope', $id, $request, $_format, 'scope', Scope::class, [ 'groups' => [ 'read' ] ]); | ||||
|        } | ||||
|    } | ||||
|  | ||||
| This will allow to add a scope by his id, and delete them. | ||||
|  | ||||
| Curl requests: | ||||
|  | ||||
| .. code-block:: bash | ||||
|  | ||||
|    # add a scope with id 5 | ||||
|    curl -X 'POST' \ | ||||
|      'http://localhost:8001/api/1.0/person/accompanying-course/2868/scope.json' \ | ||||
|      -H 'accept: */*' \ | ||||
|      -H 'Content-Type: application/json' \ | ||||
|      -d '{ | ||||
|      "type": "scope", | ||||
|      "id": 5 | ||||
|    }' | ||||
|  | ||||
|    # remove a scope with id 5 | ||||
|    curl -X 'DELETE' \ | ||||
|      'http://localhost:8001/api/1.0/person/accompanying-course/2868/scope.json' \ | ||||
|      -H 'accept: */*' \ | ||||
|      -H 'Content-Type: application/json' \ | ||||
|      -d '{ | ||||
|      "id": 5, | ||||
|      "type": "scope" | ||||
|    }' | ||||
|  | ||||
| Deserializing an association where multiple types are allowed | ||||
| ============================================================= | ||||
|  | ||||
| Sometimes, multiples types are allowed as association to one entity: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
|  | ||||
|    use Chill\PersonBundle\Entity\Person; | ||||
|    use Chill\ThirdPartyBundle\Entity\ThirdParty; | ||||
|    use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
|    class Resource | ||||
|    { | ||||
|  | ||||
|  | ||||
|        /** | ||||
|         * @ORM\ManyToOne(targetEntity=ThirdParty::class) | ||||
|         * @ORM\JoinColumn(nullable=true) | ||||
|         */ | ||||
|        private $thirdParty; | ||||
|  | ||||
|        /** | ||||
|         * @ORM\ManyToOne(targetEntity=Person::class) | ||||
|         * @ORM\JoinColumn(nullable=true) | ||||
|         */ | ||||
|        private $person; | ||||
|  | ||||
|  | ||||
|        /** | ||||
|         * | ||||
|         * @param $resource Person|ThirdParty | ||||
|         */ | ||||
|        public function setResource($resource): self | ||||
|        { | ||||
|           // ... | ||||
|        } | ||||
|         | ||||
|         | ||||
|        /** | ||||
|         * @return ThirdParty|Person | ||||
|         * @Groups({"read", "write"}) | ||||
|         */ | ||||
|        public function getResource() | ||||
|        { | ||||
|            return $this->person ?? $this->thirdParty; | ||||
|        } | ||||
|    } | ||||
|  | ||||
| This is not well taken into account by the Symfony serializer natively. | ||||
|  | ||||
| You must, then, create your own CustomNormalizer. You can help yourself using this: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    namespace Chill\PersonBundle\Serializer\Normalizer; | ||||
|  | ||||
|    use Chill\PersonBundle\Entity\Person; | ||||
|    use Chill\ThirdPartyBundle\Entity\ThirdParty; | ||||
|    use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; | ||||
|    use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository; | ||||
|    use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||||
|    use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||||
|    use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||||
|    use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait; | ||||
|    use Symfony\Component\Serializer\Exception; | ||||
|    use Chill\MainBundle\Serializer\Normalizer\DiscriminatedObjectDenormalizer; | ||||
|  | ||||
|  | ||||
|    class AccompanyingPeriodResourceNormalizer implements DenormalizerInterface, DenormalizerAwareInterface | ||||
|    { | ||||
|        use DenormalizerAwareTrait; | ||||
|        use ObjectToPopulateTrait; | ||||
|  | ||||
|        public function __construct(ResourceRepository $repository) | ||||
|        { | ||||
|            $this->repository = $repository; | ||||
|        } | ||||
|  | ||||
|        public function denormalize($data, string $type, string $format = null, array $context = []) | ||||
|        { | ||||
|            // .. snipped for brevity | ||||
|  | ||||
|            if ($resource === NULL) { | ||||
|                $resource = new Resource(); | ||||
|            } | ||||
|  | ||||
|            if (\array_key_exists('resource', $data)) { | ||||
|                $res = $this->denormalizer->denormalize( | ||||
|                    $data['resource'], | ||||
|                    // call for a "multiple type" | ||||
|                    DiscriminatedObjectDenormalizer::TYPE, | ||||
|                    $format, | ||||
|                    // into the context, we add the list of allowed types: | ||||
|                    [  | ||||
|                        DiscriminatedObjectDenormalizer::ALLOWED_TYPES =>  | ||||
|                        [  | ||||
|                            Person::class, ThirdParty::class | ||||
|                        ] | ||||
|                    ] | ||||
|                ); | ||||
|  | ||||
|                $resource->setResource($res); | ||||
|            }  | ||||
|  | ||||
|            return $resource; | ||||
|        } | ||||
|         | ||||
|  | ||||
|        public function supportsDenormalization($data, string $type, string $format = null) | ||||
|        { | ||||
|            return $type === Resource::class; | ||||
|        }   | ||||
|    } | ||||
|  | ||||
| Serialization for collection | ||||
| **************************** | ||||
|  | ||||
| A specific model has been defined for returning collection: | ||||
|  | ||||
| .. code-block:: json | ||||
|  | ||||
|    { | ||||
|        "count": 49, | ||||
|        "results": [ | ||||
|        ], | ||||
|        "pagination": { | ||||
|            "more": true, | ||||
|            "next": "/api/1.0/search.json&q=xxxx......&page=2", | ||||
|            "previous": null, | ||||
|            "first": 0, | ||||
|            "items_per_page": 1 | ||||
|        } | ||||
|    } | ||||
|  | ||||
| Where this is relevant, this model should be re-used in custom controller actions. | ||||
|  | ||||
| In custom actions, this can be achieved quickly by assembling results into a :code:`Chill\MainBundle\Serializer\Model\Collection`. The pagination information is given by using :code:`Paginator` (see :ref:`Pagination <pagination-ref>`). | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
|    use Chill\MainBundle\Pagination\PaginatorInterface; | ||||
|  | ||||
|    class MyController extends AbstractController | ||||
|    { | ||||
|  | ||||
|        protected function serializeCollection(PaginatorInterface $paginator, $entities): Response | ||||
|        { | ||||
|            $model = new Collection($entities, $paginator); | ||||
|  | ||||
|            return $this->json($model, Response::HTTP_OK, [], $context); | ||||
|        } | ||||
|    } | ||||
|  | ||||
|  | ||||
| .. _api_full_configuration: | ||||
|  | ||||
| Full configuration example | ||||
| ************************** | ||||
|  | ||||
| .. code-block:: yaml | ||||
|  | ||||
|        apis: | ||||
|            - | ||||
|                class: Chill\PersonBundle\Entity\AccompanyingPeriod | ||||
|                name: accompanying_course | ||||
|                base_path: /api/1.0/person/accompanying-course | ||||
|                controller: Chill\PersonBundle\Controller\AccompanyingCourseApiController | ||||
|                actions: | ||||
|                    _entity: | ||||
|                        roles: | ||||
|                            GET: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            HEAD: null | ||||
|                            POST: null | ||||
|                            DELETE: null | ||||
|                            PUT: null | ||||
|                        controller_action: null | ||||
|                        path: null | ||||
|                        single-collection: single | ||||
|                        methods: | ||||
|                            GET: true | ||||
|                            HEAD: true | ||||
|                            POST: false | ||||
|                            DELETE: false | ||||
|                            PUT: false | ||||
|                    participation: | ||||
|                        methods: | ||||
|                            POST: true | ||||
|                            DELETE: true | ||||
|                            GET: false | ||||
|                            HEAD: false | ||||
|                            PUT: false | ||||
|                        roles: | ||||
|                            POST: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            DELETE: CHILL_PERSON_ACCOMPANYING_PERIOD_SEE | ||||
|                            GET: null | ||||
|                            HEAD: null | ||||
|                            PUT: null | ||||
|                        controller_action: null | ||||
|                        # the requirements for the route. Will be set to `[ 'id' => '\d+' ]` if left empty. | ||||
|                        requirements:         [] | ||||
|                        path: null | ||||
|                        single-collection: single | ||||
|                base_role: null | ||||
|  | ||||
|  | ||||
| @@ -16,6 +16,7 @@ As Chill rely on the `symfony <http://symfony.com>`_ framework, reading the fram | ||||
|  | ||||
|     Instructions to create a new bundle <create-a-new-bundle.rst> | ||||
|     CRUD (Create - Update - Delete) for one entity <crud.rst> | ||||
|     Helpers for building a REST API <api.rst> | ||||
|     Routing <routing.rst> | ||||
|     Menus <menus.rst> | ||||
|     Forms <forms.rst> | ||||
|   | ||||
| @@ -7,6 +7,8 @@ | ||||
|    Free Documentation License". | ||||
|  | ||||
|  | ||||
| .. _pagination-ref: | ||||
|  | ||||
| Pagination | ||||
| ########## | ||||
|  | ||||
| @@ -15,7 +17,7 @@ The Bundle :code:`Chill\MainBundle` provides a **Pagination** api which allow yo | ||||
| A simple example | ||||
| **************** | ||||
|  | ||||
| In the controller, get the :class:`Chill\Main\Pagination\PaginatorFactory` from the `Container` and use this :code:`PaginatorFactory` to create a :code:`Paginator` instance. | ||||
| In the controller, get the :code:`Chill\Main\Pagination\PaginatorFactory` from the `Container` and use this :code:`PaginatorFactory` to create a :code:`Paginator` instance. | ||||
|  | ||||
|  | ||||
| .. literalinclude:: pagination/example.php | ||||
| @@ -26,7 +28,7 @@ Then, render the pagination using the dedicated twig function. | ||||
|  | ||||
| .. code-block:: html+twig | ||||
|  | ||||
|    {% extends "ChillPersonBundle::layout.html.twig"  %} | ||||
|    {% extends "@ChillPerson/Person/layout.html.twig"  %} | ||||
|  | ||||
|    {% block title 'Item list'|trans %} | ||||
|  | ||||
|   | ||||
| @@ -1,51 +1,42 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\MyBundle\Controller; | ||||
|  | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| class example extends Controller | ||||
| { | ||||
|     public function yourAction() | ||||
|  | ||||
| class ItemController extends Controller { | ||||
|  | ||||
|     public function yourAction()  | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         // first, get the number of total item are available | ||||
|         $total = $em | ||||
|             ->createQuery('SELECT COUNT (item.id) FROM ChillMyBundle:Item item') | ||||
|             ->getSingleScalarResult(); | ||||
|  | ||||
|              ->createQuery("SELECT COUNT (item.id) FROM ChillMyBundle:Item item") | ||||
|              ->getSingleScalarResult(); | ||||
|         | ||||
|         // get the PaginatorFactory | ||||
|         $paginatorFactory = $this->get('chill_main.paginator_factory'); | ||||
|  | ||||
|         // create a pagination instance. This instance is only valid for | ||||
|          | ||||
|         // create a pagination instance. This instance is only valid for  | ||||
|         // the current route and parameters | ||||
|         $paginator = $paginatorFactory->create($total); | ||||
|  | ||||
|          | ||||
|         // launch your query on item. Limit the query to the results | ||||
|         // for the current page using the paginator | ||||
|         $items = $em->createQuery('SELECT item FROM ChillMyBundle:Item item WHERE <your clause>') | ||||
|         $items = $em->createQuery("SELECT item FROM ChillMyBundle:Item item WHERE <your clause>") | ||||
|             // use the paginator to get the first item number | ||||
|             ->setFirstResult($paginator->getCurrentPage()->getFirstItemNumber()) | ||||
|             // use the paginator to get the number of items to display | ||||
|             ->setMaxResults($paginator->getItemsPerPage()); | ||||
|  | ||||
|         return $this->render( | ||||
|             'ChillMyBundle:Item:list.html.twig', | ||||
|             [ | ||||
|              | ||||
|         return $this->render('ChillMyBundle:Item:list.html.twig', array( | ||||
|                 'items' => $items, | ||||
|                 'paginator' => $paginator, | ||||
|             ] | ||||
|         ); | ||||
|                 'paginator' => $paginator | ||||
|                 ); | ||||
|              | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -97,7 +97,7 @@ The has the following signature : | ||||
|          *  | ||||
|          * @param string $context | ||||
|          * @param mixed[] $args the argument to the context. | ||||
|          * @return string[] | ||||
|          * @return TimelineSingleQuery | ||||
|          * @throw  \LogicException if the context is not supported | ||||
|          */ | ||||
|         public function fetchQuery($context, array $args); | ||||
| @@ -163,18 +163,16 @@ The has the following signature : | ||||
| The `fetchQuery` function | ||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||
|  | ||||
| The fetchQuery function help to build the UNION query to gather events. This function should return an associative array MUST have the following key : | ||||
| The fetchQuery function help to build the UNION query to gather events. This function should return an instance of :code:`TimelineSingleQuery`. For you convenience, this object may be build using an associative array with the following keys: | ||||
|  | ||||
| * `id` : the name of the id column | ||||
| * `type`: a string to indicate the type | ||||
| * `date`: the name of the datetime column, used to order entities by date | ||||
| * `FROM` (in capital) : the FROM clause. May contains JOIN instructions | ||||
| * `FROM`: the FROM clause. May contains JOIN instructions | ||||
| * `WHERE`: the WHERE clause; | ||||
| * `parameters`: the parameters to pass to the query | ||||
|  | ||||
| Those key are optional: | ||||
|  | ||||
| * `WHERE` (in capital) : the WHERE clause.  | ||||
|  | ||||
|  Where relevant, the data must be quoted to avoid SQL injection. | ||||
| The parameters should be replaced into the query by :code:`?`. They will be replaced into the query using prepared statements. | ||||
|  | ||||
| `$context` and `$args` are defined by the bundle which will call the timeline rendering. You may use them to build a different query depending on this context. | ||||
|  | ||||
| @@ -186,6 +184,15 @@ For instance, if the context is `'person'`, the args will be this array : | ||||
|         'person' => $person //a \Chill\PersonBundle\Entity\Person entity | ||||
|     ); | ||||
|  | ||||
| For the context :code:`center`, the args will be: | ||||
|  | ||||
| .. code-block:: php | ||||
|  | ||||
|     array( | ||||
|         'centers' => [ ]  // an array of \Chill\MainBundle\Entity\Center entities | ||||
|     ); | ||||
|  | ||||
|  | ||||
| You should find in the bundle documentation which contexts are arguments the bundle defines. | ||||
|  | ||||
| .. note:: | ||||
| @@ -199,13 +206,12 @@ Example of an implementation : | ||||
|     namespace Chill\ReportBundle\Timeline; | ||||
|  | ||||
|     use Chill\MainBundle\Timeline\TimelineProviderInterface; | ||||
|     use Chill\MainBundle\Timeline\TimelineSingleQuery; | ||||
|     use Doctrine\ORM\EntityManager; | ||||
|  | ||||
|     /** | ||||
|      * Provide report for inclusion in timeline | ||||
|      * | ||||
|      * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|      * @author Champs Libres <info@champs-libres.coop> | ||||
|      */ | ||||
|     class TimelineReportProvider implements TimelineProviderInterface | ||||
|     { | ||||
| @@ -227,16 +233,17 @@ Example of an implementation : | ||||
|                  | ||||
|                 $metadata = $this->em->getClassMetadata('ChillReportBundle:Report'); | ||||
|                  | ||||
|                 return array( | ||||
|                 return TimelineSingleQuery::fromArray([ | ||||
|                    'id' => $metadata->getColumnName('id'), | ||||
|                    'type' => 'report', | ||||
|                    'date' => $metadata->getColumnName('date'), | ||||
|                    'FROM' => $metadata->getTableName(), | ||||
|                    'WHERE' => sprintf('%s = %d', | ||||
|                    'WHERE' => sprintf('%s = ?', | ||||
|                          $metadata | ||||
|                             ->getAssociationMapping('person')['joinColumns'][0]['name'], | ||||
|                          $args['person']->getId()) | ||||
|                 ); | ||||
|                             ->getAssociationMapping('person')['joinColumns'][0]['name']) | ||||
|                          ) | ||||
|                    'parameters' => [ $args['person']->getId() ] | ||||
|                 ]); | ||||
|             } | ||||
|  | ||||
|         //.... | ||||
|   | ||||
| @@ -1,55 +1,43 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\HealthBundle\Controller; | ||||
|  | ||||
| use Chill\HealthBundle\Security\Authorization\ConsultationVoter; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
|  | ||||
| class ConsultationController extends Controller | ||||
| { | ||||
|     /** | ||||
|      *  | ||||
|      * @param int $id personId | ||||
|      * | ||||
|      * @throws type | ||||
|      * | ||||
|      * @return \Symfony\Component\HttpFoundation\Response | ||||
|      * @throws type | ||||
|      */ | ||||
|     public function listAction($id) | ||||
|     { | ||||
|         /** @var \Chill\PersonBundle\Entity\Person $person */ | ||||
|         /* @var $person \Chill\PersonBundle\Entity\Person */ | ||||
|         $person = $this->get('chill.person.repository.person') | ||||
|             ->find($id); | ||||
|  | ||||
|         if (null === $person) { | ||||
|             throw $this->createNotFoundException('The person is not found'); | ||||
|          | ||||
|         if ($person === null) { | ||||
|             throw $this->createNotFoundException("The person is not found"); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $this->denyAccessUnlessGranted(PersonVoter::SEE, $person); | ||||
|  | ||||
|         /** @var \Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper */ | ||||
|          | ||||
|         /* @var $authorizationHelper \Chill\MainBundle\Security\Authorization\AuthorizationHelper */ | ||||
|         $authorizationHelper = $this->get('chill.main.security.' | ||||
|             . 'authorization.helper'); | ||||
|  | ||||
|          | ||||
|         $circles = $authorizationHelper->getReachableCircles( | ||||
|             $this->getUser(), | ||||
|             new Role(ConsultationVoter::SEE), | ||||
|             $this->getUser(),  | ||||
|             new Role(ConsultationVoter::SEE),  | ||||
|             $person->getCenter() | ||||
|         ); | ||||
|  | ||||
|         // create a query which take circles into account | ||||
|             ); | ||||
|          | ||||
|         // create a query which take circles into account         | ||||
|         $consultations = $this->getDoctrine()->getManager() | ||||
|             ->createQuery('SELECT c FROM ChillHealthBundle:Consultation c ' | ||||
|                 . 'WHERE c.patient = :person AND c.circle IN(:circles) ' | ||||
| @@ -57,10 +45,11 @@ class ConsultationController extends Controller | ||||
|             ->setParameter('person', $person) | ||||
|             ->setParameter('circles', $circles) | ||||
|             ->getResult(); | ||||
|  | ||||
|         return $this->render('ChillHealthBundle:Consultation:list.html.twig', [ | ||||
|             'person' => $person, | ||||
|             'consultations' => $consultations, | ||||
|         ]); | ||||
|          | ||||
|         return $this->render('ChillHealthBundle:Consultation:list.html.twig', array( | ||||
|                 'person' => $person, | ||||
|                 'consultations' => $consultations | ||||
|             ));     | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -149,7 +149,7 @@ It proposes a new block : | ||||
|  | ||||
|   * where to display the admin content | ||||
|  | ||||
| ChillPersonBundle::layout.html.twig | ||||
| @ChillPersonBundle/Person/layout.html.twig | ||||
| ----------------------------------- | ||||
|  | ||||
| This layout extend `ChillMainBundle::layoutWithVerticalMenu.html.twig` add the person details in the block `top_banner`, set the menu `person` as the vertical menu. | ||||
|   | ||||
| @@ -1,70 +1,64 @@ | ||||
| <?php | ||||
|    # Chill\MainBundle\DependencyInjection\Configuration.php | ||||
|    | ||||
|    namespace Chill\MainBundle\DependencyInjection; | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| // Chill\MainBundle\DependencyInjection\Configuration.php | ||||
|  | ||||
| namespace Chill\MainBundle\DependencyInjection; | ||||
|  | ||||
|    use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait; | ||||
|    use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||||
|    use Symfony\Component\Config\Definition\ConfigurationInterface; | ||||
|    use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait; | ||||
|    use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
|  | ||||
| /** | ||||
|  * Configure the main bundle. | ||||
|  */ | ||||
| class ChillMainConfiguration implements ConfigurationInterface | ||||
| { | ||||
|     use AddWidgetConfigurationTrait; | ||||
|    /** | ||||
|     * Configure the main bundle | ||||
|     */ | ||||
|    class Configuration implements ConfigurationInterface | ||||
|    { | ||||
|         | ||||
|        use AddWidgetConfigurationTrait; | ||||
|         | ||||
|        /** | ||||
| 	* | ||||
| 	* @var ContainerBuilder | ||||
| 	*/ | ||||
|        private $containerBuilder; | ||||
|  | ||||
|     /** | ||||
|      * @var ContainerBuilder | ||||
|      */ | ||||
|     private $containerBuilder; | ||||
|         | ||||
|        public function __construct(array $widgetFactories = array(),  | ||||
| 	       ContainerBuilder $containerBuilder) | ||||
|        { | ||||
|            // we register here widget factories (see below) | ||||
| 	   $this->setWidgetFactories($widgetFactories); | ||||
|            // we will need the container builder later... | ||||
| 	   $this->containerBuilder = $containerBuilder; | ||||
|        } | ||||
|         | ||||
|        /** | ||||
| 	* {@inheritDoc} | ||||
| 	*/ | ||||
|        public function getConfigTreeBuilder() | ||||
|        { | ||||
| 	   $treeBuilder = new TreeBuilder(); | ||||
| 	   $rootNode = $treeBuilder->root('chill_main'); | ||||
|  | ||||
|     public function __construct( | ||||
|         array $widgetFactories, | ||||
|         ContainerBuilder $containerBuilder | ||||
|     ) { | ||||
|         // we register here widget factories (see below) | ||||
|         $this->setWidgetFactories($widgetFactories); | ||||
|         // we will need the container builder later... | ||||
|         $this->containerBuilder = $containerBuilder; | ||||
|     } | ||||
| 	   $rootNode | ||||
| 	       ->children() | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getConfigTreeBuilder() | ||||
|     { | ||||
|         $treeBuilder = new TreeBuilder(); | ||||
|         $rootNode = $treeBuilder->root('chill_main'); | ||||
|                    // ... | ||||
|  | ||||
|         $rootNode | ||||
|             ->children() | ||||
| 		   ->arrayNode('widgets') | ||||
| 		       ->canBeDisabled() | ||||
| 		       ->children() | ||||
|                             // we declare here all configuration for homepage place | ||||
| 			    ->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder)) | ||||
| 		       ->end() // end of widgets/children | ||||
| 		   ->end() // end of widgets | ||||
| 		  ->end() // end of root/children | ||||
| 	       ->end() // end of root | ||||
| 	   ; | ||||
|  | ||||
| 	    | ||||
| 	   return $treeBuilder; | ||||
|        } | ||||
|    } | ||||
|  | ||||
|                 // ... | ||||
|             ->arrayNode('widgets') | ||||
|             ->canBeDisabled() | ||||
|             ->children() | ||||
|                          // we declare here all configuration for homepage place | ||||
|             ->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder)) | ||||
|             ->end() // end of widgets/children | ||||
|             ->end() // end of widgets | ||||
|             ->end() // end of root/children | ||||
|             ->end() // end of root | ||||
| ; | ||||
|  | ||||
|         return $treeBuilder; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,23 +1,16 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| //Chill\MainBundle\DependencyInjection\ChillMainExtension.php | ||||
| #Chill\MainBundle\DependencyInjection\ChillMainExtension.php | ||||
|  | ||||
| namespace Chill\MainBundle\DependencyInjection; | ||||
|  | ||||
| use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface; | ||||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
| use Symfony\Component\Config\FileLocator; | ||||
| use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||||
| use Symfony\Component\DependencyInjection\Loader; | ||||
| use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
| use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface; | ||||
| use Chill\MainBundle\DependencyInjection\Configuration; | ||||
|  | ||||
| /** | ||||
|  * This class load config for chillMainExtension. | ||||
| @@ -25,42 +18,42 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||||
| class ChillMainExtension extends Extension implements Widget\HasWidgetFactoriesExtensionInterface | ||||
| { | ||||
|     /** | ||||
|      * widget factory. | ||||
|      * | ||||
|      * widget factory | ||||
|      *  | ||||
|      * @var WidgetFactoryInterface[] | ||||
|      */ | ||||
|     protected $widgetFactories = []; | ||||
|  | ||||
|     protected $widgetFactories = array(); | ||||
|      | ||||
|     public function addWidgetFactory(WidgetFactoryInterface $factory) | ||||
|     { | ||||
|         $this->widgetFactories[] = $factory; | ||||
|     } | ||||
|  | ||||
|     public function getConfiguration(array $config, ContainerBuilder $container) | ||||
|     { | ||||
|         return new Configuration($this->widgetFactories, $container); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * @return WidgetFactoryInterface[] | ||||
|      */ | ||||
|     public function getWidgetFactories() | ||||
|     { | ||||
|         return $this->widgetFactories; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function load(array $configs, ContainerBuilder $container) | ||||
|     { | ||||
|         // configuration for main bundle | ||||
|         $configuration = $this->getConfiguration($configs, $container); | ||||
|         $config = $this->processConfiguration($configuration, $configs); | ||||
|  | ||||
|          | ||||
|         // add the key 'widget' without the key 'enable' | ||||
|         $container->setParameter( | ||||
|             'chill_main.widgets', | ||||
|             ['homepage' => $config['widgets']['homepage']] | ||||
|         ); | ||||
|         $container->setParameter('chill_main.widgets',  | ||||
|             array('homepage' => $config['widgets']['homepage'])); | ||||
|  | ||||
|         // ... | ||||
|         // ...  | ||||
|     } | ||||
|      | ||||
|     public function getConfiguration(array $config, ContainerBuilder $container) | ||||
|     { | ||||
|         return new Configuration($this->widgetFactories, $container); | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -1,77 +1,69 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| // Chill/PersonBundle/Widget/PersonListWidgetFactory | ||||
| # Chill/PersonBundle/Widget/PersonListWidgetFactory | ||||
|  | ||||
| namespace Chill\PersonBundle\Widget; | ||||
|  | ||||
| use Chill\MainBundle\DependencyInjection\Widget\Factory\AbstractWidgetFactory; | ||||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
| use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||||
|  | ||||
| /** | ||||
|  * add configuration for the person_list widget. | ||||
|  */ | ||||
| class ChillPersonAddAPersonListWidgetFactory extends AbstractWidgetFactory | ||||
| class PersonListWidgetFactory extends AbstractWidgetFactory | ||||
| { | ||||
|     /* | ||||
|      * append the option to the configuration | ||||
|      * see http://symfony.com/doc/current/components/config/definition.html | ||||
|      * | ||||
|      */ | ||||
|    /* | ||||
|     * append the option to the configuration | ||||
|     * see http://symfony.com/doc/current/components/config/definition.html | ||||
|     * | ||||
|     */ | ||||
|     public function configureOptions($place, NodeBuilder $node) | ||||
|     { | ||||
|         $node->booleanNode('only_active') | ||||
|             ->defaultTrue() | ||||
|             ->end(); | ||||
|                 ->defaultTrue() | ||||
|                 ->end(); | ||||
|         $node->integerNode('number_of_items') | ||||
|             ->defaultValue(50) | ||||
|             ->end(); | ||||
|         $node->scalarNode('filtering_class') | ||||
|             ->defaultNull() | ||||
|             ->end(); | ||||
|                 ->defaultNull() | ||||
|                 ->end(); | ||||
|              | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * return an array with the allowed places where the widget can be rendered. | ||||
|      * | ||||
|      * @return string[] | ||||
|      */ | ||||
|       | ||||
|    /* | ||||
|     * return an array with the allowed places where the widget can be rendered | ||||
|     * | ||||
|     * @return string[] | ||||
|     */    | ||||
|     public function getAllowedPlaces() | ||||
|     { | ||||
|         return ['homepage']; | ||||
|         return array('homepage'); | ||||
|     } | ||||
|  | ||||
|      | ||||
|    /*  | ||||
|     * return the widget alias | ||||
|     * | ||||
|     * @return string | ||||
|     */ | ||||
|     public function getWidgetAlias() | ||||
|     { | ||||
|         return 'person_list'; | ||||
|     } | ||||
|      | ||||
|     /* | ||||
|      * return the service id for the service which will render the widget. | ||||
|      * | ||||
|      * this service must implements `Chill\MainBundle\Templating\Widget\WidgetInterface` | ||||
|      * | ||||
|      * the service must exists in the container, and it is not required that the service | ||||
|      *  | ||||
|      * the service must exists in the container, and it is not required that the service  | ||||
|      * has the `chill_main` tag. | ||||
|      */ | ||||
|     public function getServiceId(ContainerBuilder $containerBuilder, $place, $order, array $config) | ||||
|     { | ||||
|         return 'chill_person.widget.person_list'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * return the widget alias. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getWidgetAlias() | ||||
|     { | ||||
|         return 'person_list'; | ||||
|     } | ||||
|      | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,77 +1,66 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| // Chill/PersonBundle/Widget/PersonListWidget.php | ||||
| # Chill/PersonBundle/Widget/PersonListWidget.php | ||||
|  | ||||
| namespace Chill\PersonBundle\Widget; | ||||
|  | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\MainBundle\Templating\Widget\WidgetInterface; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use DateTime; | ||||
| use Doctrine\DBAL\Types\Type; | ||||
| use Doctrine\ORM\EntityManager; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\DBAL\Types\Type; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Symfony\Component\Security\Core\User\UserInterface; | ||||
| use Twig_Environment; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\ORM\EntityManager; | ||||
|  | ||||
| /** | ||||
|  * add a widget with person list. | ||||
|  * | ||||
|  * add a widget with person list.  | ||||
|  *  | ||||
|  * The configuration is defined by `PersonListWidgetFactory` | ||||
|  */ | ||||
| class ChillPersonAddAPersonWidget implements WidgetInterface | ||||
| class PersonListWidget implements WidgetInterface | ||||
| { | ||||
|      | ||||
|     /** | ||||
|      * the authorization helper. | ||||
|      * | ||||
|      * @var AuthorizationHelper; | ||||
|      * Repository for persons | ||||
|      *  | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $authorizationHelper; | ||||
|  | ||||
|     protected $personRepository; | ||||
|      | ||||
|     /** | ||||
|      * The entity manager. | ||||
|      * The entity manager | ||||
|      * | ||||
|      * @var EntityManager | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * Repository for persons. | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      * the authorization helper | ||||
|      *  | ||||
|      * @var AuthorizationHelper; | ||||
|      */ | ||||
|     protected $personRepository; | ||||
|  | ||||
|     protected $authorizationHelper; | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var TokenStorage | ||||
|      */ | ||||
|     protected $tokenStorage; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var UserInterface | ||||
|      */ | ||||
|     protected $user; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         EntityRepository $personRepostory, | ||||
|         EntityManager $em, | ||||
|         AuthorizationHelper $authorizationHelper, | ||||
|         TokenStorage $tokenStorage | ||||
|     ) { | ||||
|             EntityRepository $personRepostory, | ||||
|             EntityManager $em, | ||||
|             AuthorizationHelper $authorizationHelper, | ||||
|             TokenStorage $tokenStorage | ||||
|             ) { | ||||
|         $this->personRepository = $personRepostory; | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|         $this->tokenStorage = $tokenStorage; | ||||
| @@ -79,24 +68,27 @@ class ChillPersonAddAPersonWidget implements WidgetInterface | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      *  | ||||
|      * @param type $place | ||||
|      * | ||||
|      * @param array $context | ||||
|      * @param array $config | ||||
|      * @return string | ||||
|      */ | ||||
|     public function render(Twig_Environment $env, $place, array $context, array $config) | ||||
|     { | ||||
|     public function render(\Twig_Environment $env, $place, array $context, array $config) | ||||
|     {  | ||||
|         $qb = $this->personRepository | ||||
|             ->createQueryBuilder('person'); | ||||
|  | ||||
|                 ->createQueryBuilder('person'); | ||||
|          | ||||
|         // show only the person from the authorized centers | ||||
|         $and = $qb->expr()->andX(); | ||||
|         $centers = $this->authorizationHelper | ||||
|             ->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); | ||||
|                 ->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE)); | ||||
|         $and->add($qb->expr()->in('person.center', ':centers')); | ||||
|         $qb->setParameter('centers', $centers); | ||||
|          | ||||
|  | ||||
|         // add the "only active" where clause | ||||
|         if (true === $config['only_active']) { | ||||
|         if ($config['only_active'] === true) { | ||||
|             $qb->join('person.accompanyingPeriods', 'ap'); | ||||
|             $or = new Expr\Orx(); | ||||
|             // add the case where closingDate IS NULL | ||||
| @@ -106,30 +98,32 @@ class ChillPersonAddAPersonWidget implements WidgetInterface | ||||
|             $or->add($andWhenClosingDateIsNull); | ||||
|             // add the case when now is between opening date and closing date | ||||
|             $or->add( | ||||
|                 (new Expr())->between(':now', 'ap.openingDate', 'ap.closingDate') | ||||
|             ); | ||||
|                     (new Expr())->between(':now', 'ap.openingDate', 'ap.closingDate') | ||||
|                 ); | ||||
|             $and->add($or); | ||||
|             $qb->setParameter('now', new DateTime(), Type::DATE); | ||||
|             $qb->setParameter('now', new \DateTime(), Type::DATE); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         // adding the where clause to the query | ||||
|         $qb->where($and); | ||||
|  | ||||
|          | ||||
|         $qb->setFirstResult(0)->setMaxResults($config['number_of_items']); | ||||
|  | ||||
|          | ||||
|         $persons = $qb->getQuery()->getResult(); | ||||
|  | ||||
|          | ||||
|         return $env->render( | ||||
|             'ChillPersonBundle:Widget:homepage_person_list.html.twig', | ||||
|             ['persons' => $persons] | ||||
|         ); | ||||
|             array('persons' => $persons) | ||||
|             ); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * @return UserInterface | ||||
|      */ | ||||
|     private function getUser() | ||||
|     { | ||||
|         // return a user | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,55 +1,51 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| // Chill/PersonBundle/DependencyInjection/ChillPersonExtension.php | ||||
| # Chill/PersonBundle/DependencyInjection/ChillPersonExtension.php | ||||
|  | ||||
| namespace Chill\PersonBundle\DependencyInjection; | ||||
|  | ||||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
| use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
| use Symfony\Component\Config\FileLocator; | ||||
| use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||||
| use Symfony\Component\DependencyInjection\Loader; | ||||
| use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
| use Chill\MainBundle\DependencyInjection\MissingBundleException; | ||||
| use Chill\PersonBundle\Security\Authorization\PersonVoter; | ||||
|  | ||||
| /** | ||||
|  * This is the class that loads and manages your bundle configuration. | ||||
|  * This is the class that loads and manages your bundle configuration | ||||
|  * | ||||
|  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||||
|  */ | ||||
| class ChillPersonExtension extends Extension implements PrependExtensionInterface | ||||
| { | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * {@inheritDoc} | ||||
|      */ | ||||
|     public function load(array $configs, ContainerBuilder $container) | ||||
|     { | ||||
|         // ... | ||||
|       // ... | ||||
|     } | ||||
|  | ||||
|      | ||||
|      | ||||
|     /** | ||||
|      * Add a widget "add a person" on the homepage, automatically. | ||||
|      * | ||||
|      *  | ||||
|      * Add a widget "add a person" on the homepage, automatically | ||||
|      *  | ||||
|      * @param \Chill\PersonBundle\DependencyInjection\containerBuilder $container | ||||
|      */ | ||||
|     public function prepend(ContainerBuilder $container) | ||||
|     public function prepend(ContainerBuilder $container)  | ||||
|     { | ||||
|         $container->prependExtensionConfig('chill_main', [ | ||||
|             'widgets' => [ | ||||
|                 'homepage' => [ | ||||
|                     [ | ||||
|         $container->prependExtensionConfig('chill_main', array( | ||||
|             'widgets' => array( | ||||
|                 'homepage' => array( | ||||
|                     array( | ||||
|                         'widget_alias' => 'add_person', | ||||
|                         'order' => 2, | ||||
|                     ], | ||||
|                 ], | ||||
|             ], | ||||
|         ]); | ||||
|                         'order' => 2 | ||||
|                     ) | ||||
|                 ) | ||||
|             ) | ||||
|         )); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -82,7 +82,7 @@ Chill will be available at ``http://localhost:8001.`` Currently, there isn't any | ||||
|  | ||||
| .. code-block:: bash | ||||
|  | ||||
|    docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load | ||||
|    docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load --purge-with-truncate | ||||
|  | ||||
| There are several users available: | ||||
|  | ||||
|   | ||||
| @@ -1,8 +0,0 @@ | ||||
| imports: | ||||
|   - { resource: vendor/drupol/php-conventions/config/php73/grumphp.yml } | ||||
|  | ||||
| parameters: | ||||
|   tasks.phpcsfixer.config: .php_cs.dist | ||||
|   tasks.license.name: AGPL-3.0 | ||||
|   tasks.license.holder: Champs-Libres | ||||
|   tasks.license.date_from: 2001 | ||||
							
								
								
									
										3
									
								
								package.json.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								package.json.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| add npm/yarn dependency in package.json : | ||||
|  | ||||
| "select2-bootstrap-theme": "0.1.0-beta.10", | ||||
| @@ -18,12 +18,20 @@ | ||||
|        <testsuite name="MainBundle"> | ||||
|          <directory suffix="Test.php">src/Bundle/ChillMainBundle/Tests/</directory> | ||||
|        </testsuite> | ||||
|  | ||||
|        <testsuite name="PersonBundle"> | ||||
|          <directory suffix="Test.php">src/Bundle/ChillPersonBundle/Tests/</directory> | ||||
|          <!-- test for export will be runned later --> | ||||
|          <exclude>src/Bundle/ChillPersonBundle/Tests/Export/*</exclude> | ||||
|          <!-- we are rewriting accompanying periods... Work in progress --> | ||||
|          <exclude>src/Bundle/ChillPersonBundle/Tests/Controller/AccompanyingPeriodControllerTest.php</exclude> | ||||
|          <!-- we are rewriting address, Work in progress --> | ||||
|          <exclude>src/Bundle/ChillPersonBundle/Tests/Controller/PersonAddressControllerTest.php</exclude> | ||||
|          <!-- find a solution to create multiple configs --> | ||||
|          <exclude>src/Bundle/ChillPersonBundle/Tests/Controller/PersonControllerUpdateWithHiddenFieldsTest.php</exclude> | ||||
|          <!-- temporarily removed, the time to find a fix --> | ||||
|          <exclude>src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php</exclude> | ||||
|         </testsuite> | ||||
|  | ||||
|       </testsuites> | ||||
|     </testsuites> | ||||
|  | ||||
|     <listeners> | ||||
|         <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" /> | ||||
|   | ||||
| @@ -1,6 +0,0 @@ | ||||
| Chill is a software for social workers. | ||||
|  | ||||
| For the full copyright and license information, please view | ||||
| the LICENSE file that was distributed with this source code. | ||||
|  | ||||
| @see https://www.champs-libres.coop/ | ||||
| @@ -1,16 +1,5 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle; | ||||
|  | ||||
| use Symfony\Component\HttpKernel\Bundle\Bundle; | ||||
|   | ||||
| @@ -1,468 +1,481 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use Chill\PersonBundle\Privacy\PrivacyEvent; | ||||
| use Psr\Log\LoggerInterface; | ||||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
| use Symfony\Component\Form\Form; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\ActivityBundle\Form\ActivityType; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\PersonBundle\Privacy\PrivacyEvent; | ||||
| use DateTime; | ||||
| use Psr\Log\LoggerInterface; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Symfony\Component\Serializer\SerializerInterface; | ||||
|  | ||||
| /** | ||||
|  * Class ActivityController | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Controller | ||||
|  */ | ||||
| class ActivityController extends AbstractController | ||||
| { | ||||
|     /** | ||||
|      * @var AuthorizationHelper | ||||
|      */ | ||||
|     protected $authorizationHelper; | ||||
|     protected EventDispatcherInterface $eventDispatcher; | ||||
|  | ||||
|     /** | ||||
|      * @var EventDispatcherInterface | ||||
|      */ | ||||
|     protected $eventDispatcher; | ||||
|     protected AuthorizationHelper $authorizationHelper; | ||||
|  | ||||
|     /** | ||||
|      * @var LoggerInterface | ||||
|      */ | ||||
|     protected $logger; | ||||
|     protected LoggerInterface $logger; | ||||
|  | ||||
|     protected SerializerInterface $serializer; | ||||
|  | ||||
|     /** | ||||
|      * ActivityController constructor. | ||||
|      */ | ||||
|     public function __construct( | ||||
|         EventDispatcherInterface $eventDispatcher, | ||||
|         AuthorizationHelper $authorizationHelper, | ||||
|         LoggerInterface $logger | ||||
|         LoggerInterface $logger, | ||||
|         SerializerInterface $serializer | ||||
|     ) { | ||||
|         $this->eventDispatcher = $eventDispatcher; | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|         $this->logger = $logger; | ||||
|         $this->serializer = $serializer; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Activity entity. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      * Lists all Activity entities. | ||||
|      */ | ||||
|     public function createAction($person_id, Request $request) | ||||
|     public function listAction(Request $request): Response | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|         $view = null; | ||||
|         // TODO: add pagination | ||||
|  | ||||
|         if (null === $person) { | ||||
|             throw $this->createNotFoundException('person not found'); | ||||
|         } | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|         if ($person instanceof Person) { | ||||
|             $reachableScopes = $this->authorizationHelper | ||||
|                 ->getReachableCircles($this->getUser(), new Role('CHILL_ACTIVITY_SEE'), | ||||
|                     $person->getCenter()); | ||||
|  | ||||
|         $entity = new Activity(); | ||||
|         $entity->setPerson($person); | ||||
|         $form = $this->createCreateForm($entity, $person); | ||||
|         $form->handleRequest($request); | ||||
|             $activities = $em->getRepository(Activity::class) | ||||
|                 ->findByPersonImplied($person, $reachableScopes) | ||||
|                 ; | ||||
|  | ||||
|         if ($form->isValid()) { | ||||
|             $em = $this->getDoctrine()->getManager(); | ||||
|             $event = new PrivacyEvent($person, array( | ||||
|                 'element_class' => Activity::class, | ||||
|                 'action' => 'list' | ||||
|             )); | ||||
|             $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|  | ||||
|             $this->denyAccessUnlessGranted( | ||||
|                 'CHILL_ACTIVITY_CREATE', | ||||
|                 $entity, | ||||
|                 'creation of this activity not allowed' | ||||
|             $view = 'ChillActivityBundle:Activity:listPerson.html.twig'; | ||||
|         } elseif ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $activities = $em->getRepository('ChillActivityBundle:Activity')->findBy( | ||||
|                 ['accompanyingPeriod' => $accompanyingPeriod], | ||||
|                 ['date' => 'DESC'], | ||||
|             ); | ||||
|  | ||||
|             $view = 'ChillActivityBundle:Activity:listAccompanyingCourse.html.twig'; | ||||
|         } | ||||
|  | ||||
|         return $this->render($view, array( | ||||
|             'activities' => $activities, | ||||
|             'person'   => $person, | ||||
|             'accompanyingCourse' => $accompanyingPeriod, | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function selectTypeAction(Request $request): Response | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $view = null; | ||||
|  | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $view = 'ChillActivityBundle:Activity:selectTypeAccompanyingCourse.html.twig'; | ||||
|         } elseif ($person instanceof Person) { | ||||
|             $view = 'ChillActivityBundle:Activity:selectTypePerson.html.twig'; | ||||
|         } | ||||
|  | ||||
|         $data = []; | ||||
|  | ||||
|         $activityTypeCategories = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityTypeCategory::class) | ||||
|             ->findBy(['active' => true], ['ordering' => 'ASC']); | ||||
|  | ||||
|         foreach ($activityTypeCategories as $activityTypeCategory) { | ||||
|             $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) | ||||
|                 ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); | ||||
|  | ||||
|             $data[] = [ | ||||
|                 'activityTypeCategory' => $activityTypeCategory, | ||||
|                 'activityTypes' => $activityTypes, | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
|         if ($view === null) { | ||||
|             throw $this->createNotFoundException('Template not found'); | ||||
|         } | ||||
|  | ||||
|         return $this->render($view, [ | ||||
|             'person' => $person, | ||||
|             'accompanyingCourse' => $accompanyingPeriod, | ||||
|             'data' => $data, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function newAction(Request $request): Response | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $view = 'ChillActivityBundle:Activity:newAccompanyingCourse.html.twig'; | ||||
|         } elseif ($person instanceof Person) { | ||||
|             $view = 'ChillActivityBundle:Activity:newPerson.html.twig'; | ||||
|         } | ||||
|  | ||||
|         $activityType_id = $request->get('activityType_id', 0); | ||||
|         $activityType = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) | ||||
|             ->find($activityType_id); | ||||
|  | ||||
|         if (!$activityType instanceof \Chill\ActivityBundle\Entity\ActivityType || | ||||
|             !$activityType->isActive()) { | ||||
|  | ||||
|             $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|             return $this->redirectToRoute('chill_activity_activity_select_type', $params); | ||||
|         } | ||||
|  | ||||
|         $entity = new Activity(); | ||||
|         $entity->setUser($this->getUser()); | ||||
|  | ||||
|         if ($person instanceof Person) { | ||||
|             $entity->setPerson($person); | ||||
|         } | ||||
|  | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $entity->setAccompanyingPeriod($accompanyingPeriod); | ||||
|         } | ||||
|  | ||||
|         $entity->setType($activityType); | ||||
|         $entity->setDate(new \DateTime('now')); | ||||
|  | ||||
|         // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période | ||||
|         // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); | ||||
|  | ||||
|         $form = $this->createForm(ActivityType::class, $entity, [ | ||||
|             'center' => $entity->getCenter(), | ||||
|             'role'   => new Role('CHILL_ACTIVITY_CREATE'), | ||||
|             'activityType' => $entity->getType(), | ||||
|             'accompanyingPeriod' => $accompanyingPeriod, | ||||
|         ])->handleRequest($request); | ||||
|  | ||||
|         if ($form->isSubmitted() && $form->isValid()) { | ||||
|             $em->persist($entity); | ||||
|             $em->flush(); | ||||
|  | ||||
|             $this->get('session') | ||||
|                 ->getFlashBag() | ||||
|                 ->add( | ||||
|                     'success', | ||||
|                     $this->get('translator') | ||||
|                         ->trans('Success : activity created!') | ||||
|                 ); | ||||
|             $this->addFlash('success', $this->get('translator')->trans('Success : activity created!')); | ||||
|  | ||||
|             return $this->redirect( | ||||
|                 $this->generateUrl( | ||||
|                     'chill_activity_activity_show', | ||||
|                     ['id' => $entity->getId(), 'person_id' => $person_id] | ||||
|                 ) | ||||
|             ); | ||||
|             $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|             $params['id'] = $entity->getId(); | ||||
|  | ||||
|             return $this->redirectToRoute('chill_activity_activity_show', $params); | ||||
|         } | ||||
|  | ||||
|         $this->get('session') | ||||
|             ->getFlashBag()->add( | ||||
|                 'danger', | ||||
|                 $this->get('translator') | ||||
|                     ->trans('The form is not valid. The activity has not been created !') | ||||
|             ); | ||||
|         if ($view === null) { | ||||
|             throw $this->createNotFoundException('Template not found'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:new.html.twig', [ | ||||
|         $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); | ||||
|  | ||||
|         return $this->render($view, [ | ||||
|             'person'   => $person, | ||||
|             'accompanyingCourse' => $accompanyingPeriod, | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|             'person' => $person, | ||||
|             'activity_json' => $activity_array | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Deletes a Activity entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      * @param mixed $person_id | ||||
|      */ | ||||
|     public function deleteAction(Request $request, $id, $person_id) | ||||
|     public function showAction(Request $request, $id): Response | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         /** @var Activity $activity */ | ||||
|         $activity = $em->getRepository('ChillActivityBundle:Activity') | ||||
|             ->find($id); | ||||
|         $person = $activity->getPerson(); | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         if (!$activity) { | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $view = 'ChillActivityBundle:Activity:showAccompanyingCourse.html.twig'; | ||||
|         } elseif ($person instanceof Person) { | ||||
|             $view = 'ChillActivityBundle:Activity:showPerson.html.twig'; | ||||
|         } | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:Activity')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find Activity entity.'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); | ||||
|  | ||||
|         $form = $this->createDeleteForm($id, $person); | ||||
|  | ||||
|         if ($request->getMethod() === Request::METHOD_DELETE) { | ||||
|             $form->handleRequest($request); | ||||
|  | ||||
|             if ($form->isValid()) { | ||||
|                 $this->logger->notice('An activity has been removed', [ | ||||
|                     'by_user' => $this->getUser()->getUsername(), | ||||
|                     'activity_id' => $activity->getId(), | ||||
|                     'person_id' => $activity->getPerson()->getId(), | ||||
|                     'comment' => $activity->getComment()->getComment(), | ||||
|                     'scope_id' => $activity->getScope()->getId(), | ||||
|                     'reasons_ids' => $activity->getReasons() | ||||
|                         ->map(static function ($ar) { | ||||
|                             return $ar->getId(); | ||||
|                         }) | ||||
|                         ->toArray(), | ||||
|                     'type_id' => $activity->getType()->getId(), | ||||
|                     'duration' => $activity->getDurationTime()->format('U'), | ||||
|                     'date' => $activity->getDate()->format('Y-m-d'), | ||||
|                     'attendee' => $activity->getAttendee(), | ||||
|                 ]); | ||||
|  | ||||
|                 $em->remove($activity); | ||||
|                 $em->flush(); | ||||
|  | ||||
|                 $this->addFlash('success', $this->get('translator') | ||||
|                     ->trans('The activity has been successfully removed.')); | ||||
|  | ||||
|                 return $this->redirect($this->generateUrl( | ||||
|                     'chill_activity_activity_list', | ||||
|                     [ | ||||
|                         'person_id' => $person_id, | ||||
|                     ] | ||||
|                 )); | ||||
|             } | ||||
|          | ||||
|         if (null !== $accompanyingPeriod) { | ||||
|            $entity->personsAssociated = $entity->getPersonsAssociated(); | ||||
|            $entity->personsNotAssociated = $entity->getPersonsNotAssociated(); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:confirm_delete.html.twig', [ | ||||
|             'activity' => $activity, | ||||
|             'delete_form' => $form->createView(), | ||||
|         ]); | ||||
|         // TODO revoir le Voter de Activity pour tenir compte qu'une activité peut appartenir a une période | ||||
|         // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); | ||||
|  | ||||
|         $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); | ||||
|  | ||||
|         // TODO | ||||
|         /* | ||||
|         $event = new PrivacyEvent($person, array( | ||||
|             'element_class' => Activity::class, | ||||
|             'element_id' => $entity->getId(), | ||||
|             'action' => 'show' | ||||
|         )); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|         */ | ||||
|  | ||||
|         if ($view === null) { | ||||
|             throw $this->createNotFoundException('Template not found'); | ||||
|         } | ||||
|  | ||||
|         return $this->render($view, array( | ||||
|             'person'      => $person, | ||||
|             'accompanyingCourse' => $accompanyingPeriod, | ||||
|             'entity'      => $entity, | ||||
|             'delete_form' => $deleteForm->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to edit an existing Activity entity. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function editAction($person_id, $id) | ||||
|     public function editAction($id, Request $request): Response | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|  | ||||
|         if (!$person) { | ||||
|             throw $this->createNotFoundException('person not found'); | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $view = 'ChillActivityBundle:Activity:editAccompanyingCourse.html.twig'; | ||||
|         } elseif ($person instanceof Person) { | ||||
|             $view = 'ChillActivityBundle:Activity:editPerson.html.twig'; | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:Activity')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find Activity entity.'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); | ||||
|         // TODO | ||||
|         // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); | ||||
|  | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|         $deleteForm = $this->createDeleteForm($id, $person); | ||||
|         $form = $this->createForm(ActivityType::class, $entity, [ | ||||
|             'center' => $entity->getCenter(), | ||||
|             'role'   => new Role('CHILL_ACTIVITY_UPDATE'), | ||||
|             'activityType' => $entity->getType(), | ||||
|             'accompanyingPeriod' => $accompanyingPeriod, | ||||
|         ])->handleRequest($request); | ||||
|  | ||||
|         $event = new PrivacyEvent($person, [ | ||||
|             'element_class' => Activity::class, | ||||
|             'element_id' => $entity->getId(), | ||||
|             'action' => 'edit', | ||||
|         ]); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|             'delete_form' => $deleteForm->createView(), | ||||
|             'person' => $person, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Lists all Activity entities. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      */ | ||||
|     public function listAction($person_id, Request $request) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|  | ||||
|         if (null === $person) { | ||||
|             throw $this->createNotFoundException('Person not found'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|  | ||||
|         $reachableScopes = $this->authorizationHelper | ||||
|             ->getReachableScopes( | ||||
|                 $this->getUser(), | ||||
|                 new Role('CHILL_ACTIVITY_SEE'), | ||||
|                 $person->getCenter() | ||||
|             ); | ||||
|  | ||||
|         $activities = $em->getRepository('ChillActivityBundle:Activity') | ||||
|             ->findBy( | ||||
|                 ['person' => $person, 'scope' => $reachableScopes], | ||||
|                 ['date' => 'DESC'] | ||||
|             ); | ||||
|  | ||||
|         $event = new PrivacyEvent($person, [ | ||||
|             'element_class' => Activity::class, | ||||
|             'action' => 'list', | ||||
|         ]); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:list.html.twig', [ | ||||
|             'activities' => $activities, | ||||
|             'person' => $person, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new Activity entity. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      */ | ||||
|     public function newAction($person_id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|  | ||||
|         if (null === $person) { | ||||
|             throw $this->createNotFoundException('Person not found'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|  | ||||
|         $entity = new Activity(); | ||||
|         $entity->setUser($this->get('security.token_storage')->getToken()->getUser()); | ||||
|         $entity->setPerson($person); | ||||
|         $entity->setDate(new DateTime('now')); | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_ACTIVITY_CREATE', $entity); | ||||
|  | ||||
|         $form = $this->createCreateForm($entity, $person); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:new.html.twig', [ | ||||
|             'person' => $person, | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a Activity entity. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function showAction($person_id, $id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|  | ||||
|         if (!$person) { | ||||
|             throw $this->createNotFoundException('person not found'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:Activity')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find Activity entity.'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_ACTIVITY_SEE', $entity); | ||||
|  | ||||
|         $deleteForm = $this->createDeleteForm($id, $person); | ||||
|  | ||||
|         $event = new PrivacyEvent($person, [ | ||||
|             'element_class' => Activity::class, | ||||
|             'element_id' => $entity->getId(), | ||||
|             'action' => 'show', | ||||
|         ]); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:show.html.twig', [ | ||||
|             'person' => $person, | ||||
|             'entity' => $entity, | ||||
|             'delete_form' => $deleteForm->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Edits an existing Activity entity. | ||||
|      * | ||||
|      * @param mixed $person_id | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function updateAction(Request $request, $person_id, $id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $person = $em->getRepository('ChillPersonBundle:Person')->find($person_id); | ||||
|         $entity = $em->getRepository('ChillActivityBundle:Activity')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find Activity entity.'); | ||||
|         } | ||||
|  | ||||
|         $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); | ||||
|  | ||||
|         $deleteForm = $this->createDeleteForm($id, $person); | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|         $editForm->handleRequest($request); | ||||
|  | ||||
|         $event = new PrivacyEvent($person, [ | ||||
|             'element_class' => Activity::class, | ||||
|             'element_id' => $entity->getId(), | ||||
|             'action' => 'update', | ||||
|         ]); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|  | ||||
|         if ($editForm->isValid()) { | ||||
|         if ($form->isSubmitted() && $form->isValid()) { | ||||
|             $em->persist($entity); | ||||
|             $em->flush(); | ||||
|  | ||||
|             $this->get('session') | ||||
|                 ->getFlashBag() | ||||
|                 ->add( | ||||
|                     'success', | ||||
|                     $this->get('translator') | ||||
|                         ->trans('Success : activity updated!') | ||||
|                 ); | ||||
|             $this->addFlash('success', $this->get('translator')->trans('Success : activity updated!')); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activity_show', ['id' => $id, 'person_id' => $person_id])); | ||||
|             $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|             $params['id'] = $id; | ||||
|             return $this->redirectToRoute('chill_activity_activity_show', $params); | ||||
|         } | ||||
|  | ||||
|         $this->get('session') | ||||
|             ->getFlashBag() | ||||
|             ->add( | ||||
|                 'error', | ||||
|                 $this->get('translator') | ||||
|                     ->trans('This form contains errors') | ||||
|             ); | ||||
|         $deleteForm = $this->createDeleteForm($id, $person, $accompanyingPeriod); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:Activity:edit.html.twig', [ | ||||
|             'person' => $entity->getPerson(), | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         /* | ||||
|          * TODO | ||||
|         $event = new PrivacyEvent($person, array( | ||||
|             'element_class' => Activity::class, | ||||
|             'element_id' => $entity->getId(), | ||||
|             'action' => 'edit' | ||||
|         )); | ||||
|         $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); | ||||
|         */ | ||||
|  | ||||
|         if ($view === null) { | ||||
|             throw $this->createNotFoundException('Template not found'); | ||||
|         } | ||||
|  | ||||
|         $activity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); | ||||
|  | ||||
|         return $this->render($view, array( | ||||
|             'entity'      => $entity, | ||||
|             'edit_form'   => $form->createView(), | ||||
|             'delete_form' => $deleteForm->createView(), | ||||
|         ]); | ||||
|             'person' => $person, | ||||
|             'accompanyingCourse' => $accompanyingPeriod, | ||||
|             'activity_json' => $activity_array | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a Activity entity. | ||||
|      * Deletes a Activity entity. | ||||
|      * | ||||
|      * @param Activity $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(Activity $entity) | ||||
|     public function deleteAction(Request $request, $id) | ||||
|     { | ||||
|         return $this->createForm( | ||||
|             ActivityType::class, | ||||
|             $entity, | ||||
|             [ | ||||
|                 'action' => $this->generateUrl('chill_activity_activity_create', [ | ||||
|                     'person_id' => $entity->getPerson()->getId(), | ||||
|                 ]), | ||||
|                 'method' => 'POST', | ||||
|                 'center' => $entity->getCenter(), | ||||
|                 'role' => new Role('CHILL_ACTIVITY_CREATE'), | ||||
|             ] | ||||
|         ); | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         [$person, $accompanyingPeriod] = $this->getEntity($request); | ||||
|  | ||||
|         if ($accompanyingPeriod instanceof AccompanyingPeriod) { | ||||
|             $view = 'ChillActivityBundle:Activity:confirm_deleteAccompanyingCourse.html.twig'; | ||||
|         } elseif ($person instanceof Person) { | ||||
|             $view = 'ChillActivityBundle:Activity:confirm_deletePerson.html.twig'; | ||||
|         } | ||||
|  | ||||
|         /* @var $activity Activity */ | ||||
|         $activity = $em->getRepository('ChillActivityBundle:Activity')->find($id); | ||||
|  | ||||
|         if (!$activity) { | ||||
|             throw $this->createNotFoundException('Unable to find Activity entity.'); | ||||
|         } | ||||
|  | ||||
|         // TODO | ||||
|         // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity); | ||||
|  | ||||
|         $form = $this->createDeleteForm($id, $person, $accompanyingPeriod); | ||||
|  | ||||
|         if ($request->getMethod() === Request::METHOD_DELETE) { | ||||
|             $form->handleRequest($request); | ||||
|  | ||||
|             if ($form->isValid()) { | ||||
|  | ||||
|                 $this->logger->notice("An activity has been removed", array( | ||||
|                    'by_user' => $this->getUser()->getUsername(), | ||||
|                    'activity_id' => $activity->getId(), | ||||
|                    'person_id' => $activity->getPerson() ? $activity->getPerson()->getId() : null, | ||||
|                    'comment' => $activity->getComment()->getComment(), | ||||
|                    'scope_id' => $activity->getScope() ? $activity->getScope()->getId() : null, | ||||
|                    'reasons_ids' => $activity->getReasons() | ||||
|                       ->map(function ($ar) { return $ar->getId(); }) | ||||
|                       ->toArray(), | ||||
|                    'type_id' => $activity->getType()->getId(), | ||||
|                    'duration' => $activity->getDurationTime() ? $activity->getDurationTime()->format('U') : null, | ||||
|                    'date' => $activity->getDate()->format('Y-m-d'), | ||||
|                    'attendee' => $activity->getAttendee() | ||||
|                 )); | ||||
|  | ||||
|                 $em->remove($activity); | ||||
|                 $em->flush(); | ||||
|  | ||||
|                 $this->addFlash('success', $this->get('translator') | ||||
|                       ->trans("The activity has been successfully removed.")); | ||||
|  | ||||
|                 $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|                 return $this->redirectToRoute('chill_activity_activity_list', $params); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if ($view === null) { | ||||
|             throw $this->createNotFoundException('Template not found'); | ||||
|         } | ||||
|  | ||||
|         return $this->render($view, array( | ||||
|            'activity' => $activity, | ||||
|            'delete_form' => $form->createView(), | ||||
|            'person' => $person, | ||||
|            'accompanyingCourse' => $accompanyingPeriod, | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to delete a Activity entity by id. | ||||
|      * | ||||
|      * @param mixed $id The entity id | ||||
|      * @param mixed $person | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createDeleteForm($id, $person) | ||||
|     private function createDeleteForm(int $id, ?Person $person, ?AccompanyingPeriod $accompanyingPeriod): Form | ||||
|     { | ||||
|         $params = $this->buildParamsToUrl($person, $accompanyingPeriod); | ||||
|         $params['id'] = $id; | ||||
|  | ||||
|         return $this->createFormBuilder() | ||||
|             ->setAction($this->generateUrl( | ||||
|                 'chill_activity_activity_delete', | ||||
|                 ['id' => $id, 'person_id' => $person->getId()] | ||||
|             )) | ||||
|             ->setAction($this->generateUrl('chill_activity_activity_delete', $params)) | ||||
|             ->setMethod('DELETE') | ||||
|             ->add('submit', SubmitType::class, ['label' => 'Delete']) | ||||
|             ->getForm(); | ||||
|             ->add('submit', SubmitType::class, array('label' => 'Delete')) | ||||
|             ->getForm() | ||||
|         ; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to edit a Activity entity. | ||||
|      * | ||||
|      * @param Activity $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createEditForm(Activity $entity) | ||||
|     private function getEntity(Request $request): array | ||||
|     { | ||||
|         return $this->createForm(ActivityType::class, $entity, [ | ||||
|             'action' => $this->generateUrl( | ||||
|                 'chill_activity_activity_update', | ||||
|                 [ | ||||
|                     'id' => $entity->getId(), | ||||
|                     'person_id' => $entity->getPerson()->getId(), | ||||
|                 ] | ||||
|             ), | ||||
|             'method' => 'PUT', | ||||
|             'center' => $entity->getCenter(), | ||||
|             'role' => new Role('CHILL_ACTIVITY_UPDATE'), | ||||
|         ]); | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $person = $accompanyingPeriod  = null; | ||||
|  | ||||
|         if ($request->query->has('person_id')) { | ||||
|             $person_id = $request->get('person_id'); | ||||
|             $person = $em->getRepository(Person::class)->find($person_id); | ||||
|  | ||||
|             if ($person === null) { | ||||
|                 throw $this->createNotFoundException('Person not found'); | ||||
|             } | ||||
|  | ||||
|             $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|         } elseif ($request->query->has('accompanying_period_id')) { | ||||
|             $accompanying_period_id = $request->get('accompanying_period_id'); | ||||
|             $accompanyingPeriod = $em->getRepository(AccompanyingPeriod::class)->find($accompanying_period_id); | ||||
|  | ||||
|             if ($accompanyingPeriod === null) { | ||||
|                 throw $this->createNotFoundException('Accompanying Period not found'); | ||||
|             } | ||||
|  | ||||
|             // TODO Add permission | ||||
|             // $this->denyAccessUnlessGranted('CHILL_PERSON_SEE', $person); | ||||
|         } else { | ||||
|             throw $this->createNotFoundException("Person or Accompanying Period not found"); | ||||
|         } | ||||
|  | ||||
|         return [ | ||||
|             $person, $accompanyingPeriod | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     private function buildParamsToUrl( | ||||
|         ?Person $person, | ||||
|         ?AccompanyingPeriod $accompanyingPeriod | ||||
|     ): array { | ||||
|         $params = []; | ||||
|  | ||||
|         if ($person) { | ||||
|             $params['person_id'] = $person->getId(); | ||||
|         } | ||||
|  | ||||
|         if ($accompanyingPeriod) { | ||||
|             $params['accompanying_period_id'] = $accompanyingPeriod->getId(); | ||||
|         } | ||||
|  | ||||
|         return $params; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,28 +1,38 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReasonCategory; | ||||
| use Chill\ActivityBundle\Form\ActivityReasonCategoryType; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| /** | ||||
|  * ActivityReasonCategory controller. | ||||
|  * | ||||
|  */ | ||||
| class ActivityReasonCategoryController extends AbstractController | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * Lists all ActivityReasonCategory entities. | ||||
|      * | ||||
|      */ | ||||
|     public function indexAction() | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entities = $em->getRepository('ChillActivityBundle:ActivityReasonCategory')->findAll(); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:index.html.twig', array( | ||||
|             'entities' => $entities, | ||||
|         )); | ||||
|     } | ||||
|     /** | ||||
|      * Creates a new ActivityReasonCategory entity. | ||||
|      * | ||||
|      */ | ||||
|     public function createAction(Request $request) | ||||
|     { | ||||
| @@ -35,19 +45,71 @@ class ActivityReasonCategoryController extends AbstractController | ||||
|             $em->persist($entity); | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreasoncategory_show', ['id' => $entity->getId()])); | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreasoncategory_show', array('id' => $entity->getId()))); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:new.html.twig', [ | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:new.html.twig', array( | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|             'form'   => $form->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param ActivityReasonCategory $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(ActivityReasonCategory $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonCategoryType::class, $entity, array( | ||||
|             'action' => $this->generateUrl('chill_activity_activityreasoncategory_create'), | ||||
|             'method' => 'POST', | ||||
|         )); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, array('label' => 'Create')); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new ActivityReasonCategory entity. | ||||
|      * | ||||
|      */ | ||||
|     public function newAction() | ||||
|     { | ||||
|         $entity = new ActivityReasonCategory(); | ||||
|         $form   = $this->createCreateForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:new.html.twig', array( | ||||
|             'entity' => $entity, | ||||
|             'form'   => $form->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a ActivityReasonCategory entity. | ||||
|      * | ||||
|      */ | ||||
|     public function showAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityReasonCategory')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityReasonCategory entity.'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:show.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to edit an existing ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function editAction($id) | ||||
|     { | ||||
| @@ -61,64 +123,33 @@ class ActivityReasonCategoryController extends AbstractController | ||||
|  | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:edit.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|             'edit_form'   => $editForm->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Lists all ActivityReasonCategory entities. | ||||
|      */ | ||||
|     public function indexAction() | ||||
|     * Creates a form to edit a ActivityReasonCategory entity. | ||||
|     * | ||||
|     * @param ActivityReasonCategory $entity The entity | ||||
|     * | ||||
|     * @return \Symfony\Component\Form\Form The form | ||||
|     */ | ||||
|     private function createEditForm(ActivityReasonCategory $entity) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $form = $this->createForm(ActivityReasonCategoryType::class, $entity, array( | ||||
|             'action' => $this->generateUrl('chill_activity_activityreasoncategory_update', array('id' => $entity->getId())), | ||||
|             'method' => 'PUT', | ||||
|         )); | ||||
|  | ||||
|         $entities = $em->getRepository('ChillActivityBundle:ActivityReasonCategory')->findAll(); | ||||
|         $form->add('submit', SubmitType::class, array('label' => 'Update')); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:index.html.twig', [ | ||||
|             'entities' => $entities, | ||||
|         ]); | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new ActivityReasonCategory entity. | ||||
|      */ | ||||
|     public function newAction() | ||||
|     { | ||||
|         $entity = new ActivityReasonCategory(); | ||||
|         $form = $this->createCreateForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:new.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function showAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityReasonCategory')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityReasonCategory entity.'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:show.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Edits an existing ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function updateAction(Request $request, $id) | ||||
|     { | ||||
| @@ -136,50 +167,12 @@ class ActivityReasonCategoryController extends AbstractController | ||||
|         if ($editForm->isValid()) { | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreasoncategory_edit', ['id' => $id])); | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreasoncategory_edit', array('id' => $id))); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param ActivityReasonCategory $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(ActivityReasonCategory $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonCategoryType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activityreasoncategory_create'), | ||||
|             'method' => 'POST', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Create']); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to edit a ActivityReasonCategory entity. | ||||
|      * | ||||
|      * @param ActivityReasonCategory $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createEditForm(ActivityReasonCategory $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonCategoryType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activityreasoncategory_update', ['id' => $entity->getId()]), | ||||
|             'method' => 'PUT', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Update']); | ||||
|  | ||||
|         return $form; | ||||
|         return $this->render('ChillActivityBundle:ActivityReasonCategory:edit.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|             'edit_form'   => $editForm->createView(), | ||||
|         )); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,28 +1,38 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Form\ActivityReasonType; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| /** | ||||
|  * ActivityReason controller. | ||||
|  * | ||||
|  */ | ||||
| class ActivityReasonController extends AbstractController | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * Lists all ActivityReason entities. | ||||
|      * | ||||
|      */ | ||||
|     public function indexAction() | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entities = $em->getRepository('ChillActivityBundle:ActivityReason')->findAll(); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:index.html.twig', array( | ||||
|             'entities' => $entities, | ||||
|         )); | ||||
|     } | ||||
|     /** | ||||
|      * Creates a new ActivityReason entity. | ||||
|      * | ||||
|      */ | ||||
|     public function createAction(Request $request) | ||||
|     { | ||||
| @@ -35,19 +45,71 @@ class ActivityReasonController extends AbstractController | ||||
|             $em->persist($entity); | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreason', ['id' => $entity->getId()])); | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreason', array('id' => $entity->getId()))); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:new.html.twig', [ | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:new.html.twig', array( | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|             'form'   => $form->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a ActivityReason entity. | ||||
|      * | ||||
|      * @param ActivityReason $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(ActivityReason $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonType::class, $entity, array( | ||||
|             'action' => $this->generateUrl('chill_activity_activityreason_create'), | ||||
|             'method' => 'POST', | ||||
|         )); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, array('label' => 'Create')); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new ActivityReason entity. | ||||
|      * | ||||
|      */ | ||||
|     public function newAction() | ||||
|     { | ||||
|         $entity = new ActivityReason(); | ||||
|         $form   = $this->createCreateForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:new.html.twig', array( | ||||
|             'entity' => $entity, | ||||
|             'form'   => $form->createView(), | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a ActivityReason entity. | ||||
|      * | ||||
|      */ | ||||
|     public function showAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityReason')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityReason entity.'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:show.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to edit an existing ActivityReason entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function editAction($id) | ||||
|     { | ||||
| @@ -61,64 +123,33 @@ class ActivityReasonController extends AbstractController | ||||
|  | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|             'edit_form'   => $editForm->createView() | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Lists all ActivityReason entities. | ||||
|      */ | ||||
|     public function indexAction() | ||||
|     * Creates a form to edit a ActivityReason entity. | ||||
|     * | ||||
|     * @param ActivityReason $entity The entity | ||||
|     * | ||||
|     * @return \Symfony\Component\Form\Form The form | ||||
|     */ | ||||
|     private function createEditForm(ActivityReason $entity) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|         $form = $this->createForm(ActivityReasonType::class, $entity, array( | ||||
|             'action' => $this->generateUrl('chill_activity_activityreason_update', array('id' => $entity->getId())), | ||||
|             'method' => 'PUT', | ||||
|         )); | ||||
|  | ||||
|         $entities = $em->getRepository('ChillActivityBundle:ActivityReason')->findAll(); | ||||
|         $form->add('submit', SubmitType::class, array('label' => 'Update')); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:index.html.twig', [ | ||||
|             'entities' => $entities, | ||||
|         ]); | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new ActivityReason entity. | ||||
|      */ | ||||
|     public function newAction() | ||||
|     { | ||||
|         $entity = new ActivityReason(); | ||||
|         $form = $this->createCreateForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:new.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a ActivityReason entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function showAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityReason')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityReason entity.'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:show.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Edits an existing ActivityReason entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function updateAction(Request $request, $id) | ||||
|     { | ||||
| @@ -136,50 +167,12 @@ class ActivityReasonController extends AbstractController | ||||
|         if ($editForm->isValid()) { | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreason', ['id' => $id])); | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activityreason', array('id' => $id))); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a ActivityReason entity. | ||||
|      * | ||||
|      * @param ActivityReason $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(ActivityReason $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activityreason_create'), | ||||
|             'method' => 'POST', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Create']); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to edit a ActivityReason entity. | ||||
|      * | ||||
|      * @param ActivityReason $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createEditForm(ActivityReason $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityReasonType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activityreason_update', ['id' => $entity->getId()]), | ||||
|             'method' => 'PUT', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Update']); | ||||
|  | ||||
|         return $form; | ||||
|         return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', array( | ||||
|             'entity'      => $entity, | ||||
|             'edit_form'   => $editForm->createView() | ||||
|         )); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,185 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Chill\ActivityBundle\Form\ActivityTypeType; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
| use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| class ActivityTypeController extends AbstractController | ||||
| { | ||||
|     /** | ||||
|      * Creates a new ActivityType entity. | ||||
|      */ | ||||
|     public function createAction(Request $request) | ||||
|     { | ||||
|         $entity = new ActivityType(); | ||||
|         $form = $this->createCreateForm($entity); | ||||
|         $form->handleRequest($request); | ||||
|  | ||||
|         if ($form->isValid()) { | ||||
|             $em = $this->getDoctrine()->getManager(); | ||||
|             $em->persist($entity); | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activitytype_show', ['id' => $entity->getId()])); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:new.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to edit an existing ActivityType entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function editAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityType entity.'); | ||||
|         } | ||||
|  | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Lists all ActivityType entities. | ||||
|      */ | ||||
|     public function indexAction() | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entities = $em->getRepository('ChillActivityBundle:ActivityType')->findAll(); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:index.html.twig', [ | ||||
|             'entities' => $entities, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Displays a form to create a new ActivityType entity. | ||||
|      */ | ||||
|     public function newAction() | ||||
|     { | ||||
|         $entity = new ActivityType(); | ||||
|         $form = $this->createCreateForm($entity); | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:new.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'form' => $form->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Finds and displays a ActivityType entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function showAction($id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityType entity.'); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:show.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Edits an existing ActivityType entity. | ||||
|      * | ||||
|      * @param mixed $id | ||||
|      */ | ||||
|     public function updateAction(Request $request, $id) | ||||
|     { | ||||
|         $em = $this->getDoctrine()->getManager(); | ||||
|  | ||||
|         $entity = $em->getRepository('ChillActivityBundle:ActivityType')->find($id); | ||||
|  | ||||
|         if (!$entity) { | ||||
|             throw $this->createNotFoundException('Unable to find ActivityType entity.'); | ||||
|         } | ||||
|  | ||||
|         $editForm = $this->createEditForm($entity); | ||||
|         $editForm->handleRequest($request); | ||||
|  | ||||
|         if ($editForm->isValid()) { | ||||
|             $em->flush(); | ||||
|  | ||||
|             return $this->redirect($this->generateUrl('chill_activity_activitytype_edit', ['id' => $id])); | ||||
|         } | ||||
|  | ||||
|         return $this->render('ChillActivityBundle:ActivityType:edit.html.twig', [ | ||||
|             'entity' => $entity, | ||||
|             'edit_form' => $editForm->createView(), | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to create a ActivityType entity. | ||||
|      * | ||||
|      * @param ActivityType $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createCreateForm(ActivityType $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityTypeType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activitytype_create'), | ||||
|             'method' => 'POST', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Create']); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a form to edit a ActivityType entity. | ||||
|      * | ||||
|      * @param ActivityType $entity The entity | ||||
|      * | ||||
|      * @return \Symfony\Component\Form\Form The form | ||||
|      */ | ||||
|     private function createEditForm(ActivityType $entity) | ||||
|     { | ||||
|         $form = $this->createForm(ActivityTypeType::class, $entity, [ | ||||
|             'action' => $this->generateUrl('chill_activity_activitytype_update', ['id' => $entity->getId()]), | ||||
|             'method' => 'PUT', | ||||
|         ]); | ||||
|  | ||||
|         $form->add('submit', SubmitType::class, ['label' => 'Update']); | ||||
|  | ||||
|         return $form; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Chill\MainBundle\CRUD\Controller\CRUDController; | ||||
| use Chill\MainBundle\Pagination\PaginatorInterface; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| class AdminActivityPresenceController extends CRUDController | ||||
| { | ||||
|     /** | ||||
|      * @param string $action | ||||
|      * @param \Doctrine\ORM\QueryBuilder|mixed $query | ||||
|      * @param Request $request | ||||
|      * @param PaginatorInterface $paginator | ||||
|      * @return \Doctrine\ORM\QueryBuilder|mixed | ||||
|      */ | ||||
|     protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) | ||||
|     { | ||||
|         /** @var \Doctrine\ORM\QueryBuilder $query */ | ||||
|         return $query->orderBy('e.id', 'ASC'); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Chill\MainBundle\CRUD\Controller\CRUDController; | ||||
| use Chill\MainBundle\Pagination\PaginatorInterface; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| class AdminActivityTypeCategoryController extends CRUDController | ||||
| { | ||||
|     /** | ||||
|      * @param string $action | ||||
|      * @param \Doctrine\ORM\QueryBuilder|mixed $query | ||||
|      * @param Request $request | ||||
|      * @param PaginatorInterface $paginator | ||||
|      * @return \Doctrine\ORM\QueryBuilder|mixed | ||||
|      */ | ||||
|     protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) | ||||
|     { | ||||
|         /** @var \Doctrine\ORM\QueryBuilder $query */ | ||||
|         return $query->orderBy('e.ordering', 'ASC'); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Chill\MainBundle\CRUD\Controller\CRUDController; | ||||
| use Chill\MainBundle\Pagination\PaginatorInterface; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| class AdminActivityTypeController extends CRUDController | ||||
| { | ||||
|     /** | ||||
|      * @param string $action | ||||
|      * @param \Doctrine\ORM\QueryBuilder|mixed $query | ||||
|      * @param Request $request | ||||
|      * @param PaginatorInterface $paginator | ||||
|      * @return \Doctrine\ORM\QueryBuilder|mixed | ||||
|      */ | ||||
|     protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) | ||||
|     { | ||||
|         /** @var \Doctrine\ORM\QueryBuilder $query */ | ||||
|         return $query->orderBy('e.ordering', 'ASC'); | ||||
|     } | ||||
| } | ||||
| @@ -1,22 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * Copyright (C) 2015 Champs Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Controller; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
|  | ||||
| /** | ||||
|  * Controller for activity configuration. | ||||
|  * Controller for activity configuration | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  * @author Champs Libres <info@champs-libres.coop> | ||||
|  */ | ||||
| class AdminController extends AbstractController | ||||
| { | ||||
| @@ -24,7 +35,7 @@ class AdminController extends AbstractController | ||||
|     { | ||||
|         return $this->render('ChillActivityBundle:Admin:layout_activity.html.twig'); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function redirectToAdminIndexAction() | ||||
|     { | ||||
|         return $this->redirectToRoute('chill_main_admin_central'); | ||||
|   | ||||
| @@ -1,33 +1,44 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadScopes; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadUsers; | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use Faker\Factory as FakerFactory; | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadUsers; | ||||
| use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityReason; | ||||
| use Chill\ActivityBundle\DataFixtures\ORM\LoadActivityType; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadScopes; | ||||
| use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||||
|  | ||||
| use function in_array; | ||||
|  | ||||
| /** | ||||
|  * Load reports into DB. | ||||
|  * Load reports into DB | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class LoadActivity extends AbstractFixture implements ContainerAwareInterface, OrderedFixtureInterface | ||||
| class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface | ||||
| { | ||||
|     use \Symfony\Component\DependencyInjection\ContainerAwareTrait; | ||||
|  | ||||
| @@ -46,22 +57,54 @@ class LoadActivity extends AbstractFixture implements ContainerAwareInterface, O | ||||
|         return 16400; | ||||
|     } | ||||
|  | ||||
|     public function load(ObjectManager $manager) | ||||
|     /** | ||||
|      * Return a random scope | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\Scope | ||||
|      */ | ||||
|     private function getRandomScope() | ||||
|     { | ||||
|         $persons = $this->container->get('doctrine.orm.entity_manager') | ||||
|             ->getRepository('ChillPersonBundle:Person') | ||||
|             ->findAll(); | ||||
|         $scopeRef = LoadScopes::$references[array_rand(LoadScopes::$references)]; | ||||
|         return $this->getReference($scopeRef); | ||||
|     } | ||||
|  | ||||
|         foreach ($persons as $person) { | ||||
|             $activityNbr = mt_rand(0, 3); | ||||
|     /** | ||||
|      * Return a random activityType | ||||
|      * | ||||
|      * @return \Chill\ActivityBundle\Entity\ActivityType | ||||
|      */ | ||||
|     private function getRandomActivityType() | ||||
|     { | ||||
|         $typeRef = LoadActivityType::$references[array_rand(LoadActivityType::$references)]; | ||||
|         return $this->getReference($typeRef); | ||||
|     } | ||||
|  | ||||
|             for ($i = 0; $i < $activityNbr; ++$i) { | ||||
|                 echo 'Creating an activity type for  : ' . $person . "\n"; | ||||
|                 $activity = $this->newRandomActivity($person); | ||||
|                 $manager->persist($activity); | ||||
|             } | ||||
|     /** | ||||
|      * Return a random activityReason | ||||
|      * | ||||
|      * @return \Chill\ActivityBundle\Entity\ActivityReason | ||||
|      */ | ||||
|     private function getRandomActivityReason(array $excludingIds) | ||||
|     { | ||||
|         $reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)]; | ||||
|  | ||||
|         if (in_array($this->getReference($reasonRef)->getId(), $excludingIds)) { | ||||
|             // we have a reason which should be excluded. Find another... | ||||
|             return $this->getRandomActivityReason($excludingIds); | ||||
|         } | ||||
|         $manager->flush(); | ||||
|  | ||||
|         return $this->getReference($reasonRef); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return a random user | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\User | ||||
|      */ | ||||
|     private function getRandomUser() | ||||
|     { | ||||
|         $userRef = array_rand(LoadUsers::$refs); | ||||
|         return $this->getReference($userRef); | ||||
|     } | ||||
|  | ||||
|     public function newRandomActivity($person) | ||||
| @@ -73,11 +116,12 @@ class LoadActivity extends AbstractFixture implements ContainerAwareInterface, O | ||||
|             ->setDurationTime($this->faker->dateTime(36000)) | ||||
|             ->setType($this->getRandomActivityType()) | ||||
|             ->setScope($this->getRandomScope()) | ||||
|             ->setAttendee($this->faker->boolean()); | ||||
|             ; | ||||
|  | ||||
|         $usedId = []; | ||||
|         //      ->setAttendee($this->faker->boolean()) | ||||
|  | ||||
|         for ($i = 0; mt_rand(0, 4) > $i; ++$i) { | ||||
|         $usedId = array(); | ||||
|         for ($i = 0; $i < rand(0, 4); $i++) { | ||||
|             $reason = $this->getRandomActivityReason($usedId); | ||||
|             $usedId[] = $reason->getId(); | ||||
|             $activity->addReason($reason); | ||||
| @@ -86,56 +130,24 @@ class LoadActivity extends AbstractFixture implements ContainerAwareInterface, O | ||||
|         return $activity; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return a random activityReason. | ||||
|      * | ||||
|      * @return \Chill\ActivityBundle\Entity\ActivityReason | ||||
|      */ | ||||
|     private function getRandomActivityReason(array $excludingIds) | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         $reasonRef = LoadActivityReason::$references[array_rand(LoadActivityReason::$references)]; | ||||
|         $persons = $this->container->get('doctrine.orm.entity_manager') | ||||
|             ->getRepository('ChillPersonBundle:Person') | ||||
|             ->findAll(); | ||||
|  | ||||
|         if (in_array($this->getReference($reasonRef)->getId(), $excludingIds, true)) { | ||||
|             // we have a reason which should be excluded. Find another... | ||||
|             return $this->getRandomActivityReason($excludingIds); | ||||
|         foreach($persons as $person) { | ||||
|             $activityNbr = rand(0,3); | ||||
|             $ref = 'activity_'.$person->getFullnameCanonical(); | ||||
|  | ||||
|             for($i = 0; $i < $activityNbr; $i ++) { | ||||
|                 print "Creating an activity type for  : ".$person." (ref: ".$ref.")  \n"; | ||||
|                 $activity = $this->newRandomActivity($person); | ||||
|                 $manager->persist($activity); | ||||
|             } | ||||
|  | ||||
|             $this->setReference($ref, $activity); | ||||
|         } | ||||
|  | ||||
|         return $this->getReference($reasonRef); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return a random activityType. | ||||
|      * | ||||
|      * @return \Chill\ActivityBundle\Entity\ActivityType | ||||
|      */ | ||||
|     private function getRandomActivityType() | ||||
|     { | ||||
|         $typeRef = LoadActivityType::$references[array_rand(LoadActivityType::$references)]; | ||||
|  | ||||
|         return $this->getReference($typeRef); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return a random scope. | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\Scope | ||||
|      */ | ||||
|     private function getRandomScope() | ||||
|     { | ||||
|         $scopeRef = LoadScopes::$references[array_rand(LoadScopes::$references)]; | ||||
|  | ||||
|         return $this->getReference($scopeRef); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return a random user. | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\User | ||||
|      */ | ||||
|     private function getRandomUser() | ||||
|     { | ||||
|         $userRef = array_rand(LoadUsers::$refs); | ||||
|  | ||||
|         return $this->getReference($userRef); | ||||
|         $manager->flush(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait; | ||||
| use Chill\ActivityBundle\DataFixtures\ORM\LoadActivity; | ||||
|  | ||||
| /** | ||||
|  * Load notififications into database | ||||
|  */ | ||||
| class LoadActivityNotifications extends AbstractFixture implements DependentFixtureInterface | ||||
| { | ||||
|     use LoadAbstractNotificationsTrait; | ||||
|  | ||||
|     public $notifs = [ | ||||
|         [ | ||||
|             'message' => 'Hello !', | ||||
|             'entityClass' => Activity::class, | ||||
|             'entityRef' => 'activity_gerard depardieu', | ||||
|             'sender' => 'center a_social', | ||||
|             'addressees' => [ | ||||
|                 'center a_social', | ||||
|                 'center a_administrative', | ||||
|                 'center a_direction', | ||||
|                 'multi_center' | ||||
|             ], | ||||
|         ] | ||||
|     ]; | ||||
|  | ||||
|     public function getDependencies() | ||||
|     { | ||||
|         return [ | ||||
|             LoadActivity::class, | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
| @@ -1,70 +1,81 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  *  | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,  | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
|  | ||||
| /** | ||||
|  * Description of LoadActivityReason. | ||||
|  * Description of LoadActivityReason | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class LoadActivityReason extends AbstractFixture implements OrderedFixtureInterface | ||||
| { | ||||
|     public static $references = []; | ||||
|  | ||||
|     public function getOrder() | ||||
|     { | ||||
|         return 16300; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public static $references = array(); | ||||
|      | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         $reasons = [ | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Recherche logement', 'en' => 'Housing research', 'nl' => 'Woning zoektoch'], | ||||
|                 'category' => 'cat_Housing', ], | ||||
|                 'category' => 'cat_Housing'], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Problème avec propriétaire', 'en' => 'Landlord problems', 'nl' => 'Huisbaas problemen'], | ||||
|                 'category' => 'cat_Housing', ], | ||||
|                 'category' => 'cat_Housing'], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Retard de payement', 'en' => 'Payement problems', 'nl' => 'Betalings vertragingen'], | ||||
|                 'category' => 'cat_Housing', ], | ||||
|                 'category' => 'cat_Housing'], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Explication législation', 'en' => 'Legislation explanation', 'nl' => 'Legislative uitleg'], | ||||
|                 'category' => 'cat_Unemployment procedure', ], | ||||
|                 'category' => 'cat_Unemployment procedure'], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Coaching entretien d\'activation', 'en' => 'Interview coaching', 'nl' => 'Interview coaching'], | ||||
|                 'category' => 'cat_Unemployment procedure', ], | ||||
|                 'category' => 'cat_Unemployment procedure'], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Récupération des allocations', 'en' => 'Allowance recovery', 'nl' => 'Terugwinning van de uitkeringen'], | ||||
|                 'category' => 'cat_Unemployment procedure', ], | ||||
|                 'category' => 'cat_Unemployment procedure'] | ||||
|         ]; | ||||
|  | ||||
|          | ||||
|         foreach ($reasons as $r) { | ||||
|             echo 'Creating activity reason : ' . $r['name']['en'] . "\n"; | ||||
|             print "Creating activity reason : " . $r['name']['en'] . "\n"; | ||||
|             $activityReason = (new ActivityReason()) | ||||
|                 ->setName(($r['name'])) | ||||
|                 ->setActive(true) | ||||
|                 ->setCategory($this->getReference($r['category'])); | ||||
|             $manager->persist($activityReason); | ||||
|             $reference = 'activity_reason_' . $r['name']['en']; | ||||
|             $reference = 'activity_reason_'.$r['name']['en']; | ||||
|             $this->addReference($reference, $activityReason); | ||||
|             static::$references[] = $reference; | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $manager->flush(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,35 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  *  | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,  | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReasonCategory; | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReasonCategory; | ||||
| /** | ||||
|  * Description of LoadActivityReasonCategory. | ||||
|  * Description of LoadActivityReasonCategory | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class LoadActivityReasonCategory extends AbstractFixture implements OrderedFixtureInterface | ||||
| { | ||||
| @@ -27,26 +37,27 @@ class LoadActivityReasonCategory extends AbstractFixture implements OrderedFixtu | ||||
|     { | ||||
|         return 16200; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         $categs = [ | ||||
|             ['name' => ['fr' => 'Logement', 'en' => 'Housing', 'nl' => 'Woning']], | ||||
|             ['name' => ['fr' => 'Démarches chômage', 'en' => 'Unemployment procedure', 'nl' => 'Werkloosheid werkwijze']], | ||||
|             ['name' => | ||||
|                 ['fr' => 'Logement', 'en' => 'Housing', 'nl' => 'Woning']], | ||||
|             ['name' => | ||||
|                 ['fr' => 'Démarches chômage', 'en' => 'Unemployment procedure', 'nl' => 'Werkloosheid werkwijze']], | ||||
|         ]; | ||||
|  | ||||
|              | ||||
|         foreach ($categs as $c) { | ||||
|             echo 'Creating activity reason category : ' . $c['name']['en'] . "\n"; | ||||
|             print "Creating activity reason category : " . $c['name']['en'] . "\n"; | ||||
|             $activityReasonCategory = (new ActivityReasonCategory()) | ||||
|                 ->setName(($c['name'])) | ||||
|                 ->setActive(true); | ||||
|             $manager->persist($activityReasonCategory); | ||||
|             $this->addReference( | ||||
|                 'cat_' . $c['name']['en'], | ||||
|                 $activityReasonCategory | ||||
|             ); | ||||
|               'cat_'.$c['name']['en'], | ||||
|               $activityReasonCategory); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $manager->flush(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,49 +1,86 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| use Doctrine\Bundle\FixturesBundle\Fixture; | ||||
| use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
|  | ||||
| /** | ||||
|  * Description of LoadActivityType. | ||||
|  * Description of LoadActivityType | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class LoadActivityType extends AbstractFixture implements OrderedFixtureInterface | ||||
| class LoadActivityType extends Fixture implements OrderedFixtureInterface | ||||
| { | ||||
|     public static $references = []; | ||||
|  | ||||
|     public function getOrder() | ||||
|     { | ||||
|         return 16100; | ||||
|     } | ||||
|  | ||||
|     public static $references = array(); | ||||
|  | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         $types = [ | ||||
|             ['name' => ['fr' => 'Appel téléphonique', 'en' => 'Telephone call', 'nl' => 'Telefoon appel']], | ||||
|             ['name' => ['fr' => 'Entretien', 'en' => 'Interview', 'nl' => 'Vraaggesprek']], | ||||
|             ['name' => ['fr' => 'Inspection', 'en' => 'Inspection', 'nl' => 'Inspectie']], | ||||
|             # Exange | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Entretien physique avec l\'usager'], | ||||
|                 'category' => 'exchange' ], | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Appel téléphonique', 'en' => 'Telephone call', 'nl' => 'Telefoon appel'], | ||||
|                 'category' => 'exchange' ], | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Courriel', 'en' => 'Email', 'nl' => 'Email'], | ||||
|                 'category' => 'exchange' ], | ||||
|             # Meeting | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Point technique encadrant'], | ||||
|                 'category' => 'meeting' ], | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Réunion avec des partenaires'], | ||||
|                 'category' => 'meeting' ], | ||||
|             [ | ||||
|                 'name' => | ||||
|                     ['fr' => 'Commission pluridisciplinaire et pluri-institutionnelle'], | ||||
|                 'category' => 'meeting' ], | ||||
|         ]; | ||||
|  | ||||
|         foreach ($types as $t) { | ||||
|             echo 'Creating activity type : ' . $t['name']['en'] . "\n"; | ||||
|             print "Creating activity type : " . $t['name']['fr'] . " (cat:". $t['category']  . " \n"; | ||||
|             $activityType = (new ActivityType()) | ||||
|                 ->setName(($t['name'])); | ||||
|                 ->setName(($t['name'])) | ||||
|                 ->setCategory($this->getReference('activity_type_cat_'.$t['category'])) | ||||
|                 ->setSocialIssuesVisible(1) | ||||
|                 ->setSocialActionsVisible(1); | ||||
|             $manager->persist($activityType); | ||||
|             $reference = 'activity_type_' . $t['name']['en']; | ||||
|             $reference = 'activity_type_'.$t['name']['fr']; | ||||
|             $this->addReference($reference, $activityType); | ||||
|             static::$references[] = $reference; | ||||
|         } | ||||
|   | ||||
| @@ -0,0 +1,72 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * Copyright (C) 2014-2021, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Doctrine\Bundle\FixturesBundle\Fixture; | ||||
| use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use Chill\ActivityBundle\Entity\ActivityTypeCategory; | ||||
|  | ||||
| /** | ||||
|  * Fixtures for ActivityTypeCategory | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class LoadActivityTypeCategory extends Fixture implements OrderedFixtureInterface | ||||
| { | ||||
|     public static $references = array(); | ||||
|  | ||||
|     public function getOrder() | ||||
|     { | ||||
|         return 16050; | ||||
|     } | ||||
|  | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         $categories = [ | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Échange avec usager', 'en' => 'Exchange with user'], | ||||
|                 'ref' => 'exchange', | ||||
|             ], | ||||
|             [ | ||||
|                 'name' => ['fr' => 'Réunion', 'en' => 'Meeting'], | ||||
|                 'ref' => 'meeting', | ||||
|             ], | ||||
|         ]; | ||||
|  | ||||
|         foreach ($categories as $cat) { | ||||
|             print "Creating activity type category : " . $cat['ref'] . "\n"; | ||||
|  | ||||
|             $newCat = (new ActivityTypeCategory()) | ||||
|                 ->setName(($cat['name'])); | ||||
|  | ||||
|             $manager->persist($newCat); | ||||
|             $reference = 'activity_type_cat_'.$cat['ref']; | ||||
|  | ||||
|             $this->addReference($reference, $newCat); | ||||
|             static::$references[] = $reference; | ||||
|         } | ||||
|  | ||||
|         $manager->flush(); | ||||
|     } | ||||
| } | ||||
| @@ -1,16 +1,22 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DataFixtures\ORM; | ||||
|  | ||||
| use Doctrine\Common\DataFixtures\AbstractFixture; | ||||
| @@ -21,7 +27,12 @@ use Chill\MainBundle\Entity\RoleScope; | ||||
| use Chill\MainBundle\DataFixtures\ORM\LoadScopes; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * Add a role CHILL_ACTIVITY_UPDATE & CHILL_ACTIVITY_CREATE for all groups except administrative, | ||||
|  * and a role CHILL_ACTIVITY_SEE for administrative | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class LoadActivitytACL extends AbstractFixture implements OrderedFixtureInterface | ||||
| { | ||||
|     public function getOrder() | ||||
| @@ -29,12 +40,12 @@ class LoadActivitytACL extends AbstractFixture implements OrderedFixtureInterfac | ||||
|         return 16000; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function load(ObjectManager $manager) | ||||
|     { | ||||
|         foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) { | ||||
|             $permissionsGroup = $this->getReference($permissionsGroupRef); | ||||
|  | ||||
|             foreach (LoadScopes::$references as $scopeRef) { | ||||
|             foreach (LoadScopes::$references as $scopeRef){ | ||||
|                 $scope = $this->getReference($scopeRef); | ||||
|                 //create permission group | ||||
|                 switch ($permissionsGroup->getName()) { | ||||
| @@ -42,48 +53,47 @@ class LoadActivitytACL extends AbstractFixture implements OrderedFixtureInterfac | ||||
|                         if ($scope->getName()['en'] === 'administrative') { | ||||
|                             break 2; // we do not want any power on administrative | ||||
|                         } | ||||
|  | ||||
|                         break; | ||||
|                     case 'administrative': | ||||
|                     case 'direction': | ||||
|                         if (\in_array($scope->getName()['en'], ['administrative', 'social'], true)) { | ||||
|                         if (in_array($scope->getName()['en'], array('administrative', 'social'))) { | ||||
|                             break 2; // we do not want any power on social or administrative | ||||
|                         } | ||||
|  | ||||
|                         }   | ||||
|                         break; | ||||
|                 } | ||||
|  | ||||
|                 printf( | ||||
|                     'Adding CHILL_ACTIVITY_UPDATE & CHILL_ACTIVITY_CREATE & CHILL_ACTIVITY_DELETE, and stats and list permissions to %s ' | ||||
|                         . "permission group, scope '%s' \n", | ||||
|                     $permissionsGroup->getName(), | ||||
|                     $scope->getName()['en'] | ||||
|                 ); | ||||
|                  | ||||
|                 printf("Adding CHILL_ACTIVITY_UPDATE & CHILL_ACTIVITY_CREATE & CHILL_ACTIVITY_DELETE, and stats and list permissions to %s " | ||||
|                         . "permission group, scope '%s' \n",  | ||||
|                         $permissionsGroup->getName(), $scope->getName()['en']); | ||||
|                 $roleScopeUpdate = (new RoleScope()) | ||||
|                     ->setRole('CHILL_ACTIVITY_UPDATE') | ||||
|                     ->setScope($scope); | ||||
|                             ->setRole('CHILL_ACTIVITY_UPDATE') | ||||
|                             ->setScope($scope); | ||||
|                 $permissionsGroup->addRoleScope($roleScopeUpdate); | ||||
|                 $roleScopeCreate = (new RoleScope()) | ||||
|                     ->setRole('CHILL_ACTIVITY_CREATE') | ||||
|                     ->setScope($scope); | ||||
|                             ->setRole('CHILL_ACTIVITY_CREATE') | ||||
|                             ->setScope($scope); | ||||
|                 $permissionsGroup->addRoleScope($roleScopeCreate); | ||||
|                 $roleScopeDelete = (new RoleScope()) | ||||
|                     ->setRole('CHILL_ACTIVITY_DELETE') | ||||
|                     ->setScope($scope); | ||||
|                             ->setRole('CHILL_ACTIVITY_DELETE') | ||||
|                             ->setScope($scope); | ||||
|                 $permissionsGroup->addRoleScope($roleScopeDelete); | ||||
|                 $roleScopeList = (new RoleScope()) | ||||
|                     ->setRole(ActivityStatsVoter::LISTS); | ||||
|                             ->setRole(ActivityStatsVoter::LISTS) | ||||
|                             ; | ||||
|                 $permissionsGroup->addRoleScope($roleScopeList); | ||||
|                 $roleScopeStat = (new RoleScope()) | ||||
|                     ->setRole(ActivityStatsVoter::STATS); | ||||
|                             ->setRole(ActivityStatsVoter::STATS) | ||||
|                             ; | ||||
|                 $permissionsGroup->addRoleScope($roleScopeStat); | ||||
|  | ||||
|                  | ||||
|                 $manager->persist($roleScopeUpdate); | ||||
|                 $manager->persist($roleScopeCreate); | ||||
|                 $manager->persist($roleScopeDelete); | ||||
|             } | ||||
|              | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $manager->flush(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,27 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DependencyInjection; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Symfony\Component\Config\FileLocator; | ||||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||||
| use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
| use Symfony\Component\DependencyInjection\Loader; | ||||
| use Symfony\Component\Config\FileLocator; | ||||
| use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||||
| use Symfony\Component\DependencyInjection\Loader; | ||||
| use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
|  | ||||
| /** | ||||
|  * This is the class that loads and manages your bundle configuration. | ||||
|  * This is the class that loads and manages your bundle configuration | ||||
|  * | ||||
|  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||||
|  */ | ||||
| @@ -37,12 +47,11 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf | ||||
|  | ||||
|         $container->setParameter('chill_activity.form.time_duration', $config['form']['time_duration']); | ||||
|  | ||||
|         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config')); | ||||
|         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); | ||||
|         $loader->load('services.yaml'); | ||||
|         $loader->load('services/export.yaml'); | ||||
|         $loader->load('services/repositories.yaml'); | ||||
|         $loader->load('services/fixtures.yaml'); | ||||
|         $loader->load('services/menu.yaml'); | ||||
|         $loader->load('services/controller.yaml'); | ||||
|         $loader->load('services/form.yaml'); | ||||
|         $loader->load('services/templating.yaml'); | ||||
| @@ -52,32 +61,104 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf | ||||
|     { | ||||
|         $this->prependRoutes($container); | ||||
|         $this->prependAuthorization($container); | ||||
|         $this->prependCruds($container); | ||||
|     } | ||||
|  | ||||
|     public function prependAuthorization(ContainerBuilder $container) | ||||
|     { | ||||
|         $container->prependExtensionConfig('security', [ | ||||
|             'role_hierarchy' => [ | ||||
|                 ActivityVoter::UPDATE => [ActivityVoter::SEE_DETAILS], | ||||
|                 ActivityVoter::CREATE => [ActivityVoter::SEE_DETAILS], | ||||
|                 ActivityVoter::DELETE => [ActivityVoter::SEE_DETAILS], | ||||
|                 ActivityVoter::SEE_DETAILS => [ActivityVoter::SEE], | ||||
|             ], | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** (non-PHPdoc). | ||||
|     /* (non-PHPdoc) | ||||
|      * @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend() | ||||
|      */ | ||||
|     public function prependRoutes(ContainerBuilder $container) | ||||
|     { | ||||
|         //add routes for custom bundle | ||||
|          $container->prependExtensionConfig('chill_main', array( | ||||
|            'routing' => array( | ||||
|               'resources' => array( | ||||
|                  '@ChillActivityBundle/config/routes.yaml' | ||||
|               ) | ||||
|            ) | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function prependAuthorization(ContainerBuilder $container) | ||||
|     { | ||||
|         $container->prependExtensionConfig('security', array( | ||||
|            'role_hierarchy' => array( | ||||
|               ActivityVoter::UPDATE => array(ActivityVoter::SEE_DETAILS), | ||||
|               ActivityVoter::CREATE => array(ActivityVoter::SEE_DETAILS), | ||||
|               ActivityVoter::DELETE => array(ActivityVoter::SEE_DETAILS), | ||||
|               ActivityVoter::SEE_DETAILS => array(ActivityVoter::SEE) | ||||
|            ) | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     protected function prependCruds(ContainerBuilder $container) | ||||
|     { | ||||
|         $container->prependExtensionConfig('chill_main', [ | ||||
|             'routing' => [ | ||||
|                 'resources' => [ | ||||
|                     '@ChillActivityBundle/config/routes.yaml', | ||||
|             'cruds' => [ | ||||
|                 [ | ||||
|                     'class' => \Chill\ActivityBundle\Entity\ActivityType::class, | ||||
|                     'name' => 'activity_type', | ||||
|                     'base_path' => '/admin/activity/type', | ||||
|                     'form_class' => \Chill\ActivityBundle\Form\ActivityTypeType::class, | ||||
|                     'controller' => \Chill\ActivityBundle\Controller\AdminActivityTypeController::class, | ||||
|                     'actions' => [ | ||||
|                         'index' => [ | ||||
|                             'template' => '@ChillActivity/ActivityType/index.html.twig', | ||||
|                             'role' => 'ROLE_ADMIN' | ||||
|                         ], | ||||
|                         'new'   => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityType/new.html.twig', | ||||
|                         ], | ||||
|                         'edit'  => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityType/edit.html.twig', | ||||
|                         ] | ||||
|                     ] | ||||
|                 ], | ||||
|             ], | ||||
|                 [ | ||||
|                     'class' => \Chill\ActivityBundle\Entity\ActivityTypeCategory::class, | ||||
|                     'name' => 'activity_type_category', | ||||
|                     'base_path' => '/admin/activity/type_category', | ||||
|                     'form_class' => \Chill\ActivityBundle\Form\ActivityTypeCategoryType::class, | ||||
|                     'controller' => \Chill\ActivityBundle\Controller\AdminActivityTypeCategoryController::class, | ||||
|                     'actions' => [ | ||||
|                         'index' => [ | ||||
|                             'template' => '@ChillActivity/ActivityTypeCategory/index.html.twig', | ||||
|                             'role' => 'ROLE_ADMIN' | ||||
|                         ], | ||||
|                         'new'   => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityTypeCategory/new.html.twig', | ||||
|                         ], | ||||
|                         'edit'  => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityTypeCategory/edit.html.twig', | ||||
|                         ] | ||||
|                     ] | ||||
|                 ], | ||||
|                 [ | ||||
|                     'class' => \Chill\ActivityBundle\Entity\ActivityPresence::class, | ||||
|                     'name' => 'activity_presence', | ||||
|                     'base_path' => '/admin/activity/presence', | ||||
|                     'form_class' => \Chill\ActivityBundle\Form\ActivityPresenceType::class, | ||||
|                     'controller' => \Chill\ActivityBundle\Controller\AdminActivityPresenceController::class, | ||||
|                     'actions' => [ | ||||
|                         'index' => [ | ||||
|                             'template' => '@ChillActivity/ActivityPresence/index.html.twig', | ||||
|                             'role' => 'ROLE_ADMIN' | ||||
|                         ], | ||||
|                         'new'   => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityPresence/new.html.twig', | ||||
|                         ], | ||||
|                         'edit'  => [ | ||||
|                             'role' => 'ROLE_ADMIN', | ||||
|                             'template' => '@ChillActivity/ActivityPresence/edit.html.twig', | ||||
|                         ] | ||||
|                     ] | ||||
|                 ], | ||||
|             ] | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,25 +1,12 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\DependencyInjection; | ||||
|  | ||||
| use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||||
| use Symfony\Component\Config\Definition\ConfigurationInterface; | ||||
|  | ||||
| use function is_int; | ||||
|  | ||||
| /** | ||||
|  * This is the class that validates and merges configuration from your app/config files. | ||||
|  * This is the class that validates and merges configuration from your app/config files | ||||
|  * | ||||
|  * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | ||||
|  */ | ||||
| @@ -32,51 +19,53 @@ class Configuration implements ConfigurationInterface | ||||
|     { | ||||
|         $treeBuilder = new TreeBuilder('chill_activity'); | ||||
|         $rootNode = $treeBuilder->getRootNode('chill_activity'); | ||||
|  | ||||
|          | ||||
|         $rootNode | ||||
|             ->children() | ||||
|             ->arrayNode('form') | ||||
|             ->canBeEnabled() | ||||
|             ->children() | ||||
|             ->arrayNode('time_duration') | ||||
|             ->isRequired() | ||||
|             ->requiresAtLeastOneElement() | ||||
|             ->defaultValue( | ||||
|                 [ | ||||
|                     ['label' => '5 minutes',  'seconds' => 300], | ||||
|                     ['label' => '10 minutes', 'seconds' => 600], | ||||
|                     ['label' => '15 minutes', 'seconds' => 900], | ||||
|                     ['label' => '20 minutes', 'seconds' => 1200], | ||||
|                     ['label' => '25 minutes', 'seconds' => 1500], | ||||
|                     ['label' => '30 minutes', 'seconds' => 1800], | ||||
|                     ['label' => '45 minutes', 'seconds' => 2700], | ||||
|                     ['label' => '1 hour',     'seconds' => 3600], | ||||
|                     ['label' => '1 hour 15',  'seconds' => 4500], | ||||
|                     ['label' => '1 hour 30',  'seconds' => 5400], | ||||
|                     ['label' => '1 hour 45',  'seconds' => 6300], | ||||
|                     ['label' => '2 hours',    'seconds' => 7200], | ||||
|                 ] | ||||
|             ) | ||||
|             ->info('The intervals of time to show in activity form') | ||||
|             ->prototype('array') | ||||
|             ->children() | ||||
|             ->scalarNode('seconds') | ||||
|             ->info('The number of seconds of this duration. Must be an integer.') | ||||
|             ->cannotBeEmpty() | ||||
|             ->validate() | ||||
|             ->ifTrue(static function ($data) { | ||||
|                 return !is_int($data); | ||||
|             })->thenInvalid('The value %s is not a valid integer') | ||||
|             ->end() | ||||
|             ->end() | ||||
|             ->scalarNode('label') | ||||
|             ->cannotBeEmpty() | ||||
|             ->info('The label to show into fields') | ||||
|             ->end() | ||||
|             ->end() | ||||
|             ->end() | ||||
|                 ->children() | ||||
|                     ->arrayNode('form') | ||||
|                         ->canBeEnabled() | ||||
|                         ->children() | ||||
|                             ->arrayNode('time_duration') | ||||
|                             ->isRequired() | ||||
|                             ->requiresAtLeastOneElement() | ||||
|                             ->defaultValue( | ||||
|                                     array( | ||||
|                                         [ 'label' => '5 minutes',  'seconds' => 300],  | ||||
|                                         [ 'label' => '10 minutes', 'seconds' => 600], | ||||
|                                         [ 'label' => '15 minutes', 'seconds' => 900], | ||||
|                                         [ 'label' => '20 minutes', 'seconds' => 1200], | ||||
|                                         [ 'label' => '25 minutes', 'seconds' => 1500], | ||||
|                                         [ 'label' => '30 minutes', 'seconds' => 1800], | ||||
|                                         [ 'label' => '45 minutes', 'seconds' => 2700], | ||||
|                                         [ 'label' => '1 hour',     'seconds' => 3600], | ||||
|                                         [ 'label' => '1 hour 15',  'seconds' => 4500], | ||||
|                                         [ 'label' => '1 hour 30',  'seconds' => 5400], | ||||
|                                         [ 'label' => '1 hour 45',  'seconds' => 6300], | ||||
|                                         [ 'label' => '2 hours',    'seconds' => 7200], | ||||
|                                         ) | ||||
|                                     ) | ||||
|                             ->info('The intervals of time to show in activity form') | ||||
|  | ||||
|                             ->prototype('array') | ||||
|                                 ->children() | ||||
|                                     ->scalarNode('seconds') | ||||
|                                         ->info("The number of seconds of this duration. Must be an integer.") | ||||
|                                         ->cannotBeEmpty() | ||||
|                                         ->validate() | ||||
|                                             ->ifTrue(function($data) { | ||||
|                                                 return !is_int($data); | ||||
|                                             })->thenInvalid("The value %s is not a valid integer") | ||||
|                                         ->end() | ||||
|                                     ->end() | ||||
|                                     ->scalarNode('label') | ||||
|                                         ->cannotBeEmpty() | ||||
|                                         ->info("The label to show into fields") | ||||
|                                     ->end() | ||||
|                                 ->end() | ||||
|  | ||||
|                             ->end() | ||||
| //                            ->validate() | ||||
| // | ||||
| //                             | ||||
| //                                ->ifTrue(function ($data) { | ||||
| //                                    // test this is an array | ||||
| //                                    if (!is_array($data)) { | ||||
| @@ -95,10 +84,11 @@ class Configuration implements ConfigurationInterface | ||||
| //                                    }) | ||||
| //                                    ->thenInvalid("The data are invalid. The keys must be a string and the value integers") | ||||
| //                            ->end() | ||||
|             ->end() | ||||
|             ->end() | ||||
|             ->end() | ||||
|             ->end(); | ||||
|                             ->end() | ||||
|                         ->end() | ||||
|                  | ||||
|                     ->end() | ||||
|                 ->end(); | ||||
|  | ||||
|         return $treeBuilder; | ||||
|     } | ||||
|   | ||||
| @@ -1,333 +1,556 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Chill\MainBundle\Entity\Center; | ||||
| use Chill\DocStoreBundle\Entity\Document; | ||||
| use Chill\DocStoreBundle\Entity\StoredObject; | ||||
| use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; | ||||
| use Chill\MainBundle\Entity\HasCenterInterface; | ||||
| use Chill\MainBundle\Entity\HasScopeInterface; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialIssue; | ||||
| use Chill\ThirdPartyBundle\Entity\ThirdParty; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Chill\MainBundle\Entity\Scope; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency; | ||||
| use Chill\MainBundle\Entity\Center; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use DateTime; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Chill\MainBundle\Entity\HasCenterInterface; | ||||
| use Chill\MainBundle\Entity\HasScopeInterface; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Chill\MainBundle\Validator\Constraints\Entity\UserCircleConsistency; | ||||
| use Symfony\Component\Serializer\Annotation\Groups; | ||||
| use Symfony\Component\Serializer\Annotation\DiscriminatorMap; | ||||
|  | ||||
| /** | ||||
|  * @ORM\Entity | ||||
|  * Class Activity | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity(repositoryClass="Chill\ActivityBundle\Repository\ActivityRepository") | ||||
|  * @ORM\Table(name="activity") | ||||
|  * @ORM\HasLifecycleCallbacks | ||||
|  * @UserCircleConsistency( | ||||
|  *     "CHILL_ACTIVITY_SEE_DETAILS", | ||||
|  *     getUserFunction="getUser", | ||||
|  * path="scope") | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  * @DiscriminatorMap(typeProperty="type", mapping={ | ||||
|  *  "activity"=Activity::class | ||||
|  *  }) | ||||
|  */ | ||||
|  | ||||
| /* | ||||
|  * TODO : revoir | ||||
|  * @UserCircleConsistency( | ||||
|  *      "CHILL_ACTIVITY_SEE_DETAILS", | ||||
|  *      getUserFunction="getUser", | ||||
|  *      path="scope") | ||||
|  */ | ||||
|  | ||||
| class Activity implements HasCenterInterface, HasScopeInterface | ||||
| { | ||||
|     const SENTRECEIVED_SENT = 'sent'; | ||||
|     const SENTRECEIVED_RECEIVED = 'received'; | ||||
|  | ||||
|     /** | ||||
|      * @var bool | ||||
|      * @ORM\Column(type="boolean") | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
|      * @ORM\GeneratedValue(strategy="AUTO") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private $attendee; | ||||
|     private ?int $id = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") | ||||
|      */ | ||||
|     private User $user; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="datetime") | ||||
|      */ | ||||
|     private \DateTime $date; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="time", nullable=true) | ||||
|      */ | ||||
|     private ?\DateTime $durationTime = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="time", nullable=true) | ||||
|      */ | ||||
|     private ?\DateTime $travelTime = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence") | ||||
|      */ | ||||
|     private ?ActivityPresence $attendee = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") | ||||
|      */ | ||||
|     private Collection $reasons; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialIssue") | ||||
|      * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private Collection $socialIssues; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction") | ||||
|      * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private Collection $socialActions; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") | ||||
|      */ | ||||
|     private ActivityType $type; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope") | ||||
|      */ | ||||
|     private ?Scope $scope = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") | ||||
|      */ | ||||
|     private ?Person $person = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private ?AccompanyingPeriod $accompanyingPeriod = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") | ||||
|      */ | ||||
|     private $comment; | ||||
|     private CommentEmbeddable $comment; | ||||
|  | ||||
|     /** | ||||
|      * @var DateTime | ||||
|      * @ORM\Column(type="datetime") | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\Person") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private $date; | ||||
|     private ?Collection $persons = null; | ||||
|  | ||||
|     /** | ||||
|      * @var DateTime | ||||
|      * @ORM\Column(type="time") | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private $durationTime; | ||||
|     private ?Collection $thirdParties = null; | ||||
|  | ||||
|     /** | ||||
|      * @var int | ||||
|      * | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
|      * @ORM\GeneratedValue(strategy="AUTO") | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\DocStoreBundle\Entity\StoredObject") | ||||
|      */ | ||||
|     private $id; | ||||
|     private Collection $documents; | ||||
|  | ||||
|     /** | ||||
|      * @var Person | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\Person") | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User") | ||||
|      * @Groups({"read"}) | ||||
|      */ | ||||
|     private $person; | ||||
|     private ?Collection $users = null; | ||||
|  | ||||
|     /** | ||||
|      * @var ActivityReason | ||||
|      * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") | ||||
|      * @ORM\Column(type="boolean", options={"default"=false}) | ||||
|      */ | ||||
|     private $reasons; | ||||
|     private bool $emergency = false; | ||||
|  | ||||
|     /** | ||||
|      * @var Scope | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope") | ||||
|      * @ORM\Column(type="string", options={"default"=""}) | ||||
|      */ | ||||
|     private $scope; | ||||
|     private string $sentReceived = ''; | ||||
|  | ||||
|     /** | ||||
|      * @var ActivityType | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") | ||||
|      */ | ||||
|     private $type; | ||||
|  | ||||
|     /** | ||||
|      * @var User | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") | ||||
|      */ | ||||
|     private $user; | ||||
|  | ||||
|     /** | ||||
|      * Activity constructor. | ||||
|      */ | ||||
|     public function __construct() | ||||
|     { | ||||
|         $this->reasons = new ArrayCollection(); | ||||
|         $this->comment = new CommentEmbeddable(); | ||||
|         $this->persons = new ArrayCollection(); | ||||
|         $this->thirdParties = new ArrayCollection(); | ||||
|         $this->documents = new ArrayCollection(); | ||||
|         $this->users = new ArrayCollection(); | ||||
|         $this->socialIssues = new ArrayCollection(); | ||||
|         $this->socialActions = new ArrayCollection(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add a reason. | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function addReason(ActivityReason $reason) | ||||
|     { | ||||
|         $this->reasons[] = $reason; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get attendee. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function getAttendee() | ||||
|     { | ||||
|         return $this->attendee; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * get the center | ||||
|      * center is extracted from person. | ||||
|      * | ||||
|      * @return Center | ||||
|      */ | ||||
|     public function getCenter() | ||||
|     { | ||||
|         return $this->person->getCenter(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable | ||||
|      */ | ||||
|     public function getComment() | ||||
|     { | ||||
|         return $this->comment; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get date. | ||||
|      * | ||||
|      * @return DateTime | ||||
|      */ | ||||
|     public function getDate() | ||||
|     { | ||||
|         return $this->date; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get durationTime. | ||||
|      * | ||||
|      * @return DateTime | ||||
|      */ | ||||
|     public function getDurationTime() | ||||
|     { | ||||
|         return $this->durationTime; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get id. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getId() | ||||
|     public function getId(): ?int | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get person. | ||||
|      * | ||||
|      * @return Person | ||||
|      */ | ||||
|     public function getPerson() | ||||
|     public function setUser(User $user): self | ||||
|     { | ||||
|         return $this->person; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get reasons. | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function getReasons() | ||||
|     { | ||||
|         return $this->reasons; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get scope. | ||||
|      * | ||||
|      * @return Scope | ||||
|      */ | ||||
|     public function getScope() | ||||
|     { | ||||
|         return $this->scope; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get type. | ||||
|      * | ||||
|      * @return ActivityType | ||||
|      */ | ||||
|     public function getType() | ||||
|     { | ||||
|         return $this->type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get user. | ||||
|      * | ||||
|      * @return User | ||||
|      */ | ||||
|     public function getUser() | ||||
|     { | ||||
|         return $this->user; | ||||
|     } | ||||
|  | ||||
|     public function removeReason(ActivityReason $reason) | ||||
|     { | ||||
|         $this->reasons->removeElement($reason); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set attendee. | ||||
|      * | ||||
|      * @param bool $attendee | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setAttendee($attendee) | ||||
|     { | ||||
|         $this->attendee = $attendee; | ||||
|         $this->user = $user; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param \Chill\MainBundle\Entity\Embeddalbe\CommentEmbeddable $comment | ||||
|      */ | ||||
|     public function setComment($comment) | ||||
|     public function getUser(): User | ||||
|     { | ||||
|         $this->comment = $comment; | ||||
|         return $this->user; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set date. | ||||
|      * | ||||
|      * @param DateTime $date | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setDate($date) | ||||
|     public function setDate(\DateTime $date): self | ||||
|     { | ||||
|         $this->date = $date; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set durationTime. | ||||
|      * | ||||
|      * @param DateTime $durationTime | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setDurationTime($durationTime) | ||||
|     public function getDate(): \DateTime | ||||
|     { | ||||
|         return $this->date; | ||||
|     } | ||||
|  | ||||
|     public function setDurationTime(?\DateTime $durationTime): self | ||||
|     { | ||||
|         $this->durationTime = $durationTime; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set person. | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setPerson(Person $person) | ||||
|     public function getDurationTime(): ?\DateTime | ||||
|     { | ||||
|         $this->person = $person; | ||||
|         return $this->durationTime; | ||||
|     } | ||||
|  | ||||
|     public function setTravelTime(\DateTime $travelTime): self | ||||
|     { | ||||
|         $this->travelTime = $travelTime; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set scope. | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setScope(Scope $scope) | ||||
|     public function getTravelTime(): ?\DateTime | ||||
|     { | ||||
|         $this->scope = $scope; | ||||
|         return $this->travelTime; | ||||
|     } | ||||
|  | ||||
|     public function setAttendee(ActivityPresence $attendee): self | ||||
|     { | ||||
|         $this->attendee = $attendee; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set type. | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setType(ActivityType $type) | ||||
|     public function getAttendee(): ?ActivityPresence | ||||
|     { | ||||
|         return $this->attendee; | ||||
|     } | ||||
|  | ||||
|     public function addReason(ActivityReason $reason): self | ||||
|     { | ||||
|         $this->reasons->add($reason); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeReason(ActivityReason $reason): void | ||||
|     { | ||||
|         $this->reasons->removeElement($reason); | ||||
|     } | ||||
|  | ||||
|     public function getReasons(): Collection | ||||
|     { | ||||
|         return $this->reasons; | ||||
|     } | ||||
|  | ||||
|     public function setReasons(?ArrayCollection $reasons): self | ||||
|     { | ||||
|         $this->reasons = $reasons; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialIssues(): Collection | ||||
|     { | ||||
|         return $this->socialIssues; | ||||
|     } | ||||
|  | ||||
|     public function addSocialIssue(SocialIssue $socialIssue): self | ||||
|     { | ||||
|         if (!$this->socialIssues->contains($socialIssue)) { | ||||
|             $this->socialIssues[] = $socialIssue; | ||||
|         } | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeSocialIssue(SocialIssue $socialIssue): self | ||||
|     { | ||||
|         $this->socialIssues->removeElement($socialIssue); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialActions(): Collection | ||||
|     { | ||||
|         return $this->socialActions; | ||||
|     } | ||||
|  | ||||
|     public function addSocialAction(SocialAction $socialAction): self | ||||
|     { | ||||
|         if (!$this->socialActions->contains($socialAction)) { | ||||
|             $this->socialActions[] = $socialAction; | ||||
|         } | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeSocialAction(SocialAction $socialAction): self | ||||
|     { | ||||
|         $this->socialActions->removeElement($socialAction); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     public function setType(ActivityType $type): self | ||||
|     { | ||||
|         $this->type = $type; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set user. | ||||
|      * | ||||
|      * @return Activity | ||||
|      */ | ||||
|     public function setUser(User $user) | ||||
|     public function getType(): ActivityType | ||||
|     { | ||||
|         $this->user = $user; | ||||
|         return $this->type; | ||||
|     } | ||||
|  | ||||
|     public function setScope(Scope $scope): self | ||||
|     { | ||||
|         $this->scope = $scope; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getScope(): ?Scope | ||||
|     { | ||||
|         return $this->scope; | ||||
|     } | ||||
|  | ||||
|     public function setPerson(?Person $person): self | ||||
|     { | ||||
|         $this->person = $person; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPerson(): ?Person | ||||
|     { | ||||
|         return $this->person; | ||||
|     } | ||||
|  | ||||
|     public function getAccompanyingPeriod(): ?AccompanyingPeriod | ||||
|     { | ||||
|         return $this->accompanyingPeriod; | ||||
|     } | ||||
|  | ||||
|     public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self | ||||
|     { | ||||
|         $this->accompanyingPeriod = $accompanyingPeriod; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * get the center | ||||
|      * center is extracted from person | ||||
|      */ | ||||
|     public function getCenter(): ?Center | ||||
|     { | ||||
|         if ($this->person instanceof Person) { | ||||
|             return $this->person->getCenter(); | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public function getComment(): CommentEmbeddable | ||||
|     { | ||||
|         return $this->comment; | ||||
|     } | ||||
|  | ||||
|     public function setComment(CommentEmbeddable $comment): self | ||||
|     { | ||||
|         $this->comment = $comment; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Add a person to the person list | ||||
|      */ | ||||
|     public function addPerson(?Person $person): self | ||||
|     { | ||||
|         if (null !== $person) { | ||||
|             $this->persons[] = $person; | ||||
|         } | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removePerson(Person $person): void | ||||
|     { | ||||
|         $this->persons->removeElement($person); | ||||
|     } | ||||
|  | ||||
|     public function getPersons(): Collection | ||||
|     { | ||||
|         return $this->persons; | ||||
|     } | ||||
|  | ||||
|     public function getPersonsAssociated(): array  | ||||
|     { | ||||
|         if (null !== $this->accompanyingPeriod) { | ||||
|             $personsAssociated = []; | ||||
|             foreach ($this->accompanyingPeriod->getParticipations() as $participation) { | ||||
|                 if ($this->persons->contains($participation->getPerson())) { | ||||
|                     $personsAssociated[] = $participation->getPerson(); | ||||
|                 } | ||||
|             } | ||||
|             return $personsAssociated;  | ||||
|         } | ||||
|         return []; | ||||
|     } | ||||
|      | ||||
|     public function getPersonsNotAssociated(): array | ||||
|     { | ||||
|         if (null !== $this->accompanyingPeriod) { | ||||
|             $personsNotAssociated = []; | ||||
|             foreach ($this->persons as $person) { | ||||
|                 if (!in_array($person, $this->getPersonsAssociated())) { | ||||
|                      $personsNotAssociated[] = $person; | ||||
|                 } | ||||
|             } | ||||
|             return $personsNotAssociated; | ||||
|         } | ||||
|         return []; | ||||
|     }     | ||||
|  | ||||
|     public function setPersons(?Collection $persons): self | ||||
|     { | ||||
|         $this->persons = $persons; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function addThirdParty(?ThirdParty $thirdParty): self | ||||
|     { | ||||
|         if (null !== $thirdParty) { | ||||
|            $this->thirdParties[] = $thirdParty; | ||||
|         } | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeThirdParty(ThirdParty $thirdParty): void | ||||
|     { | ||||
|         $this->thirdParties->removeElement($thirdParty); | ||||
|     } | ||||
|  | ||||
|     public function getThirdParties(): Collection | ||||
|     { | ||||
|         return $this->thirdParties; | ||||
|     } | ||||
|  | ||||
|     public function setThirdParties(?Collection $thirdParties): self | ||||
|     { | ||||
|         $this->thirdParties = $thirdParties; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function addDocument(Document $document): self | ||||
|     { | ||||
|         $this->documents[] = $document; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeDocument(Document $document): void | ||||
|     { | ||||
|         $this->documents->removeElement($document); | ||||
|     } | ||||
|  | ||||
|     public function getDocuments(): Collection | ||||
|     { | ||||
|         return $this->documents; | ||||
|     } | ||||
|  | ||||
|     public function setDocuments(Collection $documents): self | ||||
|     { | ||||
|         $this->documents = $documents; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function addUser(?User $user): self | ||||
|     { | ||||
|         if (null !== $user) { | ||||
|             $this->users[] = $user; | ||||
|         } | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function removeUser(User $user): void | ||||
|     { | ||||
|         $this->users->removeElement($user); | ||||
|     } | ||||
|  | ||||
|     public function getUsers(): Collection | ||||
|     { | ||||
|         return $this->users; | ||||
|     } | ||||
|  | ||||
|     public function setUsers(?Collection $users): self | ||||
|     { | ||||
|         $this->users = $users; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function isEmergency(): bool | ||||
|     { | ||||
|         return $this->getEmergency(); | ||||
|     } | ||||
|  | ||||
|     public function getEmergency(): bool | ||||
|     { | ||||
|         return $this->emergency; | ||||
|     } | ||||
|  | ||||
|     public function setEmergency(bool $emergency): self | ||||
|     { | ||||
|         $this->emergency = $emergency; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSentReceived(): string | ||||
|     { | ||||
|         return $this->sentReceived; | ||||
|     } | ||||
|  | ||||
|     public function setSentReceived(?string $sentReceived): self | ||||
|     { | ||||
|         $this->sentReceived = (string) $sentReceived; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										97
									
								
								src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|  * Class ActivityPresence | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity() | ||||
|  * @ORM\Table(name="activitytpresence") | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  */ | ||||
| class ActivityPresence | ||||
| { | ||||
|     /** | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
|      * @ORM\GeneratedValue(strategy="AUTO") | ||||
|      */ | ||||
|     private ?int $id; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="json") | ||||
|      */ | ||||
|     private array $name = []; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private bool $active = true; | ||||
|  | ||||
|     public function getId(): int | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     public function setName(array $name): self | ||||
|     { | ||||
|         $this->name = $name; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getName(): array | ||||
|     { | ||||
|         return $this->name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get active | ||||
|      * return true if the category type is active. | ||||
|      */ | ||||
|     public function getActive(): bool | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is active | ||||
|      * return true if the category type is active | ||||
|      */ | ||||
|     public function isActive(): bool | ||||
|     { | ||||
|         return $this->getActive(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set active | ||||
|      * set to true if the category type is active | ||||
|      */ | ||||
|     public function setActive(bool $active): self | ||||
|     { | ||||
|         $this->active = $active; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
| @@ -1,43 +1,40 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
| /* | ||||
|  *  | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Chill\ActivityBundle\Entity\ActivityReasonCategory; | ||||
|  | ||||
| /** | ||||
|  * @ORM\Entity | ||||
|  * Class ActivityReason | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity() | ||||
|  * @ORM\Table(name="activityreason") | ||||
|  * @ORM\HasLifecycleCallbacks | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  */ | ||||
| class ActivityReason | ||||
| { | ||||
|     /** | ||||
|      * @var bool | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private $active = true; | ||||
|  | ||||
|     /** | ||||
|      * @var ActivityReasonCategory | ||||
|      * @ORM\ManyToOne( | ||||
|      *     targetEntity="Chill\ActivityBundle\Entity\ActivityReasonCategory", | ||||
|      * inversedBy="reasons") | ||||
|      */ | ||||
|     private $category; | ||||
|  | ||||
|     /** | ||||
|      * @var int | ||||
|      * @var integer | ||||
|      * | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
| @@ -52,17 +49,86 @@ class ActivityReason | ||||
|     private $name; | ||||
|  | ||||
|     /** | ||||
|      * Get active. | ||||
|      * | ||||
|      * @return bool | ||||
|      * @var ActivityReasonCategory | ||||
|      * @ORM\ManyToOne( | ||||
|      *     targetEntity="Chill\ActivityBundle\Entity\ActivityReasonCategory", | ||||
|      *     inversedBy="reasons") | ||||
|      */ | ||||
|     public function getActive() | ||||
|     private $category; | ||||
|  | ||||
|     /** | ||||
|      * @var boolean | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private $active = true; | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Get id | ||||
|      * | ||||
|      * @return integer | ||||
|      */ | ||||
|     public function getId() | ||||
|     { | ||||
|         return $this->active; | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get category. | ||||
|      * Set name | ||||
|      * | ||||
|      * @param array $name | ||||
|      * @return ActivityReason | ||||
|      */ | ||||
|     public function setName($name) | ||||
|     { | ||||
|         $this->name = $name; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name | ||||
|      * | ||||
|      * @return array | string | ||||
|      */ | ||||
|     public function getName($locale = null) | ||||
|     { | ||||
|         if ($locale) { | ||||
|             if (isset($this->name[$locale])) { | ||||
|                 return $this->name[$locale]; | ||||
|             } else { | ||||
|                 foreach ($this->name as $name) { | ||||
|                     if (!empty($name)) { | ||||
|                         return $name; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             return ''; | ||||
|         } else { | ||||
|             return $this->name; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Set category of the reason. If you set to the reason an inactive | ||||
|      * category, the reason will become inactive | ||||
|      * | ||||
|      * @param ActivityReasonCategory $category | ||||
|      * @return ActivityReason | ||||
|      */ | ||||
|     public function setCategory(ActivityReasonCategory $category) | ||||
|     { | ||||
|         if($this->category !== $category && ! $category->getActive()) { | ||||
|             $this->setActive(False); | ||||
|         } | ||||
|          | ||||
|         $this->category = $category; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get category | ||||
|      * | ||||
|      * @return ActivityReasonCategory | ||||
|      */ | ||||
| @@ -72,46 +138,9 @@ class ActivityReason | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get id. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getId() | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name. | ||||
|      * | ||||
|      * @param mixed|null $locale | ||||
|      * | ||||
|      * @return array | string | ||||
|      */ | ||||
|     public function getName($locale = null) | ||||
|     { | ||||
|         if ($locale) { | ||||
|             if (isset($this->name[$locale])) { | ||||
|                 return $this->name[$locale]; | ||||
|             } | ||||
|  | ||||
|             foreach ($this->name as $name) { | ||||
|                 if (!empty($name)) { | ||||
|                     return $name; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return ''; | ||||
|         } | ||||
|  | ||||
|         return $this->name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set active. | ||||
|      * | ||||
|      * @param bool $active | ||||
|      * Set active | ||||
|      * | ||||
|      * @param boolean $active | ||||
|      * @return ActivityReason | ||||
|      */ | ||||
|     public function setActive($active) | ||||
| @@ -122,33 +151,13 @@ class ActivityReason | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set category of the reason. If you set to the reason an inactive | ||||
|      * category, the reason will become inactive. | ||||
|      * Get active | ||||
|      * | ||||
|      * @return ActivityReason | ||||
|      * @return boolean | ||||
|      */ | ||||
|     public function setCategory(ActivityReasonCategory $category) | ||||
|     public function getActive() | ||||
|     { | ||||
|         if ($this->category !== $category && !$category->getActive()) { | ||||
|             $this->setActive(false); | ||||
|         } | ||||
|  | ||||
|         $this->category = $category; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set name. | ||||
|      * | ||||
|      * @param array $name | ||||
|      * | ||||
|      * @return ActivityReason | ||||
|      */ | ||||
|     public function setName($name) | ||||
|     { | ||||
|         $this->name = $name; | ||||
|  | ||||
|         return $this; | ||||
|         return $this->active; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,36 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
| /* | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
|  | ||||
| /** | ||||
|  * @ORM\Entity | ||||
|  * Class ActivityReasonCategory | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity() | ||||
|  * @ORM\Table(name="activityreasoncategory") | ||||
|  * @ORM\HasLifecycleCallbacks | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  */ | ||||
| class ActivityReasonCategory | ||||
| { | ||||
|     /** | ||||
|      * @var bool | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private $active = true; | ||||
|  | ||||
|     /** | ||||
|      * @var int | ||||
|      * @var integer | ||||
|      * | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
| @@ -45,15 +48,20 @@ class ActivityReasonCategory | ||||
|     private $name; | ||||
|  | ||||
|     /** | ||||
|      * Array of ActivityReason. | ||||
|      * | ||||
|      * @var boolean | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private $active = true; | ||||
|      | ||||
|     /** | ||||
|      * Array of ActivityReason | ||||
|      * @var ArrayCollection | ||||
|      * @ORM\OneToMany( | ||||
|      *     targetEntity="Chill\ActivityBundle\Entity\ActivityReason", | ||||
|      * mappedBy="category") | ||||
|      *     mappedBy="category") | ||||
|      */ | ||||
|     private $reasons; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * ActivityReasonCategory constructor. | ||||
|      */ | ||||
| @@ -61,29 +69,19 @@ class ActivityReasonCategory | ||||
|     { | ||||
|         $this->reasons = new ArrayCollection(); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function __toString() | ||||
|     { | ||||
|         return 'ActivityReasonCategory(' . $this->getName('x') . ')'; | ||||
|         return 'ActivityReasonCategory('.$this->getName('x').')'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get active. | ||||
|      * Get id | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function getActive() | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get id. | ||||
|      * | ||||
|      * @return int | ||||
|      * @return integer | ||||
|      */ | ||||
|     public function getId() | ||||
|     { | ||||
| @@ -91,58 +89,9 @@ class ActivityReasonCategory | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name. | ||||
|      * | ||||
|      * @param mixed|null $locale | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getName($locale = null) | ||||
|     { | ||||
|         if ($locale) { | ||||
|             if (isset($this->name[$locale])) { | ||||
|                 return $this->name[$locale]; | ||||
|             } | ||||
|  | ||||
|             foreach ($this->name as $name) { | ||||
|                 if (!empty($name)) { | ||||
|                     return $name; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return ''; | ||||
|         } | ||||
|  | ||||
|         return $this->name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Declare a category as active (or not). When a category is set | ||||
|      * as unactive, all the reason have this entity as category is also | ||||
|      * set as unactive. | ||||
|      * | ||||
|      * @param bool $active | ||||
|      * | ||||
|      * @return ActivityReasonCategory | ||||
|      */ | ||||
|     public function setActive($active) | ||||
|     { | ||||
|         if ($this->active !== $active && !$active) { | ||||
|             foreach ($this->reasons as $reason) { | ||||
|                 $reason->setActive($active); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $this->active = $active; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set name. | ||||
|      * Set name | ||||
|      * | ||||
|      * @param array $name | ||||
|      * | ||||
|      * @return ActivityReasonCategory | ||||
|      */ | ||||
|     public function setName($name) | ||||
| @@ -151,4 +100,59 @@ class ActivityReasonCategory | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getName($locale = null) | ||||
|     { | ||||
|         if ($locale) { | ||||
|             if (isset($this->name[$locale])) { | ||||
|                 return $this->name[$locale]; | ||||
|             } else { | ||||
|                 foreach ($this->name as $name) { | ||||
|                     if (!empty($name)) { | ||||
|                         return $name; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             return ''; | ||||
|         } else { | ||||
|             return $this->name; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Declare a category as active (or not). When a category is set | ||||
|      * as unactive, all the reason have this entity as category is also | ||||
|      * set as unactive | ||||
|      * | ||||
|      * @param boolean $active | ||||
|      * @return ActivityReasonCategory | ||||
|      */ | ||||
|     public function setActive($active) | ||||
|     { | ||||
|         if($this->active !== $active && !$active) { | ||||
|             foreach ($this->reasons as $reason) { | ||||
|                 $reason->setActive($active); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         $this->active = $active; | ||||
|          | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get active | ||||
|      * | ||||
|      * @return boolean | ||||
|      */ | ||||
|     public function getActive() | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,131 +1,822 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|  * @ORM\Entity | ||||
|  * Class ActivityType | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity() | ||||
|  * @ORM\Table(name="activitytype") | ||||
|  * @ORM\HasLifecycleCallbacks | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  */ | ||||
| class ActivityType | ||||
| { | ||||
|     /** | ||||
|      * @var bool | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private $active = true; | ||||
|     const FIELD_INVISIBLE = 0; | ||||
|     const FIELD_OPTIONAL = 1; | ||||
|     const FIELD_REQUIRED = 2; | ||||
|  | ||||
|     /** | ||||
|      * @var int | ||||
|      * | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
|      * @ORM\GeneratedValue(strategy="AUTO") | ||||
|      */ | ||||
|     private $id; | ||||
|     private ?int $id; | ||||
|  | ||||
|     /** | ||||
|      * @var array | ||||
|      * @ORM\Column(type="json_array") | ||||
|      */ | ||||
|     private $name; | ||||
|     private array $name = []; | ||||
|  | ||||
|     /** | ||||
|      * Get active | ||||
|      * return true if the type is active. | ||||
|      * | ||||
|      * @return bool | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     public function getActive() | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
|     private bool $active = true; | ||||
|  | ||||
|     /** | ||||
|      * Get id. | ||||
|      * | ||||
|      * @return int | ||||
|      * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityTypeCategory") | ||||
|      */ | ||||
|     public function getId() | ||||
|     private ?ActivityTypeCategory $category = null; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=2}) | ||||
|      */ | ||||
|     private int $personVisible = self::FIELD_REQUIRED; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $personLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=2}) | ||||
|      */ | ||||
|     private int $userVisible = self::FIELD_REQUIRED; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $userLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=2}) | ||||
|      */ | ||||
|     private int $dateVisible = self::FIELD_REQUIRED; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $dateLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $placeVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $placeLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $personsVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $personsLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $thirdPartiesVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $thirdPartiesLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $durationTimeVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $durationTimeLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $travelTimeVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $travelTimeLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $attendeeVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $attendeeLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $reasonsVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $reasonsLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $commentVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $commentLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $sentReceivedVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $sentReceivedLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $documentsVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $documentsLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $usersVisible = self::FIELD_OPTIONAL; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $usersLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $emergencyVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $emergencyLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $accompanyingPeriodVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $accompanyingPeriodLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $socialDataVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $socialDataLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $socialIssuesVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $socialIssuesLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) | ||||
|      */ | ||||
|     private int $socialActionsVisible = self::FIELD_INVISIBLE; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="string", nullable=false, options={"default"=""}) | ||||
|      */ | ||||
|     private string $socialActionsLabel = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="float", options={"default"="0.0"}) | ||||
|      */ | ||||
|     private float $ordering = 0.0; | ||||
|  | ||||
|     /** | ||||
|      * Get id | ||||
|      */ | ||||
|     public function getId(): int | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name. | ||||
|      * | ||||
|      * @param mixed|null $locale | ||||
|      * | ||||
|      * @return array | string | ||||
|      * Set name | ||||
|      */ | ||||
|     public function getName($locale = null) | ||||
|     public function setName(array $name): self | ||||
|     { | ||||
|         if ($locale) { | ||||
|             if (isset($this->name[$locale])) { | ||||
|                 return $this->name[$locale]; | ||||
|             } | ||||
|         $this->name = $name; | ||||
|  | ||||
|             foreach ($this->name as $name) { | ||||
|                 if (!empty($name)) { | ||||
|                     return $name; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             return ''; | ||||
|         } | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name | ||||
|      */ | ||||
|     public function getName(): array | ||||
|     { | ||||
|         return $this->name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is active | ||||
|      * Get active | ||||
|      * return true if the type is active. | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isActive() | ||||
|     public function getActive(): bool | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is active | ||||
|      * return true if the type is active | ||||
|      */ | ||||
|     public function isActive(): bool | ||||
|     { | ||||
|         return $this->getActive(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set active | ||||
|      * set to true if the type is active. | ||||
|      * | ||||
|      * @param bool $active | ||||
|      * | ||||
|      * @return ActivityType | ||||
|      * set to true if the type is active | ||||
|      */ | ||||
|     public function setActive($active) | ||||
|     public function setActive(bool $active): self | ||||
|     { | ||||
|         $this->active = $active; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set name. | ||||
|      * | ||||
|      * @param array $name | ||||
|      * | ||||
|      * @return ActivityType | ||||
|      */ | ||||
|     public function setName($name) | ||||
|     public function getCategory(): ?ActivityTypeCategory | ||||
|     { | ||||
|         $this->name = $name; | ||||
|         return $this->category; | ||||
|     } | ||||
|  | ||||
|     public function setCategory(?ActivityTypeCategory $category): self | ||||
|     { | ||||
|         $this->category = $category; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPersonVisible(): int | ||||
|     { | ||||
|         return $this->personVisible; | ||||
|     } | ||||
|  | ||||
|     public function setPersonVisible(int $personVisible): self | ||||
|     { | ||||
|         $this->personVisible = $personVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPersonLabel(): string | ||||
|     { | ||||
|         return $this->personLabel; | ||||
|     } | ||||
|  | ||||
|     public function setPersonLabel(string $personLabel): self | ||||
|     { | ||||
|         $this->personLabel = $personLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getUserVisible(): int | ||||
|     { | ||||
|         return $this->userVisible; | ||||
|     } | ||||
|  | ||||
|     public function setUserVisible(int $userVisible): self | ||||
|     { | ||||
|         $this->userVisible = $userVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getUserLabel(): string | ||||
|     { | ||||
|         return $this->userLabel; | ||||
|     } | ||||
|  | ||||
|     public function setUserLabel(string $userLabel): self | ||||
|     { | ||||
|         $this->userLabel = $userLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDateVisible(): int | ||||
|     { | ||||
|         return $this->dateVisible; | ||||
|     } | ||||
|  | ||||
|     public function setDateVisible(int $dateVisible): self | ||||
|     { | ||||
|         $this->dateVisible = $dateVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDateLabel(): string | ||||
|     { | ||||
|         return $this->dateLabel; | ||||
|     } | ||||
|  | ||||
|     public function setDateLabel(string $dateLabel): self | ||||
|     { | ||||
|         $this->dateLabel = $dateLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPlaceVisible(): int | ||||
|     { | ||||
|         return $this->placeVisible; | ||||
|     } | ||||
|  | ||||
|     public function setPlaceVisible(int $placeVisible): self | ||||
|     { | ||||
|         $this->placeVisible = $placeVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPlaceLabel(): string | ||||
|     { | ||||
|         return $this->placeLabel; | ||||
|     } | ||||
|  | ||||
|     public function setPlaceLabel(string $placeLabel): self | ||||
|     { | ||||
|         $this->placeLabel = $placeLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPersonsVisible(): int | ||||
|     { | ||||
|         return $this->personsVisible; | ||||
|     } | ||||
|  | ||||
|     public function setPersonsVisible(int $personsVisible): self | ||||
|     { | ||||
|         $this->personsVisible = $personsVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getPersonsLabel(): string | ||||
|     { | ||||
|         return $this->personsLabel; | ||||
|     } | ||||
|  | ||||
|     public function setPersonsLabel(string $personsLabel): self | ||||
|     { | ||||
|         $this->personsLabel = $personsLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getThirdPartiesVisible(): int | ||||
|     { | ||||
|         return $this->thirdPartiesVisible; | ||||
|     } | ||||
|  | ||||
|     public function setThirdPartiesVisible(int $thirdPartiesVisible): self | ||||
|     { | ||||
|         $this->thirdPartiesVisible = $thirdPartiesVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getThirdPartiesLabel(): string | ||||
|     { | ||||
|         return $this->thirdPartiesLabel; | ||||
|     } | ||||
|  | ||||
|     public function setThirdPartiesLabel(string $thirdPartiesLabel): self | ||||
|     { | ||||
|         $this->thirdPartiesLabel = $thirdPartiesLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDurationTimeVisible(): int | ||||
|     { | ||||
|         return $this->durationTimeVisible; | ||||
|     } | ||||
|  | ||||
|     public function setDurationTimeVisible(int $durationTimeVisible): self | ||||
|     { | ||||
|         $this->durationTimeVisible = $durationTimeVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDurationTimeLabel(): string | ||||
|     { | ||||
|         return $this->durationTimeLabel; | ||||
|     } | ||||
|  | ||||
|     public function setDurationTimeLabel(string $durationTimeLabel): self | ||||
|     { | ||||
|         $this->durationTimeLabel = $durationTimeLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getTravelTimeVisible(): int | ||||
|     { | ||||
|         return $this->travelTimeVisible; | ||||
|     } | ||||
|  | ||||
|     public function setTravelTimeVisible(int $TravelTimeVisible): self | ||||
|     { | ||||
|         $this->travelTimeVisible = $TravelTimeVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getTravelTimeLabel(): string | ||||
|     { | ||||
|         return $this->travelTimeLabel; | ||||
|     } | ||||
|  | ||||
|     public function setTravelTimeLabel(string $TravelTimeLabel): self | ||||
|     { | ||||
|         $this->travelTimeLabel = $TravelTimeLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getAttendeeVisible(): int | ||||
|     { | ||||
|         return $this->attendeeVisible; | ||||
|     } | ||||
|  | ||||
|     public function setAttendeeVisible(int $attendeeVisible): self | ||||
|     { | ||||
|         $this->attendeeVisible = $attendeeVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getAttendeeLabel(): string | ||||
|     { | ||||
|         return $this->attendeeLabel; | ||||
|     } | ||||
|  | ||||
|     public function setAttendeeLabel(string $attendeeLabel): self | ||||
|     { | ||||
|         $this->attendeeLabel = $attendeeLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getReasonsVisible(): int | ||||
|     { | ||||
|         return $this->reasonsVisible; | ||||
|     } | ||||
|  | ||||
|     public function setReasonsVisible(int $reasonsVisible): self | ||||
|     { | ||||
|         $this->reasonsVisible = $reasonsVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getReasonsLabel(): string | ||||
|     { | ||||
|         return $this->reasonsLabel; | ||||
|     } | ||||
|  | ||||
|     public function setReasonsLabel(string $reasonsLabel): self | ||||
|     { | ||||
|         $this->reasonsLabel = $reasonsLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getCommentVisible(): int | ||||
|     { | ||||
|         return $this->commentVisible; | ||||
|     } | ||||
|  | ||||
|     public function setCommentVisible(int $commentVisible): self | ||||
|     { | ||||
|         $this->commentVisible = $commentVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getCommentLabel(): string | ||||
|     { | ||||
|         return $this->commentLabel; | ||||
|     } | ||||
|  | ||||
|     public function setCommentLabel(string $commentLabel): self | ||||
|     { | ||||
|         $this->commentLabel = $commentLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSentReceivedVisible(): int | ||||
|     { | ||||
|         return $this->sentReceivedVisible; | ||||
|     } | ||||
|  | ||||
|     public function setSentReceivedVisible(int $sentReceivedVisible): self | ||||
|     { | ||||
|         $this->sentReceivedVisible = $sentReceivedVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSentReceivedLabel(): string | ||||
|     { | ||||
|         return $this->sentReceivedLabel; | ||||
|     } | ||||
|  | ||||
|     public function setSentReceivedLabel(string $sentReceivedLabel): self | ||||
|     { | ||||
|         $this->sentReceivedLabel = $sentReceivedLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDocumentsVisible(): int | ||||
|     { | ||||
|         return $this->documentsVisible; | ||||
|     } | ||||
|  | ||||
|     public function setDocumentsVisible(int $documentsVisible): self | ||||
|     { | ||||
|         $this->documentsVisible = $documentsVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getDocumentsLabel(): string | ||||
|     { | ||||
|         return $this->documentsLabel; | ||||
|     } | ||||
|  | ||||
|     public function setDocumentsLabel(string $documentsLabel): self | ||||
|     { | ||||
|         $this->documentsLabel = $documentsLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getUsersVisible(): int | ||||
|     { | ||||
|         return $this->usersVisible; | ||||
|     } | ||||
|  | ||||
|     public function setUsersVisible(int $usersVisible): self | ||||
|     { | ||||
|         $this->usersVisible = $usersVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getUsersLabel(): string | ||||
|     { | ||||
|         return $this->usersLabel; | ||||
|     } | ||||
|  | ||||
|     public function setUsersLabel(string $usersLabel): self | ||||
|     { | ||||
|         $this->usersLabel = $usersLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getEmergencyVisible(): int | ||||
|     { | ||||
|         return $this->emergencyVisible; | ||||
|     } | ||||
|  | ||||
|     public function setEmergencyVisible(int $emergencyVisible): self | ||||
|     { | ||||
|         $this->emergencyVisible = $emergencyVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getEmergencyLabel(): string | ||||
|     { | ||||
|         return $this->emergencyLabel; | ||||
|     } | ||||
|  | ||||
|     public function setEmergencyLabel(string $emergencyLabel): self | ||||
|     { | ||||
|         $this->emergencyLabel = $emergencyLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getAccompanyingPeriodVisible(): int | ||||
|     { | ||||
|         return $this->accompanyingPeriodVisible; | ||||
|     } | ||||
|  | ||||
|     public function setAccompanyingPeriodVisible(int $accompanyingPeriodVisible): self | ||||
|     { | ||||
|         $this->accompanyingPeriodVisible = $accompanyingPeriodVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getAccompanyingPeriodLabel(): string | ||||
|     { | ||||
|         return $this->accompanyingPeriodLabel; | ||||
|     } | ||||
|  | ||||
|     public function setAccompanyingPeriodLabel(string $accompanyingPeriodLabel): self | ||||
|     { | ||||
|         $this->accompanyingPeriodLabel = $accompanyingPeriodLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialDataVisible(): int | ||||
|     { | ||||
|         return $this->socialDataVisible; | ||||
|     } | ||||
|  | ||||
|     public function setSocialDataVisible(int $socialDataVisible): self | ||||
|     { | ||||
|         $this->socialDataVisible = $socialDataVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialDataLabel(): string | ||||
|     { | ||||
|         return $this->socialDataLabel; | ||||
|     } | ||||
|  | ||||
|     public function setSocialDataLabel(string $socialDataLabel): self | ||||
|     { | ||||
|         $this->socialDataLabel = $socialDataLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function isVisible(string $field): bool | ||||
|     { | ||||
|         $property = $field.'Visible'; | ||||
|  | ||||
|         if (!property_exists($this, $property)) { | ||||
|             throw new \InvalidArgumentException('Field "'.$field.'" not found'); | ||||
|         } | ||||
|  | ||||
|         return self::FIELD_INVISIBLE !== $this->$property; | ||||
|     } | ||||
|  | ||||
|     public function isRequired(string $field): bool | ||||
|     { | ||||
|         $property = $field.'Visible'; | ||||
|  | ||||
|         if (!property_exists($this, $property)) { | ||||
|             throw new \InvalidArgumentException('Field "'.$field.'" not found'); | ||||
|         } | ||||
|  | ||||
|         return self::FIELD_REQUIRED === $this->$property; | ||||
|     } | ||||
|  | ||||
|     public function getLabel(string $field): ?string | ||||
|     { | ||||
|         $property = $field.'Label'; | ||||
|  | ||||
|         if (!property_exists($this, $property)) { | ||||
|             throw new \InvalidArgumentException('Field "'.$field.'" not found'); | ||||
|         } | ||||
|  | ||||
|         return $this->$property; | ||||
|     } | ||||
|  | ||||
|     public function getOrdering(): float | ||||
|     { | ||||
|         return $this->ordering; | ||||
|     } | ||||
|  | ||||
|     public function setOrdering(float $ordering): self | ||||
|     { | ||||
|         $this->ordering = $ordering; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialIssuesVisible(): ?int | ||||
|     { | ||||
|         return $this->socialIssuesVisible; | ||||
|     } | ||||
|  | ||||
|     public function setSocialIssuesVisible(int $socialIssuesVisible): self | ||||
|     { | ||||
|         $this->socialIssuesVisible = $socialIssuesVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialIssuesLabel(): ?string | ||||
|     { | ||||
|         return $this->socialIssuesLabel; | ||||
|     } | ||||
|  | ||||
|     public function setSocialIssuesLabel(string $socialIssuesLabel): self | ||||
|     { | ||||
|         $this->socialIssuesLabel = $socialIssuesLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialActionsVisible(): ?int | ||||
|     { | ||||
|         return $this->socialActionsVisible; | ||||
|     } | ||||
|  | ||||
|     public function setSocialActionsVisible(int $socialActionsVisible): self | ||||
|     { | ||||
|         $this->socialActionsVisible = $socialActionsVisible; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getSocialActionsLabel(): ?string | ||||
|     { | ||||
|         return $this->socialActionsLabel; | ||||
|     } | ||||
|  | ||||
|     public function setSocialActionsLabel(string $socialActionsLabel): self | ||||
|     { | ||||
|         $this->socialActionsLabel = $socialActionsLabel; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										123
									
								
								src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,123 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * | ||||
|  * Copyright (C) 2015, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Entity; | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|  * Class ActivityTypeCateogry | ||||
|  * | ||||
|  * @package Chill\ActivityBundle\Entity | ||||
|  * @ORM\Entity() | ||||
|  * @ORM\Table(name="activitytypecategory") | ||||
|  * @ORM\HasLifecycleCallbacks() | ||||
|  */ | ||||
| class ActivityTypeCategory | ||||
| { | ||||
|     /** | ||||
|      * @ORM\Id | ||||
|      * @ORM\Column(name="id", type="integer") | ||||
|      * @ORM\GeneratedValue(strategy="AUTO") | ||||
|      */ | ||||
|     private ?int $id; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="json_array") | ||||
|      */ | ||||
|     private array $name = []; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="boolean") | ||||
|      */ | ||||
|     private bool $active = true; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="float", options={"default"="0.0"}) | ||||
|      */ | ||||
|     private float $ordering = 0.0; | ||||
|  | ||||
|     /** | ||||
|      * Get id | ||||
|      */ | ||||
|     public function getId(): int | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set name | ||||
|      */ | ||||
|     public function setName(array $name): self | ||||
|     { | ||||
|         $this->name = $name; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get name | ||||
|      */ | ||||
|     public function getName(): array | ||||
|     { | ||||
|         return $this->name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get active | ||||
|      * return true if the category type is active. | ||||
|      */ | ||||
|     public function getActive(): bool | ||||
|     { | ||||
|         return $this->active; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Is active | ||||
|      * return true if the category type is active | ||||
|      */ | ||||
|     public function isActive(): bool | ||||
|     { | ||||
|         return $this->getActive(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Set active | ||||
|      * set to true if the category type is active | ||||
|      */ | ||||
|     public function setActive(bool $active): self | ||||
|     { | ||||
|         $this->active = $active; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getOrdering(): float | ||||
|     { | ||||
|         return $this->ordering; | ||||
|     } | ||||
|  | ||||
|     public function setOrdering(float $ordering): self | ||||
|     { | ||||
|         $this->ordering = $ordering; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
| @@ -1,103 +1,107 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2016 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Aggregator; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use RuntimeException; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
|  | ||||
| use function array_key_exists; | ||||
| use function count; | ||||
|  | ||||
| class ActivityReasonAggregator implements | ||||
|     AggregatorInterface, | ||||
| /** | ||||
|  * | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ActivityReasonAggregator implements AggregatorInterface, | ||||
|     ExportElementValidatedInterface | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $categoryRepository; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $reasonRepository; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $stringHelper; | ||||
|  | ||||
|     public function __construct( | ||||
|         EntityRepository $categoryRepository, | ||||
|         EntityRepository $reasonRepository, | ||||
|         TranslatableStringHelper $stringHelper | ||||
|             EntityRepository $categoryRepository, | ||||
|             EntityRepository $reasonRepository, | ||||
|             TranslatableStringHelper $stringHelper | ||||
|     ) { | ||||
|         $this->categoryRepository = $categoryRepository; | ||||
|         $this->reasonRepository = $reasonRepository; | ||||
|         $this->stringHelper = $stringHelper; | ||||
|     } | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|         $this->reasonRepository   = $reasonRepository; | ||||
|         $this->stringHelper       = $stringHelper; | ||||
|     } | ||||
|  | ||||
|     public function alterQuery(QueryBuilder $qb, $data) | ||||
|     { | ||||
|         // add select element | ||||
|         if ('reasons' === $data['level']) { | ||||
|         if ($data['level'] === 'reasons') { | ||||
|             $elem = 'reasons.id'; | ||||
|             $alias = 'activity_reasons_id'; | ||||
|         } elseif ('categories' === $data['level']) { | ||||
|         } elseif ($data['level'] === 'categories') { | ||||
|             $elem = 'category.id'; | ||||
|             $alias = 'activity_categories_id'; | ||||
|         } else { | ||||
|             throw new RuntimeException('the data provided are not recognized'); | ||||
|             throw new \RuntimeException('the data provided are not recognized'); | ||||
|         } | ||||
|  | ||||
|         $qb->addSelect($elem . ' as ' . $alias); | ||||
|         $qb->addSelect($elem.' as '.$alias); | ||||
|  | ||||
|         // make a jointure only if needed | ||||
|         $join = $qb->getDQLPart('join'); | ||||
|  | ||||
|         if ( | ||||
|             ( | ||||
|                 array_key_exists('activity', $join) | ||||
|             && !$this->checkJoinAlreadyDefined($join['activity'], 'reasons') | ||||
|             (array_key_exists('activity', $join) | ||||
|             && | ||||
|             !$this->checkJoinAlreadyDefined($join['activity'], 'reasons') | ||||
|             ) | ||||
|             || (!array_key_exists('activity', $join)) | ||||
|             OR | ||||
|             (! array_key_exists('activity', $join)) | ||||
|         ) { | ||||
|             $qb->add( | ||||
|                 'join', | ||||
|                 ['activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons'), | ||||
|                 ], | ||||
|                 true | ||||
|             ); | ||||
|                     'join', | ||||
|                     array('activity' => | ||||
|                         new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons') | ||||
|                         ), | ||||
|                     true); | ||||
|         } | ||||
|  | ||||
|         // join category if necessary | ||||
|         if ('activity_categories_id' === $alias) { | ||||
|         if ($alias === 'activity_categories_id') { | ||||
|             // add join only if needed | ||||
|             if (!$this->checkJoinAlreadyDefined($qb->getDQLPart('join')['activity'], 'category')) { | ||||
|                 $qb->join('reasons.category', 'category'); | ||||
| @@ -114,107 +118,12 @@ class ActivityReasonAggregator implements | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function applyOn() | ||||
|     { | ||||
|         return 'activity'; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('level', ChoiceType::class, [ | ||||
|             'choices' => [ | ||||
|                 'By reason' => 'reasons', | ||||
|                 'By category of reason' => 'categories', | ||||
|             ], | ||||
|             'multiple' => false, | ||||
|             'expanded' => true, | ||||
|             'label' => 'Reason\'s level', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         // for performance reason, we load data from db only once | ||||
|         switch ($data['level']) { | ||||
|             case 'reasons': | ||||
|                 $this->reasonRepository->findBy(['id' => $values]); | ||||
|  | ||||
|                 break; | ||||
|             case 'categories': | ||||
|                 $this->categoryRepository->findBy(['id' => $values]); | ||||
|  | ||||
|                 break; | ||||
|  | ||||
|             default: | ||||
|                 throw new RuntimeException(sprintf( | ||||
|                     "the level data '%s' is invalid", | ||||
|                     $data['level'] | ||||
|                 )); | ||||
|         } | ||||
|  | ||||
|         return function ($value) use ($data) { | ||||
|             if ('_header' === $value) { | ||||
|                 return 'reasons' === $data['level'] ? | ||||
|                         'Group by reasons' | ||||
|                         : | ||||
|                         'Group by categories of reason'; | ||||
|             } | ||||
|  | ||||
|             switch ($data['level']) { | ||||
|                 case 'reasons': | ||||
|                     /** @var \Chill\ActivityBundle\Entity\ActivityReason $r */ | ||||
|                     $r = $this->reasonRepository->find($value); | ||||
|  | ||||
|                     return $this->stringHelper->localize($r->getCategory()->getName()) | ||||
|                             . ' > ' | ||||
|                             . $this->stringHelper->localize($r->getName()); | ||||
|  | ||||
|                     break; | ||||
|                 case 'categories': | ||||
|                     $c = $this->categoryRepository->find($value); | ||||
|  | ||||
|                     return $this->stringHelper->localize($c->getName()); | ||||
|  | ||||
|                     break; | ||||
|                 // no need for a default : the default was already set above | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         // add select element | ||||
|         if ('reasons' === $data['level']) { | ||||
|             return ['activity_reasons_id']; | ||||
|         } | ||||
|  | ||||
|         if ('categories' === $data['level']) { | ||||
|             return ['activity_categories_id']; | ||||
|         } | ||||
|  | ||||
|         throw new RuntimeException('the data provided are not recognised'); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Aggregate by activity reason'; | ||||
|     } | ||||
|  | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if (null === $data['level']) { | ||||
|             $context->buildViolation("The reasons's level should not be empty") | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if a join between Activity and another alias. | ||||
|      * Check if a join between Activity and another alias | ||||
|      * | ||||
|      * @param Join[] $joins | ||||
|      * @param string $alias the alias to search for | ||||
|      * | ||||
|      * @return bool | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|     { | ||||
| @@ -226,4 +135,99 @@ class ActivityReasonAggregator implements | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public function applyOn() | ||||
|     { | ||||
|         return 'activity'; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('level', ChoiceType::class, array( | ||||
|             'choices' => array( | ||||
|                 'By reason'             => 'reasons', | ||||
|                 'By category of reason' => 'categories' | ||||
|             ), | ||||
|             'multiple' => false, | ||||
|             'expanded' => true, | ||||
|             'label' => 'Reason\'s level' | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if ($data['level'] === null) { | ||||
|             $context->buildViolation("The reasons's level should not be empty") | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|         public function getTitle() | ||||
|     { | ||||
|         return "Aggregate by activity reason"; | ||||
|     } | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         // for performance reason, we load data from db only once | ||||
|         switch ($data['level']) { | ||||
|             case 'reasons': | ||||
|                 $this->reasonRepository->findBy(array('id' => $values)); | ||||
|                 break; | ||||
|             case 'categories': | ||||
|                 $this->categoryRepository->findBy(array('id' => $values)); | ||||
|                 break; | ||||
|             default: | ||||
|                 throw new \RuntimeException(sprintf("the level data '%s' is invalid", | ||||
|                             $data['level'])); | ||||
|         } | ||||
|  | ||||
|         return function($value) use ($data) { | ||||
|             if ($value === '_header') { | ||||
|                 return $data['level'] === 'reasons' ? | ||||
|                         'Group by reasons' | ||||
|                         : | ||||
|                         'Group by categories of reason' | ||||
|                         ; | ||||
|             } | ||||
|  | ||||
|             switch ($data['level']) { | ||||
|                 case 'reasons': | ||||
|                     /* @var $r \Chill\ActivityBundle\Entity\ActivityReason */ | ||||
|                     $r = $this->reasonRepository->find($value); | ||||
|  | ||||
|                     return $this->stringHelper->localize($r->getCategory()->getName()) | ||||
|                             ." > " | ||||
|                             . $this->stringHelper->localize($r->getName()); | ||||
|                         ; | ||||
|                     break; | ||||
|                 case 'categories': | ||||
|                     $c = $this->categoryRepository->find($value); | ||||
|  | ||||
|                     return $this->stringHelper->localize($c->getName()); | ||||
|                     break; | ||||
|                 // no need for a default : the default was already set above | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         // add select element | ||||
|         if ($data['level'] === 'reasons') { | ||||
|             return array('activity_reasons_id'); | ||||
|         } elseif ($data['level'] === 'categories') { | ||||
|             return array ('activity_categories_id'); | ||||
|         } else { | ||||
|             throw new \RuntimeException('the data provided are not recognised'); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,62 +1,89 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2016 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Aggregator; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ActivityTypeAggregator implements AggregatorInterface | ||||
| { | ||||
|     public const KEY = 'activity_type_aggregator'; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $stringHelper; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $typeRepository; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $stringHelper; | ||||
|      | ||||
|     const KEY = 'activity_type_aggregator'; | ||||
|      | ||||
|     public function __construct( | ||||
|         EntityRepository $typeRepository, | ||||
|         TranslatableStringHelper $stringHelper | ||||
|             EntityRepository $typeRepository, | ||||
|             TranslatableStringHelper $stringHelper | ||||
|     ) { | ||||
|         $this->typeRepository = $typeRepository; | ||||
|         $this->stringHelper = $stringHelper; | ||||
|         $this->typeRepository     = $typeRepository; | ||||
|         $this->stringHelper       = $stringHelper; | ||||
|     } | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function alterQuery(QueryBuilder $qb, $data) | ||||
|     { | ||||
|         // add select element | ||||
|         // add select element     | ||||
|         $qb->addSelect(sprintf('IDENTITY(activity.type) AS %s', self::KEY)); | ||||
|  | ||||
|          | ||||
|         // add the "group by" part | ||||
|         $groupBy = $qb->addGroupBy(self::KEY); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Check if a join between Activity and another alias | ||||
|      *  | ||||
|      * @param Join[] $joins | ||||
|      * @param string $alias the alias to search for | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public function applyOn() | ||||
|     { | ||||
| @@ -68,49 +95,37 @@ class ActivityTypeAggregator implements AggregatorInterface | ||||
|         // no form required for this aggregator | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return "Aggregate by activity type"; | ||||
|     } | ||||
|      | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         // for performance reason, we load data from db only once | ||||
|         $this->typeRepository->findBy(['id' => $values]); | ||||
|  | ||||
|         return function ($value) { | ||||
|             if ('_header' === $value) { | ||||
|         $this->typeRepository->findBy(array('id' => $values)); | ||||
|          | ||||
|         return function($value) use ($data) { | ||||
|             if ($value === '_header') { | ||||
|                 return 'Activity type'; | ||||
|             } | ||||
|  | ||||
|             /** @var \Chill\ActivityBundle\Entity\ActivityType $r */ | ||||
|             /* @var $r \Chill\ActivityBundle\Entity\ActivityType */ | ||||
|             $t = $this->typeRepository->find($value); | ||||
|  | ||||
|             return $this->stringHelper->localize($t->getName()); | ||||
|         }; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return [self::KEY]; | ||||
|         return array(self::KEY); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Aggregate by activity type'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if a join between Activity and another alias. | ||||
|      * | ||||
|      * @param Join[] $joins | ||||
|      * @param string $alias the alias to search for | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,41 +1,51 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Aggregator; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Closure; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Chill\MainBundle\Export\AggregatorInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Chill\MainBundle\Entity\User; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ActivityUserAggregator implements AggregatorInterface | ||||
| { | ||||
|     public const KEY = 'activity_user_id'; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $em; | ||||
|  | ||||
|     public function __construct(EntityManagerInterface $em) | ||||
|      | ||||
|     const KEY = 'activity_user_id'; | ||||
|      | ||||
|     function __construct(EntityManagerInterface $em) | ||||
|     { | ||||
|         $this->em = $em; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
| @@ -43,9 +53,9 @@ class ActivityUserAggregator implements AggregatorInterface | ||||
|  | ||||
|     public function alterQuery(QueryBuilder $qb, $data) | ||||
|     { | ||||
|         // add select element | ||||
|         // add select element     | ||||
|         $qb->addSelect(sprintf('IDENTITY(activity.user) AS %s', self::KEY)); | ||||
|  | ||||
|          | ||||
|         // add the "group by" part | ||||
|         $qb->addGroupBy(self::KEY); | ||||
|     } | ||||
| @@ -60,17 +70,16 @@ class ActivityUserAggregator implements AggregatorInterface | ||||
|         // nothing to add | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, $values, $data): Closure | ||||
|     public function getLabels($key, $values, $data): \Closure | ||||
|     { | ||||
|         // preload users at once | ||||
|         $this->em->getRepository(User::class) | ||||
|             ->findBy(['id' => $values]); | ||||
|  | ||||
|         return function ($value) { | ||||
|          | ||||
|         return function($value) { | ||||
|             switch ($value) { | ||||
|                 case '_header': | ||||
|                     return 'activity user'; | ||||
|  | ||||
|                 default: | ||||
|                     return $this->em->getRepository(User::class)->find($value) | ||||
|                         ->getUsername(); | ||||
| @@ -80,11 +89,11 @@ class ActivityUserAggregator implements AggregatorInterface | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return [self::KEY]; | ||||
|         return [ self::KEY ]; | ||||
|     } | ||||
|  | ||||
|     public function getTitle(): string | ||||
|     { | ||||
|         return 'Aggregate by activity user'; | ||||
|         return "Aggregate by activity user"; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,79 +1,64 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2015 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Export; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\ExportInterface; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\Query; | ||||
| use LogicException; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\ORM\Query; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class CountActivity implements ExportInterface | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         EntityManagerInterface $em | ||||
|     ) { | ||||
|             EntityManagerInterface $em | ||||
|             ) | ||||
|     { | ||||
|         $this->entityManager = $em; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return [\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR]; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public function getDescription() | ||||
|     { | ||||
|         return 'Count activities by various parameters.'; | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         if ('export_count_activity' !== $key) { | ||||
|             throw new LogicException("the key {$key} is not used by this export"); | ||||
|         } | ||||
|  | ||||
|         return static function ($value) { | ||||
|             return '_header' === $value ? | ||||
|                     'Number of activities' | ||||
|                     : | ||||
|                     $value; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return ['export_count_activity']; | ||||
|     } | ||||
|  | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|         return "Count activities by various parameters."; | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Count activities'; | ||||
|         return "Count activities"; | ||||
|     } | ||||
|  | ||||
|     public function getType() | ||||
| @@ -81,30 +66,61 @@ class CountActivity implements ExportInterface | ||||
|         return 'activity'; | ||||
|     } | ||||
|  | ||||
|     public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) | ||||
|     public function initiateQuery(array $requiredModifiers,  array $acl, array $data = array()) | ||||
|     { | ||||
|         $qb = $this->entityManager->createQueryBuilder(); | ||||
|         $centers = array_map(static function ($el) { | ||||
|             return $el['center']; | ||||
|         }, $acl); | ||||
|  | ||||
|         $centers = array_map(function($el) { return $el['center']; }, $acl); | ||||
|          | ||||
|         $qb->select('COUNT(activity.id) as export_count_activity') | ||||
|             ->from('ChillActivityBundle:Activity', 'activity') | ||||
|             ->join('activity.person', 'person'); | ||||
|  | ||||
|                 ->from('ChillActivityBundle:Activity', 'activity') | ||||
|                 ->join('activity.person', 'person') | ||||
|                 ; | ||||
|          | ||||
|         $qb->where($qb->expr()->in('person.center', ':centers')) | ||||
|             ->setParameter('centers', $centers); | ||||
|  | ||||
|             ->setParameter('centers', $centers) | ||||
|             ; | ||||
|          | ||||
|         return $qb; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function supportsModifiers() | ||||
|     { | ||||
|         return array('person', 'activity'); | ||||
|     } | ||||
|      | ||||
|     public function requiredRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|     public function supportsModifiers() | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return ['person', 'activity']; | ||||
|         return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR); | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         if ($key !== 'export_count_activity') { | ||||
|             throw new \LogicException("the key $key is not used by this export"); | ||||
|         } | ||||
|          | ||||
|         return function($value) { | ||||
|             return $value === '_header' ?  | ||||
|                     'Number of activities' | ||||
|                     : | ||||
|                     $value | ||||
|                     ; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return array('export_count_activity'); | ||||
|     } | ||||
|  | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,48 +1,69 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2017 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Export; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\FormatterInterface; | ||||
| use Chill\MainBundle\Export\ListInterface; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Chill\MainBundle\Entity\Scope; | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use DateTime; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\Query; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Symfony\Component\Translation\TranslatorInterface; | ||||
| use Symfony\Component\Validator\Constraints\Callback; | ||||
| use Doctrine\ORM\Query; | ||||
| use Chill\MainBundle\Export\FormatterInterface; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
|  | ||||
| use function array_key_exists; | ||||
| use function count; | ||||
| use function in_array; | ||||
|  | ||||
| /** | ||||
|  * Create a list for all activities. | ||||
|  * Create a list for all activities | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ListActivity implements ListInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|  | ||||
|     protected $fields = [ | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|     protected $fields = array( | ||||
|         'id', | ||||
|         'date', | ||||
|         'durationTime', | ||||
| @@ -53,132 +74,115 @@ class ListActivity implements ListInterface | ||||
|         'type_name', | ||||
|         'person_firstname', | ||||
|         'person_lastname', | ||||
|         'person_id', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|         'person_id' | ||||
|     ); | ||||
|  | ||||
|     public function __construct( | ||||
|         EntityManagerInterface $em, | ||||
|         TranslatorInterface $translator, | ||||
|         TranslatableStringHelper $translatableStringHelper | ||||
|     ) { | ||||
|             EntityManagerInterface $em, | ||||
|             TranslatorInterface $translator, | ||||
|             TranslatableStringHelper $translatableStringHelper | ||||
|             ) | ||||
|     { | ||||
|         $this->entityManager = $em; | ||||
|         $this->translator = $translator; | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * {@inheritDoc} | ||||
|      * | ||||
|      * @param FormBuilderInterface $builder | ||||
|      */ | ||||
|     public function buildForm(FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('fields', ChoiceType::class, [ | ||||
|         $builder->add('fields', ChoiceType::class, array( | ||||
|             'multiple' => true, | ||||
|             'expanded' => true, | ||||
|             'choices' => array_combine($this->fields, $this->fields), | ||||
|             'label' => 'Fields to include in export', | ||||
|             'constraints' => [new Callback([ | ||||
|                 'callback' => static function ($selected, ExecutionContextInterface $context) { | ||||
|             'label'    => 'Fields to include in export', | ||||
|             'constraints' => [new Callback(array( | ||||
|                 'callback' => function($selected, ExecutionContextInterface $context) { | ||||
|                     if (count($selected) === 0) { | ||||
|                         $context->buildViolation('You must select at least one element') | ||||
|                             ->atPath('fields') | ||||
|                             ->addViolation(); | ||||
|                     } | ||||
|                 }, | ||||
|             ])], | ||||
|         ]); | ||||
|                 } | ||||
|             ))] | ||||
|         )); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      * {@inheritDoc} | ||||
|      * | ||||
|      * @return type | ||||
|      */ | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return [FormatterInterface::TYPE_LIST]; | ||||
|         return array(FormatterInterface::TYPE_LIST); | ||||
|     } | ||||
|  | ||||
|     public function getDescription() | ||||
|     { | ||||
|         return 'List activities'; | ||||
|         return "List activities"; | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         switch ($key) { | ||||
|             case 'date': | ||||
|                 return static function ($value) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return 'date'; | ||||
|                     } | ||||
|         switch ($key) | ||||
|         { | ||||
|             case 'date' : | ||||
|                 return function($value) { | ||||
|                     if ($value === '_header') return 'date'; | ||||
|  | ||||
|                     $date = DateTime::createFromFormat('Y-m-d H:i:s', $value); | ||||
|                     $date = \DateTime::createFromFormat('Y-m-d H:i:s', $value); | ||||
|  | ||||
|                     return $date->format('d-m-Y'); | ||||
|                 }; | ||||
|             case 'attendee': | ||||
|                 return static function ($value) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return 'attendee'; | ||||
|                     } | ||||
|                 return function($value) { | ||||
|                     if ($value === '_header') return 'attendee'; | ||||
|  | ||||
|                     return $value ? 1 : 0; | ||||
|                 }; | ||||
|             case 'list_reasons': | ||||
|                 /** @var EntityRepository $activityReasonsRepository */ | ||||
|             case 'list_reasons' : | ||||
|                 /* @var $activityReasonsRepository EntityRepository */ | ||||
|                 $activityRepository = $this->entityManager | ||||
|                     ->getRepository('ChillActivityBundle:Activity'); | ||||
|  | ||||
|                 return function ($value) use ($activityRepository) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return 'activity reasons'; | ||||
|                     } | ||||
|                 return function($value) use ($activityRepository) { | ||||
|                     if ($value === '_header') return 'activity reasons'; | ||||
|  | ||||
|                     $activity = $activityRepository | ||||
|                         ->find($value); | ||||
|                             ->find($value); | ||||
|  | ||||
|                     return implode(', ', array_map(function (ActivityReason $r) { | ||||
|                         return '"' . | ||||
|                     return implode(", ", array_map(function(ActivityReason $r) { | ||||
|  | ||||
|                         return '"'. | ||||
|                                 $this->translatableStringHelper->localize($r->getCategory()->getName()) | ||||
|                                 . ' > ' . | ||||
|                                 .' > '. | ||||
|                                 $this->translatableStringHelper->localize($r->getName()) | ||||
|                                 . '"'; | ||||
|                                 .'"'; | ||||
|                     }, $activity->getReasons()->toArray())); | ||||
|                 }; | ||||
|             case 'circle_name': | ||||
|                 return function ($value) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return 'circle'; | ||||
|                     } | ||||
|             case 'circle_name' : | ||||
|                 return function($value) { | ||||
|                     if ($value === '_header') return 'circle'; | ||||
|  | ||||
|                     return $this->translatableStringHelper | ||||
|                         ->localize(json_decode($value, true)); | ||||
|                             ->localize(json_decode($value, true)); | ||||
|                 }; | ||||
|             case 'type_name': | ||||
|                 return function ($value) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return 'activity type'; | ||||
|                     } | ||||
|             case 'type_name' : | ||||
|                 return function($value) { | ||||
|                     if ($value === '_header') return 'activity type'; | ||||
|  | ||||
|                     return $this->translatableStringHelper | ||||
|                         ->localize(json_decode($value, true)); | ||||
|                             ->localize(json_decode($value, true)); | ||||
|                 }; | ||||
|  | ||||
|             default: | ||||
|                 return static function ($value) use ($key) { | ||||
|                     if ('_header' === $value) { | ||||
|                         return $key; | ||||
|                     } | ||||
|                 return function($value) use ($key) { | ||||
|                     if ($value === '_header') return $key; | ||||
|  | ||||
|                     return $value; | ||||
|                 }; | ||||
| @@ -205,76 +209,68 @@ class ListActivity implements ListInterface | ||||
|         return 'activity'; | ||||
|     } | ||||
|  | ||||
|     public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) | ||||
|     public function initiateQuery(array $requiredModifiers, array $acl, array $data = array()) | ||||
|     { | ||||
|         $centers = array_map(static function ($el) { | ||||
|             return $el['center']; | ||||
|         }, $acl); | ||||
|         $centers = array_map(function($el) { return $el['center']; }, $acl); | ||||
|  | ||||
|         // throw an error if any fields are present | ||||
|         if (!array_key_exists('fields', $data)) { | ||||
|             throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields ' | ||||
|                 . 'have been checked'); | ||||
|         if (!\array_key_exists('fields', $data)) { | ||||
|             throw new \Doctrine\DBAL\Exception\InvalidArgumentException("any fields " | ||||
|                 . "have been checked"); | ||||
|         } | ||||
|  | ||||
|         $qb = $this->entityManager->createQueryBuilder(); | ||||
|  | ||||
|         $qb | ||||
|             ->from('ChillActivityBundle:Activity', 'activity') | ||||
|             ->join('activity.person', 'person') | ||||
|             ->join('person.center', 'center') | ||||
|             ->andWhere('center IN (:authorized_centers)') | ||||
|             ->setParameter('authorized_centers', $centers); | ||||
|                 ->from('ChillActivityBundle:Activity', 'activity') | ||||
|                 ->join('activity.person', 'person') | ||||
|                 ->join('person.center', 'center') | ||||
|                 ->andWhere('center IN (:authorized_centers)') | ||||
|                 ->setParameter('authorized_centers', $centers); | ||||
|                 ; | ||||
|  | ||||
|         foreach ($this->fields as $f) { | ||||
|             if (in_array($f, $data['fields'], true)) { | ||||
|             if (in_array($f, $data['fields'])) { | ||||
|                 switch ($f) { | ||||
|                     case 'id': | ||||
|                         $qb->addSelect('activity.id AS id'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'person_firstname': | ||||
|                         $qb->addSelect('person.firstName AS person_firstname'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'person_lastname': | ||||
|                         $qb->addSelect('person.lastName AS person_lastname'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'person_id': | ||||
|                         $qb->addSelect('person.id AS person_id'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'user_username': | ||||
|                         $qb->join('activity.user', 'user'); | ||||
|                         $qb->addSelect('user.username AS user_username'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'circle_name': | ||||
|                         $qb->join('activity.scope', 'circle'); | ||||
|                         $qb->addSelect('circle.name AS circle_name'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'type_name': | ||||
|                         $qb->join('activity.type', 'type'); | ||||
|                         $qb->addSelect('type.name AS type_name'); | ||||
|  | ||||
|                         break; | ||||
|                     case 'list_reasons': | ||||
|                         // this is a trick... The reasons is filled with the | ||||
|                         // activity id which will be used to load reasons | ||||
|                         $qb->addSelect('activity.id AS list_reasons'); | ||||
|  | ||||
|                         break; | ||||
|  | ||||
|                     default: | ||||
|                         $qb->addSelect(sprintf('activity.%s as %s', $f, $f)); | ||||
|  | ||||
|                         break; | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
|  | ||||
|         return $qb; | ||||
|     } | ||||
|  | ||||
| @@ -285,6 +281,7 @@ class ListActivity implements ListInterface | ||||
|  | ||||
|     public function supportsModifiers() | ||||
|     { | ||||
|         return ['activity', 'person']; | ||||
|         return array('activity', 'person'); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,109 +1,89 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2015 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Export; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\ExportInterface; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
| use Doctrine\ORM\Query; | ||||
| use LogicException; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\ORM\Query; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
|  | ||||
| /** | ||||
|  * This export allow to compute stats on activity duration. | ||||
|  * | ||||
|  *  | ||||
|  * The desired stat must be given in constructor. | ||||
|  * | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class StatActivityDuration implements ExportInterface | ||||
| { | ||||
|     public const SUM = 'sum'; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|      | ||||
|     const SUM = 'sum'; | ||||
|      | ||||
|     /** | ||||
|      * The action for this report. | ||||
|      * | ||||
|      * @var string | ||||
|      */ | ||||
|     protected $action; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * @var EntityManagerInterface | ||||
|      */ | ||||
|     protected $entityManager; | ||||
|  | ||||
|     /** | ||||
|      * constructor. | ||||
|      * | ||||
|      * constructor | ||||
|      *  | ||||
|      * @param EntityManagerInterface $em | ||||
|      * @param string $action the stat to perform | ||||
|      */ | ||||
|     public function __construct( | ||||
|         EntityManagerInterface $em, | ||||
|         $action = 'sum' | ||||
|     ) { | ||||
|             EntityManagerInterface $em, | ||||
|             $action = 'sum' | ||||
|             ) | ||||
|     { | ||||
|         $this->entityManager = $em; | ||||
|         $this->action = $action; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return [\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR]; | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public function getDescription() | ||||
|     { | ||||
|         if (self::SUM === $this->action) { | ||||
|             return 'Sum activities duration by various parameters.'; | ||||
|         if ($this->action === self::SUM) { | ||||
|             return "Sum activities duration by various parameters."; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         if ('export_stat_activity' !== $key) { | ||||
|             throw new LogicException("the key {$key} is not used by this export"); | ||||
|         } | ||||
|  | ||||
|         switch ($this->action) { | ||||
|             case self::SUM: | ||||
|                 $header = 'Sum of activities  duration'; | ||||
|         } | ||||
|  | ||||
|         return static function ($value) use ($header) { | ||||
|             return '_header' === $value ? | ||||
|                     $header | ||||
|                     : | ||||
|                     $value; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return ['export_stat_activity']; | ||||
|     } | ||||
|  | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         if (self::SUM === $this->action) { | ||||
|             return 'Sum activity duration'; | ||||
|         if ($this->action === self::SUM) { | ||||
|             return "Sum activity duration"; | ||||
|         } | ||||
|          | ||||
|     } | ||||
|  | ||||
|     public function getType() | ||||
| @@ -111,34 +91,69 @@ class StatActivityDuration implements ExportInterface | ||||
|         return 'activity'; | ||||
|     } | ||||
|  | ||||
|     public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) | ||||
|     public function initiateQuery(array $requiredModifiers,  array $acl, array $data = array()) | ||||
|     { | ||||
|         $centers = array_map(static function ($el) { | ||||
|             return $el['center']; | ||||
|         }, $acl); | ||||
|         $centers = array_map(function($el) { return $el['center']; }, $acl); | ||||
|         $qb = $this->entityManager->createQueryBuilder(); | ||||
|  | ||||
|         if (self::SUM === $this->action) { | ||||
|             $select = 'SUM(activity.durationTime) AS export_stat_activity'; | ||||
|          | ||||
|         if ($this->action === self::SUM) { | ||||
|             $select = "SUM(activity.durationTime) AS export_stat_activity"; | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $qb->select($select) | ||||
|             ->from('ChillActivityBundle:Activity', 'activity') | ||||
|             ->join('activity.person', 'person') | ||||
|             ->join('person.center', 'center') | ||||
|             ->where($qb->expr()->in('center', ':centers')) | ||||
|             ->setParameter(':centers', $centers); | ||||
|  | ||||
|                 ->from('ChillActivityBundle:Activity', 'activity') | ||||
|                 ->join('activity.person',  'person') | ||||
|                 ->join('person.center', 'center') | ||||
|                 ->where($qb->expr()->in('center', ':centers')) | ||||
|                 ->setParameter(':centers', $centers) | ||||
|                 ; | ||||
|          | ||||
|         return $qb; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function supportsModifiers() | ||||
|     { | ||||
|         return array('person', 'activity'); | ||||
|     } | ||||
|      | ||||
|     public function requiredRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|     public function supportsModifiers() | ||||
|     public function getAllowedFormattersTypes() | ||||
|     { | ||||
|         return ['person', 'activity']; | ||||
|         return array(\Chill\MainBundle\Export\FormatterInterface::TYPE_TABULAR); | ||||
|     } | ||||
|  | ||||
|     public function getLabels($key, array $values, $data) | ||||
|     { | ||||
|         if ($key !== 'export_stat_activity') { | ||||
|             throw new \LogicException("the key $key is not used by this export"); | ||||
|         } | ||||
|          | ||||
|         switch ($this->action) { | ||||
|             case self::SUM: | ||||
|                 $header = "Sum of activities  duration"; | ||||
|         } | ||||
|          | ||||
|         return function($value) use ($header) { | ||||
|             return $value === '_header' ?  | ||||
|                     $header | ||||
|                     : | ||||
|                     $value | ||||
|                     ; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function getQueryKeys($data) | ||||
|     { | ||||
|         return array('export_stat_activity'); | ||||
|     } | ||||
|  | ||||
|     public function getResult($qb, $data) | ||||
|     { | ||||
|         return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,40 +1,52 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2017 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Filter; | ||||
|  | ||||
| use Chill\MainBundle\Export\FilterInterface; | ||||
| use Chill\MainBundle\Form\Type\Export\FilterType; | ||||
| use DateTime; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
| use Symfony\Component\Form\FormError; | ||||
| use Symfony\Component\Form\FormEvent; | ||||
| use Symfony\Component\Form\FormEvents; | ||||
| use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
| use Symfony\Component\Form\FormError; | ||||
| use Chill\MainBundle\Form\Type\Export\FilterType; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Translation\TranslatorInterface; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ActivityDateFilter implements FilterInterface | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|  | ||||
|     public function __construct(TranslatorInterface $translator) | ||||
|      | ||||
|     function __construct(TranslatorInterface $translator) | ||||
|     { | ||||
|         $this->translator = $translator; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function addRole() | ||||
|     { | ||||
|         return null; | ||||
| @@ -43,18 +55,15 @@ class ActivityDateFilter implements FilterInterface | ||||
|     public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) | ||||
|     { | ||||
|         $where = $qb->getDQLPart('where'); | ||||
|         $clause = $qb->expr()->between( | ||||
|             'activity.date', | ||||
|             ':date_from', | ||||
|             ':date_to' | ||||
|         ); | ||||
|         $clause = $qb->expr()->between('activity.date', ':date_from',  | ||||
|             ':date_to'); | ||||
|  | ||||
|         if ($where instanceof Expr\Andx) { | ||||
|             $where->add($clause); | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $qb->add('where', $where); | ||||
|         $qb->setParameter('date_from', $data['date_from']); | ||||
|         $qb->setParameter('date_to', $data['date_to']); | ||||
| @@ -67,58 +76,55 @@ class ActivityDateFilter implements FilterInterface | ||||
|  | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('date_from', DateType::class, [ | ||||
|             'label' => 'Activities after this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|         $builder->add('date_from', DateType::class, array( | ||||
|             'label' => "Activities after this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('date_to', DateType::class, [ | ||||
|             'label' => 'Activities before this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|         )); | ||||
|          | ||||
|         $builder->add('date_to', DateType::class, array( | ||||
|             'label' => "Activities before this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|  | ||||
|         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { | ||||
|             /** @var \Symfony\Component\Form\FormInterface $filterForm */ | ||||
|         )); | ||||
|          | ||||
|         $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) { | ||||
|             /* @var $filterForm \Symfony\Component\Form\FormInterface */ | ||||
|             $filterForm = $event->getForm()->getParent(); | ||||
|             $enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData(); | ||||
|  | ||||
|             if (true === $enabled) { | ||||
|              | ||||
|             if ($enabled === true) { | ||||
|                 // if the filter is enabled, add some validation | ||||
|                 $form = $event->getForm(); | ||||
|                 $form      = $event->getForm(); | ||||
|                 $date_from = $form->get('date_from')->getData(); | ||||
|                 $date_to = $form->get('date_to')->getData(); | ||||
|  | ||||
|                 $date_to   = $form->get('date_to')->getData(); | ||||
|                  | ||||
|                 // check that fields are not empty | ||||
|                 if (null === $date_from) { | ||||
|                 if ($date_from === null) { | ||||
|                     $form->get('date_from')->addError(new FormError( | ||||
|                         $this->translator->trans('This field ' | ||||
|                         . 'should not be empty') | ||||
|                     )); | ||||
|                         . 'should not be empty'))); | ||||
|                 } | ||||
|  | ||||
|                 if (null === $date_to) { | ||||
|                 if ($date_to   === null) { | ||||
|                     $form->get('date_to')->addError(new FormError( | ||||
|                         $this->translator->trans('This field ' | ||||
|                         . 'should not be empty') | ||||
|                     )); | ||||
|                 } | ||||
|  | ||||
|                         . 'should not be empty'))); | ||||
|                 }  | ||||
|                  | ||||
|                 // check that date_from is before date_to | ||||
|                 if ( | ||||
|                     (null !== $date_from && null !== $date_to) | ||||
|                     && $date_from >= $date_to | ||||
|                     ($date_from !== null && $date_to !== null) | ||||
|                     && | ||||
|                     $date_from >= $date_to | ||||
|                 ) { | ||||
|                     $form->get('date_to')->addError(new FormError( | ||||
|                         $this->translator->trans('This date should be after ' | ||||
|                             . 'the date given in "Implied in an activity after ' | ||||
|                             . 'this date" field') | ||||
|                     )); | ||||
|                             . 'this date" field'))); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
| @@ -126,16 +132,17 @@ class ActivityDateFilter implements FilterInterface | ||||
|  | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         return [ | ||||
|             'Filtered by date of activity: only between %date_from% and %date_to%', | ||||
|             [ | ||||
|                 '%date_from%' => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%' => $data['date_to']->format('d-m-Y'), | ||||
|             ], ]; | ||||
|         return array( | ||||
|             "Filtered by date of activity: only between %date_from% and %date_to%", | ||||
|             array( | ||||
|                 "%date_from%" => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%'   => $data['date_to']->format('d-m-Y') | ||||
|             )); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Filtered by date activity'; | ||||
|         return "Filtered by date activity"; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -1,83 +1,88 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2016 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Filter; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\MainBundle\Export\FilterInterface; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
|  | ||||
| use function array_key_exists; | ||||
| use function count; | ||||
|  | ||||
| class ActivityReasonFilter implements | ||||
|     ExportElementValidatedInterface, | ||||
|     FilterInterface | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ActivityReasonFilter implements FilterInterface, | ||||
|    ExportElementValidatedInterface | ||||
| { | ||||
|     /** | ||||
|      * The repository for activity reasons. | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|      | ||||
|     /** | ||||
|      * The repository for activity reasons | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $reasonRepository; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $helper, | ||||
|         EntityRepository $reasonRepository | ||||
|             TranslatableStringHelper $helper, | ||||
|             EntityRepository $reasonRepository | ||||
|     ) { | ||||
|         $this->translatableStringHelper = $helper; | ||||
|         $this->reasonRepository = $reasonRepository; | ||||
|         $this->reasonRepository         = $reasonRepository; | ||||
|     } | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|      | ||||
|      | ||||
|     public function alterQuery(QueryBuilder $qb, $data) | ||||
|     { | ||||
|         $where = $qb->getDQLPart('where'); | ||||
|         $join = $qb->getDQLPart('join'); | ||||
|         $join  = $qb->getDQLPart('join'); | ||||
|         $clause = $qb->expr()->in('reasons', ':selected_activity_reasons'); | ||||
|         //dump($join); | ||||
|         // add a join to reasons only if needed | ||||
|         if ( | ||||
|             ( | ||||
|                 array_key_exists('activity', $join) | ||||
|             && !$this->checkJoinAlreadyDefined($join['activity'], 'reasons') | ||||
|             (array_key_exists('activity', $join) | ||||
|             && | ||||
|             !$this->checkJoinAlreadyDefined($join['activity'], 'reasons') | ||||
|             ) | ||||
|             || (!array_key_exists('activity', $join)) | ||||
|             OR | ||||
|             (! array_key_exists('activity', $join)) | ||||
|         ) { | ||||
|             $qb->add( | ||||
|                 'join', | ||||
|                 ['activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')], | ||||
|                 true | ||||
|             ); | ||||
|                     'join',  | ||||
|                     array('activity' => new Join(Join::INNER_JOIN, 'activity.reasons', 'reasons')),  | ||||
|                     true | ||||
|                     ); | ||||
|         } | ||||
|  | ||||
|         if ($where instanceof Expr\Andx) { | ||||
| @@ -85,10 +90,27 @@ class ActivityReasonFilter implements | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $qb->add('where', $where); | ||||
|         $qb->setParameter('selected_activity_reasons', $data['reasons']); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Check if a join between Activity and Reason is already defined | ||||
|      *  | ||||
|      * @param Join[] $joins | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public function applyOn() | ||||
|     { | ||||
| @@ -99,63 +121,49 @@ class ActivityReasonFilter implements | ||||
|     { | ||||
|         //create a local copy of translatableStringHelper | ||||
|         $helper = $this->translatableStringHelper; | ||||
|  | ||||
|         $builder->add('reasons', EntityType::class, [ | ||||
|          | ||||
|         $builder->add('reasons', EntityType::class, array( | ||||
|             'class' => 'ChillActivityBundle:ActivityReason', | ||||
|             'choice_label' => static function (ActivityReason $reason) use ($helper) { | ||||
|             'choice_label' => function (ActivityReason $reason) use ($helper) { | ||||
|                 return $helper->localize($reason->getName()); | ||||
|             }, | ||||
|             'group_by' => static function (ActivityReason $reason) use ($helper) { | ||||
|             'group_by' => function(ActivityReason $reason) use ($helper) { | ||||
|                 return $helper->localize($reason->getCategory()->getName()); | ||||
|             }, | ||||
|             'multiple' => true, | ||||
|             'expanded' => false, | ||||
|         ]); | ||||
|             'expanded' => false | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         // collect all the reasons'name used in this filter in one array | ||||
|         $reasonsNames = array_map( | ||||
|             function (ActivityReason $r) { | ||||
|                 return '"' . $this->translatableStringHelper->localize($r->getName()) . '"'; | ||||
|             }, | ||||
|             $this->reasonRepository->findBy(['id' => $data['reasons']->toArray()]) | ||||
|         ); | ||||
|  | ||||
|         return ['Filtered by reasons: only %list%', | ||||
|             ['%list%' => implode(', ', $reasonsNames)], ]; | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Filter by reason'; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if (null === $data['reasons'] || count($data['reasons']) === 0) { | ||||
|             $context->buildViolation('At least one reason must be choosen') | ||||
|         if ($data['reasons'] === null || count($data['reasons']) === 0) { | ||||
|             $context->buildViolation("At least one reason must be choosen") | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if a join between Activity and Reason is already defined. | ||||
|      * | ||||
|      * @param Join[] $joins | ||||
|      * @param mixed $alias | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|         public function getTitle() | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|         return 'Filter by reason'; | ||||
|     } | ||||
|      | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|      | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         // collect all the reasons'name used in this filter in one array | ||||
|         $reasonsNames = array_map( | ||||
|                 function(ActivityReason $r) { | ||||
|                     return "\"".$this->translatableStringHelper->localize($r->getName())."\""; | ||||
|                 }, | ||||
|                 $this->reasonRepository->findBy(array('id' => $data['reasons']->toArray())) | ||||
|                 ); | ||||
|          | ||||
|         return array("Filtered by reasons: only %list%",  | ||||
|             ["%list%" => implode(", ", $reasonsNames)]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,63 +1,67 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2018 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Filter; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\MainBundle\Export\FilterInterface; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr\Join; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
|  | ||||
| use function count; | ||||
|  | ||||
| class ActivityTypeFilter implements | ||||
|     ExportElementValidatedInterface, | ||||
|     FilterInterface | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  */ | ||||
| class ActivityTypeFilter implements FilterInterface, | ||||
|    ExportElementValidatedInterface | ||||
| { | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * The repository for activity reasons. | ||||
|      * The repository for activity reasons | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $typeRepository; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $helper, | ||||
|         EntityRepository $typeRepository | ||||
|             TranslatableStringHelper $helper, | ||||
|             EntityRepository $typeRepository | ||||
|     ) { | ||||
|         $this->translatableStringHelper = $helper; | ||||
|         $this->typeRepository = $typeRepository; | ||||
|     } | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|  | ||||
|      | ||||
|      | ||||
|     public function alterQuery(QueryBuilder $qb, $data) | ||||
|     { | ||||
|         $where = $qb->getDQLPart('where'); | ||||
| @@ -68,10 +72,27 @@ class ActivityTypeFilter implements | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $qb->add('where', $where); | ||||
|         $qb->setParameter('selected_activity_types', $data['types']); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Check if a join between Activity and Reason is already defined | ||||
|      *  | ||||
|      * @param Join[] $joins | ||||
|      * @return boolean | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public function applyOn() | ||||
|     { | ||||
| @@ -82,60 +103,46 @@ class ActivityTypeFilter implements | ||||
|     { | ||||
|         //create a local copy of translatableStringHelper | ||||
|         $helper = $this->translatableStringHelper; | ||||
|  | ||||
|         $builder->add('types', EntityType::class, [ | ||||
|          | ||||
|         $builder->add('types', EntityType::class, array( | ||||
|             'class' => ActivityType::class, | ||||
|             'choice_label' => static function (ActivityType $type) use ($helper) { | ||||
|             'choice_label' => function (ActivityType $type) use ($helper) { | ||||
|                 return $helper->localize($type->getName()); | ||||
|             }, | ||||
|             'multiple' => true, | ||||
|             'expanded' => false, | ||||
|         ]); | ||||
|             'expanded' => false | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         // collect all the reasons'name used in this filter in one array | ||||
|         $reasonsNames = array_map( | ||||
|             function (ActivityType $t) { | ||||
|                 return '"' . $this->translatableStringHelper->localize($t->getName()) . '"'; | ||||
|             }, | ||||
|             $this->typeRepository->findBy(['id' => $data['types']->toArray()]) | ||||
|         ); | ||||
|  | ||||
|         return ['Filtered by activity type: only %list%', | ||||
|             ['%list%' => implode(', ', $reasonsNames)], ]; | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Filter by activity type'; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if (null === $data['types'] || count($data['types']) === 0) { | ||||
|             $context->buildViolation('At least one type must be choosen') | ||||
|         if ($data['types'] === null || count($data['types']) === 0) { | ||||
|             $context->buildViolation("At least one type must be choosen") | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Check if a join between Activity and Reason is already defined. | ||||
|      * | ||||
|      * @param Join[] $joins | ||||
|      * @param mixed $alias | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     private function checkJoinAlreadyDefined(array $joins, $alias) | ||||
|         public function getTitle() | ||||
|     { | ||||
|         foreach ($joins as $join) { | ||||
|             if ($join->getAlias() === $alias) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|         return 'Filter by activity type'; | ||||
|     } | ||||
|      | ||||
|     public function addRole() | ||||
|     { | ||||
|         return new Role(ActivityStatsVoter::STATS); | ||||
|     } | ||||
|      | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         // collect all the reasons'name used in this filter in one array | ||||
|         $reasonsNames = array_map( | ||||
|                 function(ActivityType $t) { | ||||
|                     return "\"".$this->translatableStringHelper->localize($t->getName())."\""; | ||||
|                 }, | ||||
|                 $this->typeRepository->findBy(array('id' => $data['types']->toArray())) | ||||
|                 ); | ||||
|          | ||||
|         return array("Filtered by activity type: only %list%",  | ||||
|             ["%list%" => implode(", ", $reasonsNames)]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,66 +1,79 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2017 Champs-Libres <info@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Export\Filter; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
| use Chill\MainBundle\Export\FilterInterface; | ||||
| use Chill\MainBundle\Form\Type\Export\FilterType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Chill\PersonBundle\Export\Declarations; | ||||
| use DateTime; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
| use Symfony\Component\Form\FormError; | ||||
| use Symfony\Component\Form\FormEvent; | ||||
| use Symfony\Component\Form\FormEvents; | ||||
| use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
| use Symfony\Component\Form\FormError; | ||||
| use Chill\MainBundle\Form\Type\Export\FilterType; | ||||
| use Doctrine\ORM\Query\Expr; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Doctrine\ORM\EntityManager; | ||||
| use Chill\PersonBundle\Export\Declarations; | ||||
| use Symfony\Component\Translation\TranslatorInterface; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
| use Chill\MainBundle\Export\ExportElementValidatedInterface; | ||||
|  | ||||
| use function count; | ||||
|  | ||||
| class PersonHavingActivityBetweenDateFilter implements | ||||
|     ExportElementValidatedInterface, | ||||
|     FilterInterface | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class PersonHavingActivityBetweenDateFilter implements FilterInterface,  | ||||
|     ExportElementValidatedInterface | ||||
| { | ||||
|      | ||||
|     /** | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $activityReasonRepository; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * @var TranslatorInterface | ||||
|      * | ||||
|      * @var EntityRepository | ||||
|      */ | ||||
|     protected $activityReasonRepository; | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatorInterface  | ||||
|      */ | ||||
|     protected $translator; | ||||
|  | ||||
|      | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $translatableStringHelper, | ||||
|         EntityRepository $activityReasonRepository, | ||||
|         TranslatorInterface $translator | ||||
|             TranslatableStringHelper $translatableStringHelper, | ||||
|             EntityRepository $activityReasonRepository, | ||||
|             TranslatorInterface $translator | ||||
|     ) { | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|         $this->activityReasonRepository = $activityReasonRepository; | ||||
|         $this->translator = $translator; | ||||
|         $this->translator               = $translator; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public function addRole() | ||||
|     { | ||||
|         return null; | ||||
| @@ -70,26 +83,24 @@ class PersonHavingActivityBetweenDateFilter implements | ||||
|     { | ||||
|         // create a query for activity | ||||
|         $sqb = $qb->getEntityManager()->createQueryBuilder(); | ||||
|         $sqb->select('person_person_having_activity.id') | ||||
|             ->from('ChillActivityBundle:Activity', 'activity_person_having_activity') | ||||
|             ->join('activity_person_having_activity.person', 'person_person_having_activity'); | ||||
|         $sqb->select("person_person_having_activity.id") | ||||
|                 ->from("ChillActivityBundle:Activity", "activity_person_having_activity") | ||||
|                 ->join("activity_person_having_activity.person", "person_person_having_activity") | ||||
|                 ; | ||||
|         // add clause between date | ||||
|         $sqb->where('activity_person_having_activity.date BETWEEN ' | ||||
|                 . ':person_having_activity_between_date_from' | ||||
|                 . ' AND ' | ||||
|                 . ':person_having_activity_between_date_to'); | ||||
|         $sqb->where("activity_person_having_activity.date BETWEEN " | ||||
|                 . ":person_having_activity_between_date_from" | ||||
|                 . " AND " | ||||
|                 . ":person_having_activity_between_date_to"); | ||||
|         // add clause activity reason | ||||
|         $sqb->join( | ||||
|             'activity_person_having_activity.reasons', | ||||
|             'reasons_person_having_activity' | ||||
|         ); | ||||
|         $sqb->join('activity_person_having_activity.reasons',  | ||||
|                 'reasons_person_having_activity'); | ||||
|         $sqb->andWhere( | ||||
|             $sqb->expr()->in( | ||||
|                 'reasons_person_having_activity', | ||||
|                 ':person_having_activity_reasons' | ||||
|             ) | ||||
|         ); | ||||
|  | ||||
|                 $sqb->expr()->in( | ||||
|                     'reasons_person_having_activity', | ||||
|                     ":person_having_activity_reasons") | ||||
|                 ); | ||||
|          | ||||
|         $where = $qb->getDQLPart('where'); | ||||
|         $clause = $qb->expr()->in('person.id', $sqb->getDQL()); | ||||
|  | ||||
| @@ -98,16 +109,12 @@ class PersonHavingActivityBetweenDateFilter implements | ||||
|         } else { | ||||
|             $where = $qb->expr()->andX($clause); | ||||
|         } | ||||
|  | ||||
|          | ||||
|         $qb->add('where', $where); | ||||
|         $qb->setParameter( | ||||
|             'person_having_activity_between_date_from', | ||||
|             $data['date_from'] | ||||
|         ); | ||||
|         $qb->setParameter( | ||||
|             'person_having_activity_between_date_to', | ||||
|             $data['date_to'] | ||||
|         ); | ||||
|         $qb->setParameter('person_having_activity_between_date_from',  | ||||
|                 $data['date_from']); | ||||
|         $qb->setParameter('person_having_activity_between_date_to',  | ||||
|                 $data['date_to']); | ||||
|         $qb->setParameter('person_having_activity_reasons', $data['reasons']); | ||||
|     } | ||||
|  | ||||
| @@ -118,107 +125,104 @@ class PersonHavingActivityBetweenDateFilter implements | ||||
|  | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) | ||||
|     { | ||||
|         $builder->add('date_from', DateType::class, [ | ||||
|             'label' => 'Implied in an activity after this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|         $builder->add('date_from', DateType::class, array( | ||||
|             'label' => "Implied in an activity after this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('date_to', DateType::class, [ | ||||
|             'label' => 'Implied in an activity before this date', | ||||
|             'data' => new DateTime(), | ||||
|             'attr' => ['class' => 'datepicker'], | ||||
|             'widget' => 'single_text', | ||||
|         )); | ||||
|          | ||||
|         $builder->add('date_to', DateType::class, array( | ||||
|             'label' => "Implied in an activity before this date", | ||||
|             'data'  => new \DateTime(), | ||||
|             'attr'  => array('class' => 'datepicker'), | ||||
|             'widget'=> 'single_text', | ||||
|             'format' => 'dd-MM-yyyy', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('reasons', EntityType::class, [ | ||||
|         )); | ||||
|          | ||||
|         $builder->add('reasons', EntityType::class, array( | ||||
|             'class' => 'ChillActivityBundle:ActivityReason', | ||||
|             'choice_label' => function (ActivityReason $reason) { | ||||
|                 return $this->translatableStringHelper | ||||
|                     ->localize($reason->getName()); | ||||
|                         ->localize($reason->getName()); | ||||
|             }, | ||||
|             'group_by' => function (ActivityReason $reason) { | ||||
|             'group_by' => function(ActivityReason $reason) { | ||||
|                 return $this->translatableStringHelper | ||||
|                     ->localize($reason->getCategory()->getName()); | ||||
|                         ->localize($reason->getCategory()->getName()); | ||||
|             }, | ||||
|             'data' => $this->activityReasonRepository->findAll(), | ||||
|             'multiple' => true, | ||||
|             'expanded' => false, | ||||
|             'label' => 'Activity reasons for those activities', | ||||
|         ]); | ||||
|  | ||||
|         $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { | ||||
|             /** @var \Symfony\Component\Form\FormInterface $filterForm */ | ||||
|             'label'    => "Activity reasons for those activities" | ||||
|         )); | ||||
|          | ||||
|         $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) { | ||||
|             /* @var $filterForm \Symfony\Component\Form\FormInterface */ | ||||
|             $filterForm = $event->getForm()->getParent(); | ||||
|             $enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData(); | ||||
|  | ||||
|             if (true === $enabled) { | ||||
|              | ||||
|             if ($enabled === true) { | ||||
|                 // if the filter is enabled, add some validation | ||||
|                 $form = $event->getForm(); | ||||
|                 $form      = $event->getForm(); | ||||
|                 $date_from = $form->get('date_from')->getData(); | ||||
|                 $date_to = $form->get('date_to')->getData(); | ||||
|  | ||||
|                 $date_to   = $form->get('date_to')->getData(); | ||||
|                  | ||||
|                 // check that fields are not empty | ||||
|                 if (null === $date_from) { | ||||
|                 if ($date_from === null) { | ||||
|                     $form->get('date_from')->addError(new FormError( | ||||
|                         $this->translator->trans('This field ' | ||||
|                         . 'should not be empty') | ||||
|                     )); | ||||
|                         . 'should not be empty'))); | ||||
|                 } | ||||
|  | ||||
|                 if (null === $date_to) { | ||||
|                 if ($date_to   === null) { | ||||
|                     $form->get('date_to')->addError(new FormError( | ||||
|                         $this->translator->trans('This field ' | ||||
|                         . 'should not be empty') | ||||
|                     )); | ||||
|                 } | ||||
|  | ||||
|                         . 'should not be empty'))); | ||||
|                 }  | ||||
|                  | ||||
|                 // check that date_from is before date_to | ||||
|                 if ( | ||||
|                     (null !== $date_from && null !== $date_to) | ||||
|                     && $date_from >= $date_to | ||||
|                     ($date_from !== null && $date_to !== null) | ||||
|                     && | ||||
|                     $date_from >= $date_to | ||||
|                 ) { | ||||
|                     $form->get('date_to')->addError(new FormError( | ||||
|                         $this->translator->trans('This date ' | ||||
|                         . 'should be after the date given in "Implied in an ' | ||||
|                         . 'activity after this date" field') | ||||
|                     )); | ||||
|                         . 'activity after this date" field'))); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|      | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if ($data['reasons'] === null || count($data['reasons']) === 0) { | ||||
|             $context->buildViolation("At least one reason must be choosen") | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function describeAction($data, $format = 'string') | ||||
|     { | ||||
|         return [ | ||||
|             'Filtered by person having an activity between %date_from% and ' | ||||
|             . '%date_to% with reasons %reasons_name%', | ||||
|             [ | ||||
|                 '%date_from%' => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%' => $data['date_to']->format('d-m-Y'), | ||||
|                 '%reasons_name%' => implode(', ', array_map( | ||||
|                     function (ActivityReason $r) { | ||||
|                         return '"' . $this->translatableStringHelper-> | ||||
|                                     localize($r->getName()) . '"'; | ||||
|                     }, | ||||
|                     $data['reasons'] | ||||
|                 )), | ||||
|             ], ]; | ||||
|         return array( | ||||
|             "Filtered by person having an activity between %date_from% and " | ||||
|             . "%date_to% with reasons %reasons_name%", | ||||
|             array( | ||||
|                 "%date_from%" => $data['date_from']->format('d-m-Y'), | ||||
|                 '%date_to%'   => $data['date_to']->format('d-m-Y'), | ||||
|                 "%reasons_name%"  => implode(", ", array_map( | ||||
|                         function (ActivityReason $r) { | ||||
|                             return '"'.$this->translatableStringHelper-> | ||||
|                                     localize($r->getName()).'"'; | ||||
|                         }, | ||||
|                         $data['reasons'])) | ||||
|             )); | ||||
|     } | ||||
|  | ||||
|     public function getTitle() | ||||
|     { | ||||
|         return 'Filtered by person having an activity in a period'; | ||||
|         return "Filtered by person having an activity in a period"; | ||||
|     } | ||||
|  | ||||
|     public function validateForm($data, ExecutionContextInterface $context) | ||||
|     { | ||||
|         if (null === $data['reasons'] || count($data['reasons']) === 0) { | ||||
|             $context->buildViolation('At least one reason must be choosen') | ||||
|                 ->addViolation(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										33
									
								
								src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/Bundle/ChillActivityBundle/Form/ActivityPresenceType.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityPresence; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
|  | ||||
| class ActivityPresenceType extends AbstractType | ||||
| { | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options): void | ||||
|     { | ||||
|         $builder | ||||
|             ->add('name', TranslatableStringFormType::class) | ||||
|             ->add('active', ChoiceType::class, array( | ||||
|                 'choices' => array( | ||||
|                     'Yes' => true, | ||||
|                     'No'  => false | ||||
|                 ), | ||||
|                 'expanded' => true | ||||
|             )); | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver): void | ||||
|     { | ||||
|         $resolver->setDefaults(array( | ||||
|             'data_class' => ActivityPresence::class | ||||
|         )); | ||||
|     } | ||||
| } | ||||
| @@ -1,31 +1,25 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
|  | ||||
| class ActivityReasonCategoryType extends AbstractType | ||||
| { | ||||
|     /** | ||||
|      * @param FormBuilderInterface $builder | ||||
|      * @param array $options | ||||
|      */ | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options) | ||||
|     { | ||||
|         $builder | ||||
|             ->add('name', TranslatableStringFormType::class) | ||||
|             ->add('active', CheckboxType::class, ['required' => false]); | ||||
|             ->add('active', CheckboxType::class, array('required' => false)) | ||||
|         ; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -33,9 +27,9 @@ class ActivityReasonCategoryType extends AbstractType | ||||
|      */ | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults([ | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\ActivityReasonCategory', | ||||
|         ]); | ||||
|         $resolver->setDefaults(array( | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\ActivityReasonCategory' | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,40 +1,37 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
| use Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory; | ||||
|  | ||||
| class ActivityReasonType extends AbstractType | ||||
| { | ||||
|     /** | ||||
|      * @param FormBuilderInterface $builder | ||||
|      * @param array $options | ||||
|      */ | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options) | ||||
|     { | ||||
|         $builder | ||||
|             ->add('name', TranslatableStringFormType::class) | ||||
|             ->add('active', CheckboxType::class, ['required' => false]) | ||||
|             ->add('category', TranslatableActivityReasonCategory::class); | ||||
|             ->add('active', CheckboxType::class, array('required' => false)) | ||||
|             ->add('category', TranslatableActivityReasonCategory::class) | ||||
|         ; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param OptionsResolver $resolver | ||||
|      */ | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults([ | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\ActivityReason', | ||||
|         ]); | ||||
|         $resolver->setDefaults(array( | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\ActivityReason' | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,87 +1,81 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\ActivityBundle\Form\Type\TranslatableActivityReason; | ||||
| use Chill\ActivityBundle\Form\Type\TranslatableActivityType; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Chill\MainBundle\Form\Type\ChillDateType; | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\ActivityBundle\Entity\ActivityPresence; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\DocStoreBundle\Form\StoredObjectType; | ||||
| use Chill\MainBundle\Form\Type\ChillCollectionType; | ||||
| use Chill\MainBundle\Form\Type\CommentType; | ||||
| use Chill\MainBundle\Form\Type\ScopePickerType; | ||||
| use Chill\MainBundle\Form\Type\UserPickerType; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use DateInterval; | ||||
| use DateTime; | ||||
| use DateTimeZone; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use RuntimeException; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialIssue; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use Chill\ThirdPartyBundle\Entity\ThirdParty; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Doctrine\Persistence\ObjectManager; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; | ||||
| use Symfony\Component\Form\FormEvent; | ||||
| use Symfony\Component\Form\FormEvents; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
|  | ||||
| use function in_array; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Chill\MainBundle\Form\Type\UserPickerType; | ||||
| use Chill\MainBundle\Form\Type\ScopePickerType; | ||||
| use Chill\MainBundle\Form\Type\ChillDateType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||||
| use Symfony\Component\Form\CallbackTransformer; | ||||
| use Chill\PersonBundle\Form\DataTransformer\PersonToIdTransformer; | ||||
| use Chill\PersonBundle\Templating\Entity\SocialIssueRender; | ||||
| use Chill\PersonBundle\Templating\Entity\SocialActionRender; | ||||
|  | ||||
| class ActivityType extends AbstractType | ||||
| { | ||||
|     /** | ||||
|      * @var AuthorizationHelper | ||||
|      */ | ||||
|     protected $authorizationHelper; | ||||
|     protected User $user; | ||||
|  | ||||
|     /** | ||||
|      * @var ObjectManager | ||||
|      */ | ||||
|     protected $om; | ||||
|     protected AuthorizationHelper $authorizationHelper; | ||||
|  | ||||
|     protected $timeChoices; | ||||
|     protected ObjectManager $om; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|     protected TranslatableStringHelper $translatableStringHelper; | ||||
|  | ||||
|     /** | ||||
|      * the user running this form. | ||||
|      * | ||||
|      * @var User | ||||
|      */ | ||||
|     protected $user; | ||||
|     protected SocialIssueRender $socialIssueRender; | ||||
|  | ||||
|     public function __construct( | ||||
|     protected SocialActionRender $socialActionRender; | ||||
|  | ||||
|     protected array $timeChoices; | ||||
|  | ||||
|     public function __construct ( | ||||
|         TokenStorageInterface $tokenStorage, | ||||
|         AuthorizationHelper $authorizationHelper, | ||||
|         ObjectManager $om, | ||||
|         TranslatableStringHelper $translatableStringHelper, | ||||
|         array $timeChoices | ||||
|         array $timeChoices, | ||||
|         SocialIssueRender $socialIssueRender, | ||||
|         SocialActionRender $socialActionRender | ||||
|     ) { | ||||
|         if (!$tokenStorage->getToken()->getUser() instanceof User) { | ||||
|             throw new RuntimeException('you should have a valid user'); | ||||
|             throw new \RuntimeException("you should have a valid user"); | ||||
|         } | ||||
|  | ||||
|         $this->user = $tokenStorage->getToken()->getUser(); | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|         $this->om = $om; | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|         $this->timeChoices = $timeChoices; | ||||
|         $this->socialIssueRender = $socialIssueRender; | ||||
|         $this->socialActionRender = $socialActionRender; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options) | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options): void | ||||
|     { | ||||
|         // handle times choices | ||||
|         $timeChoices = []; | ||||
| @@ -96,104 +90,301 @@ class ActivityType extends AbstractType | ||||
|             'placeholder' => 'Choose the duration', | ||||
|         ]; | ||||
|  | ||||
|         $builder | ||||
|             ->add('date', ChillDateType::class, [ | ||||
|                 'required' => true, | ||||
|             ]) | ||||
|             ->add('durationTime', ChoiceType::class, $durationTimeOptions) | ||||
|             ->add('attendee', ChoiceType::class, [ | ||||
|                 'expanded' => true, | ||||
|                 'required' => false, | ||||
|                 'choices' => [ | ||||
|                     'present' => true, | ||||
|                     'not present' => false, | ||||
|                 ], | ||||
|             ]) | ||||
|             ->add('user', UserPickerType::class, [ | ||||
|         /** @var \Chill\ActivityBundle\Entity\ActivityType $activityType */ | ||||
|         $activityType = $options['activityType']; | ||||
|  | ||||
|         if (!$activityType->isActive()) { | ||||
|             throw new \InvalidArgumentException('Activity type must be active'); | ||||
|         } | ||||
|  | ||||
|         // TODO revoir la gestion des center au niveau du form des activité. | ||||
|         if ($options['center']) { | ||||
|             $builder->add('scope', ScopePickerType::class, [ | ||||
|                 'center' => $options['center'], | ||||
|                 'role' => $options['role'], | ||||
|             ]) | ||||
|             ->add('scope', ScopePickerType::class, [ | ||||
|                 'center' => $options['center'], | ||||
|                 'role' => $options['role'], | ||||
|             ]) | ||||
|             ->add('reasons', TranslatableActivityReason::class, [ | ||||
|                 'multiple' => true, | ||||
|                 'required' => false, | ||||
|             ]) | ||||
|             ->add('type', TranslatableActivityType::class, [ | ||||
|                 'placeholder' => 'Choose a type', | ||||
|                 'active_only' => true, | ||||
|             ]) | ||||
|             ->add('comment', CommentType::class, [ | ||||
|                 'required' => false, | ||||
|                 'role' => $options['role'] | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         $builder->get('durationTime') | ||||
|             ->addModelTransformer($durationTimeTransformer); | ||||
|         /** @var ? \Chill\PersonBundle\Entity\AccompanyingPeriod  $accompanyingPeriod */ | ||||
|         $accompanyingPeriod = NULL; | ||||
|         if ($options['accompanyingPeriod']) { | ||||
|             $accompanyingPeriod = $options['accompanyingPeriod']; | ||||
|         } | ||||
|  | ||||
|         $builder->get('durationTime') | ||||
|             ->addEventListener( | ||||
|                 FormEvents::PRE_SET_DATA, | ||||
|                 static function (FormEvent $formEvent) use ( | ||||
|         if ($activityType->isVisible('socialIssues') && $accompanyingPeriod) { | ||||
|             $builder->add('socialIssues', HiddenType::class); | ||||
|             $builder->get('socialIssues') | ||||
|                ->addModelTransformer(new CallbackTransformer( | ||||
|                    function (iterable $socialIssuesAsIterable): string { | ||||
|                        $socialIssueIds = []; | ||||
|                        foreach ($socialIssuesAsIterable as $value) { | ||||
|                           $socialIssueIds[] = $value->getId(); | ||||
|                        } | ||||
|                        return implode(',', $socialIssueIds); | ||||
|                    }, | ||||
|                    function (?string $socialIssuesAsString): array { | ||||
|                        if (null === $socialIssuesAsString) { | ||||
|                           return []; | ||||
|                        } | ||||
|                        return array_map( | ||||
|                           fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]), | ||||
|                           explode(',', $socialIssuesAsString) | ||||
|                        ); | ||||
|                    } | ||||
|                )) | ||||
|             ; | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('socialActions') && $accompanyingPeriod) { | ||||
|             $builder->add('socialActions', HiddenType::class); | ||||
|             $builder->get('socialActions') | ||||
|                ->addModelTransformer(new CallbackTransformer( | ||||
|                    function (iterable $socialActionsAsIterable): string { | ||||
|                        $socialActionIds = []; | ||||
|                        foreach ($socialActionsAsIterable as $value) { | ||||
|                           $socialActionIds[] = $value->getId(); | ||||
|                        } | ||||
|                        return implode(',', $socialActionIds); | ||||
|                    }, | ||||
|                    function (?string $socialActionsAsString): array { | ||||
|                        if (null === $socialActionsAsString) { | ||||
|                           return []; | ||||
|                        } | ||||
|                        return array_map( | ||||
|                           fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]), | ||||
|                           explode(',', $socialActionsAsString) | ||||
|                        ); | ||||
|                    } | ||||
|                )) | ||||
|             ; | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('date')) { | ||||
|             $builder->add('date', ChillDateType::class, [ | ||||
|                 'label' => $activityType->getLabel('date'), | ||||
|                 'required' => $activityType->isRequired('date'), | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('durationTime')) { | ||||
|             $durationTimeOptions['label'] = $activityType->getLabel('durationTime'); | ||||
|             $durationTimeOptions['required'] = $activityType->isRequired('durationTime'); | ||||
|  | ||||
|             $builder->add('durationTime', ChoiceType::class, $durationTimeOptions); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('travelTime')) { | ||||
|             $durationTimeOptions['label'] = $activityType->getLabel('travelTime'); | ||||
|             $durationTimeOptions['required'] = $activityType->isRequired('travelTime'); | ||||
|  | ||||
|             $builder->add('travelTime', ChoiceType::class, $durationTimeOptions); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('attendee')) { | ||||
|             $builder->add('attendee', EntityType::class, [ | ||||
|                 'label' => $activityType->getLabel('attendee'), | ||||
|                 'required' => $activityType->isRequired('attendee'), | ||||
|                 'expanded' => true, | ||||
|                 'class' => ActivityPresence::class, | ||||
|                 'choice_label' => function (ActivityPresence $activityPresence) { | ||||
|                     return $this->translatableStringHelper->localize($activityPresence->getName()); | ||||
|                 }, | ||||
|                 'query_builder' => function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('a') | ||||
|                         ->where('a.active = true'); | ||||
|                 }, | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('user') && $options['center']) { | ||||
|             $builder->add('user', UserPickerType::class, [ | ||||
|                 'label' => $activityType->getLabel('user'), | ||||
|                 'required' => $activityType->isRequired('user'), | ||||
|                 'center' => $options['center'], | ||||
|                 'role'   => $options['role'] | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('reasons')) { | ||||
|             $builder->add('reasons', EntityType::class, [ | ||||
|                 'label' => $activityType->getLabel('reasons'), | ||||
|                 'required' => $activityType->isRequired('reasons'), | ||||
|                 'class' => ActivityReason::class, | ||||
|                 'multiple' => true, | ||||
|                 'choice_label' => function (ActivityReason $activityReason) { | ||||
|                     return $this->translatableStringHelper->localize($activityReason->getName()); | ||||
|                 }, | ||||
|                 'attr' => array('class' => 'select2 '), | ||||
|                 'query_builder' => function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('a') | ||||
|                         ->where('a.active = true'); | ||||
|                 }, | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('comment')) { | ||||
|             $builder->add('comment', CommentType::class, [ | ||||
|                 'label' => empty($activityType->getLabel('comment'))  | ||||
|                     ? 'activity.comment' : $activityType->getLabel('comment'), | ||||
|                 'required' => $activityType->isRequired('comment'), | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('persons')) { | ||||
|             $builder->add('persons', HiddenType::class); | ||||
|             $builder->get('persons') | ||||
|                ->addModelTransformer(new CallbackTransformer( | ||||
|                    function (iterable $personsAsIterable): string { | ||||
|                        $personIds = []; | ||||
|                        foreach ($personsAsIterable as $value) { | ||||
|                           $personIds[] = $value->getId(); | ||||
|                        } | ||||
|                        return implode(',', $personIds); | ||||
|                    }, | ||||
|                    function (?string $personsAsString): array { | ||||
|                        return array_map( | ||||
|                           fn(string $id): ?Person => $this->om->getRepository(Person::class)->findOneBy(['id' => (int) $id]), | ||||
|                           explode(',', $personsAsString) | ||||
|                        ); | ||||
|                    } | ||||
|                )) | ||||
|            ; | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('thirdParties')) { | ||||
|             $builder->add('thirdParties', HiddenType::class); | ||||
|             $builder->get('thirdParties') | ||||
|                ->addModelTransformer(new CallbackTransformer( | ||||
|                    function (iterable $thirdpartyAsIterable): string { | ||||
|                        $thirdpartyIds = []; | ||||
|                        foreach ($thirdpartyAsIterable as $value) { | ||||
|                           $thirdpartyIds[] = $value->getId(); | ||||
|                        } | ||||
|                        return implode(',', $thirdpartyIds); | ||||
|                    }, | ||||
|                    function (?string $thirdpartyAsString): array { | ||||
|                        return array_map( | ||||
|                            fn(string $id): ?ThirdParty => $this->om->getRepository(ThirdParty::class)->findOneBy(['id' => (int) $id]), | ||||
|                            explode(',', $thirdpartyAsString) | ||||
|                        ); | ||||
|                    } | ||||
|                )) | ||||
|            ; | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('documents')) { | ||||
|             $builder->add('documents', ChillCollectionType::class, [ | ||||
|                 'entry_type' => StoredObjectType::class, | ||||
|                 'label' => $activityType->getLabel('documents'), | ||||
|                 'required' => $activityType->isRequired('documents'), | ||||
|                 'allow_add' => true, | ||||
|                 'button_add_label' => 'activity.Insert a document', | ||||
|                 'button_remove_label' => 'activity.Remove a document' | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('users')) { | ||||
|             $builder->add('users', HiddenType::class); | ||||
|             $builder->get('users') | ||||
|                ->addModelTransformer(new CallbackTransformer( | ||||
|                    function (iterable $usersAsIterable): string { | ||||
|                        $userIds = []; | ||||
|                        foreach ($usersAsIterable as $value) { | ||||
|                            $userIds[] = $value->getId(); | ||||
|                        } | ||||
|                        return implode(',', $userIds); | ||||
|                    }, | ||||
|                    function (?string $usersAsString): array { | ||||
|                        return array_map( | ||||
|                            fn(string $id): ?User => $this->om->getRepository(User::class)->findOneBy(['id' => (int) $id]), | ||||
|                            explode(',', $usersAsString) | ||||
|                        ); | ||||
|                    } | ||||
|                )) | ||||
|            ; | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('emergency')) { | ||||
|             $builder->add('emergency', CheckboxType::class, [ | ||||
|                 'label' => $activityType->getLabel('emergency'), | ||||
|                 'required' => $activityType->isRequired('emergency'), | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         if ($activityType->isVisible('sentReceived')) { | ||||
|             $builder->add('sentReceived', ChoiceType::class, [ | ||||
|                 'label' => $activityType->getLabel('sentReceived'), | ||||
|                 'required' => $activityType->isRequired('sentReceived'), | ||||
|                 'choices' => [ | ||||
|                     'Sent' => Activity::SENTRECEIVED_SENT, | ||||
|                     'Received' => Activity::SENTRECEIVED_RECEIVED, | ||||
|                 ], | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         foreach (['durationTime', 'travelTime'] as $fieldName) { | ||||
|             if (!$activityType->isVisible($fieldName)) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             $builder->get($fieldName) | ||||
|                 ->addModelTransformer($durationTimeTransformer); | ||||
|  | ||||
|             $builder->get($fieldName) | ||||
|                 ->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $formEvent) use ( | ||||
|                     $timeChoices, | ||||
|                     $builder, | ||||
|                     $durationTimeTransformer, | ||||
|                     $durationTimeOptions | ||||
|                     $durationTimeOptions, | ||||
|                     $fieldName | ||||
|                 ) { | ||||
|                     // set the timezone to GMT, and fix the difference between current and GMT | ||||
|                     // the datetimetransformer will then handle timezone as GMT | ||||
|                     $timezoneUTC = new DateTimeZone('GMT'); | ||||
|                     /** @var DateTime $data */ | ||||
|                     $data = $formEvent->getData() === null ? | ||||
|                                     DateTime::createFromFormat('U', 300) : | ||||
|                                     $formEvent->getData(); | ||||
|                     $timezoneUTC = new \DateTimeZone('GMT'); | ||||
|                     /* @var $data \DateTime */ | ||||
|                     $data = $formEvent->getData() === NULL ? | ||||
|                         \DateTime::createFromFormat('U', 300) : | ||||
|                         $formEvent->getData(); | ||||
|                     $seconds = $data->getTimezone()->getOffset($data); | ||||
|                     $data->setTimeZone($timezoneUTC); | ||||
|                     $data->add(new DateInterval('PT' . $seconds . 'S')); | ||||
|                     $data->add(new \DateInterval('PT'.$seconds.'S')); | ||||
|  | ||||
|                     // test if the timestamp is in the choices. | ||||
|                     // If not, recreate the field with the new timestamp | ||||
|                     if (!in_array($data->getTimestamp(), $timeChoices, true)) { | ||||
|                     if (!in_array($data->getTimestamp(), $timeChoices)) { | ||||
|                         // the data are not in the possible values. add them | ||||
|                         $timeChoices[$data->format('H:i')] = $data->getTimestamp(); | ||||
|                         $form = $builder->create( | ||||
|                             'durationTime', | ||||
|                             ChoiceType::class, | ||||
|                             array_merge( | ||||
|                                 $durationTimeOptions, | ||||
|                                 [ | ||||
|                                     'choices' => $timeChoices, | ||||
|                                     'auto_initialize' => false, | ||||
|                                 ] | ||||
|                             ) | ||||
|                         ); | ||||
|                         $form = $builder->create($fieldName, ChoiceType::class, array_merge( | ||||
|                             $durationTimeOptions, [ | ||||
|                                 'choices' => $timeChoices, | ||||
|                                 'auto_initialize' => false | ||||
|                             ] | ||||
|                         )); | ||||
|                         $form->addModelTransformer($durationTimeTransformer); | ||||
|                         $formEvent->getForm()->getParent()->add($form->getForm()); | ||||
|                     } | ||||
|                 } | ||||
|             ); | ||||
|                 }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param OptionsResolverInterface $resolver | ||||
|      */ | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|  | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver): void | ||||
|     { | ||||
|         $resolver->setDefaults([ | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\Activity', | ||||
|             'data_class' => Activity::class | ||||
|         ]); | ||||
|  | ||||
|         $resolver | ||||
|             ->setRequired(['center', 'role']) | ||||
|             ->setAllowedTypes('center', 'Chill\MainBundle\Entity\Center') | ||||
|             ->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role'); | ||||
|             ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod']) | ||||
|             ->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center']) | ||||
|             ->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role') | ||||
|             ->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class) | ||||
|             ->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']) | ||||
|         ; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getBlockPrefix() | ||||
|     public function getBlockPrefix(): string | ||||
|     { | ||||
|         return 'chill_activitybundle_activity'; | ||||
|     } | ||||
|   | ||||
| @@ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityTypeCategory; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\NumberType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
|  | ||||
| class ActivityTypeCategoryType extends AbstractType | ||||
| { | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options): void | ||||
|     { | ||||
|         $builder | ||||
|             ->add('name', TranslatableStringFormType::class) | ||||
|             ->add('active', ChoiceType::class, array( | ||||
|                 'choices' => array( | ||||
|                     'Yes' => true, | ||||
|                     'No'  => false | ||||
|                 ), | ||||
|                 'expanded' => true | ||||
|             )) | ||||
|             ->add('ordering', NumberType::class, [ | ||||
|                 'required' => true, | ||||
|                 'scale' => 5 | ||||
|             ]) | ||||
|         ; | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver): void | ||||
|     { | ||||
|         $resolver->setDefaults(array( | ||||
|             'data_class' => ActivityTypeCategory::class | ||||
|         )); | ||||
|     } | ||||
| } | ||||
| @@ -1,26 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form; | ||||
|  | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
| use Chill\ActivityBundle\Entity\ActivityTypeCategory; | ||||
| use Chill\ActivityBundle\Form\Type\ActivityFieldPresence; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\NumberType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
| use Symfony\Component\Form\FormBuilderInterface; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Chill\MainBundle\Form\Type\TranslatableStringFormType; | ||||
|  | ||||
| class ActivityTypeType extends AbstractType | ||||
| { | ||||
|     private TranslatableStringHelper $translatableStringHelper; | ||||
|  | ||||
|     public function __construct(TranslatableStringHelper $translatableStringHelper) | ||||
|     { | ||||
|         $this->translatableStringHelper = $translatableStringHelper; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(FormBuilderInterface $builder, array $options) | ||||
|     { | ||||
|         $builder | ||||
| @@ -28,27 +30,42 @@ class ActivityTypeType extends AbstractType | ||||
|             ->add('active', ChoiceType::class, [ | ||||
|                 'choices' => [ | ||||
|                     'Yes' => true, | ||||
|                     'No' => false, | ||||
|                     'No'  => false | ||||
|                 ], | ||||
|                 'expanded' => true, | ||||
|             ]); | ||||
|                 'expanded' => true | ||||
|             ]) | ||||
|             ->add('category', EntityType::class, [ | ||||
|                 'class' => ActivityTypeCategory::class, | ||||
|                 'choice_label' => function (ActivityTypeCategory $activityTypeCategory) { | ||||
|                     return $this->translatableStringHelper->localize($activityTypeCategory->getName()); | ||||
|                 }, | ||||
|             ]) | ||||
|             ->add('ordering', NumberType::class, [ | ||||
|                 'required' => true, | ||||
|                 'scale' => 5 | ||||
|             ]) | ||||
|         ; | ||||
|  | ||||
|         $fields = [ | ||||
|             'persons', 'user', 'date', 'place', 'persons', | ||||
|             'thirdParties', 'durationTime', 'travelTime', 'attendee', | ||||
|             'reasons', 'comment', 'sentReceived', 'documents', | ||||
|             'emergency', 'accompanyingPeriod', 'socialData', 'users' | ||||
|         ]; | ||||
|         foreach ($fields as $field) { | ||||
|             $builder | ||||
|                 ->add($field.'Visible', ActivityFieldPresence::class) | ||||
|                 ->add($field.'Label', TextType::class, [ | ||||
|                     'required' => false, | ||||
|                     'empty_data' => '', | ||||
|                 ]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param OptionsResolverInterface $resolver | ||||
|      */ | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults([ | ||||
|             'data_class' => 'Chill\ActivityBundle\Entity\ActivityType', | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getBlockPrefix() | ||||
|     { | ||||
|         return 'chill_activitybundle_activitytype'; | ||||
|         $resolver->setDefaults(array( | ||||
|             'data_class' => \Chill\ActivityBundle\Entity\ActivityType::class | ||||
|         )); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form\Type; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
|  | ||||
| class ActivityFieldPresence extends AbstractType | ||||
| { | ||||
|     public function getParent() | ||||
|     { | ||||
|         return ChoiceType::class; | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults( | ||||
|             array( | ||||
|                 'choices' => [ | ||||
|                     'Invisible' => ActivityType::FIELD_INVISIBLE, | ||||
|                     'Optional' => ActivityType::FIELD_OPTIONAL, | ||||
|                     'Required' => ActivityType::FIELD_REQUIRED, | ||||
|                 ], | ||||
|             ) | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| @@ -1,40 +1,53 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form\Type; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Chill\ActivityBundle\Entity\ActivityReason; | ||||
| use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender; | ||||
|  | ||||
| /** | ||||
|  * FormType to choose amongst activity reasons. | ||||
|  * FormType to choose amongst activity reasons | ||||
|  *  | ||||
|  */ | ||||
| class TranslatableActivityReason extends AbstractType | ||||
| { | ||||
|     /** | ||||
|      * @var ActivityReasonRender | ||||
|      */ | ||||
|     protected $reasonRender; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var ActivityReasonRender | ||||
|      */ | ||||
|     protected $reasonRender; | ||||
|  | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $translatableStringHelper, | ||||
| @@ -44,30 +57,6 @@ class TranslatableActivityReason extends AbstractType | ||||
|         $this->reasonRender = $reasonRender; | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults( | ||||
|             [ | ||||
|                 'class' => 'ChillActivityBundle:ActivityReason', | ||||
|                 'choice_label' => function (ActivityReason $choice) { | ||||
|                     return $this->reasonRender->renderString($choice, []); | ||||
|                 }, | ||||
|                 'group_by' => function (ActivityReason $choice): ?string { | ||||
|                     if (null !== $category = $choice->getCategory()) { | ||||
|                         return $this->translatableStringHelper->localize($category->getName()); | ||||
|                     } | ||||
|  | ||||
|                     return null; | ||||
|                 }, | ||||
|                 'query_builder' => static function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('r') | ||||
|                         ->where('r.active = true'); | ||||
|                 }, | ||||
|                 'attr' => ['class' => ' select2 '], | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|     { | ||||
|         return 'translatable_activity_reason'; | ||||
| @@ -77,4 +66,28 @@ class TranslatableActivityReason extends AbstractType | ||||
|     { | ||||
|         return EntityType::class; | ||||
|     } | ||||
|      | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults( | ||||
|             array( | ||||
|                 'class' => 'ChillActivityBundle:ActivityReason', | ||||
|                 'choice_label' => function(ActivityReason $choice)  { | ||||
|                     return $this->reasonRender->renderString($choice, []); | ||||
|                 }, | ||||
|                 'group_by' => function(ActivityReason $choice): ?string { | ||||
|                     if (null !== $category = $choice->getCategory()) { | ||||
|                         return $this->translatableStringHelper->localize($category->getName()); | ||||
|                     } | ||||
|  | ||||
|                     return null; | ||||
|                 }, | ||||
|                 'query_builder' => function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('r') | ||||
|                         ->where('r.active = true'); | ||||
|                 }, | ||||
|                 'attr' => [ 'class' => ' select2 '] | ||||
|             ) | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,27 +1,40 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form\Type; | ||||
|  | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
|  | ||||
| /** | ||||
|  * Description of TranslatableActivityReasonCategory. | ||||
|  * Description of TranslatableActivityReasonCategory | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
|  | ||||
|  | ||||
| class TranslatableActivityReasonCategory extends AbstractType | ||||
| { | ||||
|     /** | ||||
| @@ -34,21 +47,6 @@ class TranslatableActivityReasonCategory extends AbstractType | ||||
|         $this->requestStack = $requestStack; | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $locale = $this->requestStack->getCurrentRequest()->getLocale(); | ||||
|         $resolver->setDefaults( | ||||
|             [ | ||||
|                 'class' => 'ChillActivityBundle:ActivityReasonCategory', | ||||
|                 'choice_label' => 'name[' . $locale . ']', | ||||
|                 'query_builder' => static function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('c') | ||||
|                         ->where('c.active = true'); | ||||
|                 }, | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|     { | ||||
|         return 'translatable_activity_reason_category'; | ||||
| @@ -58,4 +56,19 @@ class TranslatableActivityReasonCategory extends AbstractType | ||||
|     { | ||||
|         return EntityType::class; | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $locale = $this->requestStack->getCurrentRequest()->getLocale(); | ||||
|         $resolver->setDefaults( | ||||
|             array( | ||||
|                 'class' => 'ChillActivityBundle:ActivityReasonCategory', | ||||
|                 'choice_label' => 'name['.$locale.']', | ||||
|                 'query_builder' => function (EntityRepository $er) { | ||||
|                     return $er->createQueryBuilder('c') | ||||
|                         ->where('c.active = true'); | ||||
|                 } | ||||
|             ) | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,71 +1,60 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Form\Type; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
| use Symfony\Component\HttpFoundation\RequestStack; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Chill\ActivityBundle\Entity\ActivityType; | ||||
|  | ||||
| /** | ||||
|  * Description of TranslatableActivityType. | ||||
|  * Description of TranslatableActivityType | ||||
|  * | ||||
|  * @author Champs-Libres Coop | ||||
|  */ | ||||
| class TranslatableActivityType extends AbstractType | ||||
| { | ||||
|     protected $activityTypeRepository; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatableStringHelper | ||||
|      */ | ||||
|     protected $translatableStringHelper; | ||||
|  | ||||
|     protected $activityTypeRepository; | ||||
|  | ||||
|     public function __construct( | ||||
|         TranslatableStringHelper $helper, | ||||
|         EntityRepository $activityTypeRepository | ||||
|     ) { | ||||
|             TranslatableStringHelper $helper, | ||||
|             EntityRepository $activityTypeRepository | ||||
|             ) | ||||
|     { | ||||
|         $this->translatableStringHelper = $helper; | ||||
|         $this->activityTypeRepository = $activityTypeRepository; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) | ||||
|     { | ||||
|         /** @var \Doctrine\ORM\QueryBuilder $qb */ | ||||
|         $qb = $options['query_builder']; | ||||
|  | ||||
|         if (true === $options['active_only']) { | ||||
|             $qb->where($qb->expr()->eq('at.active', ':active')); | ||||
|             $qb->setParameter('active', true, \Doctrine\DBAL\Types\Type::BOOLEAN); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults( | ||||
|             [ | ||||
|                 'class' => 'ChillActivityBundle:ActivityType', | ||||
|                 'active_only' => true, | ||||
|                 'query_builder' => $this->activityTypeRepository | ||||
|                     ->createQueryBuilder('at'), | ||||
|                 'choice_label' => function (ActivityType $type) { | ||||
|                     return $this->translatableStringHelper->localize($type->getName()); | ||||
|                 }, | ||||
|             ] | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|     { | ||||
|         return 'translatable_activity_type'; | ||||
| @@ -75,4 +64,30 @@ class TranslatableActivityType extends AbstractType | ||||
|     { | ||||
|         return EntityType::class; | ||||
|     } | ||||
|  | ||||
|     public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options) { | ||||
|         /* @var $qb \Doctrine\ORM\QueryBuilder */ | ||||
|         $qb = $options['query_builder']; | ||||
|  | ||||
|         if ($options['active_only'] === true) { | ||||
|             $qb->where($qb->expr()->eq('at.active', ':active')); | ||||
|             $qb->setParameter('active', true, \Doctrine\DBAL\Types\Type::BOOLEAN); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|  | ||||
|         $resolver->setDefaults( | ||||
|             array( | ||||
|                 'class' => 'ChillActivityBundle:ActivityType', | ||||
|                 'active_only' => true, | ||||
|                 'query_builder' => $this->activityTypeRepository | ||||
|                     ->createQueryBuilder('at'), | ||||
|                 'choice_label' => function (ActivityType $type) { | ||||
|                     return $this->translatableStringHelper->localize($type->getName()); | ||||
|                 } | ||||
|             ) | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,47 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Menu; | ||||
|  | ||||
| use Chill\MainBundle\Routing\LocalMenuBuilderInterface; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Knp\Menu\MenuItem; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||||
|  | ||||
| class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface | ||||
| { | ||||
|     protected TokenStorageInterface $tokenStorage; | ||||
|  | ||||
|     protected AuthorizationHelper $authorizationHelper; | ||||
|  | ||||
|     protected TranslatorInterface $translator; | ||||
|  | ||||
|     public function __construct( | ||||
|         TokenStorageInterface $tokenStorage, | ||||
|         AuthorizationHelper $authorizationHelper, | ||||
|         TranslatorInterface $translator | ||||
|     ) { | ||||
|         $this->translator = $translator; | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|         $this->tokenStorage = $tokenStorage; | ||||
|     } | ||||
|     public static function getMenuIds(): array | ||||
|     { | ||||
|         return ['accompanyingCourse']; | ||||
|     } | ||||
|  | ||||
|     public function buildMenu($menuId, MenuItem $menu, array $parameters) | ||||
|     { | ||||
|         $period = $parameters['accompanyingCourse']; | ||||
|  | ||||
|         if (AccompanyingPeriod::STEP_DRAFT !== $period->getStep()) { | ||||
|             $menu->addChild($this->translator->trans('Activity list'), [ | ||||
|                 'route' => 'chill_activity_activity_list', | ||||
|                 'routeParameters' => [ | ||||
|                     'accompanying_period_id' => $period->getId(), | ||||
|                 ]]) | ||||
|                 ->setExtras(['order' => 40]); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,88 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Menu; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Chill\MainBundle\Routing\LocalMenuBuilderInterface; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Knp\Menu\MenuItem; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Symfony\Component\Translation\TranslatorInterface; | ||||
|  | ||||
| class MenuBuilder implements LocalMenuBuilderInterface | ||||
| { | ||||
|     /** | ||||
|      * @var AuthorizationHelper | ||||
|      */ | ||||
|     protected $authorizationHelper; | ||||
|  | ||||
|     /** | ||||
|      * @var TokenStorageInterface | ||||
|      */ | ||||
|     protected $tokenStorage; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|  | ||||
|     public function __construct( | ||||
|         TokenStorageInterface $tokenStorage, | ||||
|         TranslatorInterface $translator, | ||||
|         AuthorizationHelper $authorizationHelper | ||||
|     ) { | ||||
|         $this->tokenStorage = $tokenStorage; | ||||
|         $this->translator = $translator; | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|     } | ||||
|  | ||||
|     public function buildMenu($menuId, MenuItem $menu, array $parameters) | ||||
|     { | ||||
|         /** @var \Chill\PersonBundle\Entity\Person $person */ | ||||
|         $person = $parameters['person']; | ||||
|         $user = $this->tokenStorage->getToken()->getUser(); | ||||
|         $roleSee = new Role(ActivityVoter::SEE); | ||||
|         $roleAdd = new Role(ActivityVoter::CREATE); | ||||
|  | ||||
|         if ($this->authorizationHelper->userHasAccess($user, $person, $roleSee)) { | ||||
|             $menu->addChild($this->translator->trans('Activity list'), [ | ||||
|                 'route' => 'chill_activity_activity_list', | ||||
|                 'routeParameters' => [ | ||||
|                     'person_id' => $person->getId(), | ||||
|                 ], | ||||
|             ]) | ||||
|                 ->setExtras([ | ||||
|                     'order' => 201, | ||||
|                 ]); | ||||
|         } | ||||
|  | ||||
|         if ($this->authorizationHelper->userHasAccess($user, $person, $roleAdd)) { | ||||
|             $menu->addChild($this->translator->trans('Add a new activity'), [ | ||||
|                 'route' => 'chill_activity_activity_new', | ||||
|                 'routeParameters' => [ | ||||
|                     'person_id' => $person->getId(), | ||||
|                 ], | ||||
|             ]) | ||||
|                 ->setExtras([ | ||||
|                     'order' => 200, | ||||
|                 ]); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static function getMenuIds(): array | ||||
|     { | ||||
|         return ['person']; | ||||
|     } | ||||
| } | ||||
| @@ -1,69 +1,68 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
| /* | ||||
|  * Copyright (C) 2018 Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\ActivityBundle\Menu; | ||||
|  | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| namespace Chill\ActivityBundle\Menu;  | ||||
| use Chill\MainBundle\Routing\LocalMenuBuilderInterface; | ||||
| use Knp\Menu\MenuItem; | ||||
| use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Symfony\Component\Translation\TranslatorInterface; | ||||
|  | ||||
| /** | ||||
|  *  | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class PersonMenuBuilder implements LocalMenuBuilderInterface | ||||
| { | ||||
|     /** | ||||
|      * @var AuthorizationCheckerInterface | ||||
|      */ | ||||
|     protected $authorizationChecker; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|  | ||||
|      | ||||
|     /** | ||||
|      * | ||||
|      * @var AuthorizationCheckerInterface | ||||
|      */ | ||||
|     protected $authorizationChecker; | ||||
|      | ||||
|     public function __construct( | ||||
|         AuthorizationCheckerInterface $authorizationChecker, | ||||
|         TranslatorInterface $translator | ||||
|     ) { | ||||
|         TranslatorInterface $translator) | ||||
|     { | ||||
|         $this->translator = $translator; | ||||
|         $this->authorizationChecker = $authorizationChecker; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public function buildMenu($menuId, MenuItem $menu, array $parameters) | ||||
|     { | ||||
|         /** @var \Chill\PersonBundle\Entity\Person $person */ | ||||
|         /* @var $person \Chill\PersonBundle\Entity\Person */ | ||||
|         $person = $parameters['person']; | ||||
|  | ||||
|          | ||||
|         if ($this->authorizationChecker->isGranted(ActivityVoter::SEE, $person)) { | ||||
|             $menu->addChild( | ||||
|                 $this->translator->trans('Activity list'), | ||||
|                 [ | ||||
|                 $this->translator->trans('Activity list'), [ | ||||
|                     'route' => 'chill_activity_activity_list', | ||||
|                     'routeParameters' => ['person_id' => $person->getId()], | ||||
|                 ] | ||||
|             ) | ||||
|                 ->setExtra('order', 201); | ||||
|         } | ||||
|  | ||||
|         if ($this->authorizationChecker->isGranted(ActivityVoter::CREATE, $person)) { | ||||
|             $menu->addChild( | ||||
|                 $this->translator->trans('Add a new activity'), | ||||
|                 [ | ||||
|                     'route' => 'chill_activity_activity_new', | ||||
|                     'routeParameters' => ['person_id' => $person->getId()], | ||||
|                 ] | ||||
|             ) | ||||
|                 ->setExtra('order', 200); | ||||
|                     'routeParameters' => [ 'person_id' => $person->getId() ], | ||||
|                 ]) | ||||
|                 ->setExtra('order', 201) | ||||
|                 ; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,24 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Chill\ActivityBundle\Notification; | ||||
|  | ||||
| use Chill\MainBundle\Entity\Notification; | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
|  | ||||
| final class ActivityNotificationRenderer | ||||
| { | ||||
|     public function supports(Notification $notification, array $options = []): bool | ||||
|     { | ||||
|         return $notification->getRelatedEntityClass() == Activity::class; | ||||
|     } | ||||
|  | ||||
|     public function getTemplate() | ||||
|     { | ||||
|         return '@ChillActivity/Activity/showInNotification.html.twig'; | ||||
|     } | ||||
|  | ||||
|     public function getTemplateData(Notification $notification) | ||||
|     { | ||||
|         return ['notification' => $notification]; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,169 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * Copyright (C) 2021, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Repository; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use Chill\ActivityBundle\Repository\ActivityRepository; | ||||
| use Chill\ActivityBundle\Security\Authorization\ActivityVoter; | ||||
| use Chill\MainBundle\Entity\Scope; | ||||
| use Doctrine\ORM\QueryBuilder; | ||||
| use Doctrine\ORM\Query\Expr\Orx; | ||||
| use Chill\MainBundle\Security\Authorization\AuthorizationHelper; | ||||
| use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||||
| use Symfony\Component\Security\Core\Role\Role; | ||||
| use Doctrine\ORM\EntityManagerInterface; | ||||
|  | ||||
|  | ||||
| final class ActivityACLAwareRepository  | ||||
| { | ||||
|     private AuthorizationHelper $authorizationHelper; | ||||
|  | ||||
|     private TokenStorageInterface $tokenStorage; | ||||
|  | ||||
|     private ActivityRepository $repository; | ||||
|  | ||||
|     private EntityManagerInterface $em; | ||||
|  | ||||
|     public function __construct( | ||||
|         AuthorizationHelper $authorizationHelper, | ||||
|         TokenStorageInterface $tokenStorage, | ||||
|         ActivityRepository $repository, | ||||
|         EntityManagerInterface $em | ||||
|     ) { | ||||
|         $this->authorizationHelper = $authorizationHelper; | ||||
|         $this->tokenStorage = $tokenStorage; | ||||
|         $this->repository = $repository; | ||||
|         $this->em = $em; | ||||
|     } | ||||
|  | ||||
|     public function queryTimelineIndexer(string $context, array $args = []): array | ||||
|     { | ||||
|         $metadataActivity = $this->em->getClassMetadata(Activity::class); | ||||
|  | ||||
|         $from = $this->getFromClauseCenter($args); | ||||
|         [$where, $parameters] = $this->getWhereClause($context, $args); | ||||
|  | ||||
|         return [ | ||||
|            'id' => $metadataActivity->getTableName() | ||||
|                 .'.'.$metadataActivity->getColumnName('id'), | ||||
|            'type' => 'activity', | ||||
|            'date' => $metadataActivity->getTableName() | ||||
|                 .'.'.$metadataActivity->getColumnName('date'), | ||||
|            'FROM' => $from, | ||||
|            'WHERE' => $where, | ||||
|            'parameters' => $parameters | ||||
|        ]; | ||||
|     } | ||||
|  | ||||
|     private function getFromClauseCenter(array $args): string | ||||
|     { | ||||
|         $metadataActivity = $this->em->getClassMetadata(Activity::class); | ||||
|         $metadataPerson = $this->em->getClassMetadata(Person::class); | ||||
|         $associationMapping = $metadataActivity->getAssociationMapping('person'); | ||||
|          | ||||
|         return $metadataActivity->getTableName().' JOIN ' | ||||
|             .$metadataPerson->getTableName().' ON ' | ||||
|             .$metadataPerson->getTableName().'.'. | ||||
|                 $associationMapping['joinColumns'][0]['referencedColumnName'] | ||||
|             .' = ' | ||||
|             .$associationMapping['joinColumns'][0]['name'] | ||||
|             ; | ||||
|     } | ||||
|  | ||||
|     private function getWhereClause(string $context, array $args): array | ||||
|     { | ||||
|         $where = ''; | ||||
|         $parameters = []; | ||||
|          | ||||
|         $metadataActivity = $this->em->getClassMetadata(Activity::class); | ||||
|         $metadataPerson = $this->em->getClassMetadata(Person::class); | ||||
|         $activityToPerson = $metadataActivity->getAssociationMapping('person')['joinColumns'][0]['name']; | ||||
|         $activityToScope  = $metadataActivity->getAssociationMapping('scope')['joinColumns'][0]['name']; | ||||
|         $personToCenter = $metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name']; | ||||
|  | ||||
|  | ||||
|         // acls: | ||||
|         $role = new Role(ActivityVoter::SEE); | ||||
|         $reachableCenters = $this->authorizationHelper->getReachableCenters($this->tokenStorage->getToken()->getUser(),  | ||||
|                 $role); | ||||
|          | ||||
|         if (count($reachableCenters) === 0) { | ||||
|             // insert a dummy condition | ||||
|             return 'FALSE = TRUE'; | ||||
|         } | ||||
|  | ||||
|         if ($context === 'person') {  | ||||
|             // we start with activities having the person_id linked to person  | ||||
|             $where .= sprintf('%s = ? AND ', $activityToPerson); | ||||
|             $parameters[] = $person->getId(); | ||||
|         } | ||||
|          | ||||
|         // we add acl (reachable center and scopes) | ||||
|         $where .= '('; // first loop for the for centers | ||||
|         $centersI = 0; // like centers#i | ||||
|         foreach ($reachableCenters as $center) { | ||||
|             // we pass if not in centers | ||||
|             if (!\in_array($center, $args['centers'])) { | ||||
|                 continue; | ||||
|             } | ||||
|             // we get all the reachable scopes for this center | ||||
|             $reachableScopes = $this->authorizationHelper->getReachableScopes($this->tokenStorage->getToken()->getUser(), $role, $center); | ||||
|             // we get the ids for those scopes | ||||
|             $reachablesScopesId = array_map( | ||||
|                 function(Scope $scope) { return $scope->getId(); },  | ||||
|                 $reachableScopes | ||||
|             ); | ||||
|  | ||||
|             // if not the first center | ||||
|             if ($centersI > 0) { | ||||
|                 $where .= ') OR ('; | ||||
|             } | ||||
|  | ||||
|             // condition for the center | ||||
|             $where .= sprintf(' %s.%s = ? ', $metadataPerson->getTableName(), $personToCenter); | ||||
|             $parameters[] = $center->getId(); | ||||
|  | ||||
|             // begin loop for scopes | ||||
|             $where .= ' AND ('; | ||||
|             $scopesI = 0; //like scope#i | ||||
|  | ||||
|             foreach ($reachablesScopesId as $scopeId) { | ||||
|                 if ($scopesI > 0) { | ||||
|                     $where .= ' OR '; | ||||
|                 } | ||||
|                 $where .= sprintf(' %s.%s = ? ', $metadataActivity->getTableName(), $activityToScope); | ||||
|                 $parameters[] = $scopeId; | ||||
|                 $scopesI ++; | ||||
|             } | ||||
|             // close loop for scopes | ||||
|             $where .= ') '; | ||||
|             $centersI++; | ||||
|         } | ||||
|         // close loop for centers | ||||
|         $where .= ')'; | ||||
|          | ||||
|         return [$where, $parameters]; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,67 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * Copyright (C) 2021, Champs Libres Cooperative SCRLFS, | ||||
|  * <http://www.champs-libres.coop>, <info@champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  * License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\ActivityBundle\Repository; | ||||
|  | ||||
| use Chill\ActivityBundle\Entity\Activity; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
| /** | ||||
|  * @method AccompanyingPeriodParticipation|null find($id, $lockMode = null, $lockVersion = null) | ||||
|  * @method AccompanyingPeriodParticipation|null findOneBy(array $criteria, array $orderBy = null) | ||||
|  * @method AccompanyingPeriodParticipation[]    findAll() | ||||
|  * @method AccompanyingPeriodParticipation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||||
|  */ | ||||
| class ActivityRepository extends ServiceEntityRepository | ||||
| { | ||||
|     public function __construct(ManagerRegistry $registry) | ||||
|     { | ||||
|         parent::__construct($registry, Activity::class); | ||||
|     } | ||||
|  | ||||
|     public function findByPersonImplied($person, array $scopes, $orderBy = [ 'date' => 'DESC'], $limit = 100, $offset = 0) | ||||
|     { | ||||
|         $qb = $this->createQueryBuilder('a'); | ||||
|         $qb->select('a'); | ||||
|  | ||||
|         $qb | ||||
|             // TODO add acl | ||||
|             //->where($qb->expr()->in('a.scope', ':scopes')) | ||||
|             //->setParameter('scopes', $scopes) | ||||
|             ->andWhere( | ||||
|                 $qb->expr()->orX( | ||||
|                     $qb->expr()->eq('a.person', ':person'), | ||||
|                     ':person MEMBER OF a.persons' | ||||
|                 ) | ||||
|             ) | ||||
|             ->setParameter('person', $person) | ||||
|             ; | ||||
|  | ||||
|         foreach ($orderBy as $k => $dir) { | ||||
|             $qb->addOrderBy('a.'.$k, $dir); | ||||
|         } | ||||
|  | ||||
|         return $qb->getQuery() | ||||
|             ->getResult(); | ||||
|     }     | ||||
| } | ||||
| @@ -1,10 +0,0 @@ | ||||
| @import '~ChillMainSass/custom/config/colors'; | ||||
| @import '~ChillMainSass/custom/mixins/entity'; | ||||
|  | ||||
| .chill-entity.chill-entity__activity-reason { | ||||
|     @include entity($chill-pink, white); | ||||
| } | ||||
|  | ||||
| .activity { | ||||
|     color: $chill-green; | ||||
| } | ||||
| @@ -0,0 +1,129 @@ | ||||
| // Access to Bootstrap variables and mixins | ||||
| @import '~ChillMainAssets/module/bootstrap/shared'; | ||||
|  | ||||
| // activity creation first step: select type page | ||||
| div.new-activity-select-type { | ||||
|    div.activity-row { | ||||
|       display: flex; | ||||
|       flex-direction: row; | ||||
|       flex-wrap: wrap; | ||||
|       justify-content: center; | ||||
|       gap: 12px; | ||||
|  | ||||
|       div.bloc { | ||||
|          width: 200px; | ||||
|          align-self: flex-end; | ||||
|          height: 140px; | ||||
|          display: flex; | ||||
|          justify-content: center; | ||||
|          align-items: center; | ||||
|       } | ||||
|    } | ||||
| } | ||||
|  | ||||
| // exceptions for flex-table in list-records | ||||
| div.activity-list { | ||||
|    div.flex-table { | ||||
|       div.item-bloc { | ||||
|          div.item-row.main { | ||||
|             div.item-col { | ||||
|                &:first-child { | ||||
|                   flex-basis: 27%; | ||||
|                } | ||||
|                ul.list-content { | ||||
|                   li.social-issues, li.social-actions { | ||||
|                      .badge-primary { | ||||
|                         font-variant: small-caps; | ||||
|                         font-weight: bold; | ||||
|                         font-size: 88%; | ||||
|                         margin-bottom: 0.2em; | ||||
|                      } | ||||
|                   } | ||||
|                   li.social-issues .badge-primary { | ||||
|                      background-color: $orange; | ||||
|                   } | ||||
|                   li.social-actions .badge-primary { | ||||
|                      background-color: $green; | ||||
|                   } | ||||
|                } | ||||
|             } | ||||
|          } | ||||
|          div.item-row.details { | ||||
|             flex-direction: row; | ||||
|             & > div.item-col { | ||||
|                justify-content: flex-start; | ||||
|                align-self: center; | ||||
|                &:nth-child(1) { | ||||
|                   flex-grow: 1; flex-shrink: 0; flex-basis: 30%; | ||||
|                } | ||||
|                &:nth-child(2) { | ||||
|                   flex-grow: 0; flex-shrink: 1; flex-basis: 70%; | ||||
|                } | ||||
|  | ||||
|                &:only-child { | ||||
|                   flex-grow: 0; flex-shrink: 0; flex-basis: 100%; | ||||
|                   & > div.concerned-groups { | ||||
|                      flex-grow: 0; flex-shrink: 0; flex-basis: 100%; | ||||
|                      display: flex; | ||||
|                      flex-direction: column; // TODO pas fini | ||||
|                      div.group { | ||||
|                         flex-grow: 1; flex-shrink: 0; flex-basis: 30%; | ||||
|                         h4 {} | ||||
|                         ul.list-content { | ||||
|                            li { | ||||
|                               display: inline; | ||||
|                            } | ||||
|                         } | ||||
|                      } | ||||
|                   } | ||||
|                } | ||||
|             } | ||||
|             div.concerned-groups { | ||||
|                font-size: 85%; | ||||
|                h4 { | ||||
|                   text-transform: uppercase; | ||||
|                } | ||||
|             } | ||||
|          } | ||||
|          ul.list-content { | ||||
|             list-style-type: none; | ||||
|             padding-left: 1em; | ||||
|             margin: 0 0; | ||||
|             li { | ||||
|                margin-bottom: 0.2em; | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|       div.duration { | ||||
|          font-size: smaller; | ||||
|          padding-left: 1em; | ||||
|          margin-top: 1em; | ||||
|       } | ||||
|    } | ||||
| } | ||||
|  | ||||
| // exceptions for flex-bloc in concerned-groups | ||||
| div.flex-bloc.concerned-groups { | ||||
|    margin-top: 1em; | ||||
|    div.item-bloc { | ||||
|       flex-grow: 0; flex-shrink: 0; flex-basis: 25%; //4 blocs | ||||
|       ul.list-content { | ||||
|          list-style-type: none; | ||||
|          padding-left: 0; | ||||
|          li { | ||||
|             margin-bottom: 0.2em; | ||||
|             a { | ||||
|                color: $white; | ||||
|                cursor: pointer; | ||||
|                &:hover { | ||||
|                   color: #ffffffab; | ||||
|                } | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|    } | ||||
|    &.person div.item-bloc { | ||||
|       flex-basis: 33%; //3 blocs | ||||
|    } | ||||
| } | ||||
|  | ||||
| @@ -0,0 +1 @@ | ||||
| require('./chillactivity.scss'); | ||||
| @@ -1 +0,0 @@ | ||||
| require('./activity/activity.scss'); | ||||
| @@ -0,0 +1,17 @@ | ||||
| <template> | ||||
|    <concerned-groups></concerned-groups> | ||||
|    <social-issues-acc></social-issues-acc> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import ConcernedGroups from './components/ConcernedGroups.vue'; | ||||
| import SocialIssuesAcc from './components/SocialIssuesAcc.vue'; | ||||
|  | ||||
| export default { | ||||
|    name: "App", | ||||
|    components: { | ||||
|       ConcernedGroups, | ||||
|       SocialIssuesAcc | ||||
|    } | ||||
| } | ||||
| </script> | ||||
| @@ -0,0 +1,18 @@ | ||||
| import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api.js'; | ||||
|  | ||||
| /* | ||||
| *  Load socialActions by socialIssue (id) | ||||
| */ | ||||
| const getSocialActionByIssue = (id) => {  | ||||
|    const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`; | ||||
|    return fetch(url) | ||||
|       .then(response => { | ||||
|          if (response.ok) { return response.json(); } | ||||
|          throw Error('Error with request resource response');  | ||||
|       }); | ||||
| }; | ||||
|  | ||||
| export { | ||||
|    getSocialIssues, | ||||
|    getSocialActionByIssue | ||||
| }; | ||||
| @@ -0,0 +1,170 @@ | ||||
| <template> | ||||
|    <teleport to="#add-persons"> | ||||
|  | ||||
|       <div class="flex-bloc concerned-groups" :class="getContext"> | ||||
|          <persons-bloc  | ||||
|             v-for="bloc in contextPersonsBlocs" | ||||
|             v-bind:key="bloc.key" | ||||
|             v-bind:bloc="bloc" | ||||
|             v-bind:setPersonsInBloc="setPersonsInBloc"> | ||||
|          </persons-bloc> | ||||
|       </div> | ||||
|  | ||||
|       <add-persons  | ||||
|          buttonTitle="activity.add_persons" | ||||
|          modalTitle="activity.add_persons" | ||||
|          v-bind:key="addPersons.key" | ||||
|          v-bind:options="addPersons.options" | ||||
|          @addNewPersons="addNewPersons" | ||||
|          ref="addPersons"> | ||||
|       </add-persons> | ||||
|   | ||||
|   </teleport>   | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import { mapState } from 'vuex'; | ||||
| import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue'; | ||||
| import PersonsBloc from './ConcernedGroups/PersonsBloc.vue'; | ||||
|  | ||||
| export default { | ||||
|    name: "ConcernedGroups", | ||||
|    components: { | ||||
|       AddPersons, | ||||
|       PersonsBloc | ||||
|    }, | ||||
|    data() { | ||||
|       return { | ||||
|          personsBlocs: [ | ||||
|             {  key: 'persons',  | ||||
|                title: 'activity.bloc_persons',  | ||||
|                persons: [],  | ||||
|                included: false  | ||||
|             }, | ||||
|             {  key: 'personsAssociated',  | ||||
|                title: 'activity.bloc_persons_associated',  | ||||
|                persons: [],  | ||||
|                included: false  | ||||
|             }, | ||||
|             {  key: 'personsNotAssociated',  | ||||
|                title: 'activity.bloc_persons_not_associated',  | ||||
|                persons: [],  | ||||
|                included: false  | ||||
|             }, | ||||
|             {  key: 'thirdparty',  | ||||
|                title: 'activity.bloc_thirdparty',  | ||||
|                persons: [],  | ||||
|                included: true | ||||
|             }, | ||||
|             {  key: 'users',  | ||||
|                title: 'activity.bloc_users',  | ||||
|                persons: [],  | ||||
|                included: true | ||||
|             }, | ||||
|          ], | ||||
|          addPersons: { | ||||
|             key: 'activity', | ||||
|             options: { | ||||
|                type: ['person', 'thirdparty', 'user'], // TODO add 'user' | ||||
|                priority: null, | ||||
|                uniq: false, | ||||
|             } | ||||
|          } | ||||
|       } | ||||
|    }, | ||||
|    computed: { | ||||
|       ...mapState({ | ||||
|          persons: state => state.activity.persons, | ||||
|          thirdParties: state => state.activity.thirdParties, | ||||
|          users: state => state.activity.users, | ||||
|          accompanyingCourse: state => state.activity.accompanyingPeriod | ||||
|       }), | ||||
|       getContext() { | ||||
|          return (this.accompanyingCourse) ? "accompanyingCourse" : "person"; | ||||
|       }, | ||||
|       contextPersonsBlocs() { | ||||
|          return this.personsBlocs.filter(bloc => bloc.included !== false); | ||||
|       } | ||||
|    }, | ||||
|    mounted() { | ||||
|       this.setPersonsInBloc(); | ||||
|    }, | ||||
|    methods: { | ||||
|       setPersonsInBloc() { | ||||
|          let groups;  | ||||
|          if (this.accompanyingCourse) { | ||||
|             groups = this.splitPersonsInGroups(); | ||||
|          }      | ||||
|          this.personsBlocs.forEach(bloc => { | ||||
|             if (this.accompanyingCourse) { | ||||
|                switch (bloc.key) { | ||||
|                   case 'personsAssociated': | ||||
|                      bloc.persons = groups.personsAssociated; | ||||
|                      bloc.included = true; | ||||
|                      break; | ||||
|                   case 'personsNotAssociated': | ||||
|                      bloc.persons = groups.personsNotAssociated; | ||||
|                      bloc.included = true; | ||||
|                      break; | ||||
|                } | ||||
|             } else { | ||||
|                switch (bloc.key) { | ||||
|                   case 'persons':  | ||||
|                      bloc.persons = this.persons; | ||||
|                      bloc.included = true; | ||||
|                      break; | ||||
|                } | ||||
|             } | ||||
|             switch (bloc.key) { | ||||
|                case 'thirdparty': | ||||
|                   bloc.persons = this.thirdParties; | ||||
|                   break; | ||||
|                case 'users': | ||||
|                   bloc.persons = this.users; | ||||
|                   break; | ||||
|             } | ||||
|          }, groups); | ||||
|       }, | ||||
|       splitPersonsInGroups() { | ||||
|          let personsAssociated = []; | ||||
|          let personsNotAssociated = this.persons; | ||||
|          let participations = this.getCourseParticipations();          | ||||
|          this.persons.forEach(person => { | ||||
|             participations.forEach(participation => { | ||||
|                if (person.id === participation.id) { | ||||
|                   //console.log(person.id); | ||||
|                   personsAssociated.push(person); | ||||
|                   personsNotAssociated = personsNotAssociated.filter(p => p !== person); | ||||
|                } | ||||
|             }); | ||||
|          }); | ||||
|          return {  | ||||
|             'personsAssociated': personsAssociated,  | ||||
|             'personsNotAssociated': personsNotAssociated  | ||||
|          }; | ||||
|       }, | ||||
|       getCourseParticipations() { | ||||
|          let participations = []; | ||||
|          this.accompanyingCourse.participations.forEach(participation => { | ||||
|             if (!participation.endDate) { | ||||
|                participations.push(participation.person); | ||||
|             } | ||||
|          }); | ||||
|          return participations; | ||||
|       }, | ||||
|       addNewPersons({ selected, modal }) { | ||||
|          console.log('@@@ CLICK button addNewPersons', selected); | ||||
|          selected.forEach(function(item) { | ||||
|                this.$store.dispatch('addPersonsInvolved', item); | ||||
|             }, this | ||||
|          ); | ||||
|          this.$refs.addPersons.resetSearch(); // to cast child method | ||||
|          modal.showModal = false; | ||||
|          this.setPersonsInBloc(); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" scoped> | ||||
| </style> | ||||
| @@ -0,0 +1,29 @@ | ||||
| <template> | ||||
|    <li> | ||||
|       <span class="badge bg-primary" :title="person.text"> | ||||
|          <span class="chill_denomination"> | ||||
|             {{ textCutted }} | ||||
|          </span> | ||||
|          <a class="fa fa-fw fa-times" | ||||
|             @click.prevent="$emit('remove', person)"> | ||||
|          </a> | ||||
|       </span> | ||||
|    </li> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| export default { | ||||
|    name: "PersonBadge", | ||||
|    props: ['person'], | ||||
|    computed: { | ||||
|       textCutted() { | ||||
|          let more = (this.person.text.length > 15) ?'…' : ''; | ||||
|          return this.person.text.slice(0,15) + more; | ||||
|       } | ||||
|    }, | ||||
|    emits: ['remove'], | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <style lang="css" scoped> | ||||
| </style> | ||||
| @@ -0,0 +1,41 @@ | ||||
| <template> | ||||
|    <div class="item-bloc"> | ||||
|       <div class="item-row"> | ||||
|          <div class="item-col"> | ||||
|             <h4>{{ $t(bloc.title) }}</h4> | ||||
|          </div> | ||||
|          <div class="item-col"> | ||||
|             <ul class="list-content"> | ||||
|                <person-badge | ||||
|                   v-for="person in bloc.persons" | ||||
|                   v-bind:key="person.id" | ||||
|                   v-bind:person="person" | ||||
|                   @remove="removePerson"> | ||||
|                </person-badge> | ||||
|             </ul> | ||||
|          </div> | ||||
|       </div> | ||||
|    </div> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import PersonBadge from './PersonBadge.vue'; | ||||
| export default { | ||||
|    name:"PersonsBloc", | ||||
|    components: { | ||||
|       PersonBadge | ||||
|    }, | ||||
|    props: ['bloc', 'setPersonsInBloc'], | ||||
|    methods: { | ||||
|       removePerson(item) { | ||||
|          console.log('@@ CLICK remove person: item', item); | ||||
|          this.$store.dispatch('removePersonInvolved', item); | ||||
|          this.setPersonsInBloc(); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <style lang="scss"> | ||||
|  | ||||
| </style> | ||||
| @@ -0,0 +1,214 @@ | ||||
| <template> | ||||
|    <teleport to="#social-issues-acc"> | ||||
|        | ||||
|       <div class="mb-3 row"> | ||||
|          <div class="col-4"> | ||||
|             <label class="col-form-label">{{ $t('activity.social_issues') }}</label> | ||||
|          </div> | ||||
|          <div class="col-8"> | ||||
|              | ||||
|             <check-social-issue | ||||
|                v-for="issue in socialIssuesList" | ||||
|                v-bind:key="issue.id" | ||||
|                v-bind:issue="issue" | ||||
|                v-bind:selection="socialIssuesSelected" | ||||
|                @updateSelected="updateIssuesSelected"> | ||||
|             </check-social-issue> | ||||
|              | ||||
|             <div class="my-3"> | ||||
|             <VueMultiselect | ||||
|                name="otherIssues" | ||||
|                label="text" | ||||
|                track-by="id" | ||||
|                open-direction="bottom" | ||||
|                v-bind:close-on-select="true" | ||||
|                v-bind:preserve-search="false" | ||||
|                v-bind:reset-after="true" | ||||
|                v-bind:hide-selected="true" | ||||
|                v-bind:taggable="false" | ||||
|                v-bind:multiple="false" | ||||
|                v-bind:searchable="true" | ||||
|                v-bind:allow-empty="true"  | ||||
|                v-bind:show-labels="false" | ||||
|                v-bind:loading="issueIsLoading" | ||||
|                v-bind:placeholder="$t('activity.choose_other_social_issue')" | ||||
|                v-bind:options="socialIssuesOther" | ||||
|                v-model="value" | ||||
|                @select="addIssueInList"> | ||||
|             </VueMultiselect> | ||||
|             </div> | ||||
|              | ||||
|          </div> | ||||
|       </div> | ||||
|  | ||||
|       <div class="mb-3 row"> | ||||
|          <div class="col-4"> | ||||
|             <label class="col-form-label">{{ $t('activity.social_actions') }}</label> | ||||
|          </div> | ||||
|          <div class="col-8"> | ||||
|              | ||||
|             <div v-if="actionIsLoading === true"> | ||||
|                <i class="chill-green fa fa-circle-o-notch fa-spin fa-lg"></i> | ||||
|             </div> | ||||
|              | ||||
|             <check-social-action | ||||
|                v-if="socialIssuesSelected.length || socialActionsSelected.length" | ||||
|                v-for="action in socialActionsList" | ||||
|                v-bind:key="action.id" | ||||
|                v-bind:action="action" | ||||
|                v-bind:selection="socialActionsSelected" | ||||
|                @updateSelected="updateActionsSelected"> | ||||
|             </check-social-action> | ||||
|              | ||||
|             <span v-else class="inline-choice chill-no-data-statement mt-3"> | ||||
|                {{ $t('activity.select_first_a_social_issue') }} | ||||
|             </span> | ||||
|              | ||||
|          </div> | ||||
|       </div> | ||||
|        | ||||
|    </teleport> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| import { readonly } from 'vue'; | ||||
| import VueMultiselect from 'vue-multiselect'; | ||||
| import CheckSocialIssue from './SocialIssuesAcc/CheckSocialIssue.vue'; | ||||
| import CheckSocialAction from './SocialIssuesAcc/CheckSocialAction.vue'; | ||||
| import { getSocialIssues, getSocialActionByIssue } from '../api.js'; | ||||
|  | ||||
| export default { | ||||
|    name: "SocialIssuesAcc", | ||||
|    components: { | ||||
|       CheckSocialIssue, | ||||
|       CheckSocialAction, | ||||
|       VueMultiselect | ||||
|    }, | ||||
|    data() { | ||||
|       return { | ||||
|          issueIsLoading: false, | ||||
|          actionIsLoading: false | ||||
|       } | ||||
|    }, | ||||
|    computed: { | ||||
|       socialIssuesList() { | ||||
|          return this.$store.state.activity.accompanyingPeriod.socialIssues; | ||||
|       }, | ||||
|       socialIssuesSelected() { | ||||
|          return this.$store.state.activity.socialIssues; | ||||
|       }, | ||||
|       socialIssuesOther() { | ||||
|          return this.$store.state.socialIssuesOther; | ||||
|       }, | ||||
|       socialActionsList() { | ||||
|          return this.$store.state.socialActionsList; | ||||
|       }, | ||||
|       socialActionsSelected() { | ||||
|          return this.$store.state.activity.socialActions; | ||||
|       } | ||||
|    }, | ||||
|    mounted() { | ||||
|       /* Load others issues in multiselect | ||||
|       */ | ||||
|       this.issueIsLoading = true; | ||||
|       getSocialIssues().then(response => new Promise((resolve, reject) => { | ||||
|          this.$store.commit('updateIssuesOther', response.results); | ||||
|           | ||||
|          /* Add in list the issues already associated (if not yet listed) | ||||
|          */ | ||||
|          this.socialIssuesSelected.forEach(issue => { | ||||
|             if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) { | ||||
|                this.$store.commit('addIssueInList', issue); | ||||
|             } | ||||
|          }, this); | ||||
|           | ||||
|          /* Remove from multiselect the issues that are not yet in checkbox list | ||||
|          */ | ||||
|          this.socialIssuesList.forEach(issue => { | ||||
|             this.$store.commit('removeIssueInOther', issue); | ||||
|          }, this); | ||||
|           | ||||
|          /* Filter issues | ||||
|          */ | ||||
|          this.$store.commit('filterList', 'issues'); | ||||
|           | ||||
|          /* Add in list the actions already associated (if not yet listed) | ||||
|          */ | ||||
|          this.socialActionsSelected.forEach(action => { | ||||
|             this.$store.commit('addActionInList', action); | ||||
|          }, this); | ||||
|           | ||||
|          /* Filter issues | ||||
|          */ | ||||
|          this.$store.commit('filterList', 'actions'); | ||||
|           | ||||
|          this.issueIsLoading = false; | ||||
|          resolve(); | ||||
|       }));    | ||||
|    }, | ||||
|    methods: { | ||||
|     | ||||
|       /* When choosing an issue in multiselect, add it in checkboxes (as selected),  | ||||
|          remove it from multiselect, and add socialActions concerned | ||||
|       */ | ||||
|       addIssueInList(value) { | ||||
|          //console.log('addIssueInList', value); | ||||
|          this.$store.commit('addIssueInList', value); | ||||
|          this.$store.commit('removeIssueInOther', value); | ||||
|          this.$store.dispatch('addIssueSelected', value); | ||||
|          this.updateActionsList(); | ||||
|       }, | ||||
|       /* Update value for selected issues checkboxes | ||||
|       */ | ||||
|       updateIssuesSelected(issues) { | ||||
|          //console.log('updateIssuesSelected', issues); | ||||
|          this.$store.dispatch('updateIssuesSelected', issues); | ||||
|          this.updateActionsList(); | ||||
|       }, | ||||
|       /* Update value for selected actions checkboxes | ||||
|       */ | ||||
|       updateActionsSelected(actions) { | ||||
|          //console.log('updateActionsSelected', actions); | ||||
|          this.$store.dispatch('updateActionsSelected', actions); | ||||
|       }, | ||||
|       /* Add socialActions concerned: after reset, loop on each issue selected  | ||||
|          to get social actions concerned | ||||
|       */ | ||||
|       updateActionsList() { | ||||
|          //console.log('updateActionsList'); | ||||
|          this.resetActionsList(); | ||||
|          this.socialIssuesSelected.forEach(item => { | ||||
|              | ||||
|             this.actionIsLoading = true; | ||||
|             getSocialActionByIssue(item.id) | ||||
|                .then(actions => new Promise((resolve, reject) => { | ||||
|                    | ||||
|                   actions.results.forEach(action => { | ||||
|                      this.$store.commit('addActionInList', action); | ||||
|                   }, this); | ||||
|                    | ||||
|                   this.$store.commit('filterList', 'actions'); | ||||
|                    | ||||
|                   this.actionIsLoading = false; | ||||
|                   resolve(); | ||||
|             })); | ||||
|          }, this); | ||||
|       }, | ||||
|       /* Reset socialActions List: flush list and restore selected actions  | ||||
|       */ | ||||
|       resetActionsList() { | ||||
|          this.$store.commit('resetActionsList'); | ||||
|          this.socialActionsSelected.forEach(item => { | ||||
|             this.$store.commit('addActionInList', item); | ||||
|          }, this); | ||||
|       } | ||||
|    } | ||||
| } | ||||
| </script> | ||||
|  | ||||
| <style src="vue-multiselect/dist/vue-multiselect.css"></style> | ||||
| <style lang="scss"> | ||||
|    span.multiselect__single { | ||||
|       display: none !important; | ||||
|    } | ||||
| </style> | ||||
| @@ -0,0 +1,36 @@ | ||||
| <template> | ||||
|    <span class="inline-choice"> | ||||
|       <div class="form-check"> | ||||
|     | ||||
|          <input class="form-check-input" | ||||
|             type="checkbox"  | ||||
|             v-model="selected" | ||||
|             name="action" | ||||
|             v-bind:id="action.id"  | ||||
|             v-bind:value="action" | ||||
|             /> | ||||
|          <label class="form-check-label" v-bind:for="action.id"> | ||||
|             {{ action.text }} | ||||
|          </label> | ||||
|           | ||||
|       </div> | ||||
|    </span> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| export default { | ||||
|    name: "CheckSocialAction", | ||||
|    props: [ 'action', 'selection' ], | ||||
|    emits: [ 'updateSelected' ], | ||||
|    computed: { | ||||
|       selected: { | ||||
|          set(value) { | ||||
|             this.$emit('updateSelected', value); | ||||
|          }, | ||||
|          get() { | ||||
|             return this.selection; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
| } | ||||
| </script> | ||||
| @@ -0,0 +1,36 @@ | ||||
| <template> | ||||
|    <span class="inline-choice"> | ||||
|       <div class="form-check"> | ||||
|        | ||||
|          <input class="form-check-input" | ||||
|             type="checkbox"  | ||||
|             v-model="selected" | ||||
|             name="issue" | ||||
|             v-bind:id="issue.id"  | ||||
|             v-bind:value="issue" | ||||
|             /> | ||||
|          <label class="form-check-label" v-bind:for="issue.id"> | ||||
|             {{ issue.text }} | ||||
|          </label> | ||||
|           | ||||
|       </div> | ||||
|    </span> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| export default { | ||||
|    name: "CheckSocialIssue", | ||||
|    props: [ 'issue', 'selection' ], | ||||
|    emits: [ 'updateSelected' ], | ||||
|    computed: { | ||||
|       selected: { | ||||
|          set(value) { | ||||
|             this.$emit('updateSelected', value); | ||||
|          }, | ||||
|          get() { | ||||
|             return this.selection; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
| } | ||||
| </script> | ||||
| @@ -0,0 +1,27 @@ | ||||
| import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' | ||||
|  | ||||
| const appMessages = { | ||||
|    fr: { | ||||
|       activity: { | ||||
|          // | ||||
|          social_issues: "Problématiques sociales", | ||||
|          choose_other_social_issue: "Ajouter une autre problématique sociale...", | ||||
|          social_actions: "Actions d'accompagnement", | ||||
|          select_first_a_social_issue: "Sélectionnez d'abord une problématique sociale", | ||||
|           | ||||
|          // | ||||
|          add_persons: "Ajouter des personnes concernées", | ||||
|          bloc_persons: "Usagers", | ||||
|          bloc_persons_associated: "Usagers du parcours", | ||||
|          bloc_persons_not_associated: "Tiers non-pro.", | ||||
|          bloc_thirdparty: "Tiers professionnels", | ||||
|          bloc_users: "T(M)S", | ||||
|       } | ||||
|    } | ||||
| } | ||||
|  | ||||
| Object.assign(appMessages.fr, personMessages.fr); | ||||
|  | ||||
| export { | ||||
|    appMessages | ||||
| }; | ||||
| @@ -0,0 +1,16 @@ | ||||
| import { createApp } from 'vue'; | ||||
| import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n' | ||||
| import { appMessages } from './i18n' | ||||
| import store from './store' | ||||
|  | ||||
| import App from './App.vue'; | ||||
|  | ||||
| const i18n = _createI18n(appMessages); | ||||
|  | ||||
| const app = createApp({ | ||||
|    template: `<app></app>`, | ||||
| }) | ||||
| .use(store) | ||||
| .use(i18n) | ||||
| .component('app', App) | ||||
| .mount('#activity'); | ||||
| @@ -0,0 +1,170 @@ | ||||
| import 'es6-promise/auto'; | ||||
| import { createStore } from 'vuex'; | ||||
|  | ||||
| const debug = process.env.NODE_ENV !== 'production'; | ||||
| //console.log('window.activity', window.activity); | ||||
|  | ||||
| const addIdToValue = (string, id) => { | ||||
|    let array = string ? string.split(',') : []; | ||||
|    array.push(id.toString()); | ||||
|    let str = array.join(); | ||||
|    return str; | ||||
| }; | ||||
|  | ||||
| const removeIdFromValue = (string, id) => { | ||||
|    let array = string.split(','); | ||||
|    array = array.filter(el => el !== id.toString()); | ||||
|    let str = array.join(); | ||||
|    return str; | ||||
| }; | ||||
|  | ||||
| const store = createStore({ | ||||
|    strict: debug, | ||||
|    state: { | ||||
|      activity: window.activity, | ||||
|      socialIssuesOther: [], | ||||
|      socialActionsList: [], | ||||
|    }, | ||||
|    mutations: { | ||||
|        | ||||
|       // SocialIssueAcc | ||||
|       addIssueInList(state, issue) { | ||||
|          //console.log('add issue list', issue.id); | ||||
|          state.activity.accompanyingPeriod.socialIssues.push(issue);          | ||||
|       }, | ||||
|       addIssueSelected(state, issue) { | ||||
|          //console.log('add issue selected', issue.id); | ||||
|          state.activity.socialIssues.push(issue); | ||||
|       }, | ||||
|       updateIssuesSelected(state, issues) { | ||||
|          //console.log('update issues selected', issues); | ||||
|          state.activity.socialIssues = issues; | ||||
|       }, | ||||
|       updateIssuesOther(state, payload) { | ||||
|          //console.log('update issues other'); | ||||
|          state.socialIssuesOther = payload; | ||||
|       }, | ||||
|       removeIssueInOther(state, issue) { | ||||
|          //console.log('remove issue other', issue.id); | ||||
|          state.socialIssuesOther = state.socialIssuesOther.filter(i => i.id !== issue.id); | ||||
|       }, | ||||
|       resetActionsList(state) { | ||||
|          //console.log('reset list actions'); | ||||
|          state.socialActionsList = []; | ||||
|       }, | ||||
|       addActionInList(state, action) { | ||||
|          //console.log('add action list', action.id); | ||||
|          state.socialActionsList.push(action);          | ||||
|       }, | ||||
|       updateActionsSelected(state, actions) { | ||||
|          //console.log('update actions selected', actions); | ||||
|          state.activity.socialActions = actions; | ||||
|       }, | ||||
|       filterList(state, list) { | ||||
|          const filterList = (list) => { | ||||
|             // remove duplicates entries | ||||
|             list = list.filter((value, index) => list.findIndex(array => array.id === value.id) === index); | ||||
|             // alpha sort | ||||
|             list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0)); | ||||
|             return list; | ||||
|          }; | ||||
|          if (list === 'issues') { | ||||
|             state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues); | ||||
|          } | ||||
|          if (list === 'actions') { | ||||
|             state.socialActionsList = filterList(state.socialActionsList); | ||||
|          } | ||||
|       }, | ||||
|        | ||||
|       // ConcernedGroups | ||||
|       addPersonsInvolved(state, payload) { | ||||
|          //console.log('### mutation addPersonsInvolved', payload.result.type); | ||||
|          switch (payload.result.type) { | ||||
|             case 'person': | ||||
|                state.activity.persons.push(payload.result); | ||||
|                break; | ||||
|             case 'thirdparty': | ||||
|                state.activity.thirdParties.push(payload.result); | ||||
|                break; | ||||
|             case 'user': | ||||
|                state.activity.users.push(payload.result);  | ||||
|                break; | ||||
|          }; | ||||
|       }, | ||||
|       removePersonInvolved(state, payload) { | ||||
|          //console.log('### mutation removePersonInvolved', payload.type); | ||||
|          switch (payload.type) { | ||||
|             case 'person': | ||||
|                state.activity.persons = state.activity.persons.filter(person => person !== payload); | ||||
|                break; | ||||
|             case 'thirdparty': | ||||
|                state.activity.thirdParties = state.activity.thirdParties.filter(thirdparty => thirdparty !== payload); | ||||
|                break; | ||||
|             case 'user': | ||||
|                state.activity.users = state.activity.users.filter(user => user !== payload);  | ||||
|                break; | ||||
|          }; | ||||
|       } | ||||
|    }, | ||||
|    actions: { | ||||
|       addIssueSelected({ commit }, issue) { | ||||
|          let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues"); | ||||
|          aSocialIssues.value = addIdToValue(aSocialIssues.value, issue.id); | ||||
|          commit('addIssueSelected', issue); | ||||
|       }, | ||||
|       updateIssuesSelected({ commit }, payload) { | ||||
|          let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues"); | ||||
|          aSocialIssues.value = ''; | ||||
|          payload.forEach(item => { | ||||
|             aSocialIssues.value = addIdToValue(aSocialIssues.value, item.id); | ||||
|          }); | ||||
|          commit('updateIssuesSelected', payload); | ||||
|       }, | ||||
|       updateActionsSelected({ commit }, payload) { | ||||
|          let aSocialActions = document.getElementById("chill_activitybundle_activity_socialActions"); | ||||
|          aSocialActions.value = ''; | ||||
|          payload.forEach(item => { | ||||
|             aSocialActions.value = addIdToValue(aSocialActions.value, item.id); | ||||
|          }); | ||||
|          commit('updateActionsSelected', payload); | ||||
|       }, | ||||
|       addPersonsInvolved({ commit }, payload) { | ||||
|          //console.log('### action addPersonsInvolved', payload.result.type); | ||||
|          switch (payload.result.type) { | ||||
|             case 'person': | ||||
|                let aPersons = document.getElementById("chill_activitybundle_activity_persons"); | ||||
|                aPersons.value = addIdToValue(aPersons.value, payload.result.id); | ||||
|                break; | ||||
|             case 'thirdparty': | ||||
|                let aThirdParties = document.getElementById("chill_activitybundle_activity_thirdParties"); | ||||
|                aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id); | ||||
|                break; | ||||
|             case 'user': | ||||
|                let aUsers = document.getElementById("chill_activitybundle_activity_users"); | ||||
|                aUsers.value = addIdToValue(aUsers.value, payload.result.id); | ||||
|                break; | ||||
|          }; | ||||
|          commit('addPersonsInvolved', payload); | ||||
|       }, | ||||
|       removePersonInvolved({ commit }, payload) { | ||||
|          //console.log('### action removePersonInvolved', payload); | ||||
|          switch (payload.type) { | ||||
|             case 'person': | ||||
|                let aPersons = document.getElementById("chill_activitybundle_activity_persons"); | ||||
|                aPersons.value = removeIdFromValue(aPersons.value, payload.id); | ||||
|                break; | ||||
|             case 'thirdparty': | ||||
|                let aThirdParties = document.getElementById("chill_activitybundle_activity_thirdParties"); | ||||
|                aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id); | ||||
|                break; | ||||
|             case 'user': | ||||
|                let aUsers = document.getElementById("chill_activitybundle_activity_users"); | ||||
|                aUsers.value = removeIdFromValue(aUsers.value, payload.id); | ||||
|                break; | ||||
|          }; | ||||
|          commit('removePersonInvolved', payload); | ||||
|       } | ||||
|   } | ||||
| }); | ||||
|  | ||||
| export default store; | ||||
| @@ -1,40 +1,13 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| use Symfony\Component\Config\Loader\LoaderInterface; | ||||
| use Symfony\Component\HttpKernel\Kernel; | ||||
| use Symfony\Component\Config\Loader\LoaderInterface; | ||||
|  | ||||
| class AppKernel extends Kernel | ||||
| { | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getCacheDir() | ||||
|     { | ||||
|         return sys_get_temp_dir() . '/ActivityBundle/cache'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getLogDir() | ||||
|     { | ||||
|         return sys_get_temp_dir() . '/ActivityBundle/logs'; | ||||
|     } | ||||
|  | ||||
|     public function registerBundles() | ||||
|     { | ||||
|         return [ | ||||
|         return array( | ||||
|             new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||||
|             new Chill\CustomFieldsBundle\ChillCustomFieldsBundle(), | ||||
|             new Symfony\Bundle\SecurityBundle\SecurityBundle(), | ||||
| @@ -47,12 +20,28 @@ class AppKernel extends Kernel | ||||
|             new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), | ||||
|             new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), | ||||
|             new Symfony\Bundle\MonologBundle\MonologBundle(), | ||||
|             //add here all the required bundle (some bundle are not required) | ||||
|         ]; | ||||
|             #add here all the required bundle (some bundle are not required) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     public function registerContainerConfiguration(LoaderInterface $loader) | ||||
|     { | ||||
|         $loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml'); | ||||
|         $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getCacheDir() | ||||
|     { | ||||
|         return sys_get_temp_dir().'/ActivityBundle/cache'; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getLogDir() | ||||
|     { | ||||
|         return sys_get_temp_dir().'/ActivityBundle/logs'; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,22 +1,11 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| use Composer\Autoload\ClassLoader; | ||||
| use Doctrine\Common\Annotations\AnnotationRegistry; | ||||
| use Composer\Autoload\ClassLoader; | ||||
|  | ||||
| /** @var ClassLoader $loader */ | ||||
| $loader = require __DIR__ . '/../../../../../vendor/autoload.php'; | ||||
| $loader = require __DIR__.'/../../../../../vendor/autoload.php'; | ||||
|  | ||||
| AnnotationRegistry::registerLoader([$loader, 'loadClass']); | ||||
| AnnotationRegistry::registerLoader(array($loader, 'loadClass')); | ||||
|  | ||||
| return $loader; | ||||
|   | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -1,18 +1,7 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers. | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  * | ||||
|  * @see https://www.champs-libres.coop/ | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| use Symfony\Component\Debug\Debug; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\Debug\Debug; | ||||
|  | ||||
| // If you don't want to setup permissions the proper way, just uncomment the following PHP line | ||||
| // read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information | ||||
| @@ -20,20 +9,18 @@ use Symfony\Component\HttpFoundation\Request; | ||||
|  | ||||
| // This check prevents access to debug front controllers that are deployed by accident to production servers. | ||||
| // Feel free to remove this, extend it, or make something more sophisticated. | ||||
| if ( | ||||
|     isset($_SERVER['HTTP_CLIENT_IP']) | ||||
| if (isset($_SERVER['HTTP_CLIENT_IP']) | ||||
|     || isset($_SERVER['HTTP_X_FORWARDED_FOR']) | ||||
|     || !(\in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1'], true) || \PHP_SAPI === 'cli-server') | ||||
|     || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1')) || php_sapi_name() === 'cli-server') | ||||
| ) { | ||||
|     header('HTTP/1.0 403 Forbidden'); | ||||
|  | ||||
|     exit('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.'); | ||||
|     exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); | ||||
| } | ||||
|  | ||||
| $loader = require_once __DIR__ . '/../app/bootstrap.php.cache'; | ||||
| $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; | ||||
| Debug::enable(); | ||||
|  | ||||
| require_once __DIR__ . '/../app/AppKernel.php'; | ||||
| require_once __DIR__.'/../app/AppKernel.php'; | ||||
|  | ||||
| $kernel = new AppKernel('dev', true); | ||||
| $kernel->loadClassCache(); | ||||
|   | ||||
| @@ -0,0 +1,103 @@ | ||||
| {% macro href(pathname, key, value) %} | ||||
|     {% set parms = { (key): value } %} | ||||
|     {{ path(pathname, parms) }} | ||||
| {% endmacro %} | ||||
|  | ||||
| {% if context == 'person' %} | ||||
|     {% set blocs = [ | ||||
|         {   'title': 'Others persons'|trans,  | ||||
|             'items': entity.persons, | ||||
|             'path' : 'chill_person_view', | ||||
|             'key'  : 'person_id' | ||||
|         }, | ||||
|         {   'title': 'Third parties'|trans,  | ||||
|             'items': entity.thirdParties, | ||||
|             'path' : 'chill_3party_3party_show', | ||||
|             'key'  : 'thirdparty_id' | ||||
|         }, | ||||
|         {   'title': 'Users concerned'|trans,  | ||||
|             'items': entity.users, | ||||
|             'path' : 'admin_user_show', | ||||
|             'key'  : 'id' | ||||
|         }, | ||||
|     ] %} | ||||
| {% else %} | ||||
|     {% set blocs = [ | ||||
|         {   'title': 'Persons in accompanying course'|trans,  | ||||
|             'items': entity.personsAssociated, | ||||
|             'path' : 'chill_person_view', | ||||
|             'key'  : 'person_id' | ||||
|         }, | ||||
|         {   'title': 'Third persons'|trans,  | ||||
|             'items': entity.personsNotAssociated, | ||||
|             'path' : 'chill_person_view', | ||||
|             'key'  : 'person_id' | ||||
|         }, | ||||
|         {   'title': 'Third parties'|trans,  | ||||
|             'items': entity.thirdParties, | ||||
|             'path' : 'chill_3party_3party_show', | ||||
|             'key'  : 'thirdparty_id' | ||||
|         }, | ||||
|         {   'title': 'Users concerned'|trans,  | ||||
|             'items': entity.users, | ||||
|             'path' : 'admin_user_show', | ||||
|             'key'  : 'id' | ||||
|         }, | ||||
|     ] %} | ||||
| {% endif %} | ||||
|  | ||||
| {% if (with_display == 'bloc') %} | ||||
| <div class="{{ context }} flex-bloc concerned-groups"> | ||||
|     {% for bloc in blocs %} | ||||
|     <div class="item-bloc"> | ||||
|         <div class="item-row"> | ||||
|             <div class="item-col"> | ||||
|                 <h4>{{ bloc.title }}</h4> | ||||
|             </div> | ||||
|             <div class="item-col"> | ||||
|                 <ul class="list-content"> | ||||
|                     {% for item in bloc.items %} | ||||
|                     <li> | ||||
|                         <a href="{{ _self.href(bloc.path, bloc.key, item.id) }}"> | ||||
|                             <span class="badge bg-primary"> | ||||
|                                 {{ item|chill_entity_render_box({ | ||||
|                                     'render': 'raw', | ||||
|                                     'addAltNames': false | ||||
|                                 }) }} | ||||
|                             </span> | ||||
|                         </a> | ||||
|                     </li> | ||||
|                     {% endfor %} | ||||
|                 </ul> | ||||
|             </div> | ||||
|         </div> | ||||
|     </div> | ||||
|     {% endfor %} | ||||
| </div> | ||||
| {% endif %} | ||||
|  | ||||
| {% if (with_display == 'row') %} | ||||
| <div class="concerned-groups"> | ||||
|     {% for bloc in blocs %} | ||||
|     <div class="group"> | ||||
|         {% if bloc.items|length > 0 %} | ||||
|             <h4>{{ bloc.title }}</h4> | ||||
|             <ul class="list-content"> | ||||
|                 {% for item in bloc.items %} | ||||
|                 <li> | ||||
|                     <a href="{{ _self.href(bloc.path, bloc.key, item.id) }}"> | ||||
|                         <span class="badge bg-primary"> | ||||
|                             {{ item|chill_entity_render_box({ | ||||
|                                 'render': 'raw', | ||||
|                                 'addAltNames': false | ||||
|                             }) }} | ||||
|                         </span> | ||||
|                     </a> | ||||
|                 </li> | ||||
|                 {% endfor %} | ||||
|             </ul> | ||||
|         {% endif %} | ||||
|     </div> | ||||
|     {% endfor %} | ||||
| </div> | ||||
| {% endif %} | ||||
| @@ -0,0 +1,16 @@ | ||||
| {% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} | ||||
|  | ||||
| {% set activeRouteKey = 'chill_activity_activity_list' %} | ||||
|  | ||||
| {% block title  'Remove activity'|trans %} | ||||
|  | ||||
| {% block content %} | ||||
|     {{ include('@ChillMain/Util/confirmation_template.html.twig', | ||||
|         { | ||||
|             'title'             : 'Remove activity'|trans, | ||||
|             'confirm_question'  : 'Are you sure you want to remove the activity about "%name%" ?'|trans({ '%name%' : accompanyingCourse.id } ), | ||||
|             'cancel_route'      : 'chill_activity_activity_list', | ||||
|             'cancel_parameters' : { 'accompanying_course_id' : accompanyingCourse.id, 'id' : activity.id }, | ||||
|             'form'              : delete_form | ||||
|         } ) }} | ||||
| {% endblock %} | ||||
| @@ -1,4 +1,4 @@ | ||||
| {% extends "@ChillPerson/layout.html.twig"  %} | ||||
| {% extends "@ChillPerson/Person/layout.html.twig"  %} | ||||
| 
 | ||||
| {% set activeRouteKey = 'chill_activity_activity_list' %} | ||||
| {% set person = activity.person %} | ||||
| @@ -6,7 +6,6 @@ | ||||
| {% block title  'Remove activity'|trans %} | ||||
| 
 | ||||
| {% block personcontent %} | ||||
| 
 | ||||
| {{ include('@ChillMain/Util/confirmation_template.html.twig', | ||||
|     { | ||||
|         'title'             : 'Remove activity'|trans, | ||||
| @@ -15,5 +14,4 @@ | ||||
|         'cancel_parameters' : { 'person_id' : activity.person.id, 'id' : activity.id }, | ||||
|         'form'              : delete_form | ||||
|     } ) }} | ||||
|      | ||||
| {% endblock %} | ||||
| @@ -1,59 +1,104 @@ | ||||
| {# | ||||
|  * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| #} | ||||
| {% extends "@ChillPerson/layout.html.twig"  %} | ||||
| <h1>{{ "Update activity"|trans }}</h1> | ||||
| <h2 class="chill-green mb-4">{{ entity.type.name|localize_translatable_string }}</h2> | ||||
|  | ||||
| {% set activeRouteKey = 'chill_activity_activity_list' %} | ||||
| {{ form_start(edit_form) }} | ||||
| {{ form_errors(edit_form) }} | ||||
|  | ||||
| {% block title  'Update activity'|trans %} | ||||
| {%- if edit_form.emergency is defined -%} | ||||
|     {{ form_row(edit_form.emergency) }} | ||||
| {% endif %} | ||||
|  | ||||
| {% block personcontent %} | ||||
|     <h1>{{ "Update activity"|trans }}</h1> | ||||
|  | ||||
|     {{ form_start(edit_form) }} | ||||
| {%- if edit_form.sentReceived is defined -%} | ||||
|     {{ form_row(edit_form.sentReceived) }} | ||||
| {% endif %} | ||||
|  | ||||
| {%- if edit_form.user is defined -%} | ||||
|     {{ form_row(edit_form.user) }} | ||||
| {% endif %} | ||||
|  | ||||
| {%- if edit_form.scope is defined -%} | ||||
|     {{ form_row(edit_form.scope) }} | ||||
| {% endif %} | ||||
|  | ||||
|     <h2>{{ 'Activity data'|trans }}</h2> | ||||
|     {{ form_row(edit_form.date) }} | ||||
|     {{ form_row(edit_form.durationTime) }} | ||||
|     {{ form_row(edit_form.type) }} | ||||
|     {{ form_row(edit_form.attendee) }} | ||||
| {%- if edit_form.socialIssues is defined -%} | ||||
|     {{ form_row(edit_form.socialIssues) }} | ||||
| {% endif %} | ||||
|  | ||||
| {%- if edit_form.socialActions is defined -%} | ||||
|     {{ form_row(edit_form.socialActions) }} | ||||
| {% endif %} | ||||
|  | ||||
| <div id="social-issues-acc"></div> | ||||
|  | ||||
| {%- if edit_form.reasons is defined -%} | ||||
|     {{ form_row(edit_form.reasons) }} | ||||
| {% endif %} | ||||
|  | ||||
| <h2 class="chill-red">{{ 'Concerned groups'|trans }}</h2> | ||||
|  | ||||
| {%- if edit_form.persons is defined -%} | ||||
|     {{ form_widget(edit_form.persons) }} | ||||
| {% endif %} | ||||
| {%- if edit_form.thirdParties is defined -%} | ||||
|     {{ form_widget(edit_form.thirdParties) }} | ||||
| {% endif %} | ||||
| {%- if edit_form.users is defined -%} | ||||
|     {{ form_widget(edit_form.users) }} | ||||
| {% endif %} | ||||
|  | ||||
| <div id="add-persons"></div> | ||||
|  | ||||
| <h2 class="chill-red">{{ 'Activity data'|trans }}</h2> | ||||
|  | ||||
| {%- if edit_form.date is defined -%} | ||||
|     {{ form_row(edit_form.date) }} | ||||
| {% endif %} | ||||
|  | ||||
| .. location | ||||
|  | ||||
| {%- if edit_form.durationTime is defined -%} | ||||
|     {{ form_row(edit_form.durationTime) }} | ||||
| {% endif %} | ||||
|  | ||||
| {%- if edit_form.travelTime is defined -%} | ||||
|     {{ form_row(edit_form.travelTime) }} | ||||
| {% endif %} | ||||
|  | ||||
| {%- if edit_form.comment is defined -%} | ||||
|     .. public and private | ||||
|     {{ form_row(edit_form.comment) }} | ||||
| {% endif %} | ||||
|  | ||||
|     {{ form_widget(edit_form) }} | ||||
|         <ul class="record_actions sticky-form-buttons"> | ||||
|             <li class="cancel"> | ||||
|                 <a href="{{ path('chill_activity_activity_show', { 'id': entity.id, 'person_id': entity.person.id } ) }}" class="sc-button bt-cancel"> | ||||
|                     {{ 'Cancel'|trans }} | ||||
|                 </a> | ||||
|             </li> | ||||
|             <li> | ||||
|                 <button class="sc-button bt-update" type="submit">{{ 'Save activity'|trans }}</button> | ||||
|             </li> | ||||
|         </ul> | ||||
|     {{ form_end(edit_form) }} | ||||
| {%- if edit_form.documents is defined -%} | ||||
|     {{ form_row(edit_form.documents) }} | ||||
| {% endif %} | ||||
|  | ||||
|     {# {{ form(delete_form) }} #} | ||||
| {% endblock %} | ||||
| {%- if edit_form.attendee is defined -%} | ||||
|     {{ form_row(edit_form.attendee) }} | ||||
| {% endif %} | ||||
|  | ||||
| {% block js %} | ||||
| <script type="text/javascript"> | ||||
|     chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]', '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); | ||||
| </script> | ||||
| {% endblock %} | ||||
| .. status | ||||
|  | ||||
| {% set person_id = null %} | ||||
| {% if entity.person %} | ||||
|     {% set person_id = entity.person.id %} | ||||
| {% endif %} | ||||
|  | ||||
| {% set accompanying_course_id = null %} | ||||
| {% if accompanyingCourse %} | ||||
|     {% set accompanying_course_id = accompanyingCourse.id %} | ||||
| {% endif %} | ||||
|  | ||||
|     <ul class="record_actions sticky-form-buttons"> | ||||
|         <li class="cancel"> | ||||
|             <a href="{{ path('chill_activity_activity_show', { 'id': entity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id  } ) }}" class="btn btn-cancel"> | ||||
|                 {{ 'Cancel'|trans }} | ||||
|             </a> | ||||
|         </li> | ||||
|         <li> | ||||
|             <button class="btn btn-update" type="submit">{{ 'Save'|trans }}</button> | ||||
|         </li> | ||||
|     </ul> | ||||
| {{ form_end(edit_form) }} | ||||
|  | ||||
| {# {{ form(delete_form) }} #} | ||||
|   | ||||
| @@ -0,0 +1,33 @@ | ||||
| {% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} | ||||
|  | ||||
| {% set activeRouteKey = 'chill_activity_activity_list' %} | ||||
|  | ||||
| {% block title  'Update activity'|trans %} | ||||
|  | ||||
| {% block content %} | ||||
| <div class="activity-edit"> | ||||
|              | ||||
|             <div id="activity"></div> {# <=== vue component #} | ||||
|             {% include 'ChillActivityBundle:Activity:edit.html.twig' %} | ||||
|              | ||||
| </div> | ||||
| {% endblock %} | ||||
|  | ||||
| {% block js %} | ||||
|     {{ parent() }} | ||||
|     {{ encore_entry_link_tags('mod_async_upload') }} | ||||
|     <script type="text/javascript"> | ||||
|         window.addEventListener('DOMContentLoaded', function (e) { | ||||
|             chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',  | ||||
|             '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); | ||||
|         }); | ||||
|         window.activity = {{ activity_json|json_encode|raw }};  | ||||
|     </script> | ||||
|     {{ encore_entry_script_tags('vue_activity') }} | ||||
| {% endblock %} | ||||
|  | ||||
| {% block css %} | ||||
|     {{ parent() }} | ||||
|     {{ encore_entry_link_tags('mod_async_upload') }} | ||||
|     {{ encore_entry_link_tags('vue_activity') }} | ||||
| {% endblock %} | ||||
| @@ -0,0 +1,47 @@ | ||||
| {# | ||||
|  * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  * published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| #} | ||||
| {% extends "@ChillPerson/Person/layout.html.twig"  %} | ||||
|  | ||||
| {% set activeRouteKey = 'chill_activity_activity_list' %} | ||||
|  | ||||
| {% block title  'Update activity'|trans %} | ||||
|  | ||||
| {% block personcontent %} | ||||
| <div class="activity-edit"> | ||||
|              | ||||
|             <div id="activity"></div> {# <=== vue component #} | ||||
|             {% include 'ChillActivityBundle:Activity:edit.html.twig' %} | ||||
|              | ||||
| </div> | ||||
| {% endblock %} | ||||
|  | ||||
| {% block js %} | ||||
|     {{ encore_entry_link_tags('mod_async_upload') }} | ||||
|     <script type="text/javascript"> | ||||
|         window.addEventListener('DOMContentLoaded', function (e) { | ||||
|             chill.displayAlertWhenLeavingModifiedForm('form[name="{{ edit_form.vars.form.vars.name }}"]',  | ||||
|             '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); | ||||
|         }); | ||||
|         window.activity = {{ activity_json|json_encode|raw }}; | ||||
|     </script> | ||||
|     {{ encore_entry_script_tags('vue_activity') }} | ||||
| {% endblock %} | ||||
|  | ||||
| {% block css %} | ||||
|     {{ encore_entry_link_tags('mod_async_upload') }} | ||||
|     {{ encore_entry_link_tags('vue_activity') }} | ||||
| {% endblock %} | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user