/** * Create an activity from parameters. * * @param array $params Parameters describing activity * * @return ActivityModel Activity that was created. */ public function createActivity(array $params) { // Find the creator $user = $this->getServiceManager()->get('user_role'); if ($user === 'guest') { throw new \InvalidArgumentException('Guests can not create activities'); } $params['creator'] = $user; $activity = new ActivityModel(); $activity->create($params); $em = $this->getServiceManager()->get('Doctrine\\ORM\\EntityManager'); $em->persist($activity); $em->flush(); return $activity; }