16 $generated_id = rand(1, 100000);
17 $file = fopen(
'mocked_geolocation_data.txt', FILE_APPEND);
20 $write_string =
"$generated_id;$a_title;$a_latitude;$a_longitude;$a_expiration_timestamp\n";
23 fwrite($file, $write_string);
31 $a_expiration_timestamp
40 $file = fopen(
'mocked_geolocation_data.txt',
'r');
43 while ($row = fgetcsv($file)) {
44 if ($row[0] == $a_id) {
49 throw new \InvalidArgumentException(
"Unknown id for geolocation: $a_id");
57 $file = fopen(
'mocked_geolocation_data.txt',
'r');
58 $geo_locations = array();
61 while ($row = fgetcsv($file)) {
62 if ($row[2] == $a_latitude && $row[3] == $a_longitude) {
67 return $geo_locations;
75 $file = fopen(
'mocked_geolocation_data.txt',
'r');
78 while ($row = fgetcsv($file)) {
79 if ($row[0] == $a_id) {
93 $file = fopen(
'mocked_geolocation_data.txt',
'r');
96 while ($row = fgetcsv($file)) {
97 if ($row[2] == $a_latitude && $row[3] == $a_longitude) {
111 $file = fopen(
'mocked_geolocation_data.txt',
'r');
116 foreach ($geo_locations as $key => $row) {
117 if ($row[0] == $a_obj->
getId()) {
126 $file = fopen(
'mocked_geolocation_data.txt',
'w');
137 $file = fopen(
'mocked_geolocation_data.txt',
'r');
142 foreach ($geo_locations as $key => $row) {
143 if ($row[2] == $a_searched_latitude && $row[3] == $a_searched_longitude) {
144 $row[4] = $a_update_timestamp->getTimestamp();
149 $file = fopen(
'mocked_geolocation_data.txt',
'w');
159 $file = fopen(
'mocked_geolocation_data.txt',
'r');
164 foreach ($geo_locations as $key => $row) {
166 if ($row[0] == $a_id) {
167 unset($geo_locations[$key]);
172 $file = fopen(
'mocked_geolocation_data.txt',
'w');
180 $file = fopen(
'mocked_geolocation_data.txt',
'r');
186 foreach ($geo_locations as $key => $row) {
188 if ($row[2] == $a_latitude && $row[3] == $a_longitude) {
189 unset($geo_locations[$key]);
194 $file = fopen(
'mocked_geolocation_data.txt',
'w');
205 $file = fopen(
'mocked_geolocation_data.txt',
'r');
211 foreach ($geo_locations as $key => $row) {
215 if ($now->diff($dt)->s >= 0) {
216 unset($geo_locations[$key]);
221 $file = fopen(
'mocked_geolocation_data.txt',
'w');
231 $geo_locations = array();
232 while ($row = fgetcsv($file)) {
233 $geo_locations[] = $row;
235 return $geo_locations;
243 foreach ($list as $obj_data) {
245 $write_string = $obj_data[0] .
';' . $obj_data[1] .
';' . $obj_data[2] .
';' . $obj_data[3] .
';' . $obj_data[4] .
"\n";
246 fwrite($file, $write_string .
"\n");
getGeoLocationById(int $a_id)
Get a single geo location, identified by its id.
updateGeoLocation(ilGeoLocation $a_obj)
Update all attributes of a given geo location.
getExpirationAsTimestamp()
updateGeoLocationTimestampByCoordinates(float $a_searched_latitude, float $a_searched_longitude, \DateTimeImmutable $a_update_timestamp)
Example for updating multiple objects at once.
createGeoLocation(string $a_title, float $a_latitude, float $a_longitude, \DateTimeImmutable $a_expiration_timestamp)
Create a new geo location entry.
getGeoLocationsByCoordinates(float $a_latitude, float $a_longitude)
Example for reading an array of geo locations which have a given attribute.
writeGeoLocationListToFile($file, $list)
Protected function.
deleteGeoLocationsByCoordinates(float $a_latitude, float $a_longitude)
Example for a condition based deletion of multiple geo locations.
ifGeoLocationExistsById(int $a_id)
Example for checking if a geo location (one or more) with a given attribute exists.
deleteGeoLocation(int $a_id)
Delete single geo location identified by its id.
readFileAndReturnAsList($file)
Protected function.
ifAnyGeoLocationExistsByCoordinates(float $a_latitude, float $a_longitude)
Example for checking if a geo location (one or more) with a given attribute exists.
This code is just an example for the Repository Pattern! It is a basic interface to the 'ilGeoLocatio...
deleteExpiredGeoLocations()
Example for a condition based deletion of multiple geo locations.