Example #1
0
	/**
	 * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
	 * feature (like MySQL or SQLite).
	 *
	 * This method is not very speedy because it must perform a query first to get
	 * the implicated records and then perform the deletes by calling those Peer classes.
	 *
	 * This method should be used within a transaction if possible.
	 *
	 * @param      Criteria $criteria
	 * @param      PropelPDO $con
	 * @return     int The number of affected rows (if supported by underlying database driver).
	 */
	protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
	{
		// initialize var to track total num of affected rows
		$affectedRows = 0;

		// first find the objects that are implicated by the $criteria
		$objects = ElevePeer::doSelect($criteria, $con);
		foreach ($objects as $obj) {


			// delete related JEleveClasse objects
			$criteria = new Criteria(JEleveClassePeer::DATABASE_NAME);
			
			$criteria->add(JEleveClassePeer::LOGIN, $obj->getLogin());
			$affectedRows += JEleveClassePeer::doDelete($criteria, $con);

			// delete related JEleveCpe objects
			$criteria = new Criteria(JEleveCpePeer::DATABASE_NAME);
			
			$criteria->add(JEleveCpePeer::E_LOGIN, $obj->getLogin());
			$affectedRows += JEleveCpePeer::doDelete($criteria, $con);

			// delete related JEleveGroupe objects
			$criteria = new Criteria(JEleveGroupePeer::DATABASE_NAME);
			
			$criteria->add(JEleveGroupePeer::LOGIN, $obj->getLogin());
			$affectedRows += JEleveGroupePeer::doDelete($criteria, $con);

			// delete related JEleveProfesseurPrincipal objects
			$criteria = new Criteria(JEleveProfesseurPrincipalPeer::DATABASE_NAME);
			
			$criteria->add(JEleveProfesseurPrincipalPeer::LOGIN, $obj->getLogin());
			$affectedRows += JEleveProfesseurPrincipalPeer::doDelete($criteria, $con);

			// delete related EleveRegimeDoublant objects
			$criteria = new Criteria(EleveRegimeDoublantPeer::DATABASE_NAME);
			
			$criteria->add(EleveRegimeDoublantPeer::LOGIN, $obj->getLogin());
			$affectedRows += EleveRegimeDoublantPeer::doDelete($criteria, $con);

			// delete related ResponsableInformation objects
			$criteria = new Criteria(ResponsableInformationPeer::DATABASE_NAME);
			
			$criteria->add(ResponsableInformationPeer::ELE_ID, $obj->getEleId());
			$affectedRows += ResponsableInformationPeer::doDelete($criteria, $con);

			// delete related JEleveAncienEtablissement objects
			$criteria = new Criteria(JEleveAncienEtablissementPeer::DATABASE_NAME);
			
			$criteria->add(JEleveAncienEtablissementPeer::ID_ELEVE, $obj->getId());
			$affectedRows += JEleveAncienEtablissementPeer::doDelete($criteria, $con);

			// delete related JAidEleves objects
			$criteria = new Criteria(JAidElevesPeer::DATABASE_NAME);
			
			$criteria->add(JAidElevesPeer::LOGIN, $obj->getLogin());
			$affectedRows += JAidElevesPeer::doDelete($criteria, $con);

			// delete related AbsenceEleveSaisie objects
			$criteria = new Criteria(AbsenceEleveSaisiePeer::DATABASE_NAME);
			
			$criteria->add(AbsenceEleveSaisiePeer::ELEVE_ID, $obj->getId());
			$affectedRows += AbsenceEleveSaisiePeer::doDelete($criteria, $con);

			// delete related AbsenceAgregationDecompte objects
			$criteria = new Criteria(AbsenceAgregationDecomptePeer::DATABASE_NAME);
			
			$criteria->add(AbsenceAgregationDecomptePeer::ELEVE_ID, $obj->getId());
			$affectedRows += AbsenceAgregationDecomptePeer::doDelete($criteria, $con);

			// delete related CreditEcts objects
			$criteria = new Criteria(CreditEctsPeer::DATABASE_NAME);
			
			$criteria->add(CreditEctsPeer::ID_ELEVE, $obj->getId());
			$affectedRows += CreditEctsPeer::doDelete($criteria, $con);

			// delete related CreditEctsGlobal objects
			$criteria = new Criteria(CreditEctsGlobalPeer::DATABASE_NAME);
			
			$criteria->add(CreditEctsGlobalPeer::ID_ELEVE, $obj->getId());
			$affectedRows += CreditEctsGlobalPeer::doDelete($criteria, $con);

			// delete related ArchiveEcts objects
			$criteria = new Criteria(ArchiveEctsPeer::DATABASE_NAME);
			
			$criteria->add(ArchiveEctsPeer::INE, $obj->getNoGep());
			$affectedRows += ArchiveEctsPeer::doDelete($criteria, $con);
		}
		return $affectedRows;
	}
	/**
	 * Retrieve object using using composite pkey values.
	 * @param      string $ele_id
	 * @param      string $resp_legal
	 * @param      PropelPDO $con
	 * @return     ResponsableInformation
	 */
	public static function retrieveByPK($ele_id, $resp_legal, PropelPDO $con = null) {
		$_instancePoolKey = serialize(array((string) $ele_id, (string) $resp_legal));
 		if (null !== ($obj = ResponsableInformationPeer::getInstanceFromPool($_instancePoolKey))) {
 			return $obj;
		}

		if ($con === null) {
			$con = Propel::getConnection(ResponsableInformationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}
		$criteria = new Criteria(ResponsableInformationPeer::DATABASE_NAME);
		$criteria->add(ResponsableInformationPeer::ELE_ID, $ele_id);
		$criteria->add(ResponsableInformationPeer::RESP_LEGAL, $resp_legal);
		$v = ResponsableInformationPeer::doSelect($criteria, $con);

		return !empty($v) ? $v[0] : null;
	}
	/**
	 * Find object by primary key using raw SQL to go fast.
	 * Bypass doSelect() and the object formatter by using generated code.
	 *
	 * @param     mixed $key Primary key to use for the query
	 * @param     PropelPDO $con A connection object
	 *
	 * @return    ResponsableInformation A model object, or null if the key is not found
	 */
	protected function findPkSimple($key, $con)
	{
		$sql = 'SELECT ELE_ID, PERS_ID, RESP_LEGAL, PERS_CONTACT FROM responsables2 WHERE ELE_ID = :p0 AND RESP_LEGAL = :p1';
		try {
			$stmt = $con->prepare($sql);
			$stmt->bindValue(':p0', $key[0], PDO::PARAM_STR);
			$stmt->bindValue(':p1', $key[1], PDO::PARAM_STR);
			$stmt->execute();
		} catch (Exception $e) {
			Propel::log($e->getMessage(), Propel::LOG_ERR);
			throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
		}
		$obj = null;
		if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
			$obj = new ResponsableInformation();
			$obj->hydrate($row);
			ResponsableInformationPeer::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
		}
		$stmt->closeCursor();

		return $obj;
	}
	/**
	 * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
	 * feature (like MySQL or SQLite).
	 *
	 * This method is not very speedy because it must perform a query first to get
	 * the implicated records and then perform the deletes by calling those Peer classes.
	 *
	 * This method should be used within a transaction if possible.
	 *
	 * @param      Criteria $criteria
	 * @param      PropelPDO $con
	 * @return     int The number of affected rows (if supported by underlying database driver).
	 */
	protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
	{
		// initialize var to track total num of affected rows
		$affectedRows = 0;

		// first find the objects that are implicated by the $criteria
		$objects = ResponsableElevePeer::doSelect($criteria, $con);
		foreach ($objects as $obj) {


			// delete related ResponsableInformation objects
			$criteria = new Criteria(ResponsableInformationPeer::DATABASE_NAME);
			
			$criteria->add(ResponsableInformationPeer::PERS_ID, $obj->getResponsableEleveId());
			$affectedRows += ResponsableInformationPeer::doDelete($criteria, $con);

			// delete related JNotificationResponsableEleve objects
			$criteria = new Criteria(JNotificationResponsableElevePeer::DATABASE_NAME);
			
			$criteria->add(JNotificationResponsableElevePeer::PERS_ID, $obj->getResponsableEleveId());
			$affectedRows += JNotificationResponsableElevePeer::doDelete($criteria, $con);
		}
		return $affectedRows;
	}
	/**
	 * 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 = ResponsableInformationPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setEleId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setResponsableEleveId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setNiveauResponsabilite($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setPersContact($arr[$keys[3]]);
	}