Exemplo n.º 1
0
 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();
     }
 }
Exemplo n.º 2
0
 public function view($id = null)
 {
     if ($id) {
         $entity = $this->entityManager->find('Concrete\\Core\\Entity\\Express\\Entity', $id);
     }
     if (isset($entity) && is_object($entity) && $entity->supportsCustomDisplayOrder()) {
         $provider = $this->app->make('Concrete\\Core\\Express\\Search\\SearchProvider', array($entity, $entity->getAttributeKeyCategory()));
         $this->set('entity', $entity);
         $list = new EntryList($entity);
         $list->sortByDisplayOrderAscending();
         $this->set('result', $provider->createSearchResultObject($provider->getCurrentColumnSet(), $list));
     } else {
         $this->redirect('/dashboard/system/express/entities');
     }
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 6
0
 public function view()
 {
     $entity = $this->entityManager->find('Concrete\\Core\\Entity\\Express\\Entity', $this->exEntityID);
     if (is_object($entity)) {
         $category = $entity->getAttributeKeyCategory();
         $list = new EntryList($entity);
         if ($this->displayLimit > 0) {
             $list->setItemsPerPage(intval($this->displayLimit));
         }
         $set = unserialize($this->columns);
         $defaultSortColumn = $set->getDefaultSortColumn();
         if ($this->request->query->has($list->getQuerySortDirectionParameter())) {
             $direction = $this->request->query->get($list->getQuerySortDirectionParameter());
         } else {
             $direction = $defaultSortColumn->getColumnDefaultSortDirection();
         }
         if ($this->request->query->has($list->getQuerySortColumnParameter())) {
             $value = $this->request->query->get($list->getQuerySortColumnParameter());
             $column = $entity->getResultColumnSet();
             $value = $column->getColumnByKey($value);
             if (is_object($value)) {
                 $list->sanitizedSortBy($value->getColumnKey(), $direction);
             }
         } else {
             $list->sanitizedSortBy($defaultSortColumn->getColumnKey(), $direction);
         }
         if ($this->request->query->has('keywords') && $this->enableSearch) {
             $list->filterByKeywords($this->request->query->get('keywords'));
         }
         $tableSearchProperties = array();
         $searchPropertiesSelected = (array) json_decode($this->searchProperties);
         foreach ($searchPropertiesSelected as $akID) {
             $ak = $category->getAttributeKeyByID($akID);
             if (is_object($ak)) {
                 $tableSearchProperties[] = $ak;
                 $type = $ak->getAttributeType();
                 $cnt = $type->getController();
                 $cnt->setRequestArray($_REQUEST);
                 $cnt->setAttributeKey($ak);
                 $cnt->searchForm($list);
             }
         }
         $result = new Result($set, $list);
         $pagination = $list->getPagination();
         if ($pagination->getTotalPages() > 1) {
             $pagination = $pagination->renderDefaultView();
             $this->set('pagination', $pagination);
         }
         $this->set('list', $list);
         $this->set('result', $result);
         $this->set('entity', $entity);
         $this->set('tableSearchProperties', $tableSearchProperties);
         $this->set('detailPage', $this->getDetailPageObject());
     }
 }