Esempio n. 1
0
 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
 {
     // see ilStyleExporter::getXmlRepresentation()
     if (preg_match("/<StyleSheetExport><ImagePath>(.+)<\\/ImagePath>/", $a_xml, $hits)) {
         $path = $hits[1];
         $a_xml = str_replace($hits[0], "", $a_xml);
         $a_xml = str_replace("</StyleSheetExport>", "", $a_xml);
     }
     // temp xml-file
     $tmp_file = $this->getImportDirectory() . "/sty_" . $a_id . ".xml";
     file_put_contents($tmp_file, $a_xml);
     include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
     $style = new ilObjStyleSheet();
     $style->createFromXMLFile($tmp_file);
     $new_id = $style->getId();
     unlink($tmp_file);
     // images
     if ($path) {
         $source = $this->getImportDirectory() . "/" . $path;
         if (is_dir($source)) {
             $target = $style->getImagesDirectory();
             if (!is_dir($target)) {
                 ilUtil::makeDirParents($target);
             }
             ilUtil::rCopy($source, $target);
         }
     }
     $a_mapping->addMapping("Services/Style", "sty", $a_id, $new_id);
 }
Esempio n. 2
0
 public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
 {
     include_once "Services/Style/classes/class.ilObjStyleSheet.php";
     $style = new ilObjStyleSheet($a_id, false);
     // images
     $target = $this->getAbsoluteExportDirectory();
     if ($target && !is_dir($target)) {
         ilUtil::makeDirParents($target);
     }
     ilUtil::rCopy($style->getImagesDirectory(), $target);
     return "<StyleSheetExport>" . "<ImagePath>" . $this->getRelativeExportDirectory() . "</ImagePath>" . $style->getXML() . "</StyleSheetExport>";
 }
 /**
  * Create a new style
  */
 function create($a_from_style = 0, $a_import_mode = false)
 {
     global $ilDB;
     parent::create();
     if ($a_from_style == 0) {
         if (!$a_import_mode) {
             // copy styles from basic style
             $this->createFromXMLFile(self::$basic_style_file, true);
             // copy images from basic style
             $this->createImagesDirectory();
             ilUtil::rCopy(self::$basic_style_image_dir, $this->getImagesDirectory());
         }
     } else {
         // get style parameter records
         $def = array();
         $q = "SELECT * FROM style_parameter WHERE style_id = " . $ilDB->quote($a_from_style, "integer");
         $par_set = $ilDB->query($q);
         while ($par_rec = $ilDB->fetchAssoc($par_set)) {
             $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"], "parameter" => $par_rec["parameter"], "value" => $par_rec["value"], "type" => $par_rec["type"]);
         }
         // get style characteristics records
         $chars = array();
         $q = "SELECT * FROM style_char WHERE style_id = " . $ilDB->quote($a_from_style, "integer");
         $par_set = $ilDB->query($q);
         while ($par_rec = $ilDB->fetchAssoc($par_set)) {
             $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
         }
         // default style settings
         foreach ($def as $sty) {
             $id = $ilDB->nextId("style_parameter");
             $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type) VALUES " . "(" . $ilDB->quote($id, "integer") . "," . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($sty["tag"], "text") . "," . $ilDB->quote($sty["class"], "text") . "," . $ilDB->quote($sty["parameter"], "text") . "," . $ilDB->quote($sty["value"], "text") . "," . $ilDB->quote($sty["type"], "text") . ")";
             $ilDB->manipulate($q);
         }
         // insert style characteristics
         foreach ($chars as $char) {
             $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES " . "(" . $ilDB->quote($this->getId(), "integer") . "," . $ilDB->quote($char["type"], "text") . "," . $ilDB->quote($char["characteristic"], "text") . ")";
             $ilDB->manipulate($q);
         }
         // add style_data record
         $q = "INSERT INTO style_data (id, uptodate, category) VALUES " . "(" . $ilDB->quote($this->getId(), "integer") . ", 0," . $ilDB->quote((int) $this->getScope(), "integer") . ")";
         $ilDB->manipulate($q);
         // copy images
         $from_style = new ilObjStyleSheet($a_from_style);
         $this->createImagesDirectory();
         ilUtil::rCopy($from_style->getImagesDirectory(), $this->getImagesDirectory());
         // copy colors
         $colors = $from_style->getColors();
         foreach ($colors as $c) {
             $this->addColor($c["name"], $c["code"]);
         }
         // copy templates
         $tcts = ilObjStyleSheet::_getTemplateClassTypes();
         foreach ($tcts as $tct => $v) {
             $templates = $from_style->getTemplates($tct);
             foreach ($templates as $t) {
                 $this->addTemplate($tct, $t["name"], $t["classes"]);
             }
         }
     }
     $this->read();
     if (!$a_import_mode) {
         $this->writeCSSFile();
     }
 }