/** * @see parent::store() */ function store() { if (!$this->_id && $this->concept_id) { $this->prop = $this->loadRefConcept()->prop; } // pour la valeur par defaut des enums /*if ($this->prop !== null) { $this->prop = str_replace("\\", "\\\\", $this->prop); }*/ if (!$this->_id && $this->_make_unique_name) { $this->name = self::getUniqueName(); } if ($msg = $this->check()) { return $msg; } /*if (!preg_match('/^[a-z0-9_]+$/i', $this->name)) { return "Nom de champ invalide ($this->name)"; }*/ $ds = $this->_spec->ds; if (!$this->_id) { $table_name = $this->getTableName(); $sql_spec = $this->getSQLSpec(false); $query = "ALTER TABLE `{$table_name}` ADD `{$this->name}` {$sql_spec}"; if (!$ds->query($query)) { return "Le champ '{$this->name}' n'a pas pu être ajouté à la table '{$table_name}' (" . $ds->error() . ")"; } $spec_type = $this->_spec_object->getSpecType(); // ajout de l'index if (in_array($spec_type, self::$_indexed_types)) { $query = "ALTER TABLE `{$table_name}` ADD INDEX (`{$this->name}`)"; $ds->query($query); } } else { if ($this->fieldModified("name") || $this->fieldModified("prop")) { $table_name = $this->getTableName(); $sql_spec = $this->getSQLSpec(); $query = "ALTER TABLE `{$table_name}` CHANGE `{$this->_old->name}` `{$this->name}` {$sql_spec}"; if (!$ds->query($query)) { return "Le champ '{$this->name}' n'a pas pu être mis à jour (" . $ds->error() . ")"; } } } $locale = $this->_locale; $locale_desc = $this->_locale_desc; $locale_court = $this->_locale_court; $triggered_data = $this->_triggered_data; if ($msg = parent::store()) { return $msg; } // form triggers if ($triggered_data) { $triggered_object = json_decode($triggered_data, true); if (is_array($triggered_object)) { foreach ($triggered_object as $_value => $_class_trigger_id) { $trigger = new CExClassFieldTrigger(); $trigger->ex_class_field_id = $this->_id; $trigger->trigger_value = $_value; $trigger->loadMatchingObject(); if ($_class_trigger_id) { $trigger->ex_class_triggered_id = $_class_trigger_id; $trigger->store(); } else { $trigger->delete(); } } } } // self translations if ($locale || $locale_desc || $locale_court) { $trans = $this->loadRefTranslation(); $trans->std = $locale; $trans->desc = $locale_desc; $trans->court = $locale_court; if ($msg = $trans->store()) { mbTrace($msg, get_class($this), true); } } return null; }
/** * @see parent::store() */ function store() { $prop_changed = $this->fieldModified("prop"); if ($msg = parent::store()) { return $msg; } if ($prop_changed) { $fields = $this->loadRefClassFields(); foreach ($fields as $_field) { $new_prop = $this->updateFieldProp($_field->prop); $modif = $_field->prop != $new_prop; $_field->prop = $new_prop; if ($msg = $_field->store()) { continue; } if ($modif) { $_field->updateTranslation(); CAppUI::displayMsg($msg, "Champ <strong>{$_field->_view}</strong> mis à jour"); } } } }