Skip to content

Instantly share code, notes, and snippets.

@benjaminrau
Last active December 12, 2015 05:28
Show Gist options
  • Save benjaminrau/4721948 to your computer and use it in GitHub Desktop.
Save benjaminrau/4721948 to your computer and use it in GitHub Desktop.
Remove all objects from a mn relation / objectstorage
/**
* action update
*
* @param Tx_Hcbookings_Domain_Model_Item
* @dontverifyrequesthash
* @return void
*/
public function updateAction(Tx_Hcbookings_Domain_Model_Item $item) {
// Empty storage if no got submitted by form / last one has been removed
// Remember, if you use this action on a form that doesnt contain all the availabilityRanges
// we need to bind the condition to an "indicator" field and not to "if form contains this elements"
$formItem = $this->request->getArgument('item');
if(!array_key_exists('availabilityRanges', $formItem)) {
$storage = $item->getAvailabilityRanges();
$storage->removeAll(clone $storage);
}
$this->itemRepository->update($item);
$this->flashMessageContainer->add('Your Item was updated.');
$this->redirect('show', null, null, array('item'=>$item));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment