Esempio n. 1
0
 public function addEntry(Entity $entity)
 {
     $entry = new Entry();
     $entry->setEntity($entity);
     if ($entity->supportsCustomDisplayOrder()) {
         $entry->setEntryDisplayOrder($this->getNewDisplayOrder($entity));
     }
     $this->entityManager->persist($entry);
     $this->entityManager->flush();
     return $entry;
 }
 public function getEntryDisplayName(AssociationControl $control, Entry $entry)
 {
     // Do we have a custom display mask? If so, we try to use that
     if ($control->getAssociationEntityLabelMask()) {
         try {
             return preg_replace_callback('/%(.*?)%/i', function ($matches) use($entry) {
                 return $entry->getAttribute($matches[1]);
             }, $control->getAssociationEntityLabelMask());
         } catch (\Exception $e) {
         }
     }
     $targetEntity = $this->association->getTargetEntity();
     $attribute = $targetEntity->getAttributes()[0];
     if (is_object($attribute)) {
         return $entry->getAttribute($attribute);
     }
 }
 /**
  * @param ContextInterface $context
  * @param AssociationControl $control
  * @param Entry|null $entry
  * @return string
  */
 public function render(ContextInterface $context, Control $control, Entry $entry = null)
 {
     $template = new Template('association');
     $association = $control->getAssociation();
     /*
      * @var $association \Concrete\Core\Entity\Express\Association
      */
     $related = $entry->getAssociations();
     $view = new EntityPropertyControlView($context);
     foreach ($related as $relatedAssociation) {
         if ($relatedAssociation->getAssociation()->getID() == $association->getID()) {
             $view->addScopeItem('entities', $relatedAssociation->getSelectedEntries());
         }
     }
     $view->addScopeItem('control', $control);
     $view->addScopeItem('formatter', $association->getFormatter());
     return $view->render($control, $context->getTemplateLocator($template)->getFile());
 }
    public function selectEntry(Entity $entity, $fieldName, Entry $entry = null)
    {
        $v = \View::getInstance();
        $v->requireAsset('core/express');
        $args['entityID'] = $entity->getID();
        $args['inputName'] = $fieldName;
        if ($entry) {
            $args['exEntryID'] = $entry->getID();
        }
        $args = json_encode($args);
        $identifier = new \Concrete\Core\Utility\Service\Identifier();
        $identifier = $identifier->getString(32);
        $html = <<<EOL
        <div data-express-entry-selector="{$identifier}"></div>
        <script type="text/javascript">
        \$(function() {
            \$('[data-express-entry-selector={$identifier}]').concreteExpressEntrySelector({$args});
        });
        </script>
EOL;
        return $html;
    }
 public function saveFromRequest(Control $control, Entry $entry, Request $request)
 {
     $associatedEntries = $this->getAssociatedEntriesFromRequest($control, $request);
     $association = $control->getAssociation();
     if ($association->isOwningAssociation()) {
         // If the owned entity supports display order, we save display order here. Otherwise we return.
         if ($association->getTargetEntity()->supportsCustomDisplayOrder()) {
             $i = 0;
             foreach ($associatedEntries as $entry) {
                 $entry->setEntryDisplayOrder($i);
                 $this->entityManager->persist($entry);
                 $i++;
             }
             $this->entityManager->flush();
         }
         return;
     }
     if (count($associatedEntries)) {
         $this->applier->associateOneToMany($control->getAssociation(), $entry, $associatedEntries);
     } else {
         $this->applier->removeAssociation($control->getAssociation(), $entry);
     }
 }
Esempio n. 6
0
 public static function getDisplayOrder(Entry $entry)
 {
     return $entry->getEntryDisplayOrder();
 }
 protected function getViewEntryURL(Entry $entry)
 {
     return \URL::to($this->getPageObject()->getCollectionPath(), 'view_entry', $entry->getID());
 }
Esempio n. 8
0
 public function removeAssociation(Association $association, Entry $entry)
 {
     $entryAssociation = $entry->getAssociation($association);
     if ($entryAssociation) {
         $inversedAssocation = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Association')->findOneBy(['target_property_name' => $association->getInversedByPropertyName()]);
         $associatedEntries = $entryAssociation->getSelectedEntriesCollection();
         foreach ($associatedEntries as $associatedEntry) {
             $associatedEntryAssociation = $associatedEntry->getAssociation($inversedAssocation);
             if (is_object($associatedEntryAssociation)) {
                 $associatedEntryAssociation->removeSelectedEntry($entry);
                 $this->entityManager->persist($associatedEntryAssociation);
             }
         }
         $this->entityManager->remove($entryAssociation);
         $this->entityManager->flush();
     }
 }
Esempio n. 9
0
 public function removeSelectedEntry(Entry $entry)
 {
     foreach ($this->getSelectedEntries() as $selectedEntry) {
         if ($selectedEntry->getId() == $entry->getID()) {
             $this->selectedEntries->removeElement($selectedEntry);
         }
     }
 }