/**
  * Given an id, this returns the number of activities with ids smaller than that
  * @param $id
  * @return int
  */
 public static function getNumSmallerIds($id)
 {
     $em = DB::getEntityManager();
     $repo = $em->getRepository(Activity::getEntityNamespace());
     $qb = $repo->createQueryBuilder('a');
     $organisation_id = Apollo::getInstance()->getUser()->getOrganisationId();
     $notHidden = $qb->expr()->eq('a' . '.is_hidden', '0');
     $sameOrgId = $qb->expr()->eq('a' . '.organisation', $organisation_id);
     $cond = $qb->expr()->andX($notHidden, $sameOrgId);
     $qb->where($cond);
     $qb->andWhere('a.id < ' . $id);
     $result = $qb->getQuery()->getResult();
     return count($result);
 }
 /**
  * @param $alias
  * @return QueryBuilder
  */
 private function getQueryValidActivities($alias)
 {
     $em = DB::getEntityManager();
     $activityRepo = $em->getRepository(Activity::getEntityNamespace());
     $activityQB = $activityRepo->createQueryBuilder($alias);
     $organisation_id = Apollo::getInstance()->getUser()->getOrganisationId();
     $notHidden = $activityQB->expr()->eq($alias . '.is_hidden', '0');
     $sameOrgId = $activityQB->expr()->eq($alias . '.organisation', $organisation_id);
     $cond = $activityQB->expr()->andX($notHidden, $sameOrgId);
     $activityQB->where($cond);
     return $activityQB;
 }