Guest User

SearchController.php

a guest
Jun 17th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. <?php
  2. namespace Itoop\Atc\Controller;
  3.  
  4.  
  5. use TYPO3\Flow\Annotations as Flow;
  6. use TYPO3\Flow\Mvc\Controller\ActionController;
  7. use Itoop\Atc\Domain\Model\Mitglied;
  8.  
  9. /**
  10. * LoginController
  11. *
  12. *
  13. */
  14. class SearchController extends \TYPO3\Flow\Mvc\Controller\ActionController {
  15.  
  16. /**
  17. * @Flow\Inject
  18. * @var \Itoop\Atc\Domain\Repository\MitgliedRepository
  19. */
  20. protected $mitgliedRepository;
  21.  
  22. /**
  23. * @Flow\Inject
  24. * @var \Itoop\Atc\Domain\Repository\BeitragssatzTennisRepository
  25. */
  26. protected $beitragssatzTennisRepository;
  27.  
  28. /**
  29. * @Flow\Inject
  30. * @var \Itoop\Atc\Domain\Repository\BeitragssatzBreitensportRepository
  31. */
  32. protected $beitragssatzBreitensportRepository;
  33.  
  34. /**
  35. * @Flow\Inject
  36. * @var \Itoop\Atc\Domain\Repository\ArchivRepository
  37. */
  38. protected $archivRepository;
  39.  
  40. /**
  41. * index action, does only display the form
  42. */
  43. public function indexAction() {
  44. // find all members
  45. $mitgl = $this->mitgliedRepository->findAll();
  46. //$this->view->assign('beitragssaetze', $this->beitragssatzRepository->findAll());
  47.  
  48. // calculations and automatic property-settings
  49. //
  50. // for each member calculate age and update array/property age
  51. foreach ($mitgl as $P) {
  52.  
  53. $this->persistenceManager->whitelistObject($P);
  54.  
  55. // Calculate Birthday
  56. //date in mm.dd.yyyy format; or it can be in other formats as well
  57. $birthDate = $P->getGeburtsdatum();
  58. //explode the date to get month, day and year
  59. $birthDate = explode(".", $birthDate);
  60. //get age from date or birthdate
  61. $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[0], $birthDate[2]))) > date("md")
  62. ? ((date("Y") - $birthDate[2]) - 1)
  63. : (date("Y") - $birthDate[2]));
  64. $P->setAge("$age");
  65.  
  66. // get date of Geburtsdatum and make property Geburtszeit, to be able to sort by birthday
  67. $BD = $P->getGeburtsdatum();
  68. // format to timestamp
  69. $dt = strtotime($BD);
  70. // set property geburtszeit to every member
  71. $P->setGeburtszeit("$dt");
  72. // do the same for Eintrittsdatum
  73. $ED = $P->getEintrittsdatum();
  74. $et = strtotime($ED);
  75. $P->setEintrittszeit("$et");
  76.  
  77. $this->mitgliedRepository->update($P);
  78. //$this->persistenceManager->persistAll();
  79.  
  80.  
  81. // *** Calculate Beitrag ***
  82.  
  83. // read out beitragssatz, age and abteilung out of mitglieder
  84. $BS = $P->getBeitragssatz();
  85. $ABT = $P->getAbteilung();
  86. $age = $P->getAge();
  87.  
  88. $U13 = 'U13';
  89. $U22 = 'U22';
  90.  
  91. if ($ABT === 'Tennis') {
  92. // by arbitrary DQL select Beitragssatz out of beitragssatzRepository
  93. if ($BS !== 'Individual') {
  94. $abfrage = $this->beitragssatzTennisRepository->findByBeitrag($BS);
  95. $BSU13 = $this->beitragssatzTennisRepository->findU13($U13);
  96. $BSU22 = $this->beitragssatzTennisRepository->findU22($U22);
  97. }
  98. // Altersstaffel
  99. if ($age < '13' and $BS == 'Aktiv') {
  100. $P->setBeitrag($BSU13);
  101. }
  102. if ($age > '12' and $age < '22' and $BS === 'Aktiv') {
  103. $P->setBeitrag($BSU22);
  104. }
  105. if ($age > '21' and $BS === 'Aktiv') {
  106. $P->setBeitrag($abfrage);
  107. }
  108.  
  109. if ($BS === 'Passiv') {
  110. $P->setBeitrag($abfrage);
  111. }
  112. if ($BS === 'Ehepaar') {
  113. $P->setBeitrag($abfrage);
  114. }
  115.  
  116. // read out trainingssatz out of mitglied
  117. $TS = $P->getTrainingssatz();
  118. // by arbitrary DQL select Beitragssatz out of beitragssatzRepository
  119. if ($TS !== 'Individual' and $TS !=='Kein') {
  120. $TSABFRAGE = $this->beitragssatzTennisRepository->findByTrainingsbeitrag($TS);
  121. }
  122. // if trainingssatz is Training set Traininssatz standard
  123. if ($TS === 'Training') {
  124. $P->setTrainingsbeitrag($TSABFRAGE);
  125. }
  126. // if Trainingssatz is kein set Trainingsbeitrag 0,00
  127. if ($TS === 'Kein') {
  128. $P->setTrainingsbeitrag('0,00');
  129. }
  130.  
  131. }
  132.  
  133. if ($ABT == 'Breitensport') {
  134. // by arbitrary DQL select Beitragssatz out of beitragssatzRepository
  135. if ($BS != 'individual' and $BS !== 'Ehepaar') {
  136. $abfrage = $this->beitragssatzBreitensportRepository->findByBeitrag($BS);
  137. $BSU13 = $this->beitragssatzBreitensportRepository->findU13($U13);
  138. $BSU21 = $this->beitragssatzBreitensportRepository->findU22($U22);
  139. }
  140. // Altersstaffel
  141. if ($age < '13' and $BS == 'aktiv') {
  142. $P->setBeitrag($BSU13);
  143. }
  144. if ($age > '12' and $age < '22' and $BS == 'aktiv') {
  145. $P->setBeitrag($BSU22);
  146. }
  147. if ($age > '21' and $BS === 'aktiv') {
  148. $P->setBeitrag($abfrage);
  149. }
  150.  
  151. if ($BS === 'passiv') {
  152. $P->setBeitrag($abfrage);
  153. }
  154.  
  155. }
  156.  
  157.  
  158. $this->mitgliedRepository->update($P);
  159. //$this->persistenceManager->persistAll();
  160. }
  161. }
  162.  
  163. /**
  164. * @return void
  165. *
  166. *
  167. *
  168. * @Flow\Validate(argumentName="geburtsdatumab", type="Itoop.Atc:DatumEmptyAllowed")
  169. * @Flow\Validate(argumentName="geburtsdatumbis", type="Itoop.Atc:DatumEmptyAllowed")
  170. * @Flow\Validate(argumentName="eintrittab", type="Itoop.Atc:DatumEmptyAllowed")
  171. * @Flow\Validate(argumentName="eintrittbis", type="Itoop.Atc:DatumEmptyAllowed")
  172. *
  173. *
  174. * @param string $searchin
  175. * @param string $abteilung
  176. * @param string $mitgliedsnummer
  177. * @param string $geschlecht
  178. * @param string $name
  179. * @param string $vorname
  180. * @param string $strasse
  181. * @param string $plz
  182. * @param string $ort
  183. * @param string $geburtsdatumab
  184. * @param string $geburtsdatumbis
  185. * @param string $alterab
  186. * @param string $alterbis
  187. * @param string $eintrittab
  188. * @param string $eintrittbis
  189. * @param string $mandatsreferenz
  190. * @param string $sequenz
  191. * @param string $beitragssatz
  192. * @param string $trainingssatz
  193. * @param string $iban
  194. *
  195. * @return string
  196. *
  197. */
  198. public function resultsAction($searchin, $abteilung, $mitgliedsnummer, $geschlecht, $name, $vorname, $strasse, $plz, $ort, $geburtsdatumab, $geburtsdatumbis, $alterab, $alterbis, $eintrittab, $eintrittbis, $mandatsreferenz, $iban, $sequenz, $beitragssatz, $trainingssatz) {
  199.  
  200.  
  201.  
  202. if ($abteilung == 'Alle') {
  203. $abteilung = '%';
  204. }
  205. if ($mitgliedsnummer == '') {
  206. $mitgliedsnummer = '%';
  207. }
  208. if ($geschlecht == 'Beide') {
  209. $geschlecht = '%';
  210. }
  211. if ($name == '') {
  212. $name = '%';
  213. }
  214. if ($vorname == '') {
  215. $vorname = '%';
  216. }
  217. if ($strasse == '') {
  218. $strasse = '%';
  219. }
  220. if ($plz == '') {
  221. $plz = '%';
  222. }
  223. if ($ort == '') {
  224. $ort = '%';
  225. }
  226. if ($geburtsdatumab == '') {
  227. $geburtsdatumab = '01.01.1900';
  228. }
  229. if ($geburtsdatumbis == '') {
  230. $geburtsdatumbis = '31.12.9999';
  231. }
  232. if ($alterab == '') {
  233. $alterab = '0';
  234. }
  235. if ($alterbis == '') {
  236. $alterbis = '200';
  237. }
  238. if ($eintrittab == '') {
  239. $eintrittab = '01.01.1900';
  240. }
  241. if ($eintrittbis == '') {
  242. $eintrittbis = '31.12.3000';
  243. }
  244. if ($mandatsreferenz == '') {
  245. $mandatsreferenz = '%';
  246. }
  247. if ($iban == '') {
  248. $iban = '%';
  249. }
  250. if ($sequenz == 'Bitte_waehlen') {
  251. $sequenz = '%';
  252. }
  253.  
  254. if ($beitragssatz == 'Bitte_waehlen') {
  255. $beitragssatz = '%';
  256. }
  257.  
  258. if ($trainingssatz == 'Bitte_waehlen') {
  259. $trainingssatz = '%';
  260. }
  261.  
  262. if ($trainingssatz == 'Kein') {
  263. $trainingssatz = 'Kein';
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270. $gzab = strtotime($geburtsdatumab);
  271. $gzbis = strtotime($geburtsdatumbis);
  272. $ezab = strtotime($eintrittab);
  273. $ezbis = strtotime($eintrittbis);
  274.  
  275.  
  276. if ($searchin == 'Mitglieder') {
  277.  
  278. if ($trainingssatz == 'Alle') {
  279. $this->view->assign('mitglieder', $this->mitgliedRepository->searchTraining($abteilung, $mitgliedsnummer, $geschlecht, $name, $vorname, $strasse, $plz, $ort, $gzab, $gzbis, $alterab, $alterbis, $ezab, $ezbis, $mandatsreferenz, $iban, $sequenz, $beitragssatz));
  280. }
  281.  
  282.  
  283. if ($trainingssatz != 'Alle') {
  284. $this->view->assign('mitglieder', $this->mitgliedRepository->search($abteilung, $mitgliedsnummer, $geschlecht, $name, $vorname, $strasse, $plz, $ort, $gzab, $gzbis, $alterab, $alterbis, $ezab, $ezbis, $mandatsreferenz, $iban, $sequenz, $beitragssatz, $trainingssatz));
  285. }
  286. }
  287.  
  288. if ($searchin == 'Archiv') {
  289.  
  290. if ($trainingssatz == 'Alle') {
  291. $this->view->assign('archivs', $this->archivRepository->searchTraining($abteilung, $mitgliedsnummer, $geschlecht, $name, $vorname, $strasse, $plz, $ort, $gzab, $gzbis, $alterab, $alterbis, $ezab, $ezbis, $mandatsreferenz, $iban, $sequenz, $beitragssatz));
  292. }
  293.  
  294.  
  295. if ($trainingssatz != 'Alle') {
  296. $this->view->assign('archivs', $this->archivRepository->search($abteilung, $mitgliedsnummer, $geschlecht, $name, $vorname, $strasse, $plz, $ort, $gzab, $gzbis, $alterab, $alterbis, $ezab, $ezbis, $mandatsreferenz, $iban, $sequenz, $beitragssatz, $trainingssatz));
  297. }
  298. }
  299.  
  300.  
  301. }
  302.  
  303.  
  304.  
  305. /**
  306. * @return \TYPO3\Flow\Error\Message
  307. */
  308. protected function getErrorFlashMessage() {
  309. switch ($this->actionMethodName) {
  310. case 'resultsAction' :
  311. return new \TYPO3\Flow\Error\Error('Die Suche konnte nicht ausgeführt werden, weil mindestens ein Feld nicht richtig ausgefüllt wurde.');
  312.  
  313. default:
  314. return parent::getErrorFlashMessage();
  315.  
  316. }
  317. }
  318.  
  319. }
Advertisement
Add Comment
Please, Sign In to add comment