/** * Just accepts new people, adds them/deletes them from the activity * @return mixed */ public function actionActivitySavePeople() { $response['error'] = null; $data = $this->parseRequest(['activity_id' => null, 'toAdd' => null, 'toDelete' => null]); if (!$this->areFieldsEmpty($data)) { $activity = Activity::getValidActivityWithId($data['activity_id']); if ($activity) { foreach ($data['toAdd'] as $person_id) { $person = Person::getValidPersonWithId($person_id); if ($person) { $activity->addPerson($person); } } foreach ($data['toDelete'] as $person_id) { $person = Person::getValidPersonWithId($person_id); if ($person) { $activity->removePerson($person); } } try { $this->writeActivityToDB($activity); } catch (Exception $e) { $response['error'] = $this->getJSONError(4, 'Unexpected exception when saving the new data. Message: ' . $e->getMessage()); } } else { $response['error'] = $this->getJSONError(3, 'Could not find activity with given id while saving people'); } } else { $response['error'] = $this->getJSONError(1, 'Some of the fields are empty'); } return $response; }
/** * Gets all the people not in the specified activity, who meet the search criteria and who are not already temporarily added * @todo only return like the top ten results (in order to speed up the lookup) */ public function actionActivityPeople() { $data = $this->parseRequest(['activity_id' => null, 'temporarily_added' => null, 'search' => null]); $people = null; $pqb = $this->getQueryForPeopleNotInProgramme($data); $pqb->setMaxResults(10); if (empty(Activity::getValidActivityWithId($data['activity_id']))) { $response['error'] = $this->getJSONError(2, "Activity hidden."); } else { try { $response['error'] = null; $query = $pqb->getQuery(); $result = $query->getResult(); $response['data'] = Person::getFormattedPeopleShortWithRecords($result); } catch (Exception $e) { $response['error'] = $this->getJSONError(1, "Query failed with exception " . $e->getMessage()); } } echo json_encode($response); }