/** * 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->aPlugIn !== null) { if ($this->aPlugIn->isModified() || $this->aPlugIn->isNew()) { $affectedRows += $this->aPlugIn->save($con); } $this->setPlugIn($this->aPlugIn); } 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()
/** * Méthode qui enregistre le plugin en entier dans la base (avec autorisations et droits) * * @param object $xml */ public static function addPluginComplet(SimpleXMLElement $xml){ // On considère que le xml est vérifié et bon $new = new PlugIn(); $new->setNom($xml->nom); $new->setRepertoire($xml->nom); $new->setOuvert('n'); $new->setDescription($xml->description); $new->save(); /** * @todo : il faudra améliorer ce dispositif et mettre en place quelque chose de plus dynamique pour l'insertion des droits */ $liste_statuts = array('administrateur', 'professeur', 'cpe', 'scolarite', 'secours', 'eleve', 'responsable', 'autre'); $liste_abrevia = array('A', 'P', 'C', 'S', 'sec', 'E', 'R', 'autre'); # les autorisations foreach ($xml->administration->fichier->nomfichier as $fichier){ $attributes = $fichier->attributes(); $droits = explode ("-", $attributes["autorisation"]); foreach ($droits as $droit){ if (in_array($droit, $liste_abrevia)){ // on sait que cette abréviation est conforme mais pas quel est son rang dans le tableau $marqueur = 9; for($a = 0 ; $a < 8 ; $a++){ if ($droit == $liste_abrevia[$a]){ $marqueur = $a; } } // On peut maintenant enregistrer ce droit dans la base $autorisation = new PlugInAutorisation(); $autorisation->setUserStatut($liste_statuts[$marqueur]); $autorisation->setAuth('V'); $autorisation->setFichier('mod_plugins/' . $new->getNom() . '/' .$fichier); $autorisation->setPluginId($new->getId()); $autorisation->save(); }else{ // Ce statut n'est pas autorisé dans Gepi return false; } } } # Les menus foreach ($xml->administration->menu->item as $item) { $attributes = $item->attributes(); $statuts = explode("-", $attributes["autorisation"]); foreach ($statuts as $statut) { if (in_array($statut, $liste_abrevia)){ // on sait que cette abréviation est conforme mais pas quel est son rang dans le tableau $marqueur = 9; for($a = 0 ; $a < 8 ; $a++){ if ($statut == $liste_abrevia[$a]){ $marqueur = $a; } } // On peut maintenant enregistrer cet item du menu dans la base $item_menu = new PlugInMiseEnOeuvreMenu(); $item_menu->setPluginId($new->getId()); $item_menu->setUserStatut($liste_statuts[$marqueur]); $item_menu->setLienItem('mod_plugins/' . $new->getNom() . '/' .$item); $item_menu->setDescriptionItem($attributes["description"]); $item_menu->setTitreItem($attributes["titre"]); $item_menu->save(); }else{ // Ce statut n'est pas autorisé dans Gepi return false; } } } }