<?php

/**
 * Subclass for performing query and update operations on the 'DESTINOS' table.
 *
 *
 *
 * @package lib.model
 */
class DestinosPeer extends BaseDestinosPeer
{
	/**
	 * Trae los destinos de una comision
	 * @param $id
	 * @param $vigencia
	 * @return destinos array
	 */
	public static function getDestinosComision($id, $vigencia) {
		$c = new Criteria();
		$c->add(DestinosPeer::ID_COMISION, $id);
		$c->addAnd(DestinosPeer::VIGENCIA, $vigencia);
		
		return DestinosPeer::doSelect($c);
	}	
	
	public static function doSelectJoinAll(Criteria $c, $con = null)
	{
		$c = clone $c;

				if ($c->getDbName() == Propel::getDefaultDB()) {
			$c->setDbName(self::DATABASE_NAME);
		}

		DestinosPeer::addSelectColumns($c);
		$startcol2 = (DestinosPeer::NUM_COLUMNS - DestinosPeer::NUM_LAZY_LOAD_COLUMNS) + 1;

		MunicipiosPeer::addSelectColumns($c);
		$startcol3 = $startcol2 + MunicipiosPeer::NUM_COLUMNS;

		DepartamentosPeer::addSelectColumns($c);
		$startcol4 = $startcol3 + DepartamentoPeer::NUM_COLUMNS;

		ComisionesPeer::addSelectColumns($c);
		$startcol5 = $startcol4 + ComisionesPeer::NUM_COLUMNS;

		$c->addJoin(DestinosPeer::CODMUN, MunicipiosPeer::CODMUN);
		$c->addJoin(DestinosPeer::CODDEPTO, DepartamentoPeer::ID_DEPTO);
		$c->addJoin(DestinosPeer::ID_COMISION, ComisionesPeer::ID);

//		$c->addJoin(DestinosPeer::VIGENCIA, ComisionesPeer::VIGENCIA);
//
//		$c->addJoin(DestinosPeer::ID_COMISION, ComisionesPeer::VIGENCIA);

		$c->addJoin(DestinosPeer::VIGENCIA, ComisionesPeer::VIGENCIA);

		$rs = BasePeer::doSelect($c, $con);
		$results = array();

		while($rs->next()) {

			$omClass = DestinosPeer::getOMClass();


			$cls = sfPropel::import($omClass);
			$obj1 = new $cls();
			$obj1->hydrate($rs);


					
			$omClass = MunicipiosPeer::getOMClass();


			$cls = sfPropel::import($omClass);
			$obj2 = new $cls();
			$obj2->hydrate($rs, $startcol2);

			$newObject = true;
			for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
				$temp_obj1 = $results[$j];
				$temp_obj2 = $temp_obj1->getMunicipios(); 				if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
					$newObject = false;
					$temp_obj2->addDestinos($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj2->initDestinoss();
				$obj2->addDestinos($obj1);
			}


			$omClass = DepartamentoPeer::getOMClass();

			$cls = sfPropel::import($omClass);
			$obj3 = new $cls();
			$obj3->hydrate($rs, $startcol3);

			$newObject = true;
			for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
				$temp_obj1 = $results[$j];
				$temp_obj3 = $temp_obj1->getDepartamentos(); 				if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) {
					$newObject = false;
					$temp_obj3->addDestinos($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj3->initDestinoss();
				$obj3->addDestinos($obj1);
			}

					
			$omClass = ComisionesPeer::getOMClass();


			$cls = sfPropel::import($omClass);
			$obj4 = new $cls();
			$obj4->hydrate($rs, $startcol4);

			$newObject = true;
			for ($j=0, $resCount=count($results); $j < $resCount; $j++) {
				$temp_obj1 = $results[$j];
				$temp_obj4 = $temp_obj1->getComisiones(); 				if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) {
					$newObject = false;
					$temp_obj4->addDestinos($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj4->initDestinoss();
				$obj4->addDestinos($obj1);
			}

			$results[] = $obj1;
		}
		return $results;
	}
}
