Example #1
0
 /**
  * Process form
  *
  * @param  Task $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Task $entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
     $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
     if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
         $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'owner', ['read_only' => true]);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             } elseif ($targetEntityClass && $action === 'activity') {
                 // if we don't have "contexts" form field
                 // we should save association between activity and target manually
                 $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId));
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  *
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $originalChildren = new ArrayCollection();
         foreach ($entity->getChildEvents() as $childEvent) {
             $originalChildren->add($childEvent);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->ensureCalendarSet($entity);
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * Handle onFlush event
  *
  * @param OnFlushEventArgs $event
  */
 public function handleOnFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     $newEntities = $uow->getScheduledEntityInsertions();
     foreach ($newEntities as $entity) {
         if ($entity instanceof Call) {
             $hasChanges = $this->activityManager->addActivityTarget($entity, $entity->getOwner());
             // recompute change set if needed
             if ($hasChanges) {
                 $uow->computeChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
             }
         }
     }
     $changedEntities = $uow->getScheduledEntityUpdates();
     foreach ($changedEntities as $entity) {
         if ($entity instanceof Call) {
             $hasChanges = false;
             $changeSet = $uow->getEntityChangeSet($entity);
             foreach ($changeSet as $field => $values) {
                 if ($field === 'owner') {
                     list($oldValue, $newValue) = $values;
                     if ($oldValue !== $newValue) {
                         $hasChanges |= $this->activityManager->replaceActivityTarget($entity, $oldValue, $newValue);
                     }
                     break;
                 }
             }
             // recompute change set if needed
             if ($hasChanges) {
                 $uow->computeChangeSet($em->getClassMetadata(ClassUtils::getClass($entity)), $entity);
             }
         }
     }
 }
 /**
  * Returns the context for the given email
  *
  * @param Email $email
  *
  * @return array
  */
 public function getEmailContext(Email $email)
 {
     $criteria = Criteria::create();
     $criteria->andWhere(Criteria::expr()->eq('id', $email->getId()));
     $qb = $this->activityManager->getActivityTargetsQueryBuilder($this->class, $criteria);
     if (null === $qb) {
         return [];
     }
     $result = $qb->getQuery()->getResult();
     if (empty($result)) {
         return $result;
     }
     $currentUser = $this->securityFacade->getLoggedUser();
     $currentUserClass = ClassUtils::getClass($currentUser);
     $currentUserId = $currentUser->getId();
     $result = array_values(array_filter($result, function ($item) use($currentUserClass, $currentUserId) {
         return !($item['entity'] === $currentUserClass && $item['id'] == $currentUserId);
     }));
     foreach ($result as &$item) {
         $route = $this->configManager->getEntityMetadata($item['entity'])->getRoute();
         $item['entityId'] = $email->getId();
         $item['targetId'] = $item['id'];
         $item['targetClassName'] = $this->entityClassNameHelper->getUrlSafeClassName($item['entity']);
         $item['icon'] = $this->configManager->getProvider('entity')->getConfig($item['entity'])->get('icon');
         $item['link'] = $route ? $this->router->generate($route, ['id' => $item['id']]) : null;
         unset($item['id'], $item['entity']);
     }
     return $result;
 }
 /**
  * Get search aliases for specified entity class(es). By default returns all associated entities.
  *
  * @param string[] $entities
  *
  * @return string[]
  */
 protected function getSearchAliases(array $entities)
 {
     if (empty($entities)) {
         $entities = array_flip($this->activityManager->getActivityTargets($this->class));
     }
     return array_values($this->searchIndexer->getEntityAliases($entities));
 }
 /**
  * {@inheritdoc}
  */
 public function getWidgets($object)
 {
     $result = [];
     $entityClass = ClassUtils::getClass($object);
     $items = $this->activityManager->getActivityActions($entityClass);
     foreach ($items as $item) {
         $buttonWidget = $this->placeholderProvider->getItem($item['button_widget'], ['entity' => $object]);
         if ($buttonWidget) {
             $widget = ['name' => $item['button_widget'], 'button' => $buttonWidget];
             if (!empty($item['link_widget'])) {
                 $linkWidget = $this->placeholderProvider->getItem($item['link_widget'], ['entity' => $object]);
                 if ($linkWidget) {
                     $widget['link'] = $linkWidget;
                 }
             }
             if (isset($item['group'])) {
                 $widget['group'] = $item['group'];
             }
             if (isset($item['priority'])) {
                 $widget['priority'] = $item['priority'];
             }
             $result[] = $widget;
         }
     }
     return $result;
 }
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @throws \LogicException
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     if (!$entity->getCalendar()) {
         if ($this->securityFacade->getLoggedUser() && $this->securityFacade->getOrganization()) {
             /** @var Calendar $defaultCalendar */
             $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($this->securityFacade->getLoggedUser()->getId(), $this->securityFacade->getOrganization()->getId());
             $entity->setCalendar($defaultCalendar);
         } else {
             throw new \LogicException('Current user did not define');
         }
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
             if ($targetEntityClass) {
                 $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
                 $targetEntity = $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId);
                 $action = $this->entityRoutingHelper->getAction($this->request);
                 if ($action === 'activity') {
                     $this->activityManager->addActivityTarget($entity, $targetEntity);
                 }
                 if ($action === 'assign' && $targetEntity instanceof User && $targetEntityId !== $this->securityFacade->getLoggedUserId()) {
                     /** @var Calendar $defaultCalendar */
                     $defaultCalendar = $this->manager->getRepository('OroCalendarBundle:Calendar')->findDefaultCalendar($targetEntity->getId(), $targetEntity->getOrganization()->getId());
                     $entity->setCalendar($defaultCalendar);
                 }
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 protected function onSuccess($entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     if ($action === 'activity') {
         $this->activityManager->addActivityTarget($entity, $this->getTargetEntity());
     }
     parent::onSuccess($entity);
 }
 /**
  * {@inheritdoc}
  */
 protected function onSuccess($entity)
 {
     /** @var ActivityInterface $activity */
     $activity = $entity['activity'];
     /** @var ArrayCollection $relations */
     $relations = $entity['relations'];
     $this->activityManager->addActivityTargets($activity, $relations->toArray());
     $this->entityManager->flush();
 }
 /**
  * @param StrategyEvent $event
  */
 public function onProcessAfter(StrategyEvent $event)
 {
     $entity = $event->getEntity();
     if ($entity instanceof GitHubIssue && $entity->getAssignedTo()) {
         // Add activity to the related Partner entity
         /** @var GitHubAccount $githubAccount */
         $githubAccount = $entity->getAssignedTo();
         $this->activityManager->addActivityTarget($entity, $githubAccount->getPartner());
         // Populate entity owner from the Integration settings
         $this->defaultOwnerHelper->populateChannelOwner($entity, $entity->getChannel());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getListQueryBuilder($limit = 10, $page = 1, $criteria = [], $orderBy = null, $joins = [])
 {
     $currentUser = $this->securityTokenStorage->getToken()->getUser();
     $userClass = ClassUtils::getClass($currentUser);
     return $this->activityManager->getActivityTargetsQueryBuilder($this->class, $criteria, $joins, $limit, $page, $orderBy, function (QueryBuilder $qb, $targetEntityClass) use($currentUser, $userClass) {
         if ($targetEntityClass === $userClass) {
             // Need to exclude current user from result because of email context
             // @see Oro\Bundle\EmailBundle\Entity\Manager\EmailApiEntityManager::getEmailContext
             $qb->andWhere($qb->expr()->neq(QueryUtils::getSelectExprByAlias($qb, 'entityId'), $currentUser->getId()));
         }
     });
 }
Example #12
0
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $entityClass = $this->entityRoutingHelper->resolveEntityClass($parameters->get('entityClass'));
         $entityId = $parameters->get('entityId');
         // apply activity filter
         $this->activityManager->addFilterByTargetEntity($datasource->getQueryBuilder(), $entityClass, $entityId);
     }
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $email = $this->contextAccessor->getValue($context, $this->activityEntity);
     $targetEntity = $this->contextAccessor->getValue($context, $this->targetEntity);
     $activityList = $this->chainProvider->getActivityListEntitiesByActivityEntity($email);
     if ($activityList) {
         $this->entityManager->persist($activityList);
     }
     $result = $this->activityManager->addAssociation($email, $targetEntity);
     if ($this->attribute !== null) {
         $this->contextAccessor->setValue($context, $this->attribute, $result);
     }
 }
 /**
  * Returns the list of FQCN of all activity entities which can be associated with the current entity
  *
  * @return string[]
  */
 public function getActivityTypes()
 {
     $activityClasses = [];
     foreach ($this->activityManager->getActivityTypes() as $activityClass) {
         $targets = $this->activityManager->getActivityTargets($activityClass);
         if (isset($targets[$this->class])) {
             $activityClasses[] = $activityClass;
         }
     }
     return array_map(function ($class) {
         return ['entity' => $class];
     }, $activityClasses);
 }
 /**
  * Get search aliases for specified entity class(es). By default returns all search aliases
  * for all entities which can be associated with an activity this manager id work with.
  *
  * @param string[] $entities
  *
  * @return string[]
  */
 protected function getSearchAliases(array $entities)
 {
     if (empty($entities)) {
         $entities = array_flip($this->activityManager->getActivityTargets($this->class));
     }
     $aliases = [];
     foreach ($entities as $targetEntityClass) {
         $alias = $this->searchIndexer->getEntityAlias($targetEntityClass);
         if (null !== $alias) {
             $aliases[] = $alias;
         }
     }
     return $aliases;
 }
 /**
  * @param EntityManager $em
  * @param array $data
  * @param string $entityIdField
  *
  * @return QueryBuilder
  */
 protected function createActivityQueryBuilder(EntityManager $em, array $data, $entityIdField)
 {
     $joinField = sprintf('%s.%s', $this->activityListAlias, ExtendHelper::buildAssociationName($data['entityClassName'], ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND));
     $activityQb = $em->getRepository('OroActivityListBundle:ActivityList')->createQueryBuilder($this->activityListAlias)->select('1')->setMaxResults(1);
     $availableActivityAssociations = $this->activityManager->getActivityAssociations($data['entityClassName']);
     $availableClasses = array_map(function ($assoc) {
         return $assoc['className'];
     }, $availableActivityAssociations);
     $chosenActivities = $data['activityType']['value'];
     if (count($chosenActivities) === 1 && empty($chosenActivities[0])) {
         $chosenActivities = $this->activityListChainProvider->getSupportedActivities();
     }
     $chosenClasses = array_map(function ($className) {
         return $this->entityRoutingHelper->decodeClassName($className);
     }, $chosenActivities);
     $unavailableChoices = array_diff($chosenClasses, $availableClasses);
     if ($unavailableChoices) {
         $activityQb->andWhere('1 = 0');
         return $activityQb;
     }
     $activityQb->join($joinField, $this->activityAlias)->andWhere(sprintf('%s.id = %s.%s', $this->activityAlias, $this->getEntityAlias(), $entityIdField));
     $entityField = $this->getField();
     $dateRangeField = strpos($entityField, '$') === 0 ? substr($entityField, 1) : null;
     if ($dateRangeField) {
         $data['dateRange'] = $data['filter']['data'];
         unset($data['filter']);
     }
     $this->activityListFilterHelper->addFiltersToQuery($activityQb, $data, $dateRangeField, $this->activityListAlias);
     if (isset($data['filter'])) {
         $activityDs = new OrmFilterDatasourceAdapter($activityQb);
         $expr = $activityDs->expr()->exists($this->createRelatedActivityDql($activityDs, $data));
         $this->applyFilterToClause($activityDs, $expr);
     }
     return $activityQb;
 }
Example #17
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The "Entity\NotRoot" must be the root entity.
  */
 public function testAddFilterByTargetEntityWithInvalidActivityEntityClassSpecified()
 {
     $targetEntityClass = 'Oro\\Bundle\\ActivityBundle\\Tests\\Unit\\Fixtures\\Entity\\Target';
     $targetEntityId = 123;
     $qb = $this->em->createQueryBuilder()->select('activity, another')->from('Test:Activity', 'activity')->from('Test:Another', 'another')->where('another.id = activity.id');
     $this->manager->addFilterByTargetEntity($qb, $targetEntityClass, $targetEntityId, 'Entity\\NotRoot');
 }
Example #18
0
 /**
  * @param EntityManager $em
  * @param array $data
  * @param string $entityIdField
  *
  * @return QueryBuilder
  */
 protected function createActivityQueryBuilder(EntityManager $em, array $data, $entityIdField)
 {
     $joinField = sprintf('%s.%s', $this->activityListAlias, ExtendHelper::buildAssociationName($data['entityClassName'], ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND));
     $activityListRepository = $em->getRepository('OroActivityListBundle:ActivityList');
     $activityQb = $activityListRepository->createQueryBuilder($this->activityListAlias)->select('1')->setMaxResults(1);
     $availableActivityAssociations = $this->activityManager->getActivityAssociations($data['entityClassName']);
     if (!$availableActivityAssociations && !$activityListRepository->getRecordsCountForTargetClass($data['entityClassName'])) {
         $activityQb->andWhere('1 = 0');
         return $activityQb;
     }
     $activityQb->join($joinField, $this->activityAlias)->andWhere(sprintf('%s.id = %s.%s', $this->activityAlias, $this->getEntityAlias(), $entityIdField));
     $entityField = $this->getField();
     $dateRangeField = strpos($entityField, '$') === 0 ? substr($entityField, 1) : null;
     if ($dateRangeField) {
         $data['dateRange'] = $data['filter']['data'];
         unset($data['filter']);
     }
     $this->activityListFilterHelper->addFiltersToQuery($activityQb, $data, $dateRangeField, $this->activityListAlias);
     if (isset($data['filter'])) {
         $activityDs = new OrmFilterDatasourceAdapter($activityQb);
         $expr = $activityDs->expr()->exists($this->createRelatedActivityDql($activityDs, $data));
         $this->applyFilterToClause($activityDs, $expr);
     }
     return $activityQb;
 }
 /**
  * Handle delete entity object.
  *
  * @param RelationIdentifier $id
  * @param ApiEntityManager   $manager
  *
  * @throws EntityNotFoundException if an entity with the given id does not exist
  * @throws ForbiddenException if a delete operation is forbidden
  */
 public function handleDelete($id, ApiEntityManager $manager)
 {
     $em = $manager->getObjectManager();
     /** @var ActivityInterface $entity */
     $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId());
     if (!$entity) {
         throw new EntityNotFoundException();
     }
     $this->checkPermissions($entity, $em);
     $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId());
     if (!$targetEntity) {
         throw new EntityNotFoundException();
     }
     $this->checkPermissionsForTargetEntity($targetEntity, $em);
     $this->activityManager->removeActivityTarget($entity, $targetEntity);
     $em->flush();
 }
Example #20
0
 /**
  * @dataProvider getDataProvider
  */
 public function testOnBuildMetadata($keys, $calls)
 {
     $config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $this->configProvider->expects($this->any())->method('getConfig')->willReturn($config);
     $config->expects($this->exactly($calls))->method('get')->willReturn('label');
     $i = 0;
     $k = array_keys($keys);
     foreach ($k as $key) {
         $i++;
         $fieldMetadataOptions = ['display' => true, 'activity' => true, 'type' => $key, 'field_name' => $key, 'is_collection' => true, 'template' => 'OroActivityListBundle:Merge:value.html.twig', 'label' => 'Items', 'merge_modes' => [MergeModes::ACTIVITY_UNITE, MergeModes::ACTIVITY_REPLACE]];
         $fieldMetadata = new FieldMetadata($fieldMetadataOptions);
         $this->entityMetadata->expects($this->at($i))->method('addFieldMetadata')->with($this->equalTo($fieldMetadata));
     }
     $this->activityManager->expects($this->once())->method('getActivities')->willReturn($keys);
     $event = new EntityMetadataEvent($this->entityMetadata);
     $this->listener->onBuildMetadata($event);
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $datagrid = $event->getDatagrid();
     $datasource = $datagrid->getDatasource();
     if ($datasource instanceof OrmDatasource) {
         $parameters = $datagrid->getParameters();
         $entityClass = $this->entityRoutingHelper->decodeClassName($parameters->get('entityClass'));
         $entityId = $parameters->get('entityId');
         $qb = $datasource->getQueryBuilder();
         // apply activity filter
         $this->activityManager->addFilterByTargetEntity($qb, $entityClass, $entityId);
         // apply filter by date
         $start = new \DateTime('now', new \DateTimeZone($this->localeSettings->getTimeZone()));
         $start->setTime(0, 0, 0);
         $qb->andWhere('event.start >= :date OR event.end >= :date')->setParameter('date', $start);
     }
 }
 /**
  * Process form
  *
  * @param CalendarEvent $entity
  *
  * @return bool True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function getWidgets($object)
 {
     $result = [];
     $entityClass = ClassUtils::getClass($object);
     $entityId = $this->entityIdAccessor->getIdentifier($object);
     $items = $this->activityManager->getActivityAssociations($entityClass);
     foreach ($items as $item) {
         if (empty($item['acl']) || $this->securityFacade->isGranted($item['acl'])) {
             $url = $this->entityRoutingHelper->generateUrl($item['route'], $entityClass, $entityId);
             $alias = sprintf('%s_%s_%s', strtolower(ExtendHelper::getShortClassName($item['className'])), dechex(crc32($item['className'])), $item['associationName']);
             $widget = ['widgetType' => 'block', 'alias' => $alias, 'label' => $this->translator->trans($item['label']), 'url' => $url];
             if (isset($item['priority'])) {
                 $widget['priority'] = $item['priority'];
             }
             $result[] = $widget;
         }
     }
     return $result;
 }
 /**
  * Returns the context for the given activity class and id
  *
  * @param string $class The FQCN of the activity entity
  * @param        $id
  *
  * @return array
  */
 public function getActivityContext($class, $id)
 {
     $criteria = Criteria::create();
     $criteria->andWhere(Criteria::expr()->eq('id', $id));
     $currentUser = $this->securityTokenStorage->getToken()->getUser();
     $userClass = ClassUtils::getClass($currentUser);
     $queryBuilder = $this->activityManager->getActivityTargetsQueryBuilder($class, $criteria, null, null, null, null, function (QueryBuilder $qb, $targetEntityClass) use($currentUser, $userClass) {
         if ($targetEntityClass === $userClass) {
             // Exclude current user from result
             $qb->andWhere($qb->expr()->neq(QueryUtils::getSelectExprByAlias($qb, 'entityId'), $currentUser->getId()));
         }
     });
     if (null === $queryBuilder) {
         return [];
     }
     $result = $queryBuilder->getQuery()->getResult();
     if (empty($result)) {
         return $result;
     }
     $entityProvider = $this->configManager->getProvider('entity');
     foreach ($result as &$item) {
         $config = $entityProvider->getConfig($item['entity']);
         $metadata = $this->configManager->getEntityMetadata($item['entity']);
         $safeClassName = $this->entityClassNameHelper->getUrlSafeClassName($item['entity']);
         $link = null;
         if ($metadata) {
             $link = $this->router->generate($metadata->getRoute(), ['id' => $item['id']]);
         } elseif ($link === null && ExtendHelper::isCustomEntity($item['entity'])) {
             // Generate view link for the custom entity
             $link = $this->router->generate('oro_entity_view', ['id' => $item['id'], 'entityName' => $safeClassName]);
         }
         $item['activityClassAlias'] = $this->entityAliasResolver->getPluralAlias($class);
         $item['entityId'] = $id;
         $item['targetId'] = $item['id'];
         $item['targetClassName'] = $safeClassName;
         $item['icon'] = $config->get('icon');
         $item['link'] = $link;
         unset($item['id'], $item['entity']);
     }
     return $result;
 }
 /**
  * Handle delete entity object.
  *
  * @param RelationIdentifier $id
  * @param ApiEntityManager   $manager
  *
  * @throws EntityNotFoundException if an entity with the given id does not exist
  * @throws ForbiddenException if a delete operation is forbidden
  */
 public function handleDelete($id, ApiEntityManager $manager)
 {
     $em = $manager->getObjectManager();
     /** @var ActivityInterface $entity */
     $entity = $em->find($id->getOwnerEntityClass(), $id->getOwnerEntityId());
     if (!$entity) {
         throw new EntityNotFoundException();
     }
     if (!$this->securityFacade->isGranted('EDIT', $entity)) {
         throw new ForbiddenException('has no edit permissions for activity entity');
     }
     $targetEntity = $em->find($id->getTargetEntityClass(), $id->getTargetEntityId());
     if (!$targetEntity) {
         throw new EntityNotFoundException();
     }
     if (!$this->securityFacade->isGranted('VIEW', $targetEntity)) {
         throw new ForbiddenException('has no view permissions for related entity');
     }
     $this->activityManager->removeActivityTarget($entity, $targetEntity);
     $em->flush();
 }
Example #26
0
 /**
  * @param array $options
  *
  * @return bool
  */
 protected function isApplicable(array $options)
 {
     if ($options['contexts_disabled'] || empty($options['data_class'])) {
         return false;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return false;
     }
     $activities = $this->activityManager->getActivityTypes();
     return in_array($className, $activities, true);
 }
Example #27
0
 /**
  * Get search aliases for all entities which can be associated with specified activity.
  *
  * @return string[]
  */
 protected function getSearchAliases()
 {
     $class = $this->entityClassNameHelper->resolveEntityClass($this->class, true);
     $aliases = [];
     foreach ($this->activityManager->getActivityTargets($class) as $targetEntityClass => $fieldName) {
         $alias = $this->indexer->getEntityAlias($targetEntityClass);
         if (null !== $alias) {
             $aliases[] = $alias;
         }
     }
     return $aliases;
 }
 /**
  * Process form
  *
  * @param  CalendarEvent $entity
  * @return bool  True on successful processing, false otherwise
  */
 public function process(CalendarEvent $entity)
 {
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $originalChildren = new ArrayCollection();
         foreach ($entity->getChildEvents() as $childEvent) {
             $originalChildren->add($childEvent);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // TODO: should be refactored after finishing BAP-8722
             // Contexts handling should be moved to common for activities form handler
             if ($this->form->has('contexts')) {
                 $contexts = $this->form->get('contexts')->getData();
                 $this->activityManager->setActivityTargets($entity, $contexts);
             }
             $this->onSuccess($entity, $originalChildren, $this->form->get('notifyInvitedUsers')->getData());
             return true;
         }
     }
     return false;
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function merge(FieldData $fieldData)
 {
     $entityData = $fieldData->getEntityData();
     $masterEntity = $entityData->getMasterEntity();
     $sourceEntity = $fieldData->getSourceEntity();
     if ($masterEntity->getId() !== $sourceEntity->getId()) {
         $fieldMetadata = $fieldData->getMetadata();
         $activityClass = $fieldMetadata->get('type');
         $activityListItems = $this->getActivitiesByEntity($masterEntity, $activityClass);
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'relatedActivityId');
         $activities = $this->doctrineHelper->getEntityRepository($activityClass)->findBy(['id' => $activityIds]);
         foreach ($activities as $activity) {
             $this->activityManager->removeActivityTarget($activity, $masterEntity);
         }
         $activityListItems = $this->getActivitiesByEntity($sourceEntity, $activityClass);
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'id');
         $entityClass = ClassUtils::getRealClass($masterEntity);
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId());
         $activityIds = ArrayUtil::arrayColumn($activityListItems, 'relatedActivityId');
         $this->activityListManager->replaceActivityTargetWithPlainQuery($activityIds, $entityClass, $sourceEntity->getId(), $masterEntity->getId(), $activityClass);
     }
 }
Example #30
0
 /**
  * Process form
  *
  * @param  Task $entity
  *
  * @return bool  True on successful processing, false otherwise
  */
 public function process(Task $entity)
 {
     $action = $this->entityRoutingHelper->getAction($this->request);
     $targetEntityClass = $this->entityRoutingHelper->getEntityClassName($this->request);
     $targetEntityId = $this->entityRoutingHelper->getEntityId($this->request);
     if ($targetEntityClass && !$entity->getId() && $this->request->getMethod() === 'GET' && $action === 'assign' && is_a($targetEntityClass, 'Oro\\Bundle\\UserBundle\\Entity\\User', true)) {
         $entity->setOwner($this->entityRoutingHelper->getEntity($targetEntityClass, $targetEntityId));
         FormUtils::replaceField($this->form, 'owner', ['read_only' => true]);
     }
     $this->form->setData($entity);
     if (in_array($this->request->getMethod(), array('POST', 'PUT'))) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if ($targetEntityClass && $action === 'activity') {
                 $this->activityManager->addActivityTarget($entity, $this->entityRoutingHelper->getEntityReference($targetEntityClass, $targetEntityId));
             }
             $this->onSuccess($entity);
             return true;
         }
     }
     return false;
 }