Changeset ce9b376


Ignore:
Timestamp:
08/26/10 15:04:15 (21 months ago)
Author:
Benoit Grégoire <benoitg@…>
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
Message:

Snapshot

Location:
html
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • html/classes/Lom.php

    r8b111ad rce9b376  
    28702870 
    28712871    /** 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 one 
     2872     * @param $oai_id string The new OAI-id, call will fail if there is one 
    28732873     * already */ 
    28742874    function setOaiId($oai_id) { 
  • html/classes/LomIdentifier.php

    r132d4f5 rce9b376  
    1919 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   * 
    2020 *                                                                  * 
    21 \********************************************************************/ 
     21 \********************************************************************/ 
    2222/**@file LomIdentifier.php 
    2323 * @author Copyright (C) 2004 Benoit Grégoire, Technologies Coeus inc. 
    24 */ 
     24 */ 
    2525 
    2626require_once 'GenericDataObject.php'; 
     
    2828error_reporting(E_ALL); 
    2929 
    30 /** Représente un identifiant LOM (Élément 1.1).  
     30/** Représente un identifiant LOM (Élément 1.1). 
    3131 */ 
    3232class LomIdentifier extends GenericDataObject 
    3333{ 
    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     */ 
    347349    function IsCompliant($profile, $lom_element) 
    348350    { 
    349351        $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    } 
    363365 
    364366} /* end class LomIdentifier */ 
  • html/classes/SearchEngine.php

    rdd37b7c rce9b376  
    607607        return $sql_candidates_join_sql; 
    608608    } 
     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 
    609676    /** SQL fragment to join LO with themes */ 
    610677    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; 
    617704    } 
    618705 
     
    703790 
    704791            /* 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"; 
    707793            $themes_results = null; 
    708794            $db->ExecuterSql($sql, $themes_results, false); 
     
    831917 
    832918    /** Count all Learning Objects associated with this theme 
    833      * @param $recursive If set to true, will also find all LOs associated with 
     919     * @param $recursive boolean If set to true, will also find all LOs associated with 
    834920     * childrens of the theme. 
    835921     * @param $only_valid 
     
    15731659        if ($this->themes_results != null) { 
    15741660            $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; 
    15791663            $themelist_html = ""; 
    15801664            foreach ($this->themes_results as $value) { 
     
    15831667                $value['vdex_4_vocabulary_identifier'] 
    15841668                )); // 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++; 
    15861671                    $parents = $theme->getParents(true); 
    15871672                    $num_child_ressources = $this->getThemeNumLearningObjects($theme, true, true); 
     
    15941679                } 
    15951680            } 
     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 
    15961685            $themes_html_footer = ""; 
    15971686            $themes_html_footer .= "</ul>\n"; 
     
    16041693        $tsHeadlineOptions = 'StartSel="<span class=\'\'search_matching_text\'\'>", StopSel="</span>", MaxWords=35, MinWords=15, ShortWord=3,  HighlightAll=FALSE'; 
    16051694        $summaryTsHeadlineOptions = 'StartSel="<span class=\'\'search_matching_text\'\'>", StopSel="</span>", MaxWords=35, MinWords=34, ShortWord=3,  HighlightAll=FALSE'; 
    1606          
     1695 
    16071696 
    16081697        $summaryRegconfig = self::localeToPostgresqlIndexingLanguage(Session::getObject()->getPrefLocale()); 
     
    16551744                $ret_html .= "<div class='found_resource'>\n"; 
    16561745                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"; 
    16601749                } 
    16611750                /* Result title and summary */ 
     
    16961785                    $sql = "SELECT ts_headline('$summaryRegconfig', '".$db->escapeString($lo->getSummary(240))."', $tsQuery, E'$summaryTsHeadlineOptions')"; 
    16971786                    $db->ExecuterSql($sql, $summary_results, false); 
    1698                      
     1787 
    16991788                    $match_str = $summary_results[0]['ts_headline']; 
    17001789                } 
  • html/classes/Vocabulary.php

    rf4e524f rce9b376  
    462462var termsArray = new Array($termsCount+1); 
    463463termsArray[0]='---'; 
    464                 $jsTerms 
     464$jsTerms 
    465465                                //alert("New length: " + termsArray.length) 
    466466</script> 
    467467EOT; 
    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                 } 
     468echo $script; 
     469 
     470foreach ($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} 
    475475            } 
    476476 
     
    11701170                        foreach ($vocabulary_relations_result as $relations_row) 
    11711171                        { 
    1172                             $relation = new VocabularyRelation(array ($relations_row['vdex_7_1_identifier'], $relations_row['vdex_4_vocabulary_identifier'])); 
     1172                            $relation = new VocabularyRelation($relations_row); 
    11731173                            $relation->export($export_format, $document, $vdex); 
    11741174                        } 
     
    12261226        $sql = "DELETE FROM vocabularies WHERE vdex_4_vocabulary_identifier = '$this->mId'"; 
    12271227        $this->mBd->execSqlUpdate($sql, FALSE); 
     1228        apc_delete(APP_NAME.__CLASS__.$this->mId); 
    12281229    } 
    12291230 
  • html/classes/VocabularyRelation.php

    rf4e524f rce9b376  
    3030require_once 'Vocabulary.php'; 
    3131require_once 'exceptions/ImportException.php'; 
     32require_once 'exceptions/ObjectInstanciationException.php'; 
    3233 
    3334error_reporting(E_ALL); 
     
    6364    { 
    6465        parent :: __construct(); 
     66        if(empty($row['id'])) { 
     67            throw new ObjectInstanciationException("id isn't present, this isn't a valid vocabulary_relationships row"); 
     68        } 
    6569        $this->mRow = $row; 
    6670        //var_dump($this->mRow); 
    6771        $this->mId = $this->mRow['id']; 
     72 
    6873    } 
    6974    /** Get relation from the eureka internal id 
  • html/classes/VocabularyTerm.php

    rf4e524f rce9b376  
    13691369    { 
    13701370        $this->DeleteTree(); 
     1371        apc_delete(APP_NAME.__CLASS__.$this->mId[0].'_'.$this->mId[1]); 
    13711372    } 
    13721373    /**Met à jour les attributs de l'objet à partir de la base de donnée 
  • html/classes/exceptions/ObjectInstanciationException.php

    r3550449 rce9b376  
    3333        public function __toString()  
    3434        { 
    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()); 
    3636        } 
    3737} 
  • html/config/config.php

    r8b111ad rce9b376  
    212212define('VOC_LOM_YES_NO', 'http://eureka.ntic.org/vdex/LOMv1.0_common_yes_no_voc.xml'); 
    213213 
     214/* Vocabulary relationships */ 
     215global $NAVIGATE_VOC_RELATIONS_ENABLED; 
     216$NAVIGATE_VOC_RELATIONS_ENABLED = TRUE; 
     217 
     218function 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 
    214233/* 
    215234 * Application profile compliance flags 
  • html/include/schema_validate.php

    r9f704d6 rce9b376  
    484484            $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"; 
    485485        } 
     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         
    486498        $db->execSqlUpdate("BEGIN;\n$sql\nCOMMIT;\n", true); 
    487499        $db->execSqlUpdate("VACUUM ANALYSE;\n", true); 
  • html/tests/VocabRelationshipNavigationTest.php

    rc644bf6 rce9b376  
    66require_once 'classes/Lom.php'; 
    77require_once 'classes/SearchEngine.php'; 
     8 
    89class VocabRelationshipImportTest extends PHPUnit_Framework_TestCase 
    910{ 
    10     private $fixTurePersistent = false; 
     11    private $fixTurePersistent = true; 
     12 
     13    private $pivotVocIdStr='pivotVoc'; 
     14    private $rVoc1IdStr='rVoc1'; 
     15    private $rVoc2IdStr='rVoc2'; 
     16     
    1117    protected function setUp() 
    1218    { 
    13         $this->pivotVocIdStr='pivotVoc'; 
    14         $this->rVoc1IdStr='rVoc1'; 
    15         $this->rVoc2IdStr='rVoc2'; 
    1619        try { 
    1720            $voc = Vocabulary::getObject($this->pivotVocIdStr); 
     
    2225        if($this->fixTurePersistent==false||$voc==null) { 
    2326            /* 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(); 
    4228 
    4329            $this->pivotVoc = new Vocabulary('NEW'); 
     
    4531            $this->pivotVoc->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 
    4632 
    47  
    4833            $this->rVoc1 = new Vocabulary('NEW'); 
    4934            $vocXml = file_get_contents(dirname(__FILE__) . '/testVocs/rVoc1.xml'); 
    5035            $this->rVoc1->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 
    51  
    5236 
    5337            $this->rVoc2 = new Vocabulary('NEW'); 
     
    5539            $this->rVoc2->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 
    5640            /* 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); 
    6942        } 
    7043        else { 
     
    7245            $this->rVoc1 = Vocabulary::getObject($this->rVoc1IdStr); 
    7346            $this->rVoc2 = Vocabulary::getObject($this->rVoc2IdStr); 
    74  
    7547        } 
    7648    } 
     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     
    7768    /** 
    7869     * @param $oaiId string example:  'oai:eureka.coeus.ca:r1' 
    7970     * @param $termId array example array('rVoc1T1', 'rVoc1') 
     71     * @param $loArray array to store objects 
     72     * @param $create boolean Create the object if not present 
    8073     */ 
    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) { 
    8377            $db = AbstractDb::getObject(); 
    8478            global $bypassAccessControl; 
     
    9286            $sql = "INSERT INTO lom_has_lom_9_classification (lom_id, lom_9_classification_id) VALUES (".$lo->getId()."," . $theme_classification->getId() . "); \n"; 
    9387            $db->execSqlUpdate($sql, false); 
     88        } 
     89        if($lo) { 
     90            $loArray[]=$lo; 
    9491        } 
    9592        return $lo; 
     
    110107        return $retval; 
    111108    } 
     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     
    112136    protected function tearDown() 
    113137    { 
    114138        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(); 
    121140        } 
    122141    } 
     142     
    123143    /** Normally i'd do more than one test, but the fixtures are unbearably slow */ 
    124144    public function testNoRegressionWhenVocabularyNavigationIsTurnedOff() 
    125145    { 
    126         /* Check that the test vocabularies have been imported successfully */ 
    127146        $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 
    128147        $this->assertEquals($this->rVoc1IdStr, $this->rVoc1->getId()); 
     
    130149 
    131150        /* 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; 
    132153        $this->assertEquals(array('oai:eureka.coeus.ca:r1'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 
    133154        $this->assertEquals(array('oai:eureka.coeus.ca:r2'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')))); 
     
    143164        $this->assertEquals(array('oai:eureka.coeus.ca:r12'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T7', 'rVoc2')))); 
    144165    } 
     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    } 
    145187} 
  • html/tests/testVocs/rVoc2.xml

    rdf1a05b rce9b376  
    11<?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"> 
    33  <vocabName> 
    44    <langstring language="en">related vocabulary 2 to test relationship navigations</langstring> 
Note: See TracChangeset for help on using the changeset viewer.