<?php

/**
 * Subclass for performing query and update operations on the 'COMISIONADOS_CONTRATO' table.
 *
 *
 *
 * @package lib.model
 */
class ComisionadosContratoPeer extends BaseComisionadosContratoPeer
{
  public static function getComisionados($id_comision,$vigencia)
  {
    $c = new Criteria();
    $c->add(ComisionadosContratoPeer::ID_COMISION,$id_comision);
    $c->add(ComisionadosContratoPeer::VIGENCIA,$vigencia);
    $c->add(ComisionadosContratoPeer::ESTADO,1);
    return ComisionadosContratoPeer::doSelect($c);    
  }
  
	public static function doSelectJoinAll(Criteria $c, $con = null)
	{
		$c = clone $c;

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

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

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

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

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

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

		$c->addJoin(ComisionadosContratoPeer::NITOCC, TercerosPeer::NITOCC);

		$c->addJoin(ComisionadosContratoPeer::ID_TRANSPORTE, TransportesPeer::ID);

		$c->addJoin(ComisionadosContratoPeer::CODREG, RegionalesPeer::CODREG);

		$c->addJoin(ComisionadosContratoPeer::ID_COMISION, ComisionesPeer::ID);

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

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

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

		while($rs->next()) {

			$omClass = ComisionadosContratoPeer::getOMClass();


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


					
			$omClass = TercerosPeer::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->getTerceros(); 				if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
					$newObject = false;
					$temp_obj2->addComisionadosContrato($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj2->initComisionadosContratos();
				$obj2->addComisionadosContrato($obj1);
			}


					
			$omClass = TransportesPeer::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->getTransportes(); 				if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) {
					$newObject = false;
					$temp_obj3->addComisionadosContrato($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj3->initComisionadosContratos();
				$obj3->addComisionadosContrato($obj1);
			}


					
			$omClass = RegionalesPeer::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->getRegionales(); 				if ($temp_obj4->getPrimaryKey() === $obj4->getPrimaryKey()) {
					$newObject = false;
					$temp_obj4->addComisionadosContrato($obj1); 					break;
				}
			}

			if ($newObject) {
				$obj4->initComisionadosContratos();
				$obj4->addComisionadosContrato($obj1);
			}


					
			$omClass = ComisionesPeer::getOMClass();


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

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

			if ($newObject) {
				$obj5->initComisionadosContratos();
				$obj5->addComisionadosContrato($obj1);
			}

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