An error occurred while loading the file. Please try again.
-
Guillaume Perréal authorede721fb6a
<?php
/*
* © 2016 IRSTEA
* Guillaume Perréal <guillaume.perreal@irstea.fr>
* Tous droits réservés.
*/
namespace Irstea\PlantUmlBundle\Doctrine;
use Doctrine\ORM\Mapping\ClassMetadata;
use Irstea\PlantUmlBundle\Model\Arrow\BaseArrow;
use Irstea\PlantUmlBundle\Model\ClassVisitorInterface;
use Irstea\PlantUmlBundle\Model\NodeInterface;
use ReflectionClass;
/**
* Description of RelationDecorator
*
* @author Guillaume Perréal <guillaume.perreal@irstea.fr>
*/
class AssociationDecorator extends AbstractDoctrineDecorator
{
protected function decorateEntity(ClassMetadata $metadata, NodeInterface $node, ClassVisitorInterface $visitor)
{
$associations = $metadata->getAssociationMappings();
if(empty($associations)) {
return;
}
foreach($associations as $association) {
$this->visitAssociation($node, $visitor, $association);
}
}
protected function visitAssociation(NodeInterface $node, ClassVisitorInterface $visitor, array $association)
{
if (!$association['isOwningSide']) {
return;
}
$target = $visitor->visitClass($association['targetEntity']);
if ($target === false) {
return;
}
$link = "-->";
if ($association["isCascadeRemove"]) {
$link = "o".$link;
}
$leftLabel = "";
$rightLabel = "";
switch($association["type"]) {
case ClassMetadata::ONE_TO_ONE:
$leftLabel = '1';
$rightLabel = '1';
break;
case ClassMetadata::ONE_TO_MANY:
$leftLabel = '1';
$rightLabel = '*';
break;
case ClassMetadata::MANY_TO_MANY:
$leftLabel = '*';
$rightLabel = '*';
break;
case ClassMetadata::MANY_TO_ONE:
$leftLabel = '*';
$rightLabel = '1';
break;
717273747576777879
}
$link = sprintf('"%s" %s "%s"', $leftLabel, $link, $rightLabel);
$node->addArrow(
new BaseArrow($node, $target, $link, $association["fieldName"]." >")
);
}
}