/** * Formats an activity as a valid JSON object (with all the information about the activity) * @param ActivityEntity $activity * @return array */ public static function getFormattedData(ActivityEntity $activity) { $people = Person::getFormattedPeopleShortWithRecords($activity->getPeople()); $activityInfo = ['error' => null, 'id' => $activity->getId(), 'name' => $activity->getName(), 'target_groups' => TargetGroup::getFormattedTargetGroups($activity->getTargetGroup()), 'target_group_comment' => $activity->getTargetGroupComment(), 'start_date' => $activity->getStartDate()->format('Y-m-d H:i:s'), 'end_date' => $activity->getEndDate()->format('Y-m-d H:i:s'), 'participants' => $people]; return $activityInfo; }
/** * @todo: Consider putting this into activity component * @todo: I doubt this code will ever get reused anywhere else, might as well put it back where it came from * @param $data * @param $bonus * @return ActivityEntity * @since 0.0.6 */ private function createActivityFromData($data, $bonus) { $user = Apollo::getInstance()->getUser(); $activity = new ActivityEntity(); $activity->setOrganisation($user->getOrganisation()); $activity->setName($data['activity_name']); $start_date = new DateTime($data['start_date']); $end_date = new DateTime($data['end_date']); $activity->setStartDate($start_date); $activity->setEndDate($end_date); if ($bonus) { if (!empty($bonus['people'])) { $activity->addPeople($bonus['people']); } if (!empty($bonus['target_group'])) { $activity->setTargetGroup($bonus['target_group']); } if (!empty($bonus['target_group_comment'])) { $activity->setTargetGroupComment($bonus['target_group_comment']); } } return $activity; }