00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once ("classes/class.ilMetaTechnical.php");
00025 require_once ("classes/class.ilMetaTechnicalRequirement.php");
00026 require_once ("classes/class.ilMetaTechnicalRequirementSet.php");
00027 require_once ("classes/class.ilNestedSetXML.php");
00028
00040 class ilMetaData
00041 {
00042 var $ilias;
00043
00044 var $id;
00045 var $type;
00046
00047 var $nested_obj;
00048
00049 var $meta;
00050 var $section;
00051
00052 var $obj;
00053
00054 var $import_id;
00055 var $title;
00056 var $language;
00057 var $description;
00058 var $technicals;
00059
00064 function ilMetaData($a_type = "", $a_id = 0)
00065 {
00066 global $ilias;
00067
00068 $this->ilias =& $ilias;
00069
00070 $this->import_id = "";
00071 $this->title = "";
00072 $this->language = array();
00073 $this->description = "";
00074 $this->technicals = array();
00075 $this->type = $a_type;
00076 $this->id = $a_id;
00077 if($a_id != 0)
00078 {
00079 $this->read();
00080 }
00081 }
00082
00083 function clean($a_data)
00084 {
00085 $a_data = preg_replace("/&(?!amp;|lt;|gt;|quot;)/","&",$a_data);
00086 $a_data = preg_replace("/</","<",$a_data);
00087 $a_data = preg_replace("/>/",">",$a_data);
00088
00089 return $a_data;
00090 }
00091
00092 function setObject(&$a_obj)
00093 {
00094 $this->obj =& $a_obj;
00095 }
00096
00097 function __initNestedSet()
00098 {
00099 include_once("classes/class.ilNestedSetXML.php");
00100
00101 $this->nested_obj =& new ilNestedSetXML();
00102 $this->nested_obj->init($this->getID(), $this->getType());
00103 return $this->nested_obj->initDom();
00104 }
00105
00106 function read()
00107 {
00108
00109 if ($this->getType() == "pg" ||
00110 $this->getType() == "st" ||
00111 $this->getType() == "lm" ||
00112 $this->getType() == "glo" ||
00113 $this->getType() == "mob" ||
00114 $this->getType() == "crs" ||
00115 $this->getType() == "sahs" ||
00116 $this->getType() == "htlm" ||
00117 $this->getType() == "tst" ||
00118 $this->getType() == "qpl" ||
00119 $this->getType() == "svy" ||
00120 $this->getType() == "spl" ||
00121 $this->getType() == "gdf" ||
00122 $this->getType() == "dbk")
00123 {
00124 if ( !$this->__initNestedSet() )
00125 {
00126 $metaData = $this->create();
00127 }
00128 else
00129 {
00130 $metaData["title"] = $this->nested_obj->getFirstDomContent("//MetaData/General/Title");
00131 $metaData["description"] = $this->nested_obj->getFirstDomContent("//MetaData/General/Description");
00132 }
00133
00134 $this->setTitle($metaData["title"]);
00135 $this->setDescription($metaData["description"]);
00136 }
00137
00138 }
00139
00143 function create()
00144 {
00145 #echo "<b>meta create()</b><br>";
00146 $this->__initNestedSet();
00147 if (is_object($this->obj))
00148 {
00149 $metaData["title"] = $this->obj->getTitle();
00150 $metaData["description"] = $this->obj->getDescription();
00151 }
00152 else
00153 {
00154 $metaData["title"] = "NO TITLE";
00155 $metaData["description"] = "";
00156 }
00157
00158
00159 $metaData["title"] = $this->clean($metaData["title"]);
00160 $metaData["description"] = $this->clean($metaData["description"]);
00161
00162 $xml = '
00163 <MetaData>
00164 <General Structure="Hierarchical">
00165 <Identifier Catalog="ILIAS" Entry="il__' . $this->getType() . '_' . $this->getId() . '"></Identifier>
00166 <Title Language="' . $this->ilias->account->getLanguage() . '">' . $metaData["title"] . '</Title>
00167 <Description Language="' . $this->ilias->account->getLanguage() . '">' . $metaData["description"] . '</Description>
00168 <Keyword Language="' . $this->ilias->account->getLanguage() . '"></Keyword>
00169 </General>
00170 </MetaData>
00171 ';
00172 $this->nested_obj->import($xml, $this->getID(), $this->getType());
00173 return $metaData;
00174 }
00175
00179 function update()
00180 {
00181 #echo "<b>meta update()</b><br>";
00182 $query = "REPLACE INTO meta_data (obj_id, obj_type, title, language, description) VALUES (".
00183 "'".$this->getId()."', ".
00184 "'".$this->getType()."', ".
00185 "'".ilUtil::prepareDBString($this->getTitle())."', ".
00186 "'".$this->getLanguage()."', ".
00187 "'".ilUtil::prepareDBString($this->getDescription())."')";
00188 $this->ilias->db->query($query);
00189 $this->updateTechnicalSections();
00190
00191 if ($this->getType() == "pg" ||
00192 $this->getType() == "st" ||
00193 $this->getType() == "lm" ||
00194 $this->getType() == "crs" ||
00195 $this->getType() == "glo" ||
00196 $this->getType() == "gdf" ||
00197 $this->getType() == "dbk" ||
00198 $this->getType() == "tst" ||
00199 $this->getType() == "qpl" ||
00200 $this->getType() == "svy" ||
00201 $this->getType() == "spl" ||
00202 $this->getType() == "mob" ||
00203 $this->getType() == "htlm" ||
00204 $this->getType() == "sahs")
00205 {
00206 # echo "Section: " . $this->section . "<br>\n";
00207 if ( $this->__initNestedSet() )
00208 {
00209 $p = "//MetaData";
00210 if ($this->section != "")
00211 {
00212 $p .= "/" . $this->section;
00213 }
00214
00215 $this->nested_obj->updateDomNode($p, $this->meta);
00216 $this->nested_obj->updateFromDom();
00217
00218
00219 if (isset($this->meta["Title"]["Value"]))
00220 {
00221 $this->setTitle(ilUtil::stripSlashes($this->meta["Title"]["Value"]));
00222 $this->setDescription(ilUtil::stripSlashes($this->meta["Description"][0]["Value"]));
00223 }
00224 }
00225 }
00226 }
00227
00228 function updateTitleAndDescription($title, $description)
00229 {
00230 if ( $this->__initNestedSet() )
00231 {
00232 $p = "//MetaData/General";
00233 if ($this->section != "")
00234 {
00235 $p .= "/" . $this->section;
00236 }
00237 $this->nested_obj->replaceDomContent($p, "Title", 0, array("value" => $title));
00238 $this->nested_obj->replaceDomContent($p, "Description", 0, array("value" => $description));
00239 $this->nested_obj->updateFromDom();
00240 }
00241 $this->setTitle($title);
00242 $this->setDescription($description);
00243 $this->update();
00244 }
00245
00249 function delete($a_name, $a_path, $a_index)
00250 {
00251 if ($a_name != "")
00252 {
00253 if ( $this->__initNestedSet() )
00254 {
00255 $p = "//MetaData";
00256 if ($a_path != "")
00257 {
00258 $p .= "/" . $a_path;
00259 }
00260 $this->nested_obj->deleteDomNode($p, $a_name, $a_index);
00261 $this->nested_obj->updateFromDom();
00262 }
00263 }
00264 }
00265
00269 function add($a_name, $a_path, $a_index = 0)
00270 {
00271 if ( $this->__initNestedSet() )
00272 {
00273 $p = "//MetaData";
00274 if ($a_path != "")
00275 {
00276 $p .= "/" . $a_path;
00277 }
00278 $attributes = array();
00279 # echo "Index: " . $a_index . " | Path: " . $a_path . " | Name: " . $a_name . "<br>\n";
00280 switch ($a_name)
00281 {
00282 case "Relation" : $xml = '
00283 <Relation>
00284 <Resource>
00285 <Identifier_ Catalog="ILIAS" Entry=""/>
00286 <Description Language="' . $this->ilias->account->getLanguage() . '"/>
00287 </Resource>
00288 </Relation>
00289 ';
00290 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00291 break;
00292 case "Lifecycle": $xml = '
00293 <Lifecycle Status="Draft">
00294 <Version Language="' . $this->ilias->account->getLanguage() . '"></Version>
00295 <Contribute Role="Author">
00296 <Entity/>
00297 <Data/>
00298 </Contribute>
00299 </Lifecycle>
00300 ';
00301 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00302 break;
00303 case "Meta-Metadata": $xml = '
00304 <Meta-Metadata MetadataScheme="LOM v 1.0" Language="' . $this->ilias->account->getLanguage() . '">
00305 <Identifier Catalog="ILIAS" Entry=""/>
00306 <Contribute Role="Author">
00307 <Entity/>
00308 <Data/>
00309 </Contribute>
00310 </Meta-Metadata>
00311 ';
00312 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00313 break;
00314 case "Technical" : $xml = '
00315 <Technical/>
00316 ';
00317 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00318 break;
00319 case "Educational" : $xml = '
00320 <Educational InteractivityType="Active" LearningResourceType="Exercise" InteractivityLevel="Medium" SemanticDensity="Medium" IntendedEndUserRole="Learner" Context="Other" Difficulty="Medium">
00321 <TypicalAgeRange></TypicalAgeRange>
00322 <TypicalLearningTime></TypicalLearningTime>
00323 </Educational>
00324 ';
00325 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00326 break;
00327 case "Rights" : $xml = '
00328 <Rights Cost="No" CopyrightAndOtherRestrictions="No">
00329 <Description Language="' . $this->ilias->account->getLanguage() . '"/>
00330 </Rights>
00331 ';
00332 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00333 break;
00334 case "Annotation" : $xml = '
00335 <Annotation>
00336 <Entity/>
00337 <Date/>
00338 <Description Language="' . $this->ilias->account->getLanguage() . '"/>
00339 </Annotation>
00340 ';
00341 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00342 break;
00343 case "Classification": $xml = '
00344 <Classification Purpose="Idea">
00345 <TaxonPath>
00346 <Source Language="' . $this->ilias->account->getLanguage() . '"/>
00347 <Taxon Language="' . $this->ilias->account->getLanguage() . '" Id=""/>
00348 </TaxonPath>
00349 <Description Language="' . $this->ilias->account->getLanguage() . '"/>
00350 <Keyword Language="' . $this->ilias->account->getLanguage() . '"/>
00351 </Classification>
00352 ';
00353 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00354 break;
00355 case "Contribute" : $xml = '
00356 <Contribute Role="Author">
00357 <Entity/>
00358 <Data/>
00359 </Contribute>
00360 ';
00361 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00362 break;
00363 case "Requirement" : $xml = '
00364 <Requirement>
00365 <Type>
00366 <Browser Name="Any" MinimumVersion="" MaximumVersion=""/>
00367 </Type>
00368 </Requirement>
00369 ';
00370 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00371 break;
00372 case "OrComposite" : $xml = '
00373 <OrComposite>
00374 <Requirement>
00375 <Type>
00376 <Browser Name="Any" MinimumVersion="" MaximumVersion=""/>
00377 </Type>
00378 </Requirement>
00379 </OrComposite>
00380 ';
00381 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00382 break;
00383 case "TaxonPath" : $xml = '
00384 <TaxonPath>
00385 <Source Language="' . $this->ilias->account->getLanguage() . '"/>
00386 <Taxon Language="' . $this->ilias->account->getLanguage() . '" Id=""/>
00387 </TaxonPath>
00388 ';
00389 $this->nested_obj->addXMLNode($p, $xml, $a_index);
00390 break;
00391 case "Taxon" : $value = "";
00392 $attributes[0] = array("name" => "Language", value => $this->ilias->account->getLanguage());
00393 $attributes[1] = array("name" => "Id", value => "");
00394 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00395 break;
00396 case "Identifier" : ;
00397 case "Identifier_" : $value = "";
00398 $attributes[0] = array("name" => "Catalog", "value" => "");
00399 $attributes[1] = array("name" => "Entry", "value" => "");
00400 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00401 break;
00402 case "Language" : $value = "";
00403 $attributes[0] = array("name" => "Language", value => $this->ilias->account->getLanguage());
00404 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00405 break;
00406 case "InstallationRemarks" : ;
00407 case "OtherPlattformRequirements" : ;
00408 case "TypicalAgeRange" : ;
00409 case "Title" : ;
00410 case "Description" : ;
00411 case "Coverage" : ;
00412 case "Keyword" : $value = "";
00413 $attributes[0] = array("name" => "Language", value => $this->ilias->account->getLanguage());
00414 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00415 break;
00416 case "Location" : $value = "";
00417 $attributes[0] = array("name" => "Type", value => "LocalFile");
00418 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00419 break;
00420 default : $value = "";
00421 $attributes = "";
00422 $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
00423 break;
00424 }
00425 $this->nested_obj->updateFromDom();
00426 }
00427 }
00428
00429 function getDom()
00430 {
00431 if ( $this->__initNestedSet() )
00432 {
00433 return $this->nested_obj->initDom();
00434 }
00435 }
00436
00440 function setElement($a_name, $a_data)
00441 {
00442 $this->$a_name = $a_data;
00443 }
00444
00448 function getElement($a_name, $a_path = "", $a_index = 0)
00449 {
00450 if ( $this->__initNestedSet() )
00451 {
00452 $p = "//MetaData";
00453 if ($a_path != "")
00454 {
00455 $p .= "/" . $a_path;
00456 }
00457 # echo "Index: " . $a_index . " | Path: " . $p . " | Name: " . $a_name . "<br>\n";
00458 $nodes = $this->nested_obj->getDomContent($p, $a_name, $a_index);
00459 $this->setElement($a_name, $nodes);
00460 # vd($this->$a_name);
00461 return $this->$a_name;
00462 }
00463 }
00464
00468 function setImportIdentifierEntryID($a_id)
00469 {
00470 $this->import_id = $a_id;
00471 }
00472
00476 function getImportIdentifierEntryID()
00477 {
00478 return $this->import_id;
00479 }
00480
00484 function setTitle($a_title)
00485 {
00486 if ($a_title == "")
00487 {
00488 $a_title = "NO TITLE";
00489 }
00490 $this->title = $a_title;
00491 }
00492
00496 function getTitle()
00497 {
00498 return $this->title;
00499 }
00500
00504 function setMeta($a_data)
00505 {
00506 $this->meta = $a_data;
00507 }
00508
00512 function getMeta()
00513 {
00514 return $this->meta;
00515 }
00516
00520 function setSection($a_section)
00521 {
00522 $this->section = $a_section;
00523 }
00524
00528 function getSection()
00529 {
00530 return $this->section;
00531 }
00532
00536 function setID($a_id)
00537 {
00538 $this->id = $a_id;
00539 }
00540
00544 function getID()
00545 {
00546 return $this->id;
00547 }
00548
00552 function setType($a_type)
00553 {
00554 $this->type = $a_type;
00555 }
00556
00560 function getType()
00561 {
00562 return $this->type;
00563 }
00564
00568 function setLanguage($a_lang)
00569 {
00570 $this->language = $a_lang;
00571 }
00572
00576 function getLanguage()
00577 {
00578 return $this->language;
00579 }
00580
00584 function setDescription($a_desc)
00585 {
00586 $this->description = $a_desc;
00587 }
00588
00592 function getDescription()
00593 {
00594 return $this->description;
00595 }
00596
00602 function addTechnicalSection(&$a_tech)
00603 {
00604 $this->technicals[] =& $a_tech;
00605 }
00606
00607 function &getTechnicalSections()
00608 {
00609 return $this->technicals;
00610 }
00611
00612 function updateTechnicalSections()
00613 {
00614 ilMetaTechnical::delete($this->getId(), $this->getType());
00615 foreach($this->technicals as $technical)
00616 {
00617 $technical->create();
00618 }
00619 }
00620
00621 function readTechnicalSections()
00622 {
00623 ilMetaTechnical::readTechnicalSections($this);
00624 }
00625
00629 function &getTechnicalSection($a_nr = 1)
00630 {
00631 if ($a_nr > count($this->technicals))
00632 {
00633 return false;
00634 }
00635 else
00636 {
00637 return $this->technicals[$a_nr - 1];
00638 }
00639 }
00640
00641 function getCountries()
00642 {
00643 global $lng;
00644
00645 $lng->loadLanguageModule("meta");
00646
00647 $cntcodes = array ("DE","ES","FR","GB","AT","CH","AF","AL","DZ","AS","AD","AO",
00648 "AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY",
00649 "BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF",
00650 "BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM",
00651 "CG","CK","CR","CI","HR","CU","CY","CZ","DK","DJ","DM","DO","TP","EC",
00652 "EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","FX","GF","PF",
00653 "TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GN",
00654 "GW","GY","HT","HM","HN","HU","IS","IN","ID","IR","IQ","IE","IL","IT",
00655 "JM","JP","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS",
00656 "LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH",
00657 "MQ","MR","MU","YT","MX","FM","MD","MC","MN","MS","MA","MZ","MM","NA",
00658 "NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM",
00659 "PK","PW","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO",
00660 "RU","RW","KN","LC","VC","WS","SM","ST","SA","CH","SN","SC","SL","SG",
00661 "SK","SI","SB","SO","ZA","GS","ES","LK","SH","PM","SD","SR","SJ","SZ",
00662 "SE","SY","TW","TJ","TZ","TH","TG","TK","TO","TT","TN","TR","TM","TC",
00663 "TV","UG","UA","AE","GB","UY","US","UM","UZ","VU","VA","VE","VN","VG",
00664 "VI","WF","EH","YE","ZR","ZM","ZW");
00665 $cntrs = array();
00666 foreach($cntcodes as $cntcode)
00667 {
00668 $cntrs[$cntcode] = $lng->txt("meta_c_".$cntcode);
00669 }
00670 asort($cntrs);
00671 return $cntrs;
00672
00673 }
00674
00679 function getLanguages()
00680 {
00681 global $lng;
00682
00683 $lng->loadLanguageModule("meta");
00684
00685 $lngcodes = array("aa","ab","af","am","ar","as","ay","az","ba","be","bg","bh",
00686 "bi","bn","bo","br","ca","co","cs","cy","da","de","dz","el","en","eo",
00687 "es","et","eu","fa","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu",
00688 "ha","he","hi","hr","hu","hy","ia","ie","ik","id","is","it","iu","ja",
00689 "jv","ka","kk","kl","km","kn","ko","ks","ku","ky","la","ln",
00690 "lo","lt","lv","mg","mi","mk","ml","mn","mo","mr","ms","mt",
00691 "my","na","ne","nl","no","oc","om","or","pa","pl","ps","pt",
00692 "qu","rm","rn","ro",
00693 "ru","rw",
00694 "sa","sd","sg","sh","si","sk","sl","sm","sn","so","sq","sr","ss","st",
00695 "su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts",
00696 "tt","tw","ug","uk","ur","uz","vi","vo","wo","xh","yi","yo","za","zh",
00697 "zu");
00698 $langs = array();
00699 foreach($lngcodes as $lngcode)
00700 {
00701 $langs[$lngcode] = $lng->txt("meta_l_".$lngcode);
00702 }
00703 asort($langs);
00704 return $langs;
00705 }
00706
00715 function setXMLContent($a_xml, $a_encoding = "UTF-8")
00716 {
00717 $this->encoding = $a_encoding;
00718 $this->xml = $a_xml;
00719 }
00720
00721
00728 function appendXMLContent($a_xml)
00729 {
00730 $this->xml.= $a_xml;
00731 }
00732
00733
00737 function getXMLContent()
00738 {
00739 return $this->xml;
00740 }
00741
00742 }
00743 ?>