protected function doPreSave(Doctrine_Record $record, sfForm $form) { // loop through relations if ($relations = $form->getOption('dynamic_relations')) { foreach ($relations as $field => $config) { $collection = $record->get($config['relation']->getAlias()); // collect form objects for comparison $search = array(); foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) { $search[] = $embed->getObject(); } foreach ($collection as $i => $object) { if (false === ($pos = array_search($object, $search, true))) { // if a related object exists in the record but isn't represented // in the form, the reference has been removed $collection->remove($i); // if the foreign column is a notnull columns, delete the object $column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName()); if ($object->exists() && isset($column['notnull']) && $column['notnull']) { $object->delete(); } } } } } }
protected function doPreSave(Doctrine_Record $record, sfForm $form) { // loop through relations if ($relations = $form->getOption('dynamic_relations')) { foreach ($relations as $field => $config) { $collection = $record->get($config['relation']->getAlias()); // collect form objects for comparison $search = array(); try { foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) { $search[] = $embed->getObject(); } } catch (InvalidArgumentException $e) { // previously embedded form was removed at the end of form.filter_values as there were no values for it. // @see sfDoctrineDynamicFormRelations::correctValidators() } foreach ($collection as $i => $object) { $pos = array_search($object, $search, true); if (false === $pos && $this->filterObject($object, $config['arguments'])) { // if a related object exists in the record but isn't represented // in the form, the reference has been removed $collection->remove($i); // if the foreign column is a notnull columns, delete the object $column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName()); if ($object->exists() && isset($column['notnull']) && $column['notnull']) { $object->delete(); } } } } } }
/** * Finds a form embedded in the supplied form based on id. * * @param sfForm $form A form * @param string $field The field name used for embedding * @param mixed $id An id value * * @return sfForm|null The embedded form, if one is found */ protected function findEmbeddedFormById(sfForm $form, $field, $id) { foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $embed) { if ($id == $embed->getObject()->get('id')) { return $embed; } } }
/** * * @param sfWebRequest $request * @param sfForm $form */ private function processForm(sfWebRequest $request, sfForm $form, $account_id = null) { $parameters = $request->getParameter($form->getName()); if ($parameters['imputation']['imputation_type'] == ImputationDefaultValues::COUNTABLE_SERVICE_TYPE) { $parameters['account']['value'] = $parameters['initial_value']; $parameters['account']['monetary_account'] = $form->getObject()->getImputation()->getAct()->getMonetaryAccount(); $parameters['account']['created_at'] = $parameters['imputation']['date']; $parameters['account']['act_id'] = $form->getObject()->getImputation()->getActId(); unset($parameters['account_is_shared']); } $form->bind($parameters); if ($form->isValid()) { //If the method of payment is 'account': if ($parameters['imputation']['method_of_payment_id'] == ImputationDefaultValues::getAccountMethodId()) { //We create a new 'hidden' imputation of type account_transaction if (ImputationAccountTransaction::buildAndSaveTransactionFrom($parameters)) { $saved_object = $form->save(); $this->error_account = false; } else { if ($parameters['imputation']['account_id'] == 0) { $this->error_account = true; } else { $this->error_account = false; } return false; } } else { $saved_object = $form->save(); $this->error_account = false; } //If the type of the imputation is 'countable_service' if ($parameters['imputation']['imputation_type'] == ImputationDefaultValues::COUNTABLE_SERVICE_TYPE) { //We create a new account user entry: if (!is_null($account_id)) { ImputationCountableService::createAccountUser($form->getEmbeddedForm('imputation')->getObject()->getUserId(), $account_id); } else { $this->current_account_id = ImputationCountableService::createAccountUser($form->getEmbeddedForm('imputation')->getObject()->getUserId(), $form->getEmbeddedForm('account')->getObject()->getId()); } } //A FAIRE ICI: DUPLICATION DANS LA TABLE ARCHIVE /** * @todo */ $archive = new ImputationArchive(); $archive->fillAndSave($form); return true; } else { if ($parameters['imputation']['account_id'] == 0) { $this->error_account = true; } else { $this->error_account = false; } return false; } }
protected function processForm(sfWebRequest $request, sfForm $form) { $this->getResponse()->setContentType('application/json'); $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $isNew = $this->ei_block->isNew(); $this->ei_block = $form->save(); if ($isNew && !$this->isFull) { if ($this->insert_after) { $this->ei_block->getNode()->insertAsNextSiblingOf($this->ei_block_parent); } else { $this->ei_block->getNode()->insertAsFirstChildOf($this->ei_block_parent); } } elseif ($isNew && $this->isFull && $this->ei_vs_precedent != null) { $this->ei_block->getNode()->insertAsNextSiblingOf($this->ei_vs_precedent); } elseif ($isNew && $this->isFull && $this->ei_block_parent != null && $this->ei_vs_precedent == null) { $this->ei_block->getNode()->insertAsFirstChildOf($this->ei_block_parent); } if ($isNew && $this->isFull && array_key_exists("EiBlockParams", $form->getEmbeddedForms()) && !$this->ei_block->isEiLoop()) { $forms = $form->getEmbeddedForm("EiBlockParams")->getEmbeddedForms(); $prev = null; /** @var EiBlockParamForm $form */ foreach ($forms as $form) { if ($prev == null) { $form->getObject()->getNode()->insertAsLastChildOf($this->ei_block); } else { $form->getObject()->getNode()->insertAsNextSiblingOf($prev); } $prev = $form->getObject(); } } elseif ($isNew && $this->isFull && $this->ei_block->isEiLoop()) { $this->ei_block->createAutoMapping(); } elseif (!$isNew && $this->isFull && array_key_exists("EiBlockParams", $form->getEmbeddedForms())) { $forms = $form->getEmbeddedForm("EiBlockParams")->getEmbeddedForms(); $prev = null; $nouvelleCollection = array(); /** @var EiBlockParamForm $form */ foreach ($forms as $form) { $nouvelleCollection[] = $form->getObject()->getId(); if ($prev == null && $form->getObject()->getLft() == null) { $form->getObject()->getNode()->insertAsLastChildOf($this->ei_block); } elseif ($form->getObject()->getLft() == null) { $form->getObject()->getNode()->insertAsNextSiblingOf($prev); } $prev = $form->getObject(); } foreach ($this->ei_block->getEiVersionStructures() as $key => $structureElt) { if ($structureElt instanceof EiBlockParam && !in_array($structureElt->getId(), $nouvelleCollection)) { $this->ei_block->getEiVersionStructures()->remove($key); } } $this->ei_block->save(); } return false; } else { $JSONResponse['status'] = "error"; $errors = $form->getErrorSchema()->getErrors(); if (isset($errors["name"])) { $nomErreur = $errors["name"]; } else { $nomErreur = ""; } $JSONResponse['message'] = "Unable to save the block. " . $nomErreur; } return $JSONResponse; }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $form->save(); $form_pass = $form->getEmbeddedForm('MdP'); $form_pass->bind($form->getValue('MdP')); $form_pass->save(); $this->getUser()->setFlash('notice', 'Mise à jour du profil effectuée.'); $this->redirect('etudiant/edit'); } }