src/Controller/LibraryController.php line 520

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Card;
  4. use App\Service\LearningClass;
  5. use App\Service\LibraryClass;
  6. use App\Service\CardClass;
  7. use App\Repository\CardRepository;
  8. use App\Repository\CoreClassificationRepository;
  9. use App\Repository\CoreLibraryPoolRepository;
  10. use App\Repository\CoreLibraryRepository;
  11. use App\Repository\PlanRepository;
  12. use App\Repository\UserLibraryPoolRepository;
  13. use App\Repository\UserLibraryRepository;
  14. use App\Repository\UserLibrarySubscriptionRepository;
  15. use App\Repository\UserPlanRepository;
  16. use App\Repository\UserPropertiesRepository;
  17. use App\Repository\VPoolcardsRepository;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  21. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  22. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  23. use Symfony\Component\Form\Extension\Core\Type\TextType;
  24. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. class LibraryController extends AbstractController
  28. {
  29. /**
  30. * @Route("/library", name="app_library_overview", schemes={"https"})
  31. */
  32. public function index(Request $request, UserLibraryRepository $rep, CoreLibraryRepository $repCoreLib, CoreLibraryPoolRepository $repCoreLibPool, UserLibraryRepository $repUserLib, UserPlanRepository $repUserPlan, PlanRepository $repPlan, CoreClassificationRepository $repCoreClassification)
  33. {
  34. $user = $this->get('security.token_storage')->getToken()->getUser();
  35. $userId = $user->getId();
  36. $libary = $rep->getUserLibrary($userId);
  37. $planId = $repUserPlan->getUserPlanId($userId);
  38. $maxPlanLibs = $repPlan->getQuantityLibrary($planId);
  39. $cntUserLibs = $repUserLib->getUserLibraryCount($userId);
  40. $corelibs = $repCoreLib->getCoreLibrary();
  41. $choices = [];
  42. foreach ($corelibs as $t) {
  43. $choices[$t['name']] = $t['id'];
  44. }
  45. // Form new library
  46. $libform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post', 'action' => $this->generateUrl('app_library_overview'))))
  47. ->setAttribute('class', 'php-email-form')
  48. ->add('libname', TextType::class,[
  49. 'required' => true,
  50. 'label' => 'Bezeichnung',
  51. 'attr' => array(
  52. 'class' => 'form-control'),
  53. 'label_attr' => array(
  54. 'class' => 'form-label'),
  55. ])
  56. ->add('libdesc', TextareaType::class,[
  57. 'required' => true,
  58. 'label' => 'Beschreibung',
  59. 'attr' => array(
  60. 'class' => 'form-control'),
  61. 'label_attr' => array(
  62. 'class' => 'form-label'),
  63. ])
  64. ->add('corelib', ChoiceType::class,[
  65. 'choices' => $choices,
  66. 'label' => 'Themengebiet',
  67. 'attr' => array(
  68. 'class' => 'form-control'),
  69. 'label_attr' => array(
  70. 'class' => 'form-label'),
  71. ])
  72. ->add('Speichern', SubmitType::class,[
  73. ])
  74. ->getForm();
  75. // Form handleRequest new library
  76. $libform->handleRequest($request);
  77. if ($libform->isSubmitted() && $libform->isValid()) {
  78. // Check, if library name for user exists
  79. $a = $rep->checkLibraryNameExists($userId, $libform['libname']->getData());
  80. if($a == 0) {
  81. $service = new LibraryClass;
  82. $em2 = $this->getDoctrine()->getManager();
  83. $service->saveNewLibrary($user->getId(), $libform['corelib']->getData(), $libform['libname']->getData(), $libform['libdesc']->getData(), $em2, $repCoreLib, $repCoreLibPool, $repUserLib, $repCoreClassification);
  84. }
  85. return $this->redirect($this->generateUrl('app_library_overview'));
  86. }
  87. return $this->render('library/index.html.twig', [
  88. 'libary' => $libary,
  89. 'maxPlanLibs' => $maxPlanLibs,
  90. 'cntUserLibs' => $cntUserLibs,
  91. 'libform' => $libform->createView()
  92. ]);
  93. }
  94. /**
  95. * @Route("/library/{libId}/pool", name="app_library_pool", schemes={"https"})
  96. */
  97. public function library($libId, Request $request, UserLibraryPoolRepository $repPool, UserLibraryRepository $repLib, VPoolcardsRepository $view)
  98. {
  99. $user = $this->get('security.token_storage')->getToken()->getUser();
  100. $libname = $repLib->getUserLibraryName($libId);
  101. $pool = $repPool->getLibraryPools($libId);
  102. $cardcount = $view->getCardCount();
  103. $poolform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post')))
  104. ->setAttribute('class', 'php-email-form')
  105. ->add('poolname', TextType::class,[
  106. 'required' => true,
  107. 'label' => 'Bezeichnung',
  108. 'attr' => array(
  109. 'class' => 'form-control text-name'),
  110. 'label_attr' => array(
  111. 'class' => 'form-label'),
  112. ])
  113. ->add('pooldesc', TextareaType::class,[
  114. 'required' => true,
  115. 'label' => 'Beschreibung',
  116. 'attr' => array(
  117. 'rows' => '6',
  118. 'class' => 'form-control text-desc'),
  119. 'label_attr' => array(
  120. 'class' => 'form-label'),
  121. ])
  122. ->add('mon', CheckboxType::class,[
  123. 'required' => false,
  124. 'label' => 'Mo',
  125. 'data' => false,
  126. 'attr' => array(
  127. 'class' => 'form-check-input text-mon'),
  128. 'label_attr' => array(
  129. 'class' => 'form-label'),
  130. ])
  131. ->add('tue', CheckboxType::class,[
  132. 'required' => false,
  133. 'label' => 'Di',
  134. 'data' => false,
  135. 'attr' => array(
  136. 'class' => 'form-check-input text-tue'),
  137. 'label_attr' => array(
  138. 'class' => 'form-label'),
  139. ])
  140. ->add('wed', CheckboxType::class,[
  141. 'required' => false,
  142. 'label' => 'Mi',
  143. 'data' => false,
  144. 'attr' => array(
  145. 'class' => 'form-check-input text-wed'),
  146. 'label_attr' => array(
  147. 'class' => 'form-label'),
  148. ])
  149. ->add('thu', CheckboxType::class,[
  150. 'required' => false,
  151. 'label' => 'Do',
  152. 'attr' => array(
  153. 'class' => 'form-check-input text-thu'),
  154. 'data' => false,
  155. 'label_attr' => array(
  156. 'class' => 'form-label'),
  157. ])
  158. ->add('fri', CheckboxType::class,[
  159. 'required' => false,
  160. 'label' => 'Fr',
  161. 'data' => false,
  162. 'attr' => array(
  163. 'class' => 'form-check-input text-fri'),
  164. 'label_attr' => array(
  165. 'class' => 'form-label'),
  166. ])
  167. ->add('sat', CheckboxType::class,[
  168. 'required' => false,
  169. 'label' => 'Sa',
  170. 'data' => false,
  171. 'attr' => array(
  172. 'class' => 'form-check-input text-sat'),
  173. 'label_attr' => array(
  174. 'class' => 'form-label'),
  175. ])
  176. ->add('sun', CheckboxType::class,[
  177. 'required' => false,
  178. 'label' => 'So',
  179. 'data' => false,
  180. 'attr' => array(
  181. 'class' => 'form-check-input text-sun'),
  182. 'label_attr' => array(
  183. 'class' => 'form-label'),
  184. ])
  185. ->add('Erstellen', SubmitType::class,[
  186. ])
  187. ->getForm();
  188. $poolform->handleRequest($request);
  189. if ($poolform->isSubmitted() && $poolform->isValid()) {
  190. // Check, if library name for user exists
  191. $a = $repPool->checkPoolNameExists($poolform['poolname']->getData(), $libId);
  192. if($a == 0) {
  193. $service = new LibraryClass;
  194. $em2 = $this->getDoctrine()->getManager();
  195. $service->saveNewPool($user->getId(), $libId, $poolform['poolname']->getData(), $poolform['pooldesc']->getData(), $poolform['mon']->getData(), $poolform['tue']->getData(), $poolform['wed']->getData(), $poolform['thu']->getData(), $poolform['fri']->getData(), $poolform['sat']->getData(), $poolform['sun']->getData(), $em2);
  196. }
  197. return $this->redirect($this->generateUrl('app_library_pool', array('libId' => $libId)));
  198. }
  199. return $this->render('library/library.html.twig', [
  200. 'poolform' => $poolform->createView(),
  201. 'pool' => $pool,
  202. 'libname' => $libname,
  203. 'cardcount' => $cardcount,
  204. 'libId' => $libId,
  205. ]);
  206. }
  207. /**
  208. * @Route("/library/{libId}/pool/{poolId}", name="app_pool", schemes={"https"})
  209. */
  210. public function pool($libId, $poolId, Request $request, UserLibraryPoolRepository $repPool, UserLibraryRepository $repLib, CardRepository $repCards, UserLibrarySubscriptionRepository $repSubs, UserPlanRepository $repUserPlan, PlanRepository $repPlan)
  211. {
  212. $user = $this->get('security.token_storage')->getToken()->getUser();
  213. $userId = $user->getId();
  214. $planId = $repUserPlan->getUserPlanId($userId);
  215. $showsolution = 1;
  216. $poolname = $repPool->getUserLibraryPoolName($poolId);
  217. $pooltype = $repPool->getUserLibraryPoolType($poolId);
  218. $libname = $repLib->getUserLibraryName($libId);
  219. $cards = $repCards->getCards($poolId);
  220. $cardscount = $repCards->getPoolCardsCount($poolId);
  221. $maxPlanCards = $repPlan->getQuantityCard($planId);
  222. $cntUserCards = $repCards->getUserCardsCount($userId);
  223. $classifications = $repPool->getLibraryPoolClassifications($libId);
  224. $choices = [];
  225. foreach ($classifications as $t) {
  226. $choices[$t['name']] = $t['id'];
  227. }
  228. if($pooltype != 0) {
  229. $showsolution = 0;
  230. }
  231. $cardform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post')))
  232. ->setAttribute('class', 'php-email-form')
  233. ->add('task', TextType::class,[
  234. 'required' => true,
  235. 'label' => 'Wort/Phrase',
  236. 'attr' => array(
  237. 'class' => 'form-control'),
  238. 'label_attr' => array(
  239. 'class' => 'form-label'),
  240. ])
  241. ->add('solution', TextareaType::class,[
  242. 'required' => true,
  243. 'label' => 'Lösung',
  244. 'attr' => array(
  245. 'class' => 'form-control',
  246. 'rows' => '7'
  247. ),
  248. 'label_attr' => array(
  249. 'class' => 'form-label'),
  250. ])
  251. ->add('classification', ChoiceType::class,[
  252. 'choices' => $choices,
  253. 'label' => 'Einordnung',
  254. 'attr' => array(
  255. 'class' => 'form-control'),
  256. 'label_attr' => array(
  257. 'class' => 'form-label'),
  258. ])
  259. ->add('Erstellen', SubmitType::class,[
  260. ])
  261. ->getForm();
  262. $cardform->handleRequest($request);
  263. if ($cardform->isSubmitted() && $cardform->isValid()) {
  264. $userCard = new Card();
  265. $userCard->setUserId($userId);
  266. $userCard->setPoolId($poolId);
  267. $userCard->setReferenceId(0);
  268. $userCard->setReferenceVersion(0);
  269. $userCard->setCopyId(0);
  270. $userCard->setCopyVersion(0);
  271. $userCard->setTask($cardform['task']->getData());
  272. $userCard->setSolution($cardform['solution']->getData());
  273. $userCard->setClassificationId($cardform['classification']->getData());
  274. $userCard->setVersion(1);
  275. $userCard->setCorrect(0);
  276. $userCard->setCorrect2(0);
  277. $userCard->setSkilled(0);
  278. $userCard->setDelflag(0);
  279. $userCard->setCreatedDate(new \DateTime());
  280. $userCard->setModifyDate(new \DateTime());
  281. $em = $this->getDoctrine()->getManager();
  282. $em->persist($userCard);
  283. $em->flush();
  284. /*
  285. $service = new CardClass;
  286. $service->initialCopyCard(2, 2, 1, $em, $repPool, $repCards);
  287. */
  288. // Subscription durchlaufen
  289. $subsData = $repSubs->getUserSubscriptions($userId, $libId);
  290. foreach ($subsData as $d) {
  291. $service = new CardClass;
  292. $em2 = $this->getDoctrine()->getManager();
  293. $service->copyCard($d['user_id'], $d['user_library_id'], $libId, $cardform['task']->getData(), $cardform['solution']->getData(), $cardform['classification']->getData(), $em2, $repLib, $repPool, $repCards);
  294. }
  295. return $this->redirect($this->generateUrl('app_pool', array('libId' => $libId, 'poolId' => $poolId)));
  296. }
  297. return $this->render('library/pool.html.twig', [
  298. 'cardform' => $cardform->createView(),
  299. 'libId' => $libId,
  300. 'poolId' => $poolId,
  301. 'poolname' => $poolname,
  302. 'pooltype' => $pooltype,
  303. 'libname' => $libname,
  304. 'cards' => $cards,
  305. 'showsolution' => $showsolution,
  306. 'cardscount' => $cardscount,
  307. 'action' => null,
  308. 'cardId' => null,
  309. 'maxPlanCards' => $maxPlanCards,
  310. 'cntUserCards' => $cntUserCards,
  311. ]);
  312. }
  313. /**
  314. * @Route("/library/{libId}/pool/{poolId}/{action}", name="app_pool2", schemes={"https"})
  315. */
  316. public function pool2($libId, $poolId, $action, UserLibraryPoolRepository $repPool, UserLibraryRepository $repLib, CardRepository $repCards, UserPropertiesRepository $repProps, EntityManagerInterface $em)
  317. {
  318. $user = $this->get('security.token_storage')->getToken()->getUser();
  319. $userId = $user->getId();
  320. $showsolution = 1;
  321. $randomValue = "";
  322. $poolname = $repPool->getUserLibraryPoolName($poolId);
  323. $pooltype = $repPool->getUserLibraryPoolType($poolId);
  324. $libname = $repLib->getUserLibraryName($libId);
  325. $classifications = $repPool->getLibraryPoolClassifications($libId);
  326. $choices = [];
  327. foreach ($classifications as $t) {
  328. $choices[$t['name']] = $t['id'];
  329. }
  330. if($pooltype != 0) {
  331. $showsolution = 0;
  332. }
  333. if($action == "show") {
  334. $showsolution = 1;
  335. }
  336. if($action == "hide") {
  337. $showsolution = 0;
  338. }
  339. if($action == "refresh") {
  340. $service = new LearningClass;
  341. $em2 = $this->getDoctrine()->getManager();
  342. $service->refreshPool($poolId, $libId, $userId, $em2, $repPool);
  343. $action = "fill";
  344. }
  345. if($action == "fill") {
  346. $fuserId = $user->getId();
  347. $fpoolId = $repPool->getUserLibraryPoolIdByType($fuserId, $libId, 0);
  348. $fpoolId1 = $repPool->getUserLibraryPoolIdByType($fuserId, $libId, 1);
  349. $fcards = $repCards->getCardsId($fpoolId);
  350. $fcardscount = $repCards->getPoolCardsCount($fpoolId1);
  351. $value1 = $repProps->getPoolType1Value($fuserId);
  352. $diff = $value1 - $fcardscount;
  353. if($diff > 0) {
  354. shuffle($fcards);
  355. $randomValue = array_rand($fcards, $diff);
  356. if($diff > 1) {
  357. for($i=0; $i < $diff; $i++) {
  358. $articleClass = 'App\Entity\Card';
  359. $card = $em->getReference($articleClass, $fcards[$randomValue[$i]]);
  360. $card->setPoolId($fpoolId1);
  361. $card->setModifyDate(new \DateTime());
  362. $em = $this->getDoctrine()->getManager();
  363. $em->persist($card);
  364. $em->flush();
  365. }
  366. }
  367. else {
  368. $articleClass = 'App\Entity\Card';
  369. $card = $em->getReference($articleClass, $fcards[$randomValue]);
  370. $card->setPoolId($fpoolId1);
  371. $card->setModifyDate(new \DateTime());
  372. $em = $this->getDoctrine()->getManager();
  373. $em->persist($card);
  374. $em->flush();
  375. }
  376. return $this->redirect($this->generateUrl('app_pool', array('libId' => $libId, 'poolId' => $poolId)));
  377. }
  378. }
  379. if($action == "learn") {
  380. $service = new LearningClass;
  381. $em = $this->getDoctrine()->getManager();
  382. $service->resetPool($poolId, $em);
  383. $cards = $repCards->getLearningCards($poolId);
  384. }
  385. if($action == "continue") {
  386. $action = "learn";
  387. }
  388. $cardform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post', 'action' => $this->generateUrl('app_library_overview'))))
  389. ->setAttribute('class', 'php-email-form')
  390. ->add('task', TextType::class,[
  391. 'required' => true,
  392. 'label' => 'Wort/Phrase',
  393. 'attr' => array(
  394. 'class' => 'form-control'),
  395. 'label_attr' => array(
  396. 'class' => 'form-label'),
  397. ])
  398. ->add('solution', TextareaType::class,[
  399. 'required' => true,
  400. 'label' => 'Lösung',
  401. 'attr' => array(
  402. 'class' => 'form-control',
  403. 'rows' => '7'
  404. ),
  405. 'label_attr' => array(
  406. 'class' => 'form-label'),
  407. ])
  408. ->add('classification', ChoiceType::class,[
  409. 'choices' => $choices,
  410. 'label' => 'Einordnung',
  411. 'attr' => array(
  412. 'class' => 'form-control'),
  413. 'label_attr' => array(
  414. 'class' => 'form-label'),
  415. ])
  416. ->add('Erstellen', SubmitType::class,[
  417. ])
  418. ->getForm();
  419. $cards = $repCards->getCards($poolId);
  420. shuffle($cards);
  421. $cardscount = $repCards->getPoolCardsCount($poolId);
  422. if($action == "fill" || $action == "show" || $action == "hide") {
  423. return $this->render('library/pool.html.twig', [
  424. 'cardform' => $cardform->createView(),
  425. 'libId' => $libId,
  426. 'poolId' => $poolId,
  427. 'poolname' => $poolname,
  428. 'pooltype' => $pooltype,
  429. 'libname' => $libname,
  430. 'cards' => $cards,
  431. 'showsolution' => $showsolution,
  432. 'cardscount' => $cardscount,
  433. 'action' => $action,
  434. 'cardId' => null,
  435. ]);
  436. }
  437. if($action == "learn" || $action == "continue") {
  438. return $this->render('library/learning.html.twig', [
  439. 'libId' => $libId,
  440. 'poolId' => $poolId,
  441. 'poolname' => $poolname,
  442. 'pooltype' => $pooltype,
  443. 'libname' => $libname,
  444. 'cards' => $cards,
  445. 'showsolution' => $showsolution,
  446. 'cardscount' => $cardscount,
  447. 'action' => $action,
  448. 'cardId' => null,
  449. ]);
  450. }
  451. }
  452. /**
  453. * @Route("/library/{libId}/pool/{poolId}/{action}/{cardId}", name="app_pool3", schemes={"https"})
  454. */
  455. public function pool3($libId, $poolId, $action, $cardId, UserLibraryPoolRepository $repPool, UserLibraryRepository $repLib, CardRepository $repCards, UserPropertiesRepository $repProps, EntityManagerInterface $em, Request $request)
  456. {
  457. $showsolution = 1;
  458. $cardform = null;
  459. $poolname = $repPool->getUserLibraryPoolName($poolId);
  460. $pooltype = $repPool->getUserLibraryPoolType($poolId);
  461. $libname = $repLib->getUserLibraryName($libId);
  462. $classifications = $repPool->getLibraryPoolClassifications($libId);
  463. $choices = [];
  464. foreach ($classifications as $t) {
  465. $choices[$t['name']] = $t['id'];
  466. }
  467. $pool = $repPool->getLibraryPools($libId);
  468. $choices2 = [];
  469. foreach ($pool as $t) {
  470. $choices2[$t['name']] = $t['id'];
  471. }
  472. if($pooltype != 0) {
  473. $showsolution = 0;
  474. }
  475. if($action == "true") {
  476. $cardClass = 'App\Entity\Card';
  477. $card = $em->getReference($cardClass, $cardId);
  478. $card->setCorrect(1);
  479. $card->setCorrect2(1);
  480. $em = $this->getDoctrine()->getManager();
  481. $em->persist($card);
  482. $em->flush();
  483. return $this->redirect($this->generateUrl('app_pool2', array('libId' => $libId, 'poolId' => $poolId, 'action' => "continue")));
  484. }
  485. if($action == "false") {
  486. $cardClass = 'App\Entity\Card';
  487. $card = $em->getReference($cardClass, $cardId);
  488. $card->setCorrect(2);
  489. $card->setCorrect2(2);
  490. $em = $this->getDoctrine()->getManager();
  491. $em->persist($card);
  492. $em->flush();
  493. return $this->redirect($this->generateUrl('app_pool2', array('libId' => $libId, 'poolId' => $poolId, 'action' => "continue")));
  494. }
  495. $cardform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post')))
  496. ->setAttribute('class', 'php-email-form')
  497. ->add('task', TextType::class,[
  498. 'required' => true,
  499. 'label' => 'Wort/Phrase',
  500. 'data' => $repCards->getTask($cardId),
  501. 'attr' => array(
  502. 'class' => 'form-control'),
  503. 'label_attr' => array(
  504. 'class' => 'form-label'),
  505. ])
  506. ->add('solution', TextareaType::class,[
  507. 'required' => true,
  508. 'label' => 'Lösung',
  509. 'data' => $repCards->getSolution($cardId),
  510. 'attr' => array(
  511. 'class' => 'form-control',
  512. 'rows' => '7'
  513. ),
  514. 'label_attr' => array(
  515. 'class' => 'form-label'),
  516. ])
  517. ->add('classification', ChoiceType::class,[
  518. 'choices' => $choices,
  519. 'label' => 'Einordnung',
  520. 'data' => $repCards->getClassificationId($cardId),
  521. 'attr' => array(
  522. 'class' => 'form-control'),
  523. 'label_attr' => array(
  524. 'class' => 'form-label'),
  525. ])
  526. ->add('pool', ChoiceType::class,[
  527. 'choices' => $choices2,
  528. 'label' => 'Pool',
  529. 'data' => $repCards->getPoolId($cardId),
  530. 'attr' => array(
  531. 'class' => 'form-control'),
  532. 'label_attr' => array(
  533. 'class' => 'form-label'),
  534. ])
  535. ->add('Speichern', SubmitType::class,[
  536. 'label' => 'Ändern',
  537. ])
  538. ->getForm();
  539. $cardform->handleRequest($request);
  540. if ($cardform->isSubmitted() && $cardform->isValid()) {
  541. $cardClass = 'App\Entity\Card';
  542. $card = $em->getReference($cardClass, $cardId);
  543. $version = $card->getVersion();
  544. $version = $version + 1;
  545. $card->setVersion($version);
  546. $card->setTask($cardform['task']->getData());
  547. $card->setSolution($cardform['solution']->getData());
  548. $card->setClassificationId($cardform['classification']->getData());
  549. $card->setPoolId($cardform['pool']->getData());
  550. $em = $this->getDoctrine()->getManager();
  551. $em->persist($card);
  552. $em->flush();
  553. return $this->redirect($this->generateUrl('app_pool', array('libId' => $libId, 'poolId' => $poolId)));
  554. }
  555. $delcardform = $this->createFormBuilder(null, array('attr' => array('class' => 'php-email-form', 'method' => 'post')))
  556. ->setAttribute('class', 'php-email-form')
  557. ->add('task', TextType::class,[
  558. 'required' => true,
  559. 'label' => 'Wort/Phrase',
  560. 'data' => $repCards->getTask($cardId),
  561. 'attr' => array(
  562. 'class' => 'form-control'),
  563. 'label_attr' => array(
  564. 'class' => 'form-label'),
  565. ])
  566. ->add('solution', TextareaType::class,[
  567. 'required' => true,
  568. 'label' => 'Lösung',
  569. 'data' => $repCards->getSolution($cardId),
  570. 'attr' => array(
  571. 'class' => 'form-control',
  572. 'rows' => '7'
  573. ),
  574. 'label_attr' => array(
  575. 'class' => 'form-label'),
  576. ])
  577. ->add('classification', ChoiceType::class,[
  578. 'choices' => $choices,
  579. 'label' => 'Einordnung',
  580. 'data' => $repCards->getClassificationId($cardId),
  581. 'attr' => array(
  582. 'class' => 'form-control'),
  583. 'label_attr' => array(
  584. 'class' => 'form-label'),
  585. ])
  586. ->add('DelButton', SubmitType::class,[
  587. 'label' => 'Löschen',
  588. ])
  589. ->getForm();
  590. $delcardform->handleRequest($request);
  591. if ($delcardform->isSubmitted() && $delcardform->isValid()) {
  592. $cardClass = 'App\Entity\Card';
  593. $card = $em->getReference($cardClass, $cardId);
  594. $card->setTask($delcardform['task']->getData());
  595. $card->setSolution($delcardform['solution']->getData());
  596. $card->setClassificationId($delcardform['classification']->getData());
  597. $card->setDelflag("1");
  598. $em = $this->getDoctrine()->getManager();
  599. $em->persist($card);
  600. $em->flush();
  601. return $this->redirect($this->generateUrl('app_pool', array('libId' => $libId, 'poolId' => $poolId)));
  602. }
  603. $cards = $repCards->getCards($poolId);
  604. $cardscount = $repCards->getPoolCardsCount($poolId);
  605. if($action != "learnshow") {
  606. return $this->render('library/pool2.html.twig', [
  607. 'cardform' => $cardform->createView(),
  608. 'delcardform' => $delcardform->createView(),
  609. 'libId' => $libId,
  610. 'poolId' => $poolId,
  611. 'poolname' => $poolname,
  612. 'pooltype' => $pooltype,
  613. 'libname' => $libname,
  614. 'cards' => $cards,
  615. 'showsolution' => $showsolution,
  616. 'cardscount' => $cardscount,
  617. 'action' => $action,
  618. 'cardId' => $cardId,
  619. ]);
  620. } else {
  621. return $this->render('library/learning.html.twig', [
  622. 'cardform' => null,
  623. 'delcardform' => null,
  624. 'libId' => $libId,
  625. 'poolId' => $poolId,
  626. 'poolname' => $poolname,
  627. 'pooltype' => $pooltype,
  628. 'libname' => $libname,
  629. 'cards' => $cards,
  630. 'showsolution' => $showsolution,
  631. 'cardscount' => $cardscount,
  632. 'action' => $action,
  633. 'cardId' => $cardId,
  634. ]);
  635. }
  636. }
  637. }