Konfiguration
Verfasst: Mo 10. Okt 2005, 07:30
ich habe einen entwicklungsvorschlag als erweiterung publiziert. siehe hier:
http://www.contenido.org/forum/viewtopic.php?t=9644
http://www.contenido.org/forum/viewtopic.php?t=9644
Das Diskussionsforum zum Open Source Content Management System
https://forum.contenido.org/
richtig, der aufruf würde dann natürlich aus dem kopierscript erfolgen müssen...kummer hat geschrieben:so gesehen bin ich mit dir einverstanden. ich bau das also in die klasse ein. aber funktionieren - ich verstehe das doch richtig - wird es erst nach der integration. der aufruf der kopiermethode würde also über das kopierscript erfolgen, nicht?
Code: Alles auswählen
<?php
/**
* $Revision: 1.12 $
* $Source: D:/cvs/cvsrepo/test/CONTENIDO_MODULE/wdreiConf/wdreiConf.class.inc.php,v $
* $Date: 2005/10/10 11:29:53 $
*/
/**
* wdreiConf - Klasse zur vereinfachten Konfiguration in Contenido
* @author Andreas Kummer
* @copyright Copyright © 2005, mumprecht & kummer w3concepts
*/
class wdreiConf {
/**
* Konstruktor der Klasse
*/
function wdreiConf() {
global $idart, $lang, $cnumber, $cCurrentContainer, $idtpl, $idcat, $cfg;
$this->tblName = $cfg['sql']['sqlprefix']."_wdreiConf";
/*
* Globale Variablen in den Kontext der Klasse aufnehmen
*/
$this->idart = (empty($idart))?(0):($idart);
$this->lang = (empty($lang))?(0):($lang);
$this->cnumber = (empty($cnumber))?(0):($cnumber);
$this->cCurrentContainer = (empty($cCurrentContainer))?(0):($cCurrentContainer);
$this->idtpl = (empty($idtpl))?(0):($idtpl);
$this->idcat = (empty($idcat))?(0):($idcat);
/*
* Ermitteln der Konfigurationsstufe (Template, Kategorie, Artikel)
*/
$this->getConfigurationLevel();
/*
* Contenido-Datenbank im Klassenkontext initialisieren
*/
$this->db = new DB_Contenido();
/*
* Tabelle anlegen, falls diese noch nicht existieren sollte
*/
$this->createTable();
/*
* Daten speichern, falls eine Übertragung erfolgt ist
*/
$this->saveData();
/*
* Zurück holen der Daten
*/
$this->restoreValues();
}
/**
* Speicherung der übergebenen Konfigurationsdaten.
* @param Struct Zu serialisierende und zu speichernde Werte
* @return Boolean Die Funktion gibt in jedem Fall TRUE zurück
*/
function saveSerial($value) {
/*
* Serial erstellen
*/
$content = $this->createSerial($value);
/*
* Ermitteln, ob bereits ein Serial in der Datenbank vorhanden ist.
*/
$this->db->query("SELECT * FROM {$this->tblName} WHERE idlang = {$this->lang} AND cnumber = {$this->cnumber} AND idtpl = {$this->idtpl} AND idcat = {$this->idcat} AND idart = {$this->idart}");
if ($this->db->next_record()) {
/*
* Serial ist bereits vorhanden; Update wird ausgeführt
*/
$this->db->query("UPDATE {$this->tblName} SET content = '{$content}' WHERE idlang = {$this->lang} AND cnumber = {$this->cnumber} AND idtpl = {$this->idtpl} AND idcat = {$this->idcat} AND idart = {$this->idart}");
return true;
}
/*
* Serial ist noch nicht vorhanden; Insert wird ausgeführt
*/
$this->db->query("INSERT INTO {$this->tblName} (content, idart, idlang, idtpl, idcat, cnumber) VALUES('{$content}', {$this->idart}, {$this->lang}, {$this->idtpl}, {$this->idcat}, {$this->cnumber})");
return true;
}
/**
* Erstellt den zur Speicherung notwendigen WDDX-Serial.
* @param Struct Zu serialisierende Werte
* @return String WDDX-Paket (XML) mit der Struktur sowie den Werten
*/
function createSerial($value) {
return mysql_real_escape_string(wddx_serialize_value($value));
}
/**
* Prüft, ob sich eine Tabelle mit der Bezeichnung con_wdreConf bereits in
* der Datenbank befindet oder nicht. Falls die Tabelle nicht existiert,
* wird sie in der aktuellen Datenbank angelegt werden.
* @return Boolean Die Funktion gibt in jedem Fall TRUE zurück
*/
function createTable() {
$this->db->query("SHOW TABLES LIKE '{$this->tblName}'");
if ($this->db->next_record()) {
/*
* Tabelle existiert bereits
*/
return true;
}
/*
* Tabelle existiert noch nicht und muss angelegt werden
*/
$this->db->query("CREATE TABLE {$this->tblName} (pk_wdreiConf int(10) unsigned NOT NULL auto_increment, cnumber int(11) NOT NULL default '0', idart int(11) NOT NULL default '0', idlang int(11) NOT NULL default '0', idtpl int(10) unsigned NOT NULL default '0', idcat int(10) unsigned NOT NULL default '0', content text NOT NULL, PRIMARY KEY (pk_wdreiConf)) TYPE=MyISAM");
return true;
}
/**
* Gibt die HTML-formatierte Konfigurationsmaske zurück.
*/
function showConfiguration() {
$returnValue = '<table width="100%" cellpadding="3" cellspacing="0" border="0">';
$returnValue .= '<tr><td width="35%" class="text_medium"></td><td class="text_medium"></td></tr>';
if (!empty($this->field)) {
foreach ($this->field as $field) {
$returnValue .= '<tr><td valign="top" width="35%" class="text_medium">'.$field[0].'</td><td valign="top" class="text_medium">'.$field[1].'</td></tr>';
}
}
$returnValue .= '</table>';
echo $returnValue;
}
/**
* Erzeugt in Textfeld.
* @param String Feldbezeichner (Anzeige links)
* @param String Feldname
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
*/
function makeText($label, $name, $attributes = null) {
if (empty($attributes['size'])) {
$attributes['size'] = 40;
}
$returnValue = '<input type="text" name="'.$this->cnumber.'_'.$name.'" ';
$returnValue .= $this->addAttributes($attributes);
$returnValue .= 'value="'.$this->getValue($name).'" />';
$this->field[] = array($label, $returnValue);
}
/**
* Erzeugt eine Textarea.
* @param String Feldbezeichner (Anzeige links)
* @param String Feldname
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
*/
function makeTextarea($label, $name, $attributes = null) {
if (empty($attributes['rows'])) {
$attributes['rows'] = 6;
}
if (empty($attributes['cols'])) {
$attributes['cols'] = 40;
}
$returnValue = '<textarea name="'.$this->cnumber.'_'.$name.'" ';
$returnValue .= $this->addAttributes($attributes);
$returnValue .= '>'.$this->getValue($name).'</textarea>';
$this->field[] = array($label, $returnValue);
}
/**
* Erzeugt ein Select-Feld.
* @param String Feldbezeichner (Anzeige links)
* @param String Feldname
* @param Array Assoziatives Array mit dem Werte-Schlüssel-Paaren. Der
* Schlüssel wird angezeigt, der Wert dient als Übergabewert
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
* @param Boolean Bestimmt, ob das Selectfeld eine Mehrfachauswahl erlaubt
* oder nicht
*/
function makeSelect($label, $name, $valuePairs, $attributes = null, $multiple = false) {
if (empty($attributes['size'])) {
if ($multiple) {
$attributes['size'] = 5;
$attributes['multiple'] = 'multiple';
} else {
$attributes['size'] = 1;
}
}
if ($multiple) {
$returnValue = '<select name="'.$this->cnumber.'_'.$name.'[]" ';
} else {
$returnValue = '<select name="'.$this->cnumber.'_'.$name.'" ';
}
$returnValue .= $this->addAttributes($attributes);
$returnValue .= '>';
if (!empty($valuePairs)) {
foreach ($valuePairs as $key => $value) {
if ($multiple) {
if (in_array($value, $this->getValue($name))) {
$returnValue .= '<option value="'.$value.'" selected="selected">'.$key.'</option>';
} else {
$returnValue .= '<option value="'.$value.'">'.$key.'</option>';
}
} else {
if ($this->getValue($name) == $value) {
$returnValue .= '<option value="'.$value.'" selected="selected">'.$key.'</option>';
} else {
$returnValue .= '<option value="'.$value.'">'.$key.'</option>';
}
}
}
}
$returnValue .= '</select>';
$this->field[] = array($label, $returnValue);
}
/**
* Erzeugt Radio-Buttons.
* @param String Feldbezeichner (Anzeige links)
* @param String Feldname
* @param Array Assoziatives Array mit dem Werte-Schlüssel-Paaren. Der
* Schlüssel wird angezeigt, der Wert dient als Übergabewert
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
*/
function makeRadio($label, $name, $valuePairs, $attributes = null) {
$returnValue = '';
if (!empty($valuePairs)) {
foreach ($valuePairs as $key => $value) {
if ($this->getValue($name) == $value) {
$returnValue .= '<div><input type="radio" name="'.$this->cnumber.'_'.$name.'" value="'.$value.'" checked="checked"> '.$key.'</div>';
} else {
$returnValue .= '<div><input type="radio" name="'.$this->cnumber.'_'.$name.'" value="'.$value.'"> '.$key.'</div>';
}
}
}
$this->field[] = array($label, $returnValue);
}
/**
* Erzeugt Checkboxen.
* @param String Feldbezeichner (Anzeige links)
* @param String Feldname
* @param Array Assoziatives Array mit dem Werte-Schlüssel-Paaren. Der
* Schlüssel wird angezeigt, der Wert dient als Übergabewert
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
*/
function makeCheckbox($label, $name, $valuePairs, $attributes = null) {
$returnValue = '';
if (!empty($valuePairs)) {
foreach ($valuePairs as $key => $value) {
if (in_array($value, $this->getValue($name))) {
$returnValue .= '<div><input type="checkbox" name="'.$this->cnumber.'_'.$name.'[]" value="'.$value.'" checked="checked"> '.$key.'</div>';
} else {
$returnValue .= '<div><input type="checkbox" name="'.$this->cnumber.'_'.$name.'[]" value="'.$value.'"> '.$key.'</div>';
}
}
}
$this->field[] = array($label, $returnValue);
}
/**
* Fügt die Attribute zu einem String zusammen und gibt diesen zurück
* @param Array Assoziatives Array mit dem Attributbezeichner als Schlüssel
* und dem Attributwert als Wert
* @return String Attributte als String
*/
function addAttributes($attributes) {
$returnValue = '';
if (!empty($attributes)) {
foreach ($attributes as $key => $value) {
$returnValue .= $key.'="'.$value.'" ';
}
}
return $returnValue;
}
/**
* Ermittelt die Konfigurationsstufe (2 = Artikel, 1 = Kategorie, 0 =
* Template) und speichert diese als Klassenattribut
*/
function getConfigurationLevel() {
$this->configLevel = 2;
if ($this->idart != 0) return;
$this->configLevel--;
if ($this->idcat != 0) return;
$this->configLevel--;
}
/**
* Holt die Daten aus der Datenbank und deserialisiert diese in das
* Klassenattribut confValues
*/
function restoreValues() {
$cnumber = $this->cnumber;
if ($cnumber == 0) {
$cnumber = $this->cCurrentContainer;
}
$this->db->query("SELECT * FROM {$this->tblName} WHERE idlang = {$this->lang} AND cnumber = {$cnumber} AND idtpl = {$this->idtpl} AND idcat = {$this->idcat} AND idart = {$this->idart}");
if (!$this->db->next_record()) {
$this->db->query("SELECT * FROM {$this->tblName} WHERE idlang = {$this->lang} AND cnumber = {$cnumber} AND idtpl = {$this->idtpl} AND idcat = {$this->idcat}");
if (!$this->db->next_record()) {
$this->db->query("SELECT * FROM {$this->tblName} WHERE idlang = {$this->lang} AND cnumber = {$cnumber} AND idtpl = {$this->idtpl}");
if (!$this->db->next_record()) {
$this->confValues = array();
return;
}
}
}
$this->confValues = wddx_deserialize($this->db->f('content'));
}
/**
* Gibt den Wert mit der Bezeichnung $name aus dem Klassenattribut
* confValues zurück.
*/
function getValue($name) {
$cnumber = $this->cnumber;
if ($cnumber == 0) {
$cnumber = $this->cCurrentContainer;
}
if (!isset($this->confValues[$cnumber.'_'.$name])) {
return null;
} else {
return $this->confValues[$cnumber.'_'.$name];
}
}
/**
* Setzt den Wert mit der Bezeichnung $name im Klassenattribut confValues.
* @param String Variablenbezeichner
* @param Mixed Objekt, das gesetzt werden soll
*/
function setValue($name, $value) {
$cnumber = $this->cnumber;
if ($cnumber == 0) {
$cnumber = $this->cCurrentContainer;
}
$this->confValues[$cnumber.'_'.$name] = $value;
}
/**
* Setzt den Wert mit der Bezeichnung $name im Klassenattribut confValues
* unter der Bedingung, dass diese nicht bereits einen Wert zugewiesen hat.
* @param String Variablenbezeichner
* @param Mixed Objekt, das gesetzt werden soll
*/
function setDefaultValue($name, $value) {
$cnumber = $this->cnumber;
if ($cnumber == 0) {
$cnumber = $this->cCurrentContainer;
}
if ($this->getValue($name) == null) {
$this->confValues[$cnumber.'_'.$name] = $value;
}
}
/**
* Speichert die übertragenen Daten aus dem Formularversand, falls ein
* solcher vorgenommen worden ist.
*/
function saveData() {
if (empty($_POST)) {
return true;
}
if ($this->cnumber == 0) {
return true;
}
$saveValue = array();
foreach ($_POST as $key => $value) {
if ($this->beginsWith($key, $this->cnumber.'_')) {
$saveValue[$key] = $value;
}
}
$this->saveSerial($saveValue);
}
/**
* Speichert die serialisierten Daten nach Aktualisierung durch das Modul.
*/
function actualizeData() {
$cnumber = $this->cnumber;
if ($cnumber == 0) {
$cnumber = $this->cCurrentContainer;
}
if ($cnumber == 0) {
return;
}
$this->saveSerial($this->confValues);
}
/**
* Prüft, ob str mit sub beginnt.
* @param string str Quellstring.
* @param string sub Überprüfstring.
* @return boolean True bei Übereinstimmung. Sonst false.
*/
function beginsWith($str, $sub) {
return (substr($str, 0, strlen($sub)) == $sub);
}
/**
* Statische Funktion zur Löschung einer Konfiguration
* @param Integer Primärschlüssel der Sprache
* @param Integer Primärschlüssel des Templates
* @param Integer Primärschlüssel der Kategorie
* @param Integer Primärschlüssel des Artikels
*/
function deleteConfiguration($idlang, $idtpl, $icat = 0, $idtpl = 0) {
$this->db->query("DELETE FROM {$this->tblName} WHERE idlang = {$idlang} AND idtpl = {$idtpl} AND idcat = {$idcat} AND idart = {$idart}");
}
/**
* Dupliziert eine Konfiguration
* @param Integer Primärschlüssel der Sprache der Quellkonfiguration
* @param Integer Primärschlüssel des Artikels der Quellkonfiguration
* @param Integer Primärschlüssel der Sprache der Zielkonfiguration
* @param Integer Primärschlüssel des Artikels der Zielkonfiguration
*/
function duplicateConfiguration($srcIdLang, $srcIdArt, $desIdLang, $desIdArt) {
$this->db->query("SELECT * FROM {$this->tblName} WHERE idlang = {$srcIdLang} AND idart = {$srcIdArt}");
while ($this->db->next_record()) {
$idtpl = $this->db->f('idtpl');
$idcat = $this->db->f('idcat');
$cnumber = $this->db->f('cnumber');
$content = $this->db->f('content');
$this->db->query("INSERT INTO {$this->tblName} (content, idart, idlang, idtpl, idcat, cnumber) VALUES('{$content}', {$desIdArt}, {$desIdLang}, {$idtpl}, {$idcat}, {$cnumber})");
}
}
}
?>