Example #1
0
 /**
  * Gibt den PHP Parameter Namen für das Relation Interface
  * 
  * das ist quasi der selbe wie der ProperytName jedoch ist dieser immer singular
  * 
  * OID => oid
  * OIDMeta => oidMeta
  * SomeClassName => someClassName
  * @return string immer in Singular und in property-kleinschreibweise
  */
 public function getParamName()
 {
     if (isset($this->paramName)) {
         return $this->paramName;
     }
     return $this->inflector->propertyName($this->getName());
 }
Example #2
0
 /**
  * Der EntityName in Plural ist eine KurzForm der Klasse in plural
  *
  * Dies ist für \tiptoi\Entities\Sound z. b. "sounds"
  */
 public function getEntityNamePlural()
 {
     return \Psc\Inflector::plural($this->getEntityName());
 }
Example #3
0
 protected function isPlural($name)
 {
     // das ist nicht so schön, aber ich hab grad keine schönere idee als eine liste aller entities zu haben (entity meta?)
     return Inflector::plural(Inflector::singular($name)) === $name;
 }
Example #4
0
 /**
  * Gibt den Namen für die Methoden des Relation Interfaces zurück
  * 
  * z.B.               wird dann verwendet als
  * OID                addOID, removeOID, getOIDs
  * OIDMeta            addOIDMeta, setOIDMeta
  * SomeClassName      addSomeClassName, removeSomeClassName, setSomeClassNames
  * usw
  *
  * @return string
  */
 public function getMethodName($singularOrPlural = 'singular')
 {
     if (!isset($singularOrPlural)) {
         $singularOrPlural = $this->getValueType() === self::COLLECTION_VALUED ? 'plural' : 'singular';
     }
     if (!isset($this->methodName)) {
         $this->methodName = array($this->getName(), Inflector::plural($this->getName()));
     }
     return $singularOrPlural === 'singular' ? $this->methodName[0] : $this->methodName[1];
 }
Example #5
0
 /**
  * Synchronisiert eine Collection eines Entities mit Entities in der Datenbank (deprecated)
  *
  * Diese Art der Synchroniserung ist deprecated, weil es mittlerweile ausgelagerte Funktionen dafür gibt
  * (siehe Psc\Doctrine\*Synchro*)
  * 
  * also es werden für die bestehenden Objekte in $entity->$collectionProperty die objekte gelöscht
  * die nicht in newCollection drin sind und die, die in $newCollection drin sind aber nicht in
  * $entity->$collectionProperty gelöscht
  * 
  * - Achtung(!): dies führt persist() auf den Entitys der Collection (also quasi andere Seite der Association) aus, wenn $this->entity nicht die Owning-Side der CollectionAssociation ist
  * - Dies führt persist für items in newCollection, die neu sind
  * 
  * Die Basis für eine erfolgreiche Synchronization ist eine $newCollection die wirklich die gleichen Objekte enthält, für die Updates gemacht werden sollen. Also vorsicht mit serialisierten Einträgen und clones
  * 
  * @param string $associationName der Name des Properties der Collection in $entity
  */
 public function synchronizeCollection($associationName, $newCollection)
 {
     if (!is_string($associationName)) {
         throw new \Psc\Exception('string erwartet: ' . Code::varInfo($associationName));
     }
     /*
         $mapping     = $coll->getMapping();
         $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']);
         $sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']);
         $id          = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner());
     */
     if ($this->entity instanceof \Psc\Doctrine\Object) {
         $entityClass = $this->entity->getDoctrineMetadata();
         // Sound
     } elseif ($this->entity instanceof \Psc\Doctrine\Entity) {
         $entityClass = $this->em->getClassMetadata($this->entity->getEntityName());
     } else {
         throw new \InvalidArgumentException('$this->entity ist von der Klasse: ' . Code::getClass($this->entity) . ' und diese ist unbekannt');
     }
     $entityAssoc = $entityClass->getAssociationMapping($associationName);
     // speakers
     $owning = $entityAssoc['isOwningSide'];
     // true
     $targetClass = $this->em->getClassMetadata($entityAssoc['targetEntity']);
     // Metadata:Speaker
     if ($owning) {
         $entityProperty = $entityAssoc['inversedBy'];
         $collectionProperty = $entityAssoc['fieldName'];
     } else {
         $entityProperty = $entityAssoc['mappedBy'];
         $collectionProperty = $entityAssoc['fieldName'];
     }
     // entityProperty = sounds
     // collectionProperty = speakers
     $getter = Code::castGetter($collectionProperty);
     //getSpeakers
     $collection = $getter($this->entity);
     // $this->entity->getSpeakers()
     $collection = Code::castCollection($collection);
     $newCollection = Code::castCollection($newCollection);
     $this->log(sprintf("synchronizeCollection '%s'", $associationName));
     $this->log('in DBCollection:');
     $this->log(DoctrineHelper::debugCollection($collection));
     $this->log(NULL);
     $this->log('in FormCollection:');
     $this->log(DoctrineHelper::debugCollection($newCollection));
     $this->log(NULL);
     $this->log('Processing:');
     /*
       Wir synchronisieren hier auf der Owning Side oder Reverse Side
       jenachdem müssen wir auf der owning oder reverse side die add + remove funktionen aufrufen
     */
     if ($owning) {
         $remove = 'remove' . ucfirst(Inflector::singular($collectionProperty));
         // removeSpeaker
         $add = 'add' . ucfirst(Inflector::singular($collectionProperty));
         // addSpeaker
     } else {
         $remove = 'remove' . ucfirst(Inflector::singular($entityProperty));
         // removeSound
         $add = 'add' . ucfirst(Inflector::singular($entityProperty));
         // addSound
     }
     $logThis = Code::getClassName($entityClass->getName());
     // @TODO hier mit reflection prüfen
     //if (!->hasMethod($remove)) {
     //  throw new \Psc\Exception('Es gibt keine '.$remove.' Methode im Entity: '.$owningEntity);
     //}
     //if (!$this->entity->hasMethod($add)) {
     //  throw new \Psc\Exception('Es gibt keine '.$add.' Methode im Entity: '.$owningEntity);
     //}
     //
     foreach ($collection->deleteDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
         if ($owning) {
             $this->entity->{$remove}($entity);
             // $sound->removeSpeaker($speaker)
         } else {
             $this->em->persist($entity);
             // $speaker persist
             $entity->{$remove}($this->entity);
             // $speaker->removeSound($sound)
         }
     }
     foreach ($collection->insertDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) {
         if ($owning) {
             $this->entity->{$add}($entity);
             $this->em->persist($entity);
         } else {
             $entity->{$add}($this->entity);
             $this->em->persist($entity);
         }
     }
 }
 /**
  * @return list(string $add, string $remove)
  */
 protected function getRelationInterface(EntityPropertyMeta $collectionMeta = NULL)
 {
     $collectionMeta = $collectionMeta ?: $this->getCollectionPropertyMeta();
     $remove = 'remove' . ucfirst(Inflector::singular($collectionMeta->getName()));
     // removeTag
     $add = 'add' . ucfirst(Inflector::singular($collectionMeta->getName()));
     // addTag
     return array($add, $remove);
 }