public static function countElecciones() { $cache = sfcontext::getInstance()->getViewCacheManager() ? sfcontext::getInstance()->getViewCacheManager()->getCache() : false; if ($cache) { $key = md5("elecciones_counter"); $data = unserialize($cache->get($key)); } else { $data = false; } if (!$data) { $cele = new Criteria(); $cele->setDistinct(); $cele->addJoin(EleccionPeer::ID, ConvocatoriaPeer::ELECCION_ID); $cele->addJoin(ListaPeer::CONVOCATORIA_ID, ConvocatoriaPeer::ID); $data = EleccionPeer::doCount($cele); if ($cache) { $cache->set($key, serialize($data), 3600); } } return $data; }
/** * Get the associated Eleccion object * * @param PropelPDO Optional Connection object. * @return Eleccion The associated Eleccion object. * @throws PropelException */ public function getEleccion(PropelPDO $con = null) { if ($this->aEleccion === null && $this->eleccion_id !== null) { $this->aEleccion = EleccionPeer::retrieveByPk($this->eleccion_id); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aEleccion->addConvocatorias($this); */ } return $this->aEleccion; }
/** * Selects a collection of {@link Eleccion} objects with a {@link EleccionI18n} translation populated. * * @param Criteria $criteria * @param string $culture * @param PropelPDO $con * @param string $join_behavior * * @return array */ public static function doSelectWithI18n(Criteria $criteria, $culture = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; if (null === $culture) { $culture = sfPropel::getDefaultCulture(); } // Set the correct dbName if it has not been overridden if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } EleccionPeer::addSelectColumns($criteria); $startcol = EleccionPeer::NUM_COLUMNS - EleccionPeer::NUM_LAZY_LOAD_COLUMNS; EleccionI18nPeer::addSelectColumns($criteria); $criteria->addJoin(EleccionPeer::ID, EleccionI18nPeer::ID, $join_behavior); $criteria->add(EleccionI18nPeer::CULTURE, $culture); foreach (sfMixer::getCallables('BaseEleccion:doSelectJoin:doSelectJoin') as $sf_hook) { call_user_func($sf_hook, 'Eleccion', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = EleccionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = EleccionPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = EleccionPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); EleccionPeer::addInstanceToPool($obj1, $key1); } // if $obj1 already loaded $key2 = EleccionI18nPeer::getPrimaryKeyHashFromRow($row, $startcol); if ($key2 !== null) { $obj2 = EleccionI18nPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = EleccionI18nPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol); EleccionI18nPeer::addInstanceToPool($obj2, $key2); } // if obj2 already loaded $obj1->setEleccionI18nForCulture($obj2, $culture); } // if joined row was not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = EleccionPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setVanity($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCreatedAt($arr[$keys[2]]); } }
/** * Selects a collection of EleccionInstitucion objects pre-filled with all related objects except Institucion. * * @param Criteria $criteria * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of EleccionInstitucion objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptInstitucion(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $criteria = clone $criteria; // Set the correct dbName if it has not been overridden // $criteria->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($criteria->getDbName() == Propel::getDefaultDB()) { $criteria->setDbName(self::DATABASE_NAME); } EleccionInstitucionPeer::addSelectColumns($criteria); $startcol2 = EleccionInstitucionPeer::NUM_COLUMNS - EleccionInstitucionPeer::NUM_LAZY_LOAD_COLUMNS; EleccionPeer::addSelectColumns($criteria); $startcol3 = $startcol2 + (EleccionPeer::NUM_COLUMNS - EleccionPeer::NUM_LAZY_LOAD_COLUMNS); $criteria->addJoin(EleccionInstitucionPeer::ELECCION_ID, EleccionPeer::ID, $join_behavior); // symfony_behaviors behavior foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) { call_user_func($sf_hook, 'BaseEleccionInstitucionPeer', $criteria, $con); } $stmt = BasePeer::doSelect($criteria, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = EleccionInstitucionPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = EleccionInstitucionPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $cls = EleccionInstitucionPeer::getOMClass(false); $obj1 = new $cls(); $obj1->hydrate($row); EleccionInstitucionPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined Eleccion rows $key2 = EleccionPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = EleccionPeer::getInstanceFromPool($key2); if (!$obj2) { $cls = EleccionPeer::getOMClass(false); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); EleccionPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (EleccionInstitucion) to the collection in $obj2 (Eleccion) $obj2->addEleccionInstitucion($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
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()); }