Changeset aafb30d
- Timestamp:
- 08/23/10 14:17:27 (21 months ago)
- Branches:
- ('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
- Children:
- f4e524f46ba145b3a6938dad4e9babdcfac160bf
- Parents:
- e0e292f0315a09d924cdb2910962574fdaef290e
- git-author:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-23 14:17:27-04:00
- git-committer:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-23 14:17:27-04:00
- Location:
- html
- Files:
-
- 4 edited
-
admin/vocabulary_admin.php (modified) (1 diff)
-
classes/Langstring.php (modified) (6 diffs)
-
classes/Vocabulary.php (modified) (8 diffs)
-
classes/VocabularyTerm.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
html/admin/vocabulary_admin.php
r9f704d6 raafb30d 278 278 279 279 $vocabulary = new Vocabulary('NEW'); 280 $ num_imported_terms = $vocabulary->import($dom, $format);281 if ($ num_imported_terms == 0)280 $importResults = $vocabulary->import($dom, $format); 281 if ($importResults === false) 282 282 { 283 283 284 echo _(" No terms imported, importation failed; Erasing the vocabulary<br/>");284 echo _("Importation failed; Erasing the vocabulary<br/>"); 285 285 $vocabulary->delete(); 286 286 } 287 287 else 288 288 { 289 echo sprintf(ngettext("%d vocabulary term has been added.", "%d vocabulary terms have been added.", $num_imported_terms), $num_imported_terms)."<br/>";289 echo sprintf(ngettext("%d new vocabulary term has been added (%d updated).", "%d new vocabulary terms have been added (%d updated).",$importResults['new']), $importResults['new'], $importResults['updated'])."<br/>"; 290 290 } 291 291 } -
html/classes/Langstring.php
r3550449 raafb30d 30 30 define('LANGSTRING_BUTTON_ADD_NEW_VALUE', 'Ajouter une chaîne supplémentaire'); 31 31 32 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin 32 /** Représente un Langstring en particulier, ne créez pas un objet langstrings si wous n'en avez pas spécifiquement besoin 33 33 */ 34 34 class Langstring extends GenericDataObject … … 36 36 37 37 /** Returns the cached string in the class-wide cache, or null in no cached value exists 38 * @param $langstring_id The id of the langstring for which we ask a cached38 * @param $langstring_id int The id of the langstring for which we ask a cached 39 39 * value */ 40 40 static private function getCachedString($langstring_id, $locale) … … 89 89 90 90 /**Constructeur 91 @param id Clef maitresse du langstring ou "NEW" pour créer un nouveau LangString dans la base de donnée. 91 @param id Clef maitresse du langstring ou "NEW" pour créer un nouveau LangString dans la base de donnée. 92 92 */ 93 93 function __construct($id = null) … … 217 217 $string = $this->mBd->EscapeString($string); 218 218 $this->mBd->execSqlUpdate("INSERT INTO langstring_entries (langstrings_id, locales_id, value) VALUES ('$this->mId', $id , '$string')", false); 219 $this->dirtyCachedString(); 219 220 $retval = true; 220 221 } … … 248 249 try 249 250 { 250 $this->mBd->executerSqlResUnique("SELECT * FROM langstring_entries WHERE locales_id {$equality_operator} {$id} AND langstrings_id = '$this->mId'", $row, false); 251 if ($row != null) 252 { 253 $string = $this->mBd->EscapeString($string); 254 $this->mBd->execSqlUpdate("UPDATE langstring_entries SET value = '$string' WHERE langstrings_id = '$this->mId' AND locales_id = $id", false); 251 $this->mBd->executerSqlResUnique("SELECT * FROM langstring_entries WHERE locales_id {$equality_operator} {$id} AND langstrings_id = '$this->mId'", $row, false); 252 if ($row != null) { 253 if ($row['value'] != $string) { 254 $string = $this->mBd->EscapeString($string); 255 $this->mBd->execSqlUpdate("UPDATE langstring_entries SET value = '$string' WHERE langstrings_id = '$this->mId' AND locales_id = $id", false); 256 } 257 $this->dirtyCachedString(); 258 } 259 else { 260 $this->addString($string, $locale); 261 } 255 262 $retval = true; 256 }257 else258 {259 $this->addString($string, $locale);260 $retval = true;261 262 }263 263 } 264 264 catch (Exception $e) … … 273 273 /**Affiche l'interface d'administration de l'objet 274 274 @param type_interface SIMPLE pour éditer un seul champ, COMPLETE pour voir toutes les chaînes, LARGE pour avoir un textarea. 275 @param num_nouveau Nombre de champ à afficher pour entrer de nouvelles chaîne en une seule opération. Si 0, il n'y aura un nouveau 275 @param num_nouveau Nombre de champ à afficher pour entrer de nouvelles chaîne en une seule opération. Si 0, il n'y aura un nouveau 276 276 champ que s'il n'y a pas déjà une sous-chaîne. 277 277 */ -
html/classes/Vocabulary.php
rf533742 raafb30d 461 461 var termsArray = new Array($termsCount+1); 462 462 termsArray[0]='---'; 463 $jsTerms463 $jsTerms 464 464 //alert("New length: " + termsArray.length) 465 465 </script> 466 466 EOT; 467 echo $script;468 469 foreach ($vocabulary_terms_result as $vocabulary_terms_row)470 {471 $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId));472 $term->displayAdminUI();473 }467 echo $script; 468 469 foreach ($vocabulary_terms_result as $vocabulary_terms_row) 470 { 471 $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId)); 472 $term->displayAdminUI(); 473 } 474 474 } 475 475 … … 729 729 format VDEX : DOMDocument object 730 730 @param $format string either CSV_array or VDEX 731 @return Le nombre d'entrées (terme) ajoutées dans la base de donnée731 @return array array('new'=>$inserted_terms, 'updated'=>$updated_terms) Le nombre d'entrées (terme) ajoutées dans la base de donnée, ===false if failed 732 732 */ 733 733 function import($data, $format, $debug = false) 734 734 { 735 735 //$debug=true; 736 $ inserted_terms = 0;736 $retval = array('new'=>0, 'updated'=>0); 737 737 if ($format == 'CSV_array') 738 738 { … … 753 753 pretty_print_r($pk); 754 754 $this->mBd->execSqlUpdate("INSERT INTO vocabulary_terms (vdex_4_vocabulary_identifier, caption ,identifier) VALUES (".$this->getSqlId().", ".$langstring->getId().", $pk)", false); 755 $ inserted_terms++;755 $retval['new']++; 756 756 } 757 757 } … … 930 930 931 931 // Création du nouveau vocabulaire 932 // Note: la source à l'importation est une cop îe de vdex_4_vocabulary_identifier932 // Note: la source à l'importation est une copie de vdex_4_vocabulary_identifier 933 933 $this->mBd->ExecuterSqlResUnique("INSERT INTO vocabularies (vdex_1_order_significant, vdex_2_profile_type, vdex_3_vocabulary_name, vdex_4_vocabulary_identifier, vdex_4_1_registration_status, vdex_5_default_language, vocabulary_source, is_system_vocabulary, is_relationship_vocabulary) 934 934 VALUES ($vdex_1_order_significant, $vdex_2_profile_type, $vdex_3_vocabulary_name, '$vdex_4_vocabulary_identifier', $vdex_4_1_registration_status, $vdex_5_default_language, '$vocabulary_source', $is_system_vocabulary, $is_relationship_vocabulary); … … 946 946 foreach ($terms_list as $term) 947 947 { 948 $inserted_terms ++;949 948 $node_list = $xpath->query("dns:termIdentifier", $term); 950 949 foreach ($node_list as $node) … … 967 966 echo "The term $vdex_6_1_identifier is missing, importing it !<br/>"; 968 967 $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId), $vdex_6_1_identifier, null); 969 $ vocabulary_term->import($term, $format, $data, $debug);968 $retval['new']++; //For the term itself 970 969 } 971 970 else 972 971 { 973 // Update th isterm972 // Update the term 974 973 if ($debug) 975 974 echo "The term $vdex_6_1_identifier already exists, updating it !<br/>"; 976 975 $vocabulary_term = VocabularyTerm::getObject(array ('0' => $vdex_6_1_identifier, '1' => $this->mId)); 977 $ vocabulary_term->import($term, $format, $data, $debug);976 $retval['updated']++; //For the term itself 978 977 } 979 978 } … … 981 980 { 982 981 $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId), $vdex_6_1_identifier, null); 983 $vocabulary_term->import($term, $format, $data, $debug); 984 } 982 $retval['new']++; //For the term itself 983 } 984 $importResult = $vocabulary_term->import($term, $format, $data, $debug); 985 if($importResult===false){ 986 throw new Exception ("Failed importing a term"); 987 } 988 $retval['new']+=$importResult['new']; 989 $retval['updated']+=$importResult['updated']; 985 990 } 986 991 987 992 /* 7 Relationship :: 0 - n*/ 988 993 $relationships_list = $xpath->query("//dns:vdex/dns:relationship"); 994 $currentRelationshipsIdArray=array(); 989 995 if($debug){ 990 996 echo "\n Found {$relationships_list->length} relationship(s)"; … … 1046 1052 else { 1047 1053 echo '<h1>ERROR: Vocabulary::import(); $format = '.$format.' Format inconnu!</h1>'; 1048 } 1049 return $inserted_terms; 1054 $retval=false; 1055 } 1056 return $retval; 1050 1057 } 1051 1058 -
html/classes/VocabularyTerm.php
r9f704d6 raafb30d 108 108 109 109 /** Constructeur 110 @param $id_array Anarray: $id_array[0]=vdex_6_1_identifier ou NEW pour ajouter une nouvelle entrée110 @param $id_array array: $id_array[0]=vdex_6_1_identifier ou NEW pour ajouter une nouvelle entrée 111 111 $id_array[1]=vdex_4_vocabulary_identifier (l'identifiant du vocabulaire auquel le terme appartient) 112 112 or 113 113 $id_array[1]=array(vdex_4_vocabulary_identifier, vdex_4_vocabulary_identifier, ...) to look for the term in more than one voc 114 @param $id_new If $id_array[0]='NEW', must contain the specific id of the new term114 @param $id_new string If $id_array[0]='NEW', must contain the specific id of the new term 115 115 @param $parent_id DEPRECATED and ignored 116 116 @param $allow_vdex_update, Allow automatic VDEX download for update … … 285 285 } 286 286 287 /** Indique si la clef primaire de l'objet est une chaîne de caractÚre. 287 /** Indique si la clef primaire de l'objet est une chaîne de caractÚre. 288 288 */ 289 289 static function primaryKeyIsString() … … 314 314 { 315 315 return Langstring::getObject($this->mRow['vdex_6_3_caption']); 316 } 317 318 /** 319 * @return boolean 320 */ 321 public function getIsValidIndex() { 322 return $this->mRow['vdex_6_2_valid_index']=='t'?true:false; 323 } 324 325 /** 326 * @return boolean 327 */ 328 public function getIsOrderSignificant() { 329 return $this->mRow['vdex_6_6_order_significant']=='t'?true:false; 316 330 } 317 331 … … 474 488 } 475 489 476 /** Retourne le thÚme parent de celui-ci 490 /** Retourne le thÚme parent de celui-ci 477 491 * @return Retourne le parent, un objet de même type que celui qui a été 478 492 * instancié ou null si le terme est à la racine … … 497 511 } 498 512 499 /* Retourne la hiérarchie de termes au dessus de celui-ci, en commençant pas la racine 513 /* Retourne la hiérarchie de termes au dessus de celui-ci, en commençant pas la racine 500 514 * @param = $include_self=false 501 515 * @return array de VocabularyTerm représentant le chemin d'accÚs de cet entré thésaurus … … 1045 1059 @param $export_format format de la sortie: LOM ou VDEX 1046 1060 @param $document Le document auquel la sortie doit être ajouté. Le type peut varier 1047 @param $parent Le parent de l'élément à ajouter. Le type peut varier 1061 @param $parent Le parent de l'élément à ajouter. Le type peut varier 1048 1062 @param $entree ID de l'entree de Vocabulary 1049 1063 */ … … 1156 1170 @param $document DOMDocument where the node comes from 1157 1171 @debug activate debug 1158 @return true si résussi1172 @return array array('new'=>$inserted_terms, 'updated'=>$updated_terms) number of new inserted or updated >subterms< (could be 0). ===false if failed 1159 1173 */ 1160 1174 function import($data, $format, $document, $debug = false) … … 1162 1176 $sql = "SELECT * FROM vocabulary_terms NATURAL JOIN vocabularies WHERE vdex_6_1_identifier=".$this->getSqlId().""; 1163 1177 $this->mBd->executerSqlResUnique($sql, $vocabulary_terms_row, false); 1164 1178 $retval = array('new'=>0, 'updated'=>0); 1179 $sqlUpdatesArray = array(); 1165 1180 if ($vocabulary_terms_row != null) 1166 1181 { … … 1174 1189 if ($debug) 1175 1190 echo "{$attr->nodeName}={$attr->nodeValue}<br/>"; 1176 $vdex_6_2_valid_index = $this->mBd->EscapeString($attr->nodeValue); 1177 $sql = "UPDATE vocabulary_terms SET vdex_6_2_valid_index = $vdex_6_2_valid_index WHERE vdex_6_1_identifier=".$this->getSqlId().";\n"; 1178 $this->mBd->execSqlUpdate($sql, false); 1191 $value = $attr->nodeValue=='true'?true:false; 1192 $sqlValue = $this->mBd->EscapeString($attr->nodeValue); 1193 if($this->getIsValidIndex()!=$value) { 1194 $sqlUpdatesArray[] = "vdex_6_2_valid_index = $sqlValue"; 1195 } 1179 1196 } 1180 1197 … … 1253 1270 if ($debug) 1254 1271 echo "{$attr->nodeName}={$attr->nodeValue}<br/>"; 1255 $vdex_6_6_order_significant = $this->mBd->EscapeString($attr->nodeValue); 1256 $sql = "UPDATE vocabulary_terms SET vdex_6_6_order_significant = $vdex_6_6_order_significant WHERE vdex_6_1_identifier=".$this->getSqlId().";\n"; 1257 $this->mBd->execSqlUpdate($sql, false); 1272 $value = $attr->nodeValue=='true'?true:false; 1273 $sqlValue = $this->mBd->EscapeString($attr->nodeValue); 1274 if($this->getIsOrderSignificant()!=$value) { 1275 $sqlUpdatesArray[] = "vdex_6_6_order_significant = $sqlValue"; 1276 } 1258 1277 } 1259 1278 … … 1283 1302 echo "The term $vdex_6_1_identifier is missing, importing it !<br/>"; 1284 1303 $vocabulary_term = new VocabularyTerm(array ('0' => 'NEW', '1' => $this->mId[1]), $vdex_6_1_identifier, array ('0' => $this->mId[0], '1' => $this->mId[1])); 1285 $ vocabulary_term->import($term, $format, $document, $debug);1304 $retval['new']++; 1286 1305 } 1287 1306 else … … 1291 1310 echo "The term $vdex_6_1_identifier already exists, updating it !<br/>"; 1292 1311 $vocabulary_term = VocabularyTerm::getObject(array ('0' => $vdex_6_1_identifier, '1' => $this->mId[1])); 1293 $vocabulary_term->import($term, $format, $document, $debug); 1294 } 1295 1296 } 1297 return true; 1312 $retval['updated']++; 1313 } 1314 $importResult = $vocabulary_term->import($term, $format, $document, $debug); 1315 if($importResult===false){ 1316 throw new Exception ("Failed importing a term"); 1317 } 1318 $retval['new']+=$importResult['new']; 1319 $retval['updated']+=$importResult['updated']; 1320 } 1321 if (!empty($sqlUpdatesArray)){ 1322 $updates = implode(", ", $sqlUpdatesArray); 1323 $sql = "UPDATE vocabulary_terms SET $updates WHERE vdex_6_1_identifier=".$this->getSqlId().";\n"; 1324 $this->mBd->execSqlUpdate($sql, false); 1325 $this->refresh(); 1326 } 1327 return $retval; 1298 1328 } 1299 1329 else … … 1339 1369 { 1340 1370 $this->DeleteTree(); 1371 } 1372 /**Met à jour les attributs de l'objet à partir de la base de donnée 1373 */ 1374 function refresh() 1375 { 1376 $this->__construct($this->mId); 1341 1377 } 1342 1378
Note: See TracChangeset
for help on using the changeset viewer.
