public function getList($entityHandle, $asObject = false)
 {
     $entity = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Entity')->findOneByHandle($entityHandle);
     $list = new EntryList($entity);
     if ($asObject) {
         return $list;
     } else {
         return $list->getResults();
     }
 }
 public function preRemove(Entity $entity, LifecycleEventArgs $event)
 {
     $em = $event->getEntityManager();
     $entity->setDefaultEditForm(null);
     $entity->setDefaultViewForm(null);
     $em->persist($entity);
     foreach ($entity->getForms() as $form) {
         $em->remove($form);
     }
     $em->flush();
     // Delete the keys
     $category = $entity->getAttributeKeyCategory();
     foreach ($category->getList() as $key) {
         $em->remove($key);
     }
     $em->flush();
     $list = new EntryList($entity);
     foreach ($list->getResults() as $result) {
         $em->remove($result);
     }
     $em->flush();
 }
Exemple #3
0
 public function associateOneToMany(Association $association, Entry $entry, $associatedEntries)
 {
     // First create the owning entry association
     $manyAssociation = $entry->getAssociation($association->getTargetPropertyName());
     if (!is_object($manyAssociation)) {
         $manyAssociation = new Entry\ManyAssociation();
         $manyAssociation->setAssociation($association);
         $manyAssociation->setEntry($entry);
     }
     $manyAssociation->setSelectedEntries($associatedEntries);
     $this->entityManager->persist($manyAssociation);
     $this->entityManager->flush();
     // Now, we go to the inverse side, and we get all possible entries. We loop through them to see whether they're in the associated entries array
     $entity = $association->getTargetEntity();
     $list = new EntryList($entity);
     $possibleResults = $list->getResults();
     foreach ($possibleResults as $possibleResult) {
         $oneAssociation = $possibleResult->getAssociation($association->getInversedByPropertyName());
         if (!is_object($oneAssociation)) {
             $inversedAssocation = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Association')->findOneBy(['target_property_name' => $association->getInversedByPropertyName()]);
             $oneAssociation = new Entry\OneAssociation();
             $oneAssociation->setAssociation($inversedAssocation);
         } else {
             // We clear out the one association
             $oneAssociation->getSelectedEntriesCollection()->remove(0);
         }
         $oneAssociation->setEntry($possibleResult);
         if (in_array($possibleResult, $associatedEntries)) {
             $oneAssociation->setSelectedEntry($entry);
             $this->entityManager->persist($oneAssociation);
         } else {
             // It's not in the array, which means we have to remove it from
             // the inverse one assocation
             $this->entityManager->remove($oneAssociation);
         }
     }
     $this->entityManager->flush();
 }
 /**
  * @param ContextInterface $context
  * @param AssociationControl $control
  * @return string
  */
 public function render(ContextInterface $context, Control $control, Entry $entry = null)
 {
     $element = $this->getFormFieldElement($control);
     // Is this an owning entity with display order? If so, we render a separate reordering control
     $association = $control->getAssociation();
     if ($association->isOwningAssociation()) {
         if ($association->getTargetEntity()->supportsCustomDisplayOrder()) {
             $element = 'select_multiple_reorder';
         } else {
             return false;
         }
     }
     $template = new Template('association/' . $element);
     $entity = $association->getTargetEntity();
     $list = new EntryList($entity);
     $entities = $list->getResults();
     $view = new EntityPropertyControlView($context);
     if (is_object($entry)) {
         $related = $entry->getAssociations();
         foreach ($related as $relatedAssociation) {
             if ($relatedAssociation->getAssociation()->getID() == $association->getID()) {
                 $view->addScopeItem('selectedEntities', $relatedAssociation->getSelectedEntries());
             }
         }
     } else {
         // Is this an owned entity? In which case we get the association from the owning entity
         $renderer = $context->getFormRenderer();
         $form = $renderer->getForm();
         if ($form instanceof OwnedEntityForm) {
             $view->addScopeItem('selectedEntities', array($form->getOwningEntry()));
         }
     }
     $view->addScopeItem('entities', $entities);
     $view->addScopeItem('control', $control);
     $view->addScopeItem('formatter', $association->getFormatter());
     return $view->render($control, $context->getTemplateLocator($template)->getFile());
 }