private function getEdgeAction(Campaign $campaign, $position)
    {
        if($position != 'first' && $position != 'last'){
            throw new \Exception('Position must be either "first" or "last"');
        }
        if($position == 'first'){
            $order = 'ASC';
        } else {
            $order = 'DESC';
        }

        // Get first Activity
        /** @var Activity $activity */
        $activity = $this->createQueryBuilder('c')
            ->select('a')
            ->from('CampaignChain\CoreBundle\Entity\Activity', 'a')
            ->where('a.campaign = :campaign')
            ->setParameter('campaign', $campaign)
            ->orderBy('a.startDate', $order)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();

        // Get first Milestone
        /** @var Milestone $milestone */
        $milestone = $this->createQueryBuilder('c')
            ->select('m')
            ->from('CampaignChain\CoreBundle\Entity\Milestone', 'm')
            ->where('m.campaign = :campaign')
            ->setParameter('campaign', $campaign)
            ->orderBy('m.startDate', $order)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();

        // Does Activity or Milestone exist?
        if($activity == null && $milestone == null){
            return null;
        }
        if($milestone == null){
            return $activity;
        }
        if($activity == null){
            return $milestone;
        }

        // Does Activity or Milestone come first/last?
        if($position == 'first') {
            if ($activity->getStartDate() < $milestone->getStartDate()) {
                return $activity;
            } else {
                return $milestone;
            }
        } else {
            if ($activity->getStartDate() > $milestone->getStartDate()) {
                return $activity;
            } else {
                return $milestone;
            }
        }
    }