Added specific treatment for very detailed situations about multiple relations
Esse commit está contido em:
@@ -13,7 +13,7 @@
|
||||
<script>
|
||||
function setLoading()
|
||||
{
|
||||
document.getElementById('result').innerHTML= "<img src='gif-loading.gif' />";
|
||||
document.getElementById('result').innerHTML= " <img src='loading_animation.gif' /><br/>Loading...";
|
||||
}
|
||||
|
||||
function autenticate(){
|
||||
|
||||
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 12 KiB |
@@ -16,15 +16,38 @@
|
||||
private $refTo= Array();
|
||||
private $refBy= Array();
|
||||
|
||||
/**
|
||||
* Gets the array of entities which are referred by this entity.
|
||||
* @return Array
|
||||
*/
|
||||
public function &getRefTo()
|
||||
{
|
||||
return $this->refTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of the entities which point to this entity.
|
||||
* @return Array
|
||||
*/
|
||||
public function &getRefBy()
|
||||
{
|
||||
return $this->refBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the entity has a hardKey, or only weakKeys.
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasHardKey()
|
||||
{
|
||||
foreach($this->pks as &$pk)
|
||||
{
|
||||
if($pk->key === true)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the definition describes an entity or not
|
||||
*
|
||||
@@ -46,8 +69,6 @@
|
||||
public function addProperty(MindProperty $property)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
//if($property->key && $_MIND->defaults['add_pk_prefix_to_all_keys'])
|
||||
// $property->setName($_MIND->defaults['pk_prefix'].$property->name);
|
||||
$this->properties[$property->name]= $property;
|
||||
if($property->key)
|
||||
$this->pks[$property->name]= $property;
|
||||
|
||||
@@ -17,11 +17,18 @@
|
||||
public $refTo = false;
|
||||
public $refBy = Array();
|
||||
public $key = false;
|
||||
public $comment = false;
|
||||
public $comment = false;
|
||||
|
||||
/**
|
||||
* Sets the entity and property the current property is referred to.
|
||||
* @param MindEntity $entity
|
||||
* @param MindProperty $prop
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setRefTo(MindEntity $entity, MindProperty $prop)
|
||||
{
|
||||
$this->refTo= Array($entity, $prop);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +89,6 @@
|
||||
{
|
||||
//TODO: Darwin::add($this->type);
|
||||
Darwin::addDoubt($this->type, 'dataType');
|
||||
echo "UNKNOWN TYPE ".$this->type."...for a while";
|
||||
return false;
|
||||
}
|
||||
return $this;
|
||||
@@ -131,6 +137,16 @@
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property as a weak key
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setAsWeakKey()
|
||||
{
|
||||
$this->key= 'weak';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the string sent indicates that it is about a property
|
||||
* @param String $definition
|
||||
|
||||
@@ -219,7 +219,6 @@ abstract class Analysis {
|
||||
* it means it is the second entity on the
|
||||
* instruction, so, it is a relation between entities
|
||||
*/
|
||||
|
||||
self::addRelationToFocused(self::$entities[$word],
|
||||
$linkType,
|
||||
$linkVerb,
|
||||
|
||||
@@ -202,9 +202,6 @@ class Analyst extends Analysis {
|
||||
*/
|
||||
public static function sweep($matches)
|
||||
{
|
||||
// let's clear the Analyst memory as it uses static properties
|
||||
//self::reset();
|
||||
|
||||
// now we gotta analyze each valid expression
|
||||
foreach($matches as $found)
|
||||
{
|
||||
|
||||
@@ -178,7 +178,6 @@ abstract class Normal {
|
||||
while($rel= current(Analyst::$relations))
|
||||
{
|
||||
next(Analyst::$relations);
|
||||
|
||||
$relName = $rel->name;
|
||||
$relOtherName= $rel->rel->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
@@ -207,7 +206,14 @@ abstract class Normal {
|
||||
Analyst::unsetRelation($otherRel);
|
||||
}
|
||||
}else{
|
||||
self::$oneByN[]= &Analyst::$relations[$rel->name];
|
||||
if($rel->max == 1)
|
||||
{
|
||||
$tmpFocus= $rel->focus;
|
||||
$rel->setFocus($rel->rel);
|
||||
$rel->setRel($tmpFocus);
|
||||
self::$oneByN[]= &Analyst::$relations[$rel->name];
|
||||
}else
|
||||
self::$oneByN[]= &Analyst::$relations[$rel->name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
public static $tmpEntities = Array();
|
||||
public static $tmpRelations = Array();
|
||||
public static $linkedTables = Array();
|
||||
|
||||
/**
|
||||
* Redirects all the relations between entities.
|
||||
@@ -200,77 +201,58 @@
|
||||
|
||||
foreach($pointed->pks as &$pk)
|
||||
{
|
||||
$propName= $fkPrefix.preg_replace("/^".$pkPrefix."/",
|
||||
if($pk->key !== true)
|
||||
continue;
|
||||
$tmpName= $pk->name;
|
||||
$propName= $fkPrefix.preg_replace("/^".$pkPrefix."|".$fkPrefix."/",
|
||||
'',
|
||||
$pk->name);
|
||||
$tmpName);
|
||||
$entity= &$relation->rel;
|
||||
|
||||
if($entity->linkTable)
|
||||
// we will mark the linkTables
|
||||
if($pointed->linkTable)
|
||||
{
|
||||
$pkToRemove= $pkPrefix.$entity->name;
|
||||
if($entity->hasProperty($pkToRemove))
|
||||
$entity->removeProperty($pkToRemove);
|
||||
$refTo= $entity->getRefTo();
|
||||
|
||||
if(
|
||||
(
|
||||
!in_array($pointed->name, $entity->linkTable)
|
||||
&&
|
||||
$relation->max == QUANTIFIER_MAX_MAX
|
||||
)
|
||||
)
|
||||
self::$linkedTables[$pointed->name]= &$pointed;
|
||||
}elseif($entity->linkTable)
|
||||
{
|
||||
$p= new MindProperty();
|
||||
$p ->setName($_MIND->defaults['counter_col'])
|
||||
->setRequired(true)
|
||||
->setType('int')
|
||||
->comment= Mind::$l10n->getMessage('additionalCounterCol');
|
||||
$entity->addProperty($p);
|
||||
self::$linkedTables[$entity->name]= &$entity;
|
||||
}
|
||||
}elseif($pointed->linkTable &&
|
||||
$relation->max == QUANTIFIER_MAX_MIN)
|
||||
{
|
||||
echo $pointed->name." - ".$entity->name."\n";
|
||||
}
|
||||
/*if($pointed->linkTable)
|
||||
{
|
||||
if($relation->max == QUANTIFIER_MAX_MIN)
|
||||
{
|
||||
echo $pointed->name." <<< ".$entity->name."\n";
|
||||
|
||||
$fkToRemove= $fkPrefix.$pointed->name;
|
||||
echo $fkToRemove."\n";
|
||||
if($entity->hasProperty($fkToRemove))
|
||||
$entity->removeProperty($fkToRemove);
|
||||
}
|
||||
$refTo= $pointed->getRefTo();
|
||||
|
||||
if(!in_array($pointed->name, $pointed->linkTable) &&
|
||||
$relation->max == QUANTIFIER_MAX_MAX)
|
||||
{
|
||||
|
||||
$p= new MindProperty();
|
||||
$p ->setName($_MIND->defaults['counter_col'])
|
||||
->setRequired(true)
|
||||
->setType('int')
|
||||
->comment= Mind::$l10n->getMessage('additionalCounterCol');
|
||||
$pointed->addProperty($p);
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
// we've got to treat the repeated properties
|
||||
if($entity->hasProperty($propName)
|
||||
&&
|
||||
$entity->properties[$propName]->refTo)
|
||||
{
|
||||
$propName= $fkPrefix.$pointed->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$pk->name;
|
||||
}
|
||||
|
||||
// if there ain't not property with that name already
|
||||
if(!$entity->hasProperty($propName))
|
||||
{
|
||||
// let's create it
|
||||
$fk= new MindProperty();
|
||||
$fk ->setName($propName)
|
||||
->setRequired(true)
|
||||
//->setAsKey()
|
||||
->setType('int')
|
||||
->setRefTo($relation->focus, $pk);
|
||||
if($relation->uniqueRef)
|
||||
$fk->setAsKey();
|
||||
{
|
||||
if(!$entity->linkTable||
|
||||
($entity->linkTable && $entity->hasHardKey())
|
||||
||
|
||||
($entity->linkTable && sizeof($entity->getRefBy())==0)
|
||||
)
|
||||
{
|
||||
$fk->setAsWeakKey();
|
||||
}else{
|
||||
$fk->setAsKey();
|
||||
}
|
||||
}
|
||||
$entity->addProperty($fk);
|
||||
}else{
|
||||
// otherwise, we simply use/change the existing one
|
||||
$entity ->properties[$propName]
|
||||
->setRefTo($relation->focus, $pk);
|
||||
if($relation->uniqueRef)
|
||||
@@ -290,8 +272,8 @@
|
||||
foreach(Analyst::$entities as &$entity)
|
||||
{
|
||||
if( sizeof($entity->pks) == 0
|
||||
||
|
||||
sizeof($entity->properties) != sizeof($entity->pks))
|
||||
&&
|
||||
(!$entity->linkTable || sizeof($entity->getRefBy())>0 ))
|
||||
{
|
||||
$propName= $pkPrefix.$entity->name;
|
||||
if(!$entity->hasProperty($propName))
|
||||
@@ -310,6 +292,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is calledto execute any needed adjust.
|
||||
*/
|
||||
public static function fixOneByNRel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Will set the primary and foreign keys to entities.
|
||||
*/
|
||||
@@ -319,8 +308,8 @@
|
||||
Analyst::$entities= array_filter(Analyst::$entities);
|
||||
Analyst::$relations= array_filter(Analyst::$relations);
|
||||
|
||||
self::addPks();
|
||||
self::addFks();
|
||||
self::addPks(); // OK
|
||||
self::addFks(); // OK
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,16 +318,18 @@
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$oneByOne = false;
|
||||
self::$oneByOne = Array();
|
||||
self::$nByN = false;
|
||||
self::$nByN = Array();
|
||||
self::$oneByN = false;
|
||||
self::$oneByN = Array();
|
||||
self::$focus = false;
|
||||
self::$focus = Array();
|
||||
self::$predicate= false;
|
||||
self::$predicate= Array();
|
||||
self::$oneByOne = false;
|
||||
self::$oneByOne = Array();
|
||||
self::$nByN = false;
|
||||
self::$nByN = Array();
|
||||
self::$oneByN = false;
|
||||
self::$oneByN = Array();
|
||||
self::$focus = false;
|
||||
self::$focus = Array();
|
||||
self::$predicate = false;
|
||||
self::$predicate = Array();
|
||||
self::$linkedTables= false;
|
||||
self::$linkedTables= Array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,6 +363,7 @@
|
||||
self::separateByRelationQuantifiers();
|
||||
self::fixOneByOneRel();
|
||||
self::fixNByNRel();
|
||||
self::fixOneByNRel();
|
||||
self::setUpKeys();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,21 @@
|
||||
professor tem muitos aluno e todo aluno pode ter vários professores.
|
||||
aluno_professor tem muitas aulas.
|
||||
aulas tem vários aluno-professor.
|
||||
aula tem data:data().
|
||||
|
||||
/*
|
||||
cada igreja tem um padre.
|
||||
cada padre tem uma igreja.
|
||||
padre tem nome:varchar.
|
||||
|
||||
@import drafts/draft1.
|
||||
@ import drafts/draft1.
|
||||
|
||||
igreja tem nome:varchar.
|
||||
|
||||
@import drafts/draft2
|
||||
@ import drafts/draft2
|
||||
|
||||
igreja tem data:data.
|
||||
|
||||
*/
|
||||
|
||||
/*A universidade tem muitos alunos. Aluno tem nome:varchar, matrícula:int,
|
||||
cpf:int e identidade:int, endereço:varchar,
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário