public function __construct() { $this->people = new ArrayCollection(); $this->is_hidden = false; $this->setTargetGroup(TargetGroup::getMin()); $this->target_group_comment = ''; }
/** * @todo: make this better? put this in components? in any case, do something with it. This looks horrible * @return mixed */ private function activityUpdate() { $response['error'] = null; $data = $this->parseRequest(['activity_id' => null, 'activity_name' => null, 'target_group' => null, 'target_group_comment' => null, 'start_date' => null, 'end_date' => null, 'added_people' => null, 'removed_people' => null]); try { $activity = Activity::getValidActivityWithId($data['activity_id']); if ($data['activity_id'] > 0 && !empty($activity)) { if (!empty($data['activity_name'])) { $activity->setName($data['activity_name']); } if (!empty($data['target_group'])) { $tg = TargetGroup::getValidTargetGroupWithId($data['target_group']); if (!empty($tg)) { $activity->setTargetGroup($tg); } } if (!empty($data['target_group_comment'])) { $activity->setTargetGroupComment($data['target_group_comment']); } if (!empty($data['start_date'])) { $start_date = new DateTime($data['start_date']); $activity->setStartDate($start_date); } if (!empty($data['end_date'])) { $end_date = new DateTime($data['end_date']); $activity->setEndDate($end_date); } if (!empty($data['added_people'])) { $r = $this->getPeopleEntitiesFromData($data['added_people']); if (!empty($r['error'])) { $response['error'] = $r['error']; } else { $activity->addPeople($r['people']); } } if (!empty($data['removed_people'])) { $r = $this->getPeopleEntitiesFromData($data['removed_people']); if (!empty($r['error'])) { $response['error'] = $r['error']; } else { $activity->removePeople($r['people']); } } $this->writeActivityToDB($activity); } } catch (Exception $e) { $response['error'] = $this->getJSONError(2, 'Error while querying database for activity, message: ' . $e->getMessage()); } //$response['error'] = $this->getJSONError(0, 'update not implemented.'); return $response; }
/** * 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; }
/** * Given an id, returns a target group (hopefully) * @param $id * @return TargetGroupEntity */ public static function getValidTargetGroupWithId($id) { $org_id = Apollo::getInstance()->getUser()->getOrganisationId(); return TargetGroup::getRepository()->findBy(['organisation' => $org_id, 'is_hidden' => false, 'id' => $id])[0]; }