ArticleTypeField::isConvertibleFrom PHP Method

isConvertibleFrom() public method

Returns true if the given type can be converted to the current field type.
public isConvertibleFrom ( $p_type ) : boolean
$p_type
return boolean
    public function isConvertibleFrom($p_type)
    {
        if (is_object($p_type) && get_class($p_type) == __CLASS__) {
            if ($this->getType() == 'topic' && $p_type->getType() == 'topic') {
                return $this->getTopicTypeRootElement() == $p_type->getTopicTypeRootElement();
            }
            $p_type = $p_type->getType();
        }
        return $this->getType() == $p_type && $p_type != 'topic' || array_search($p_type, $this->getConvertibleFromTypes()) !== false;
    }

Usage Example

Ejemplo n.º 1
0
	$f_src_c[$destColumn->getPrintName()] = $tmp;
}


// Verify the merge rules
$ok = true;
$errMsgs = array();

foreach ($f_src_c as $destColumn => $srcColumn) {
	if ($srcColumn == 'NULL') {
		continue;
	}
	$destATF = new ArticleTypeField($f_dest, $destColumn);
	$srcATF = new ArticleTypeField($f_src, $srcColumn);

	if (!$destATF->isConvertibleFrom($srcATF)) {
        $errMsgs[] = getGS('Cannot merge a $1 field ($2) into a $3 field ($4).',
                            getGS($srcATF->getType()), $srcATF->getDisplayName(),
                            getGS($destATF->getType()), $destATF->getDisplayName());
        $ok = false;
	}
}

//
// if f_action is Merge, do the merge and return them to article_types/ screen (or an error)
//
if ($ok && $f_action == 'Merge') {
	if (!SecurityToken::isValid()) {
		camp_html_display_error(getGS('Invalid security token!'));
		exit;
	}