public function saveEleccionInstitucionList($con = null) { if (!$this->isValid()) { throw $this->getErrorSchema(); } if (!isset($this->widgetSchema['eleccion_institucion_list'])) { // somebody has unset this widget return; } if (null === $con) { $con = $this->getConnection(); } $c = new Criteria(); $c->add(EleccionInstitucionPeer::ELECCION_ID, $this->object->getPrimaryKey()); EleccionInstitucionPeer::doDelete($c, $con); $values = $this->getValue('eleccion_institucion_list'); if (is_array($values)) { foreach ($values as $value) { $obj = new EleccionInstitucion(); $obj->setEleccionId($this->object->getPrimaryKey()); $obj->setInstitucionId($value); $obj->save(); } } }
public function configure() { unset($this['eleccion_institucion_list']); $this->embedI18n(array('es', 'ca')); $this->widgetSchema['sf_eleccion_id'] = new sfWidgetFormChoice(array('choices' => array(), 'renderer_class' => 'sfWidgetFormPropelJQueryAutocompleter', 'renderer_options' => array('model' => 'Institucion', 'url' => $this->getOption('url')))); if (!$this->isNew()) { // embed all institucion forms foreach ($this->getObject()->getEleccionInstitucions() as $institucion) { // create a new insti form for the current insti model object $institucionForm = new EleccionInstitucionForm($institucion); $institucionForm->setOption('url', $this->getOption('url')); $institucionForm->configure(); // embed the institucion form in the main eleccion form $this->embedForm('institucion' . $institucion->getInstitucion()->getId(), $institucionForm); // set a custom label for the embedded form $this->widgetSchema['institucion' . $institucion->getInstitucion()->getId()]->setLabel('Institucion ' . $institucion->getInstitucion()->getId()); // change the name widget to sfWidgetFormInputDelete /* $this->widgetSchema['institucion'.$institucion->getInstitucion()->getId()]['url'] = new sfWidgetFormInputDelete(array( 'url' => 'eleccion/deleteInstitucion', // required 'model_id' => $institucion->getInstitucion()->getId(), // required 'confirm' => 'Sure???', // optional )); */ } // create a new institucion form for a new institucion model object $eleccionInstitucion = new EleccionInstitucion(); $eleccionInstitucion->setEleccionId($this->getObject()->getId()); $institucionForm = new EleccionInstitucionForm($eleccionInstitucion); $institucionForm->setOption('url', $this->getOption('url')); $institucionForm->configure(); // embed the institucion form in the main eleccion form $this->embedForm('institucion', $institucionForm); // set a custom label for the embedded form $this->widgetSchema['institucion']->setLabel('Nueva institución'); } }