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'); } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param EleccionInstitucion $value A EleccionInstitucion object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(EleccionInstitucion $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = serialize(array((string) $obj->getEleccionId(), (string) $obj->getInstitucionId())); } // if key === null self::$instances[$key] = $obj; } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $c = new Criteria(); $c->add(InstitucionI18nPeer::NOMBRE, 'Ayuntamiento%', Criteria::LIKE); $c->add(InstitucionI18nPeer::CULTURE, 'es'); $pager = new sfPropelPager('InstitucionI18n', 100); $pager->setCriteria($c); $pageNum = 0; do { $pageNum++; echo "\nBlock no. {$pageNum} \n"; $pager->setPage($pageNum); $pager->init(); $instituciones = $pager->getResults(); foreach ($instituciones as $institucion) { $geo = GeoPeer::retrieveByPK($institucion->getInstitucion()->getGeoId()); if ($geo) { echo "."; $nombreCorto = $geo->getNombre(); //$nombreCorto = $institucion->getInstitucion()->getGeo()->getNombre(); $vanityUrl = SfVoUtil::encodeVanity($nombreCorto); $c2 = new Criteria(); $c2->add(EleccionPeer::VANITY, "{$vanityUrl}%", Criteria::LIKE); //$c2->add(EleccionPeer::ID, $id, Criteria::NOT_EQUAL); $eleccionesLikeMe = EleccionPeer::doSelect($c2); $counter = 0; foreach ($eleccionesLikeMe as $eleccionLikeMe) { $counter++; } $vanity = "{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"); $eleccion = new Eleccion(); $eleccion->setVanity($vanity); $eleccion->save(); $ei = new EleccionInstitucion(); $ei->setEleccion($eleccion); $ei->setInstitucion($institucion->getInstitucion()); $ei->save(); $eleccion_i18n = new EleccionI18n(); $eleccion_i18n->setCulture('es'); $eleccion_i18n->setNombreCorto($nombreCorto); $eleccion_i18n->setNombre("Elecciones al Ayuntamiento de {$nombreCorto}"); $eleccion_i18n->setEleccion($eleccion); $eleccion_i18n->save(); $eleccion_i18n = new EleccionI18n(); $eleccion_i18n->setCulture('ca'); $eleccion_i18n->setNombreCorto($nombreCorto); $eleccion_i18n->setNombre("Eleccions al Ajuntament de {$nombreCorto}"); $eleccion_i18n->setEleccion($eleccion); $eleccion_i18n->save(); $convocatoria = new Convocatoria(); $convocatoria->setEleccion($eleccion); $convocatoria->setNombre('2011'); $convocatoria->setFecha('2011/05/22'); $convocatoria->save(); $convocatoria_i18n = new ConvocatoriaI18n(); $convocatoria_i18n->setConvocatoria($convocatoria); $convocatoria_i18n->setCulture('es'); $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle."); $convocatoria_i18n->save(); $convocatoria_i18n = new ConvocatoriaI18n(); $convocatoria_i18n->setConvocatoria($convocatoria); $convocatoria_i18n->setCulture('ca'); $convocatoria_i18n->setDescripcion("Las listas y candidatos que se presentan a las elecciones de mayo. Vota y elige al alcalde y a los concejales de {$nombreCorto}. Compara las listas cerradas de los partidos con las listas abiertas de Voota, la lista oficial contra lo que dice la calle."); $convocatoria_i18n->save(); $circu = new Circunscripcion(); $circu->setGeo($geo); $criteria = new Criteria(); $criteria->add(PoliticoInstitucionPeer::INSTITUCION_ID, $institucion->getId()); $count = PoliticoInstitucionPeer::doCount($criteria); $circu->setEscanyos($count); $circu->save(); } } } while (!$pager->isLastPage()); }