public function create($p_type = null, array $p_params = array())
{
global $g_ado_db;
$p_type = strtolower($p_type);
$numericPrecision = isset($p_params['precision']) ? $p_params['precision'] : null;
$types = self::DatabaseTypes(null, $numericPrecision);
if ($this->getPrintName() != 'NULL' && !array_key_exists($p_type, $types)) {
return false;
}
if ($p_type == self::TYPE_TOPIC && $this->getPrintName() != 'NULL') {
if (!isset($p_params['root_topic_id']) && !is_numeric($p_params['root_topic_id'])) {
return false;
}
$rootTopicId = (int) $p_params['root_topic_id'];
$queryStr2 = "INSERT INTO TopicFields (ArticleType, FieldName, RootTopicId) " . "VALUES (" . $g_ado_db->escape($this->m_data['type_name']) . ", " . $g_ado_db->escape($this->m_data['field_name']) . ", '{$rootTopicId}')";
if (!$g_ado_db->Execute($queryStr2)) {
return false;
}
}
if ($this->getPrintName() != 'NULL') {
$queryStr = "ALTER TABLE `X" . $this->m_data['type_name'] . "` ADD COLUMN `" . $this->getName() . '` ' . $types[$p_type];
$success = $g_ado_db->Execute($queryStr);
}
if ($this->getPrintName() == 'NULL' || $success) {
$data = array();
if ($this->getPrintName() != 'NULL') {
if ($p_type == self::TYPE_BODY && isset($p_params['is_content'])) {
$data['is_content_field'] = (int) $p_params['is_content'];
}
if ($p_type == self::TYPE_BODY && isset($p_params['editor_size'])) {
$data['field_type_param'] = 'editor_size=' . $p_params['editor_size'];
}
if ($p_type == self::TYPE_NUMERIC && isset($p_params['precision'])) {
$data['field_type_param'] = 'precision=' . (int) $p_params['precision'];
}
if ($p_type == self::TYPE_TEXT && isset($p_params['maxsize'])) {
$data['max_size'] = (int) $p_params['maxsize'];
}
$data['show_in_editor'] = (int) $p_params['show_in_editor'];
$data['field_type'] = $p_type;
$data['field_weight'] = $this->getNextOrder();
}
$success = parent::create($data);
}
if ($success) {
if ($p_type == self::TYPE_COMPLEX_DATE && isset($p_params['event_color'])) {
$success = $this->setColor($p_params['event_color']);
}
}
if ($success) {
CampCache::singleton()->clear('user');
}
return $success;
}