ArticleTypeField::setType PHP Méthode

setType() public méthode

Changes the type of the field
public setType ( $p_type )
    public function setType($p_type)
    {
        global $g_ado_db;
        $p_type = strtolower($p_type);
        $types = self::DatabaseTypes();
        if (!array_key_exists($p_type, $types)) {
            return false;
        }
        if ($this->getType() == $p_type) {
            return true;
        }
        if ($this->getType() == self::TYPE_TOPIC) {
            $queryStr = "DELETE FROM TopicFields WHERE ArticleType = " . $g_ado_db->escape($this->m_data['type_name']) . " AND FieldName = " . $g_ado_db->escape($this->m_data['field_name']);
            if (!$g_ado_db->Execute($queryStr)) {
                return false;
            }
        }
        $queryStr = "ALTER TABLE `X" . $this->m_data['type_name'] . "` MODIFY `" . $this->getName() . '` ' . $types[$p_type];
        $success = $g_ado_db->Execute($queryStr);
        if ($success) {
            $this->setProperty('field_type_param', null);
            $success = $this->setProperty('field_type', $p_type);
            $this->m_rootTopicId = null;
        }
        return $success;
    }

Usage Example

Exemple #1
0
$articleTypeName = Input::Get('f_article_type');
$fieldName = trim(Input::Get('f_field_name'));
$fieldType = trim(Input::Get('f_article_field_type'));
$field = new ArticleTypeField($articleTypeName, $fieldName);
$correct = true;
$errorMsgs = array();
if (!$field->exists()) {
    $errorMsgs[] = $translator->trans('The field $1 does not exist.', array('$1' => '<B>' . urlencode($fieldName) . '</B>'), 'article_type_fields');
    $correct = false;
}
if (array_search($fieldType, $field->getConvertibleToTypes()) === false) {
    $errorMsgs[] = $translator->trans('Can not convert the field $1 from $2 to type $3.', array('$1' => $fieldName, '$2' => $field->getType(), '$3' => $fieldType), 'article_type_fields');
    $correct = false;
}
if ($correct) {
    $field->setType($fieldType);
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $cacheService->clearNamespace('article_type');
    camp_html_goto_page("/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
}
$crumbs = array();
$crumbs[] = array($translator->trans('Configure'), "");
$crumbs[] = array($translator->trans('Article Types'), "/{$ADMIN}/article_types/");
$crumbs[] = array($articleTypeName, '');
$crumbs[] = array($translator->trans("Article type fields", array(), 'article_type_fields'), "/{$ADMIN}/article_types/fields/?f_article_type=" . urlencode($articleTypeName));
$crumbs[] = array($translator->trans("Adding new field", array(), 'article_type_fields'), "");
echo camp_html_breadcrumbs($crumbs);
?>

<P>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="8" class="message_box">