Changeset ce9b376
- Timestamp:
- 08/26/10 15:04:15 (21 months ago)
- Branches:
- ('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
- Children:
- 80d44661cba844705c64610a0ddc0bc60f2d9950
- Parents:
- 7329a7409a9b5dbfd010361d0df93b771d1fecd3
- git-author:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-26 15:04:15-04:00
- git-committer:
- Benoit Grégoire <benoitg@coeus.ca>2010-08-26 15:04:15-04:00
- Location:
- html
- Files:
-
- 11 edited
-
classes/Lom.php (modified) (1 diff)
-
classes/LomIdentifier.php (modified) (2 diffs)
-
classes/SearchEngine.php (modified) (9 diffs)
-
classes/Vocabulary.php (modified) (3 diffs)
-
classes/VocabularyRelation.php (modified) (2 diffs)
-
classes/VocabularyTerm.php (modified) (1 diff)
-
classes/exceptions/ObjectInstanciationException.php (modified) (1 diff)
-
config/config.php (modified) (1 diff)
-
include/schema_validate.php (modified) (1 diff)
-
tests/VocabRelationshipNavigationTest.php (modified) (9 diffs)
-
tests/testVocs/rVoc2.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
html/classes/Lom.php
r8b111ad rce9b376 2870 2870 2871 2871 /** set the OAI id to this learning object in element 3.1. If there is one already, it will be replaced. 2872 * @param $oai_id A string, the new OAI-id, call will fail if there is one2872 * @param $oai_id string The new OAI-id, call will fail if there is one 2873 2873 * already */ 2874 2874 function setOaiId($oai_id) { -
html/classes/LomIdentifier.php
r132d4f5 rce9b376 19 19 * Boston, MA 02111-1307, USA gnu@gnu.org * 20 20 * * 21 \********************************************************************/21 \********************************************************************/ 22 22 /**@file LomIdentifier.php 23 23 * @author Copyright (C) 2004 Benoit Grégoire, Technologies Coeus inc. 24 */24 */ 25 25 26 26 require_once 'GenericDataObject.php'; … … 28 28 error_reporting(E_ALL); 29 29 30 /** Représente un identifiant LOM (Ãlément 1.1). 30 /** Représente un identifiant LOM (Ãlément 1.1). 31 31 */ 32 32 class LomIdentifier extends GenericDataObject 33 33 { 34 private $mEntry; 35 private $mCatalog; 36 static private $object_cache = array (); 37 /** Get an instance of the object 38 * @param The first argument is the object class, the rest are passed to the 39 * constructor 40 * @return the Content object, or null if there was an error (an exception is also thrown) 41 */ 42 static public function & getObject() 43 { 44 $args = func_get_args(); 45 //pretty_print_r($args); 46 $id = $args[0]; 47 if (isset (self :: $object_cache[$id])) 48 { 49 //echo "CACHE HIT!"; 50 $retval = & self :: $object_cache[$id]; 51 } 52 else 53 { 54 //echo "CACHE MISS!"; 55 $retval = new self($id); 56 self :: $object_cache[$id] = $retval; 57 } 58 return $retval; 59 } 60 61 /**Constructeur 62 * @param id Clef maîtresse de l'Identifiant ou 63 * "NEW" pour créer un nouvel Identifiant dans la base de donnée ou 64 * "OAI" pour générer un nouvel Identifiant OAI dans la base de donnée 65 */ 66 function __construct($id) 67 { 68 parent :: __construct(); 69 $this->row_identifier = null; 70 if ($id == 'NEW' || $id == 'OAI') 71 { 72 //echo "<h1>LomIdentifier(): Debug: Constructeur-création</h1>"; 73 if ($id == 'OAI') { 74 $entry = $this->mBd->EscapeString($this->GenOaiId()); 75 $catalog = 'URI'; 76 } 77 else { 78 $entry = null; 79 $catalog = null; 80 } 81 $sql = ''; 82 $sql .= "INSERT INTO lom_identifiers (lom_identifiers_id, catalog, entry) "; 83 $sql .= "VALUES (DEFAULT,'$catalog', '$entry') RETURNING *;\n"; 84 $this->mBd->ExecuterSqlResUnique($sql, $this->row_identifier, FALSE); 85 //echo print_r($row); 86 } 87 else 88 { 89 $this->mBd->ExecuterSqlResUnique("SELECT * FROM lom_identifiers WHERE lom_identifiers_id=$id", $this->row_identifier, false); 90 } 91 92 if ($this->row_identifier == null) 93 { 94 throw new Exception("L'id $id n'est pas dans la base de données", EurekaException :: EXCEPTION_CREATE_OBJECT_FAILED); 95 } 96 else 97 { 98 $this->mId = $this->row_identifier['lom_identifiers_id']; 99 $this->mEntry = $this->row_identifier['entry']; 100 $this->mCatalog = $this->row_identifier['catalog']; 101 } 102 } 103 104 /**Affiche l'interface d'administration de l'objet 105 */ 106 function displayAdminUI($reference_vocabulaire = null) 107 { 108 $application_profile = $this->mSession->getApplicationProfile(); 109 110 if(Lom::getLomByOaiId($this->getEntry())) 111 { 112 // In this is the OAI identifier of a LOM, do NOT allow the user to edit it. 113 $this->displayUserUI(); 114 } 115 else 116 { 117 /* lom_1_1_1_catalog */ 118 echo "<div class='admintitle3 no_compliance_title'>".$application_profile->getLomCaptionHelp('1_1_1',false, false,"normal")."</div>\n"; 119 echo "<div class='admin3 no_compliance_title'>\n"; 120 $vocabulaire = new Vocabulary(VOC_EUREKA_IDENTIFIERS_SOURCES); 121 $field_name = "identifier_".$this->mId."_catalog"; 122 if ($vocabulaire != null) 123 { 124 $select = $vocabulaire->GenererFormSelectOptionnel($this->getCatalog(), $field_name, 'LomIdentifier', true, $field_name); 125 echo _("Select")." : $select<br>"; 126 echo _("or other")." : "; 127 } 128 echo "<input type='text' name='$field_name' id='$field_name' size='30' value='".htmlspecialchars($this->getCatalog(), ENT_QUOTES, 'UTF-8')."'>\n"; 129 echo "</div>\n"; 130 131 /* lom_1_1_2_entry */ 132 echo "<div class='admintitle3 no_compliance_title'>".$application_profile->getLomCaptionHelp('1_1_2',false, false,"normal")."</div>\n"; 133 echo "<div class='admin3 no_compliance_title'>\n"; 134 $field_name = "identifier_".$this->mId."_entry"; 135 echo "<input type='text' name='$field_name' id='$field_name' size='50' value='".htmlspecialchars($this->getEntry(), ENT_QUOTES, 'UTF-8')."'>\n"; 136 echo "</div>\n"; 137 } 138 } 139 140 function processAdminUI() 141 { 142 $application_profile = $this->mSession->getApplicationProfile(); 143 //$generateur_form_select = new FormSelectGenerator(); 144 if(Lom::getLomByOaiId($this->getEntry())) 145 { 146 // In this is the OAI identifier of a LOM, do NOT allow the user to edit it. 147 } 148 else 149 { 150 /* lom_1_1_1_catalog */ 151 $field_name = "identifier_".$this->mId."_catalog"; 152 $catalog_sql = $this->mBd->EscapeString($_REQUEST[$field_name]); 153 if ($catalog_sql == '') 154 { 155 $catalog_sql = 'NULL'; 156 } 157 else 158 { 159 $catalog_sql = "'$catalog_sql'"; 160 } 161 162 /* lom_1_1_2_entry */ 163 $field_name = "identifier_".$this->mId."_entry"; 164 $entry_sql = $this->mBd->EscapeString($_REQUEST[$field_name]); 165 if ($entry_sql == '') 166 { 167 $entry_sql = 'NULL'; 168 } 169 else 170 { 171 $entry_sql = "'$entry_sql'"; 172 } 173 174 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET catalog = $catalog_sql, entry = $entry_sql WHERE lom_identifiers_id = $this->mId", FALSE); 175 176 $this->refresh(); 177 } 178 179 } 180 181 /**Affiche l'interface usager de l'objet 182 */ 183 function displayUserUI() 184 { 185 $application_profile = $this->mSession->getApplicationProfile(); 186 187 echo "<table>"; 188 189 if ($this->row_identifier != null) 190 { 191 /* lom_1_1_1_catalog */ 192 echo "<TR><td>".$application_profile->getLomCaptionHelp('1_1_1',false, false,"normal").": </td><TD>\n"; 193 194 echo htmlspecialchars($this->getCatalog(), ENT_QUOTES, 'UTF-8')."\n"; 195 echo "</TD></TR>\n"; 196 197 /* lom_1_1_2_entry */ 198 echo "<TR><td>".$application_profile->getLomCaptionHelp('1_1_2',false, false,"normal").": </td><TD>\n"; 199 echo htmlspecialchars($this->getEntry(), ENT_QUOTES, 'UTF-8')."\n"; 200 echo "</TD></TR>\n"; 201 } 202 echo "</table>"; 203 } 204 205 /**Exporte l'élément dans un format d'échange 206 @param $export_format format de la sortie 207 @param $document Le document auquel la sortie doit être ajouté. Le type peut varier 208 @param $parent Le parent de l'élément à ajouter. Le type peut varier 209 */ 210 function export($export_format, & $document, $parent) 211 { 212 if ($this->row_identifier != null) 213 { 214 $identifier = $document->createElementNS(LOM_EXPORT_NS,"identifier"); 215 $identifier = $parent->appendChild($identifier); 216 217 /* lom_1_1_1_catalog */ 218 $catalog = $document->createElementNS(LOM_EXPORT_NS,"catalog"); 219 $catalog = $identifier->appendChild($catalog); 220 $textnode = $document->createTextNode($this->getCatalog()); 221 $catalog->appendChild($textnode); 222 223 /* lom_1_1_2_entry */ 224 $entry = $document->createElementNS(LOM_EXPORT_NS,"entry"); 225 $entry = $identifier->appendChild($entry); 226 $textnode = $document->createTextNode($this->getEntry()); 227 $entry->appendChild($textnode); 228 } 229 } 230 231 /* Return the catalog for the LomIdentifier 232 * @return The catalog, a string 233 */ 234 function getCatalog() 235 { 236 return $this->mCatalog; 237 } 238 239 /* Enregistre une entrée Catalog pour un LomIdentifier 240 * @param $string : Entrée catalog 241 */ 242 function setCatalog($string) 243 { 244 $string = $this->mBd->EscapeString($string); 245 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET catalog = '".$string."' WHERE lom_identifiers_id = $this->mId", FALSE); 246 $this->refresh(); 247 } 248 249 /* Enregistre une entrée Entry pour un LomIdentifier 250 * @param $string : Entrée Entry 251 */ 252 function setEntry($string) 253 { 254 $string = $this->mBd->EscapeString($string); 255 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET entry = '".$string."' WHERE lom_identifiers_id = $this->mId", FALSE); 256 $this->refresh(); 257 } 258 259 /* Return the entry for the LomIdentifier 260 * @return The entry, a string 261 */ 262 function getEntry() 263 { 264 return $this->mEntry; 265 } 266 267 /* set this LOM identifier to a new OAI ID (http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm) identifier to this 268 */ 269 private function GenOaiId() 270 { 271 return uniqid('oai:'.CONF_OAI_NAMESPACE_IDENTIFIER.':', true); 272 } 273 274 /**Efface cet identifiant de la base de donnée 275 */ 276 function delete() 277 { 278 $sql = "DELETE FROM lom_identifiers WHERE lom_identifiers_id = $this->mId"; 279 $this->mBd->execSqlUpdate($sql, FALSE); 280 } 281 282 /**Met à jour les attributs de l'objet à partir de la base de donnée 283 */ 284 function refresh() 285 { 286 $this->__construct($this->mId); 287 } 288 289 /** Fonction gérant la partie LomIdentifier 290 * @param $import_format Format des données XML à être importées. 291 *@param $identifier parent du XPath 292 *@param $document DOMDocument where the node comes from 293 */ 294 function import($import_format, $identifier, $document, $is_duplicate = false) { 295 if ($import_format == FORMAT_LOM_XML) { 296 $xpath = new DOMXPath($document); 297 $xpath->registerNamespace("dns", "http://ltsc.ieee.org/xsd/LOM"); 298 299 $nodes = $xpath->query("dns:catalog", $identifier); 300 foreach ($nodes as $node) 301 $catalog = $node->nodeValue; 302 303 $nodes = $xpath->query("dns:entry", $identifier); 304 foreach ($nodes as $node) 305 $entry = $node->nodeValue; 306 307 // Make sure we're not creating a duplicate OAI ID ! 308 if($is_duplicate == true && $catalog == 'URI' && substr($entry, 0, 4) == 'oai:') 309 return false; 310 else 311 { 312 $this->setCatalog($catalog); 313 $this->setEntry($entry); 314 return true; 315 } 316 } else 317 return false; 318 } 319 320 /** 321 * Checks if the object and all children contain no data 322 * @return boolean 323 */ 324 function isEmpty() 325 { 326 $isEmpty = false; 327 328 if($this->getCatalog() == "") 329 $isEmpty += true; 330 else 331 return false; 332 333 334 if($this->getEntry() == "") 335 $isEmpty += true; 336 else 337 return false; 338 339 return $isEmpty; 340 } 341 342 /** 343 * Checks if the object complies with the specified profile settings 344 * @param obligation 345 * @return Compliance constant 346 */ 34 private $mEntry; 35 private $mCatalog; 36 static private $object_cache = array (); 37 /** Get an instance of the object 38 * @param The first argument is the object class, the rest are passed to the 39 * constructor 40 * @return the Content object, or null if there was an error (an exception is also thrown) 41 */ 42 static public function & getObject() 43 { 44 $args = func_get_args(); 45 //pretty_print_r($args); 46 $id = $args[0]; 47 if (isset (self :: $object_cache[$id])) 48 { 49 //echo "CACHE HIT!"; 50 $retval = & self :: $object_cache[$id]; 51 } 52 else 53 { 54 //echo "CACHE MISS!"; 55 $retval = new self($id); 56 self :: $object_cache[$id] = $retval; 57 } 58 return $retval; 59 } 60 61 /**Constructeur 62 * @param id Clef maîtresse de l'Identifiant ou 63 * "NEW" pour créer un nouvel Identifiant dans la base de donnée ou 64 * "OAI" pour générer un nouvel Identifiant OAI dans la base de donnée 65 */ 66 function __construct($id) 67 { 68 parent :: __construct(); 69 $this->row_identifier = null; 70 if ($id == 'NEW' || $id == 'OAI') 71 { 72 //echo "<h1>LomIdentifier(): Debug: Constructeur-création</h1>"; 73 if ($id == 'OAI') { 74 $entry = $this->mBd->EscapeString($this->GenOaiId()); 75 $catalog = 'URI'; 76 } 77 else { 78 $entry = null; 79 $catalog = null; 80 } 81 $sql = ''; 82 $sql .= "INSERT INTO lom_identifiers (lom_identifiers_id, catalog, entry) "; 83 $sql .= "VALUES (DEFAULT,'$catalog', '$entry') RETURNING *;\n"; 84 $this->mBd->ExecuterSqlResUnique($sql, $this->row_identifier, FALSE); 85 //echo print_r($row); 86 } 87 else 88 { 89 $this->mBd->ExecuterSqlResUnique("SELECT * FROM lom_identifiers WHERE lom_identifiers_id=$id", $this->row_identifier, false); 90 } 91 92 if ($this->row_identifier == null) 93 { 94 throw new Exception("L'id $id n'est pas dans la base de données", EurekaException :: EXCEPTION_CREATE_OBJECT_FAILED); 95 } 96 else 97 { 98 $this->mId = $this->row_identifier['lom_identifiers_id']; 99 $this->mEntry = $this->row_identifier['entry']; 100 $this->mCatalog = $this->row_identifier['catalog']; 101 } 102 } 103 104 /**Affiche l'interface d'administration de l'objet 105 */ 106 function displayAdminUI($reference_vocabulaire = null) 107 { 108 $application_profile = $this->mSession->getApplicationProfile(); 109 110 if(Lom::getLomByOaiId($this->getEntry())) 111 { 112 // In this is the OAI identifier of a LOM, do NOT allow the user to edit it. 113 $this->displayUserUI(); 114 } 115 else 116 { 117 /* lom_1_1_1_catalog */ 118 echo "<div class='admintitle3 no_compliance_title'>".$application_profile->getLomCaptionHelp('1_1_1',false, false,"normal")."</div>\n"; 119 echo "<div class='admin3 no_compliance_title'>\n"; 120 $vocabulaire = new Vocabulary(VOC_EUREKA_IDENTIFIERS_SOURCES); 121 $field_name = "identifier_".$this->mId."_catalog"; 122 if ($vocabulaire != null) 123 { 124 $select = $vocabulaire->GenererFormSelectOptionnel($this->getCatalog(), $field_name, 'LomIdentifier', true, $field_name); 125 echo _("Select")." : $select<br>"; 126 echo _("or other")." : "; 127 } 128 echo "<input type='text' name='$field_name' id='$field_name' size='30' value='".htmlspecialchars($this->getCatalog(), ENT_QUOTES, 'UTF-8')."'>\n"; 129 echo "</div>\n"; 130 131 /* lom_1_1_2_entry */ 132 echo "<div class='admintitle3 no_compliance_title'>".$application_profile->getLomCaptionHelp('1_1_2',false, false,"normal")."</div>\n"; 133 echo "<div class='admin3 no_compliance_title'>\n"; 134 $field_name = "identifier_".$this->mId."_entry"; 135 echo "<input type='text' name='$field_name' id='$field_name' size='50' value='".htmlspecialchars($this->getEntry(), ENT_QUOTES, 'UTF-8')."'>\n"; 136 echo "</div>\n"; 137 } 138 } 139 140 function processAdminUI() 141 { 142 $application_profile = $this->mSession->getApplicationProfile(); 143 //$generateur_form_select = new FormSelectGenerator(); 144 if(Lom::getLomByOaiId($this->getEntry())) 145 { 146 // In this is the OAI identifier of a LOM, do NOT allow the user to edit it. 147 } 148 else 149 { 150 /* lom_1_1_1_catalog */ 151 $field_name = "identifier_".$this->mId."_catalog"; 152 $catalog_sql = $this->mBd->EscapeString($_REQUEST[$field_name]); 153 if ($catalog_sql == '') 154 { 155 $catalog_sql = 'NULL'; 156 } 157 else 158 { 159 $catalog_sql = "'$catalog_sql'"; 160 } 161 162 /* lom_1_1_2_entry */ 163 $field_name = "identifier_".$this->mId."_entry"; 164 $entry_sql = $this->mBd->EscapeString($_REQUEST[$field_name]); 165 if ($entry_sql == '') 166 { 167 $entry_sql = 'NULL'; 168 } 169 else 170 { 171 $entry_sql = "'$entry_sql'"; 172 } 173 174 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET catalog = $catalog_sql, entry = $entry_sql WHERE lom_identifiers_id = $this->mId", FALSE); 175 176 $this->refresh(); 177 } 178 179 } 180 181 /**Affiche l'interface usager de l'objet 182 */ 183 function displayUserUI() 184 { 185 $application_profile = $this->mSession->getApplicationProfile(); 186 187 echo "<table>"; 188 189 if ($this->row_identifier != null) 190 { 191 /* lom_1_1_1_catalog */ 192 echo "<TR><td>".$application_profile->getLomCaptionHelp('1_1_1',false, false,"normal").": </td><TD>\n"; 193 194 echo htmlspecialchars($this->getCatalog(), ENT_QUOTES, 'UTF-8')."\n"; 195 echo "</TD></TR>\n"; 196 197 /* lom_1_1_2_entry */ 198 echo "<TR><td>".$application_profile->getLomCaptionHelp('1_1_2',false, false,"normal").": </td><TD>\n"; 199 echo htmlspecialchars($this->getEntry(), ENT_QUOTES, 'UTF-8')."\n"; 200 echo "</TD></TR>\n"; 201 } 202 echo "</table>"; 203 } 204 205 /**Exporte l'élément dans un format d'échange 206 @param $export_format format de la sortie 207 @param $document Le document auquel la sortie doit être ajouté. Le type peut varier 208 @param $parent Le parent de l'élément à ajouter. Le type peut varier 209 */ 210 function export($export_format, & $document, $parent) 211 { 212 if ($this->row_identifier != null) 213 { 214 $identifier = $document->createElementNS(LOM_EXPORT_NS,"identifier"); 215 $identifier = $parent->appendChild($identifier); 216 217 /* lom_1_1_1_catalog */ 218 $catalog = $document->createElementNS(LOM_EXPORT_NS,"catalog"); 219 $catalog = $identifier->appendChild($catalog); 220 $textnode = $document->createTextNode($this->getCatalog()); 221 $catalog->appendChild($textnode); 222 223 /* lom_1_1_2_entry */ 224 $entry = $document->createElementNS(LOM_EXPORT_NS,"entry"); 225 $entry = $identifier->appendChild($entry); 226 $textnode = $document->createTextNode($this->getEntry()); 227 $entry->appendChild($textnode); 228 } 229 } 230 231 /* Return the catalog for the LomIdentifier 232 * @return The catalog, a string 233 */ 234 function getCatalog() 235 { 236 return $this->mCatalog; 237 } 238 239 /* Enregistre une entrée Catalog pour un LomIdentifier 240 * @param $string : Entrée catalog 241 */ 242 function setCatalog($string) 243 { 244 $string = $this->mBd->EscapeString($string); 245 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET catalog = '".$string."' WHERE lom_identifiers_id = $this->mId", FALSE); 246 $this->refresh(); 247 } 248 249 /* Enregistre une entrée Entry pour un LomIdentifier 250 * @param $string : Entrée Entry 251 */ 252 function setEntry($string) 253 { 254 if($string!=$this->getEntry()) { 255 $string = $this->mBd->EscapeString($string); 256 $this->mBd->execSqlUpdate("UPDATE lom_identifiers SET entry = '".$string."' WHERE lom_identifiers_id = $this->mId", FALSE); 257 $this->refresh(); 258 } 259 } 260 261 /* Return the entry for the LomIdentifier 262 * @return The entry, a string 263 */ 264 function getEntry() 265 { 266 return $this->mEntry; 267 } 268 269 /* set this LOM identifier to a new OAI ID (http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm) identifier to this 270 */ 271 private function GenOaiId() 272 { 273 return uniqid('oai:'.CONF_OAI_NAMESPACE_IDENTIFIER.':', true); 274 } 275 276 /**Efface cet identifiant de la base de donnée 277 */ 278 function delete() 279 { 280 $sql = "DELETE FROM lom_identifiers WHERE lom_identifiers_id = $this->mId"; 281 $this->mBd->execSqlUpdate($sql, FALSE); 282 } 283 284 /**Met à jour les attributs de l'objet à partir de la base de donnée 285 */ 286 function refresh() 287 { 288 $this->__construct($this->mId); 289 } 290 291 /** Fonction gérant la partie LomIdentifier 292 * @param $import_format Format des données XML à être importées. 293 *@param $identifier parent du XPath 294 *@param $document DOMDocument where the node comes from 295 */ 296 function import($import_format, $identifier, $document, $is_duplicate = false) { 297 if ($import_format == FORMAT_LOM_XML) { 298 $xpath = new DOMXPath($document); 299 $xpath->registerNamespace("dns", "http://ltsc.ieee.org/xsd/LOM"); 300 301 $nodes = $xpath->query("dns:catalog", $identifier); 302 foreach ($nodes as $node) 303 $catalog = $node->nodeValue; 304 305 $nodes = $xpath->query("dns:entry", $identifier); 306 foreach ($nodes as $node) 307 $entry = $node->nodeValue; 308 309 // Make sure we're not creating a duplicate OAI ID ! 310 if($is_duplicate == true && $catalog == 'URI' && substr($entry, 0, 4) == 'oai:') 311 return false; 312 else 313 { 314 $this->setCatalog($catalog); 315 $this->setEntry($entry); 316 return true; 317 } 318 } else 319 return false; 320 } 321 322 /** 323 * Checks if the object and all children contain no data 324 * @return boolean 325 */ 326 function isEmpty() 327 { 328 $isEmpty = false; 329 330 if($this->getCatalog() == "") 331 $isEmpty += true; 332 else 333 return false; 334 335 336 if($this->getEntry() == "") 337 $isEmpty += true; 338 else 339 return false; 340 341 return $isEmpty; 342 } 343 344 /** 345 * Checks if the object complies with the specified profile settings 346 * @param obligation 347 * @return Compliance constant 348 */ 347 349 function IsCompliant($profile, $lom_element) 348 350 { 349 351 $obligation = $profile->getObligation($lom_element); 350 switch($obligation)351 {352 case 'MANDATORY':353 if($this->isEmpty())354 return NOT_COMPLIANT_MASK;355 break;356 case 'RECOMMENDED':357 if($this->isEmpty())358 return NOT_ALL_RECOMMENDED_MASK;359 break;360 }361 return COMPLIANT_MASK;362 }352 switch($obligation) 353 { 354 case 'MANDATORY': 355 if($this->isEmpty()) 356 return NOT_COMPLIANT_MASK; 357 break; 358 case 'RECOMMENDED': 359 if($this->isEmpty()) 360 return NOT_ALL_RECOMMENDED_MASK; 361 break; 362 } 363 return COMPLIANT_MASK; 364 } 363 365 364 366 } /* end class LomIdentifier */ -
html/classes/SearchEngine.php
rdd37b7c rce9b376 607 607 return $sql_candidates_join_sql; 608 608 } 609 610 /** 611 * 612 * Enter description here ... 613 * @param integer $navLevel 614 * @return true 615 */ 616 static private function getSqlLomThemeJoinHelper($navLevel, &$sql, Array &$selectListArray) { 617 if($navLevel==1) { 618 $leftTable='vocabulary_terms'; 619 } 620 else { 621 $leftTable='navigated_terms_level_'.(string)($navLevel-1); 622 } 623 624 $navigableRelationships = configGetNavigableRelationshipsIdArray(); 625 626 //navigableSourceToDest 627 if(count($navigableRelationships['navigableSourceToDest']>0)){ 628 $tmpSql = null; 629 $tmpSql .= " LEFT JOIN vocabulary_relationships AS navigated_relationship_level_{$navLevel}_sourceToDest ON ( \n"; 630 $tmpSql .= " navigated_relationship_level_{$navLevel}_sourceToDest.source_term_vocabulary_identifier=$leftTable.vdex_4_vocabulary_identifier \n"; 631 $tmpSql .= " AND navigated_relationship_level_{$navLevel}_sourceToDest.source_term_identifier=$leftTable.vdex_6_1_identifier \n"; 632 $tmpSql .= " AND navigated_relationship_level_{$navLevel}_sourceToDest.target_term_vocabulary_identifier!=$leftTable.vdex_4_vocabulary_identifier \n"; 633 $tmpSql .= " AND navigated_relationship_level_{$navLevel}_sourceToDest.target_term_identifier!=$leftTable.vdex_6_1_identifier \n"; 634 $internaljoinCondArray = array(); 635 foreach($navigableRelationships['navigableSourceToDest'] as $relationshipType) { 636 $internaljoinCondArray[] = "(navigated_relationship_level_{$navLevel}_sourceToDest.vdex_7_4_1_relationship_type_source='$relationshipType[1]' AND navigated_relationship_level_{$navLevel}_sourceToDest.vdex_7_4_2_relationship_type_value='$relationshipType[0]') \n"; 637 } 638 $internalJoinCond=implode(" OR \n", $internaljoinCondArray); 639 $tmpSql .= " AND (\n$internalJoinCond) \n"; 640 $tmpSql .=")\n"; 641 $sql.=$tmpSql; 642 } 643 //navigableDestToSource 644 if(count($navigableRelationships['navigableDestToSource']>0)){ 645 $tmpSql = null; 646 $tmpSql .= " LEFT JOIN vocabulary_relationships AS navigated_relationship_level_{$navLevel}_destToSource ON ( \n"; 647 $tmpSql .= " navigated_relationship_level_{$navLevel}_destToSource.target_term_vocabulary_identifier=$leftTable.vdex_4_vocabulary_identifier \n"; 648 $tmpSql .= " AND navigated_relationship_level_{$navLevel}_sourceToDest.source_term_identifier IS NULL \n"; 649 $internaljoinCondArray = array(); 650 foreach($navigableRelationships['navigableDestToSource'] as $relationshipType) { 651 $internaljoinCondArray[] = "(navigated_relationship_level_{$navLevel}_destToSource.vdex_7_4_1_relationship_type_source='$relationshipType[1]' AND navigated_relationship_level_{$navLevel}_destToSource.vdex_7_4_2_relationship_type_value='$relationshipType[0]') \n"; 652 } 653 $internalJoinCond=implode(" OR \n", $internaljoinCondArray); 654 $tmpSql .= " AND (\n$internalJoinCond) \n"; 655 $tmpSql .=")\n"; 656 $sql.=$tmpSql; 657 } 658 659 $joinCondArray = array(); 660 $selectListArray[] = "navigated_relationship_level_{$navLevel}_destToSource.vdex_7_4_2_relationship_type_value as destToSourceRT"; 661 $selectListArray[] = "navigated_relationship_level_{$navLevel}_sourceToDest.vdex_7_4_2_relationship_type_value as sourceToDestRT"; 662 $selectListArray[] = "navigated_relationship_level_{$navLevel}_destToSource.source_term_identifier as l{$navLevel}_destToSourceSTid, navigated_relationship_level_{$navLevel}_sourceToDest.target_term_identifier as l{$navLevel}_sourceToDestDTid"; 663 /* 664 $selectListArray[] = "navigated_terms_level_{$navLevel}.vdex_4_vocabulary_identifier as l{$navLevel}_voc, navigated_terms_level_{$navLevel}.vdex_6_1_identifier as l{$navLevel}_term"; 665 666 $sql .= " LEFT JOIN vocabulary_terms AS navigated_terms_level_$navLevel ON ( \n"; 667 $tmpSql = " (navigated_terms_level_$navLevel.vdex_4_vocabulary_identifier=COALESCE(navigated_relationship_level_{$navLevel}_destToSource.source_term_vocabulary_identifier, navigated_relationship_level_{$navLevel}_sourceToDest.target_term_vocabulary_identifier) \n"; 668 $tmpSql .= " AND navigated_terms_level_$navLevel.vdex_6_1_identifier=COALESCE(navigated_relationship_level_{$navLevel}_destToSource.source_term_identifier, navigated_relationship_level_{$navLevel}_sourceToDest.target_term_identifier)) \n"; 669 $joinCondArray[]=$tmpSql; 670 $sql .= implode(" OR \n", $joinCondArray); 671 $sql .= " ) \n";*/ 672 673 return true; 674 } 675 609 676 /** SQL fragment to join LO with themes */ 610 677 static private function getSqlLomThemeJoin() { 611 return " NATURAL JOIN lom_has_lom_9_classification NATURAL JOIN lom_9_classification NATURAL JOIN lom_9_classification_has_lom_9_2_taxon_path NATURAL JOIN lom_9_2_taxon_path JOIN vocabulary_terms AS theme_limit_terms ON (path_identifier=theme_limit_terms.vdex_6_1_identifier AND path_vdex_4_vocabulary_identifier=theme_limit_terms.vdex_4_vocabulary_identifier) \n"; 612 } 613 614 /** SQL fragment to join themes with LO */ 615 static private function getSqlThemeLomJoin() { 616 return " JOIN lom_9_2_taxon_path ON (path_identifier=vdex_6_1_identifier AND path_vdex_4_vocabulary_identifier=vdex_4_vocabulary_identifier) NATURAL JOIN lom_9_classification_has_lom_9_2_taxon_path NATURAL JOIN lom_9_classification NATURAL JOIN lom_has_lom_9_classification NATURAL JOIN lom \n"; 678 global $NAVIGATE_VOC_RELATIONS_ENABLED; 679 if($NAVIGATE_VOC_RELATIONS_ENABLED) { 680 $db = AbstractDb::getObject(); 681 682 $selectListArray=array(); 683 $selectListArray[]='vocabulary_terms.vdex_4_vocabulary_identifier, vocabulary_terms.vdex_6_1_identifier'; 684 $sqlJoin = null; 685 self::getSqlLomThemeJoinHelper(1, $sqlJoin, $selectListArray); 686 //self::getSqlLomThemeJoinHelper(2, $sqlJoin, $selectListArray); 687 $selectList = implode(", \n ", $selectListArray); 688 $sql = "SELECT $selectList \n"; 689 $sql .= " FROM vocabulary_terms \n"; 690 $sql .= $sqlJoin; 691 //$sql .= " WHERE vocabulary_terms.vdex_4_vocabulary_identifier='rVoc1' AND vocabulary_terms.vdex_6_1_identifier='rVoc1T2'\n"; 692 $sql .= " WHERE vocabulary_terms.vdex_4_vocabulary_identifier='pivotVoc' AND vocabulary_terms.vdex_6_1_identifier='pivotVocT3'\n"; 693 pretty_print_r($sql); 694 ob_flush();flush(); 695 $db->ExecuterSql($sql, $rows, true); 696 //pretty_print_r($navigableRelationships); 697 $retval = " NATURAL JOIN lom_has_lom_9_classification NATURAL JOIN lom_9_classification NATURAL JOIN lom_9_classification_has_lom_9_2_taxon_path NATURAL JOIN lom_9_2_taxon_path JOIN vocabulary_terms AS theme_limit_terms ON (path_identifier=theme_limit_terms.vdex_6_1_identifier AND path_vdex_4_vocabulary_identifier=theme_limit_terms.vdex_4_vocabulary_identifier) \n"; 698 699 } 700 else { 701 $retval = " NATURAL JOIN lom_has_lom_9_classification NATURAL JOIN lom_9_classification NATURAL JOIN lom_9_classification_has_lom_9_2_taxon_path NATURAL JOIN lom_9_2_taxon_path JOIN vocabulary_terms AS theme_limit_terms ON (path_identifier=theme_limit_terms.vdex_6_1_identifier AND path_vdex_4_vocabulary_identifier=theme_limit_terms.vdex_4_vocabulary_identifier) \n"; 702 } 703 return $retval; 617 704 } 618 705 … … 703 790 704 791 /* Find themes matching keywords */ 705 $sql_has_lom_join = self::getSqlThemeLomJoin();//The purpose of this is to only list themes that actually have LOs 706 $sql = "SELECT DISTINCT ON (vdex_6_1_identifier, vdex_4_vocabulary_identifier) vdex_6_1_identifier, vdex_4_vocabulary_identifier, value FROM vocabulary_terms JOIN {$this->value_match_table} ON (vdex_6_3_caption={$this->value_match_table}.langstrings_id OR vdex_6_4_description={$this->value_match_table}.langstrings_id) $sql_has_lom_join WHERE 1=1 $sql_theme_limit_where ORDER BY vdex_6_1_identifier, vdex_4_vocabulary_identifier"; 792 $sql = "SELECT DISTINCT ON (vdex_6_1_identifier, vdex_4_vocabulary_identifier) vdex_6_1_identifier, vdex_4_vocabulary_identifier, value FROM vocabulary_terms JOIN {$this->value_match_table} ON (vdex_6_3_caption={$this->value_match_table}.langstrings_id OR vdex_6_4_description={$this->value_match_table}.langstrings_id) WHERE 1=1 $sql_theme_limit_where ORDER BY vdex_6_1_identifier, vdex_4_vocabulary_identifier"; 707 793 $themes_results = null; 708 794 $db->ExecuterSql($sql, $themes_results, false); … … 831 917 832 918 /** Count all Learning Objects associated with this theme 833 * @param $recursive If set to true, will also find all LOs associated with919 * @param $recursive boolean If set to true, will also find all LOs associated with 834 920 * childrens of the theme. 835 921 * @param $only_valid … … 1573 1659 if ($this->themes_results != null) { 1574 1660 $themes_html_header = ""; 1575 $numThemes = count($this->themes_results); 1576 $themes_html_header .= "<div class='theme_search_results'>\n"; 1577 $themes_html_header .= "<h2>" . sprintf(ngettext("Found %d theme with your keywords in it's name or description", "Found %d themes with your keywords in their name or description", $numThemes), $numThemes) . "</h2>"; 1578 $themes_html_header .= "<ul>\n"; 1661 1662 $numThemes = 0; 1579 1663 $themelist_html = ""; 1580 1664 foreach ($this->themes_results as $value) { … … 1583 1667 $value['vdex_4_vocabulary_identifier'] 1584 1668 )); // Show only 1585 if (true) {//No longuer needed (first is no longuer desirable, second is already filtered out in the original query):$theme->IsRealTheme() && $theme->getNumLearningObjects(true, true) > 0 1669 if ($theme->getNumLearningObjects(true, true) > 0) { 1670 $numThemes++; 1586 1671 $parents = $theme->getParents(true); 1587 1672 $num_child_ressources = $this->getThemeNumLearningObjects($theme, true, true); … … 1594 1679 } 1595 1680 } 1681 $themes_html_header .= "<div class='theme_search_results'>\n"; 1682 $themes_html_header .= "<h2>" . sprintf(ngettext("Found %d theme with your keywords in it's name or description", "Found %d themes with your keywords in their name or description", $numThemes), $numThemes) . "</h2>"; 1683 $themes_html_header .= "<ul>\n"; 1684 1596 1685 $themes_html_footer = ""; 1597 1686 $themes_html_footer .= "</ul>\n"; … … 1604 1693 $tsHeadlineOptions = 'StartSel="<span class=\'\'search_matching_text\'\'>", StopSel="</span>", MaxWords=35, MinWords=15, ShortWord=3, HighlightAll=FALSE'; 1605 1694 $summaryTsHeadlineOptions = 'StartSel="<span class=\'\'search_matching_text\'\'>", StopSel="</span>", MaxWords=35, MinWords=34, ShortWord=3, HighlightAll=FALSE'; 1606 1695 1607 1696 1608 1697 $summaryRegconfig = self::localeToPostgresqlIndexingLanguage(Session::getObject()->getPrefLocale()); … … 1655 1744 $ret_html .= "<div class='found_resource'>\n"; 1656 1745 if (!empty ($this->valid_search_terms)) { 1657 $rank = (int)(100*($this->learning_objects_results[$i]['total_rank'])/$rank_denominator);1658 1659 $ret_html .= "<div class='rank' style='width: {$rank}%;'></div>\n";1746 $rank = (int)(100*($this->learning_objects_results[$i]['total_rank'])/$rank_denominator); 1747 1748 $ret_html .= "<div class='rank' style='width: {$rank}%;'></div>\n"; 1660 1749 } 1661 1750 /* Result title and summary */ … … 1696 1785 $sql = "SELECT ts_headline('$summaryRegconfig', '".$db->escapeString($lo->getSummary(240))."', $tsQuery, E'$summaryTsHeadlineOptions')"; 1697 1786 $db->ExecuterSql($sql, $summary_results, false); 1698 1787 1699 1788 $match_str = $summary_results[0]['ts_headline']; 1700 1789 } -
html/classes/Vocabulary.php
rf4e524f rce9b376 462 462 var termsArray = new Array($termsCount+1); 463 463 termsArray[0]='---'; 464 $jsTerms464 $jsTerms 465 465 //alert("New length: " + termsArray.length) 466 466 </script> 467 467 EOT; 468 echo $script;469 470 foreach ($vocabulary_terms_result as $vocabulary_terms_row)471 {472 $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId));473 $term->displayAdminUI();474 }468 echo $script; 469 470 foreach ($vocabulary_terms_result as $vocabulary_terms_row) 471 { 472 $term = VocabularyTerm::getObject(array ($vocabulary_terms_row['vdex_6_1_identifier'], $this->mId)); 473 $term->displayAdminUI(); 474 } 475 475 } 476 476 … … 1170 1170 foreach ($vocabulary_relations_result as $relations_row) 1171 1171 { 1172 $relation = new VocabularyRelation( array ($relations_row['vdex_7_1_identifier'], $relations_row['vdex_4_vocabulary_identifier']));1172 $relation = new VocabularyRelation($relations_row); 1173 1173 $relation->export($export_format, $document, $vdex); 1174 1174 } … … 1226 1226 $sql = "DELETE FROM vocabularies WHERE vdex_4_vocabulary_identifier = '$this->mId'"; 1227 1227 $this->mBd->execSqlUpdate($sql, FALSE); 1228 apc_delete(APP_NAME.__CLASS__.$this->mId); 1228 1229 } 1229 1230 -
html/classes/VocabularyRelation.php
rf4e524f rce9b376 30 30 require_once 'Vocabulary.php'; 31 31 require_once 'exceptions/ImportException.php'; 32 require_once 'exceptions/ObjectInstanciationException.php'; 32 33 33 34 error_reporting(E_ALL); … … 63 64 { 64 65 parent :: __construct(); 66 if(empty($row['id'])) { 67 throw new ObjectInstanciationException("id isn't present, this isn't a valid vocabulary_relationships row"); 68 } 65 69 $this->mRow = $row; 66 70 //var_dump($this->mRow); 67 71 $this->mId = $this->mRow['id']; 72 68 73 } 69 74 /** Get relation from the eureka internal id -
html/classes/VocabularyTerm.php
rf4e524f rce9b376 1369 1369 { 1370 1370 $this->DeleteTree(); 1371 apc_delete(APP_NAME.__CLASS__.$this->mId[0].'_'.$this->mId[1]); 1371 1372 } 1372 1373 /**Met à jour les attributs de l'objet à partir de la base de donnée -
html/classes/exceptions/ObjectInstanciationException.php
r3550449 rce9b376 33 33 public function __toString() 34 34 { 35 return "<h1>"._("Could not instantiate the object : ").$this->message."</h1> \n";35 return sprintf(_("Could not instantiate the object: %s. Thrown in: <pre>%s</pre>"),$this->message,$this->getTraceAsString()); 36 36 } 37 37 } -
html/config/config.php
r8b111ad rce9b376 212 212 define('VOC_LOM_YES_NO', 'http://eureka.ntic.org/vdex/LOMv1.0_common_yes_no_voc.xml'); 213 213 214 /* Vocabulary relationships */ 215 global $NAVIGATE_VOC_RELATIONS_ENABLED; 216 $NAVIGATE_VOC_RELATIONS_ENABLED = TRUE; 217 218 function configGetNavigableRelationshipsIdArray() { 219 $retval = array( 220 "navigableSourceToDest" => array( 221 array('RT','http://www.imsglobal.org/vocabularies/iso2788_relations.xml'), 222 array('NT','http://www.imsglobal.org/vocabularies/iso2788_relations.xml') 223 ), 224 "navigableDestToSource" => array( 225 array('RT','http://www.imsglobal.org/vocabularies/iso2788_relations.xml'), 226 array('BT','http://www.imsglobal.org/vocabularies/iso2788_relations.xml') 227 ) 228 ); 229 return $retval; 230 } 231 232 214 233 /* 215 234 * Application profile compliance flags -
html/include/schema_validate.php
r9f704d6 rce9b376 484 484 $sql .= "CREATE UNIQUE INDEX real_primary_key_index ON vocabulary_relationships (vdex_4_vocabulary_identifier, vdex_7_1_identifier, source_term_vocabulary_identifier, source_term_identifier, target_term_vocabulary_identifier, target_term_identifier, vdex_7_4_1_relationship_type_source, vdex_7_4_2_relationship_type_value);\n"; 485 485 } 486 $new_schema_version = 25; 487 if ($current_schema_version < $new_schema_version && $new_schema_version <= REQUIRED_SCHEMA_VERSION) 488 { 489 echo "<h2>"._("Preparing SQL statements to update schema to version:")." $new_schema_version</h2>"; 490 491 $sql .= "UPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 492 $sql .= "CREATE INDEX sessions_username_index ON sessions (username);\n"; 493 $sql .= "\n"; 494 $sql .= "\n"; 495 $sql .= "\n"; 496 } 497 486 498 $db->execSqlUpdate("BEGIN;\n$sql\nCOMMIT;\n", true); 487 499 $db->execSqlUpdate("VACUUM ANALYSE;\n", true); -
html/tests/VocabRelationshipNavigationTest.php
rc644bf6 rce9b376 6 6 require_once 'classes/Lom.php'; 7 7 require_once 'classes/SearchEngine.php'; 8 8 9 class VocabRelationshipImportTest extends PHPUnit_Framework_TestCase 9 10 { 10 private $fixTurePersistent = false; 11 private $fixTurePersistent = true; 12 13 private $pivotVocIdStr='pivotVoc'; 14 private $rVoc1IdStr='rVoc1'; 15 private $rVoc2IdStr='rVoc2'; 16 11 17 protected function setUp() 12 18 { 13 $this->pivotVocIdStr='pivotVoc';14 $this->rVoc1IdStr='rVoc1';15 $this->rVoc2IdStr='rVoc2';16 19 try { 17 20 $voc = Vocabulary::getObject($this->pivotVocIdStr); … … 22 25 if($this->fixTurePersistent==false||$voc==null) { 23 26 /* Otherwise everytime the test crashes the teardown won't be done properly */ 24 try { 25 $voc = new Vocabulary('pivotVoc'); 26 $voc->delete(); 27 } 28 catch (Exception $e) { 29 } 30 try { 31 $voc = new Vocabulary('rVoc1'); 32 $voc->delete(); 33 } 34 catch (Exception $e) { 35 } 36 try { 37 $voc = new Vocabulary('rVoc2'); 38 $voc->delete(); 39 } 40 catch (Exception $e) { 41 } 27 $this->deleteEverything(); 42 28 43 29 $this->pivotVoc = new Vocabulary('NEW'); … … 45 31 $this->pivotVoc->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 46 32 47 48 33 $this->rVoc1 = new Vocabulary('NEW'); 49 34 $vocXml = file_get_contents(dirname(__FILE__) . '/testVocs/rVoc1.xml'); 50 35 $this->rVoc1->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 51 52 36 53 37 $this->rVoc2 = new Vocabulary('NEW'); … … 55 39 $this->rVoc2->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 56 40 /* Link Learning objects to the vocabulary terms */ 57 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r1', array('rVoc1T1', 'rVoc1')); 58 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r2', array('rVoc1T2', 'rVoc1')); 59 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r3', array('pivotVocT1', 'pivotVoc')); 60 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r4', array('pivotVocT2', 'pivotVoc')); 61 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r5', array('pivotVocT3', 'pivotVoc')); 62 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r6', array('rVoc2T1', 'rVoc2')); 63 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r7', array('rVoc2T2', 'rVoc2')); 64 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r8', array('rVoc2T3', 'rVoc2')); 65 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r9', array('rVoc2T4', 'rVoc2')); 66 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r10', array('rVoc2T5', 'rVoc2')); 67 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r11', array('rVoc2T6', 'rVoc2')); 68 $this->los[] = $this->addLo('oai:eureka.coeus.ca:r12', array('rVoc2T7', 'rVoc2')); 41 $this->los=$this->addAllLos(true); 69 42 } 70 43 else { … … 72 45 $this->rVoc1 = Vocabulary::getObject($this->rVoc1IdStr); 73 46 $this->rVoc2 = Vocabulary::getObject($this->rVoc2IdStr); 74 75 47 } 76 48 } 49 50 private function addAllLos($create=true) { 51 $los = array(); 52 /* Link Learning objects to the vocabulary terms */ 53 $this->addLo('oai:eureka.coeus.ca:r1', array('rVoc1T1', 'rVoc1'), $los, $create); 54 $this->addLo('oai:eureka.coeus.ca:r2', array('rVoc1T2', 'rVoc1'), $los, $create); 55 $this->addLo('oai:eureka.coeus.ca:r3', array('pivotVocT1', 'pivotVoc'), $los, $create); 56 $this->addLo('oai:eureka.coeus.ca:r4', array('pivotVocT2', 'pivotVoc'), $los, $create); 57 $this->addLo('oai:eureka.coeus.ca:r5', array('pivotVocT3', 'pivotVoc'), $los, $create); 58 $this->addLo('oai:eureka.coeus.ca:r6', array('rVoc2T1', 'rVoc2'), $los, $create); 59 $this->addLo('oai:eureka.coeus.ca:r7', array('rVoc2T2', 'rVoc2'), $los, $create); 60 $this->addLo('oai:eureka.coeus.ca:r8', array('rVoc2T3', 'rVoc2'), $los, $create); 61 $this->addLo('oai:eureka.coeus.ca:r9', array('rVoc2T4', 'rVoc2'), $los, $create); 62 $this->addLo('oai:eureka.coeus.ca:r10', array('rVoc2T5', 'rVoc2'), $los, $create); 63 $this->addLo('oai:eureka.coeus.ca:r11', array('rVoc2T6', 'rVoc2'), $los, $create); 64 $this->addLo('oai:eureka.coeus.ca:r12', array('rVoc2T7', 'rVoc2'), $los, $create); 65 return $los; 66 } 67 77 68 /** 78 69 * @param $oaiId string example: 'oai:eureka.coeus.ca:r1' 79 70 * @param $termId array example array('rVoc1T1', 'rVoc1') 71 * @param $loArray array to store objects 72 * @param $create boolean Create the object if not present 80 73 */ 81 private function addLo($oaiId, $termId) { 82 if($lo=Lom::getLomByOaiId($oaiId)==null) { 74 private function addLo($oaiId, $termId, &$loArray, $create) { 75 $lo=Lom::getLomByOaiId($oaiId); 76 if($lo==null && $create==true) { 83 77 $db = AbstractDb::getObject(); 84 78 global $bypassAccessControl; … … 92 86 $sql = "INSERT INTO lom_has_lom_9_classification (lom_id, lom_9_classification_id) VALUES (".$lo->getId()."," . $theme_classification->getId() . "); \n"; 93 87 $db->execSqlUpdate($sql, false); 88 } 89 if($lo) { 90 $loArray[]=$lo; 94 91 } 95 92 return $lo; … … 110 107 return $retval; 111 108 } 109 110 private function deleteEverything() 111 { 112 $los=$this->addAllLos(false); 113 foreach($los as $lo) { 114 $lo->delete(); 115 } 116 try { 117 $voc = Vocabulary::getObject($this->pivotVocIdStr); 118 $voc->delete(); 119 } 120 catch (Exception $e) { 121 } 122 try { 123 $voc = Vocabulary::getObject($this->rVoc1IdStr); 124 $voc->delete(); 125 } 126 catch (Exception $e) { 127 } 128 try { 129 $voc = Vocabulary::getObject($this->rVoc2IdStr); 130 $voc->delete(); 131 } 132 catch (Exception $e) { 133 } 134 } 135 112 136 protected function tearDown() 113 137 { 114 138 if($this->fixTurePersistent==false) { 115 foreach($this->los as $lo) { 116 $lo->delete(); 117 } 118 $this->rVoc2->delete(); 119 $this->rVoc1->delete(); 120 $this->pivotVoc->delete(); 139 $this->deleteEverything(); 121 140 } 122 141 } 142 123 143 /** Normally i'd do more than one test, but the fixtures are unbearably slow */ 124 144 public function testNoRegressionWhenVocabularyNavigationIsTurnedOff() 125 145 { 126 /* Check that the test vocabularies have been imported successfully */127 146 $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 128 147 $this->assertEquals($this->rVoc1IdStr, $this->rVoc1->getId()); … … 130 149 131 150 /* Check that the resources have been put in the right vocabularies, and that there are no regressing if navigation is disabled */ 151 global $NAVIGATE_VOC_RELATIONS_ENABLED; 152 $NAVIGATE_VOC_RELATIONS_ENABLED = false; 132 153 $this->assertEquals(array('oai:eureka.coeus.ca:r1'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 133 154 $this->assertEquals(array('oai:eureka.coeus.ca:r2'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')))); … … 143 164 $this->assertEquals(array('oai:eureka.coeus.ca:r12'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T7', 'rVoc2')))); 144 165 } 166 167 public function testVocabularyNavigationWorks() 168 { 169 global $NAVIGATE_VOC_RELATIONS_ENABLED; 170 $NAVIGATE_VOC_RELATIONS_ENABLED = false; 171 $expected = array('oai:eureka.coeus.ca:r1'); 172 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 173 174 $expected = array('oai:eureka.coeus.ca:r2', 175 'oai:eureka.coeus.ca:r4', 176 'oai:eureka.coeus.ca:r5', 177 'oai:eureka.coeus.ca:r7', 178 'oai:eureka.coeus.ca:r8', 179 'oai:eureka.coeus.ca:r9', 180 'oai:eureka.coeus.ca:r12' 181 ); 182 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')))); 183 184 $expected = array('oai:eureka.coeus.ca:r3'); 185 $this->assertEquals($expected, $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc'))), "Backward relationships must not be followed!"); 186 } 145 187 } -
html/tests/testVocs/rVoc2.xml
rdf1a05b rce9b376 1 1 <?xml version="1.0"?> 2 <vdex xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0" orderSignificant="false" profileType=" lax" language="en-US">2 <vdex xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0" orderSignificant="false" profileType="hierarchicalTokenTerms" language="en-US"> 3 3 <vocabName> 4 4 <langstring language="en">related vocabulary 2 to test relationship navigations</langstring>
Note: See TracChangeset
for help on using the changeset viewer.
