Ejemplo n.º 1
0
	/**
	 * Performs the work of inserting or updating the row in the database.
	 *
	 * If the object is new, it inserts it; otherwise an update is performed.
	 * All related objects are also updated in this method.
	 *
	 * @param      PropelPDO $con
	 * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
	 * @throws     PropelException
	 * @see        save()
	 */
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; // initialize var to track total num of affected rows
		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

			// We call the save method on the following object(s) if they
			// were passed to this object by their coresponding set
			// method.  This object relates to these object(s) by a
			// foreign key reference.

			if ($this->aGroupe !== null) {
				if ($this->aGroupe->isModified() || $this->aGroupe->isNew()) {
					$affectedRows += $this->aGroupe->save($con);
				}
				$this->setGroupe($this->aGroupe);
			}

			if ($this->aMatiere !== null) {
				if ($this->aMatiere->isModified() || $this->aMatiere->isNew()) {
					$affectedRows += $this->aMatiere->save($con);
				}
				$this->setMatiere($this->aMatiere);
			}

			if ($this->isNew() || $this->isModified()) {
				// persist changes
				if ($this->isNew()) {
					$this->doInsert($con);
				} else {
					$this->doUpdate($con);
				}
				$affectedRows += 1;
				$this->resetModified();
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} // doSave()
Ejemplo n.º 2
0
 $nb_matieres = $matieres['count'];
 /*
  * Ajout des matières
  */
 for ($cpt = 0; $cpt < $matieres['count']; $cpt++) {
     $code_matiere = $matieres[$cpt]['cn'][0];
     $nom_matiere = $matieres[$cpt]['description'][0];
     // On test si on a déjà cette matière
     $nouvelle_matiere = MatierePeer::retrieveByPK($code_matiere);
     if ($nouvelle_matiere != null) {
         echo "La matière " . $nouvelle_matiere->getMatiere() . " (" . $nouvelle_matiere->getNomComplet() . ") existe d&eacute;j&agrave;<br/>";
     } else {
         $nouvelle_matiere = new Matiere();
         $nouvelle_matiere->setMatiere($code_matiere);
         $nouvelle_matiere->setNomComplet($nom_matiere);
         $nouvelle_matiere->save();
     }
     // Maintenant on associe les profs à cette matiere
     $nb_profs = $matieres[$cpt]['memberuid']['count'];
     $matiere_profs = $nouvelle_matiere->getProfesseurs();
     if ($nb_profs > 0) {
         for ($i = 0; $i < $nb_profs; $i++) {
             // On vérifie que le prof existe, quand même...
             $prof = UtilisateurProfessionnelPeer::retrieveByPK($matieres[$cpt]['memberuid'][$i]);
             // Le prof existe, on créer l'association, si elle n'existe pas encore
             if ($prof != null) {
                 // L'association n'existe pas, on la créé
                 // Pour ça, on doit déterminer l'ordre
                 if (!$matiere_profs->contains($prof)) {
                     $assoc = JProfesseursMatieresQuery::create()->filterByProfesseur($prof)->orderByOrdreMatieres('desc')->findOne();
                     $nouvel_ordre = $assoc == null ? 1 : $assoc->getOrdreMatieres() + 1;