ArticleTypeField::create PHP Method

create() public method

Create a column in the table.
public create ( string $p_type = null, array $p_params = [] )
$p_type string Can be one of: 'text', 'date', 'body', 'switch', 'numeric'.
$p_params array
    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;
    }

Usage Example

Esempio n. 1
0
	/**
	 * Create a new Article Type.  Creates a new table in the database.
	 * @return boolean
	 */
	public function create()
	{
		global $g_ado_db;

		if (strlen($this->m_dbTableName) <= 1) {
			return false;
		}
		$queryStr = "CREATE TABLE `".$this->m_dbTableName."` (\n"
                  . "    NrArticle INT UNSIGNED NOT NULL,\n"
                  . "    IdLanguage INT UNSIGNED NOT NULL,\n"
                  . "    PRIMARY KEY(NrArticle, IdLanguage)\n"
                  . ") DEFAULT CHARSET=utf8";
		$success = $g_ado_db->Execute($queryStr);

		if ($success) {
			$metadata = new ArticleTypeField($this->getTypeName(), 'NULL');
			$success = $metadata->create(null);
		} else {
			return false;
		}

		if ($success) {
			if (function_exists("camp_load_translation_strings")) {
				camp_load_translation_strings("api");
			}
			$logtext = getGS('The article type "$1" has been added.', $this->m_name);
	    	Log::Message($logtext, null, 61);
            CampCache::singleton()->clear('user');
		} else {
			$queryStr = "DROP TABLE `" . $this->m_dbTableName . "`";
			$result = $g_ado_db->Execute($queryStr);
		}

		return $success;
	} // fn create
All Usage Examples Of ArticleTypeField::create