/** * 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(); } }