Danke für deine Antwort 🙂
Das geschilderte Problem bin ich mit einem Click-Handler "umgangen", jedoch bin ich nicht umhin gekommen mehrere Objekte aus einem Formular zu speichern.
Ich habe sie jetzt "per Hand" in die Datenbank geschrieben. Auf jedenfall werde ich mich weiter in Typo3 einarbeiten.
Template:
<f:if condition="{survey.appiontments}" >
<f:form action="add" object="{poll}" name="poll" arguments="{survey:survey, timeofday:timeofday, subscriber:subscriber}">
<f:form.hidden name="polls[subscriber][]" value="{subscriber.uid}" />
<ul class="list-group">
<f:for each="{survey.appiontments}" as="appiontment" iteration="iterator" >
<f:form.hidden name="polls[appiontment][]" value="{iterator.index}" />
<li class="list-group-item">
<table class="table table-bordered table-sm">
<thead>
<tr>
<th rowspan="2"></th>
<th colspan="{appiontment.timeOfDay -> f:count()}"><f:format.date format="d.m.Y">{appiontment.appiontmentdate}</f:format.date></th>
</tr>
<tr>
<f:for each="{appiontment.timeOfDay}" as="timeofday" >
<th>{timeofday.timevalue} Uhr</th>
</f:for>
</tr>
</thead>
<tbody>
<tr>
<th width="150px">{subscriber.nameSubscriber}</th>
<f:for each="{appiontment.timeOfDay}" as="timeofday" iteration="iteratorb" >
<td>
<f:form.checkbox name="polls[poll][{iterator.index}][{iteratorb.index}]" class="checkbox" checked="true" value="1" />
<f:form.hidden name="polls[timeofday][{iterator.index}][{iteratorb.index}]" value="{timeofday.uid}" />
</td>
</f:for>
</tr>
</tbody>
</table>
</li>
</f:for>
<br />
<f:form.submit value="Abschicken" class="btn btn-primary" />
</ul>
</f:form>
</f:if>
Controller:
public function addAction (
\Schmidtch\Survey\Domain\Model\Survey $survey,
\Schmidtch\Survey\Domain\Model\Subscriber $subscriber,
\Schmidtch\Survey\Domain\Model\Poll $poll = NULL)
{
$polls = $_POST['tx_survey_surveylisting']['polls'];
$pollArray = $polls['poll'];
$timeofdayArray = $polls['timeofday'];
$uid = $polls['subscriber'][0];
$appiontmentArray = $polls['appiontment'];
$resultPoll = $this->pollRepository->addPoll($uid,$pollArray,$timeofdayArray,$appiontmentArray);
$resultTimeofday = $this->timeofdayRepository->updatePoll($appiontmentArray,$timeofdayArray);
$countSubscriber = $this->pollRepository->countSubscriber($uid);
$resultSubscriber = $this->subscriberRepository->updatePoll($uid,$countSubscriber);
$this->redirect('showAfter', 'Subscriber', NULL, array('subscriber' => $subscriber,'survey' => $survey));
}
Repository:
public function countSubscriber($uid)
{
$sql = "SELECT * FROM tx_survey_domain_model_poll WHERE subscriber='".$uid."'";
$result = $GLOBALS['TYPO3_DB']->sql_query($sql);
$num_rows = $result->num_rows;
return $num_rows;
}
public function addPoll($uid,$pollArray,$timeofdayArray,$appiontmentArray)
{
for($a=0;$a<sizeof($appiontmentArray);$a++) {
for($b=0;$b<sizeof($timeofdayArray[$a]);$b++) {
if($pollArray[$a][$b] != NULL) {
$sql = "INSERT INTO tx_survey_domain_model_poll (pid, subscriber,timeofday,poll,tstamp,crdate)
VALUES (70,'".$uid."','".$timeofdayArray[$a][$b]."','".$pollArray[$a][$b]."',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);";
$resultInsert = $GLOBALS['TYPO3_DB']->sql_query($sql);
}
else {
$sql = "INSERT INTO tx_survey_domain_model_poll (pid, subscriber,timeofday,poll,tstamp,crdate)
VALUES (70,'".$uid."','".$timeofdayArray[$a][$b]."',0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);";
$resultInsert = $GLOBALS['TYPO3_DB']->sql_query($sql);
}
}
}
return $resultInsert;
}
public function updatePoll($appiontmentArray,$timeofdayArray)
{
for($a=0;$a<sizeof($appiontmentArray);$a++) {
for($b=0;$b<sizeof($timeofdayArray[$a]);$b++) {
$sql = "SELECT * FROM tx_survey_domain_model_poll WHERE timeofday='".$timeofdayArray[$a][$b]."'";
$result = $GLOBALS['TYPO3_DB']->sql_query($sql);
$num_rows = $result->num_rows;
$sql = "UPDATE tx_survey_domain_model_timeofday
SET timecheck='".$num_rows."'
WHERE uid='".$timeofdayArray[$a][$b]."'";
$resultInsert = $GLOBALS['TYPO3_DB']->sql_query($sql);
}
}
return $resultInsert;
}
public function countTimeofday($timeofday)
{
$query = $this->createQuery();
$sql = "SELECT * FROM tx_survey_domain_model_poll WHERE timeofday='".$timeofday."'";
$query->statement( $sql );
$result = $query->count();
return $result;
}
public function updatePoll($uid,$countSubscriber)
{
$sql = "UPDATE tx_survey_domain_model_subscriber
SET subcheck='".$countSubscriber."'
WHERE uid='".$uid."'";
$resultInsert = $GLOBALS['TYPO3_DB']->sql_query($sql);
return $resultInsert;
}