ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilGeoLocationDBRepository Class Reference
+ Inheritance diagram for ilGeoLocationDBRepository:
+ Collaboration diagram for ilGeoLocationDBRepository:

Public Member Functions

 __construct (\ilDBInterfacee $a_db)
 
 createGeoLocation (string $a_title, float $a_latitude, float $a_longitude, \DateTimeImmutable $a_expiration_timestamp)
 Create a new geo location entry. More...
 
 getGeoLocationById (int $a_id)
 Get a single geo location, identified by its id. More...
 
 getGeoLocationsByCoordinates (float $a_latitude, float $a_longitude)
 Example for reading an array of geo locations which have a given attribute. More...
 
 ifGeoLocationExistsById (int $a_id)
 Example for checking if geo location with a certain id exists. More...
 
 ifAnyGeoLocationExistsByCoordinates (float $a_latitude, float $a_longitude)
 Example for checking if a geo location (one or more) with a given attribute exists. More...
 
 updateGeoLocation (ilGeoLocation $a_obj)
 Example for updating all attributes of a given geo location. More...
 
 updateGeoLocationTimestampByCoordinates (float $a_searched_latitude, float $a_searched_longitude, \DateTimeImmutable $a_update_timestamp)
 Example for updating multiple objects at once. More...
 
 deleteGeoLocation (int $a_id)
 Exaple for deleting single geo location identified by its id. More...
 
 deleteGeoLocationsByCoordinates (float $a_latitude, float $a_longitude)
 Example for a condition based deletion of multiple geo locations. More...
 
 deleteExpiredGeoLocations ()
 Example for a condition based deletion of multiple geo locations. More...
 

Data Fields

const TABLE_NAME = 'geo_location'
 

Detailed Description

Definition at line 3 of file ilGeoLocationDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilGeoLocationDBRepository::__construct ( \ilDBInterfacee  $a_db)

Definition at line 7 of file ilGeoLocationDBRepository.php.

8  {
9  $this->db = $a_db;
10  }

Member Function Documentation

◆ createGeoLocation()

ilGeoLocationDBRepository::createGeoLocation ( string  $a_title,
float  $a_latitude,
float  $a_longitude,
\DateTimeImmutable  $a_expiration_timestamp 
)

Create a new geo location entry.

Implements ilGeoLocationRepository.

Definition at line 12 of file ilGeoLocationDBRepository.php.

18  {
19  // Get next free id for object
20  $id = $this->db->nextId($this->db->quoteIdentifier(self::TABLE_NAME));
21 
22  // Insert in database
23  $this->db->insert($this->db->quoteIdentifier(self::TABLE_NAME), array(
24  'id' => array('integer', $id),
25  'title' => array('text', $a_title),
26  'latitude' => array('float', $a_latitude),
27  'longitude' => array('float', $a_longitude),
28  'expiration_timestamp' => array('timestamp', $a_expiration_timestamp->getTimestamp())
29  ));
30 
31  // Return the new created object or just the id
32  return new ilGeoLocation(
33  $id,
34  $a_title,
35  $a_latitude,
36  $a_longitude,
37  $a_expiration_timestamp
38  );
39  }

◆ deleteExpiredGeoLocations()

ilGeoLocationDBRepository::deleteExpiredGeoLocations ( )

Example for a condition based deletion of multiple geo locations.

Implements ilGeoLocationRepository.

Definition at line 168 of file ilGeoLocationDBRepository.php.

References $query.

169  {
170  // Set up delete query
171  $query = 'DELETE FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
172  ' WHERE expiration_timestamp < ' . $this->db->quote(time(), 'timestamp');
173 
174  // Execute delete query
175  $this->db->manipulate($query);
176  }
$query

◆ deleteGeoLocation()

ilGeoLocationDBRepository::deleteGeoLocation ( int  $a_id)

Exaple for deleting single geo location identified by its id.

Implements ilGeoLocationRepository.

Definition at line 147 of file ilGeoLocationDBRepository.php.

References $query.

148  {
149  // Set up delete query
150  $query = 'DELETE FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
151  ' WHERE id = ' . $this->db->quote($a_id, 'integer');
152 
153  // Execute delete query
154  $this->db->manipulate($query);
155  }
$query

◆ deleteGeoLocationsByCoordinates()

ilGeoLocationDBRepository::deleteGeoLocationsByCoordinates ( float  $a_latitude,
float  $a_longitude 
)

Example for a condition based deletion of multiple geo locations.

Implements ilGeoLocationRepository.

Definition at line 157 of file ilGeoLocationDBRepository.php.

References $query.

158  {
159  // Set up delete query
160  $query = 'DELETE FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
161  ' WHERE latitude < ' . $this->db->quote($a_latitude, 'float') .
162  ' AND longitude = ' . $this->db->quote($a_longitude, 'float');
163 
164  // Execute delete query
165  $this->db->manipulate($query);
166  }
$query

◆ getGeoLocationById()

ilGeoLocationDBRepository::getGeoLocationById ( int  $a_id)

Get a single geo location, identified by its id.

Implements ilGeoLocationRepository.

Definition at line 41 of file ilGeoLocationDBRepository.php.

References $query, and $result.

42  {
43  // Set up SQL-Statement
44  $query = 'Select * FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
45  ' WHERE id = ' . $this->db->quote($a_id, 'integer');
46 
47  // Execute query
48  $result = $this->db->query($query);
49 
50  // Fetch row for returning
51  if($row = $this->db->fetchAssoc($result))
52  {
53  // Create object out of fetched data and return it
54  return new ilGeoLocation(
55  (int)$row['id'],
56  $row['title'],
57  (float)$row['latitude'],
58  (float)$row['longitude'],
59  new DateTimeImmutable($row['expiration_timestamp'])
60  );
61  }
62 
63  throw new \InvalidArgumentException("Unknown id for geolocation: $a_id");
64  }
$result
$query

◆ getGeoLocationsByCoordinates()

ilGeoLocationDBRepository::getGeoLocationsByCoordinates ( float  $a_latitude,
float  $a_longitude 
)

Example for reading an array of geo locations which have a given attribute.

Returns
ilGeoLocation[]

Implements ilGeoLocationRepository.

Definition at line 66 of file ilGeoLocationDBRepository.php.

References $query, and $result.

66  : array
67  {
68  // Set up SQL-Statement
69  $query = 'Select * FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
70  ' WHERE latitude = ' . $this->db->quote($a_latitude, 'float') .
71  ' AND longitude = ' . $this->db->quote($a_longitude, 'float');
72 
73  // Execute query
74  $result = $this->db->query($query);
75 
76  // Fill array with all matching objects
77  $locations = array();
78  while($row = $this->db->fetchAssoc($result))
79  {
80  // Create object and add it to list
81  $locations[] = new ilGeoLocation(
82  (int)$row['id'],
83  $row['title'],
84  (float)$row['latitude'],
85  (float)$row['longitude'],
86  new DateTimeImmutable($row['expiration_timestamp'])
87  );
88  }
89 
90  // Return list of objects (might be empty if no object was found)
91  return $locations;
92  }
$result
$query

◆ ifAnyGeoLocationExistsByCoordinates()

ilGeoLocationDBRepository::ifAnyGeoLocationExistsByCoordinates ( float  $a_latitude,
float  $a_longitude 
)

Example for checking if a geo location (one or more) with a given attribute exists.

Implements ilGeoLocationRepository.

Definition at line 107 of file ilGeoLocationDBRepository.php.

References $query, and $result.

107  : bool
108  {
109  // Set up SQL-Statement
110  $query = 'Select count(*) AS count FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
111  ' WHERE latitude = ' . $this->db->quote($a_latitude, 'float') .
112  ' AND longitude = ' . $this->db->quote($a_longitude, 'float');
113 
114  // Execute statement
115  $result = $this->db->query($query);
116 
117  // Return if any object was found
118  return $result['count'] > 0;
119  }
$result
$query

◆ ifGeoLocationExistsById()

ilGeoLocationDBRepository::ifGeoLocationExistsById ( int  $a_id)

Example for checking if geo location with a certain id exists.

Implements ilGeoLocationRepository.

Definition at line 94 of file ilGeoLocationDBRepository.php.

References $query, and $result.

94  : bool
95  {
96  // Set up SQL-Statement
97  $query = 'Select count(*) AS count FROM ' . $this->db->quoteIdentifier(self::TABLE_NAME) .
98  ' WHERE id = ' . $this->db->quote($a_id, 'integer');
99 
100  // Execute statement
101  $result = $this->db->query($query);
102 
103  // Return if object was found
104  return $result['count'] > 0;
105  }
$result
$query

◆ updateGeoLocation()

ilGeoLocationDBRepository::updateGeoLocation ( ilGeoLocation  $a_obj)

Example for updating all attributes of a given geo location.

Implements ilGeoLocationRepository.

Definition at line 121 of file ilGeoLocationDBRepository.php.

References ilGeoLocation\getExpirationAsTimestamp(), ilGeoLocation\getId(), ilGeoLocation\getLatitude(), ilGeoLocation\getLongitude(), and ilGeoLocation\getTitle().

122  {
123  // Update of one entire geo location object
124  $this->db->update($this->db->quoteIdentifier(self::TABLE_NAME),
125  // Update columns (in this case all except for id):
126  array('title' => array($a_obj->getTitle(), 'text')),
127  array('latitude' => array($a_obj->getLatitude(), 'float')),
128  array('longitude' => array($a_obj->getLongitude(), 'float')),
129  array('expiration_timestamp' => array($a_obj->getExpirationAsTimestamp(), 'timestamp')),
130  // Where (in this case only the object with the given id):
131  array('id' => array($a_obj->getId(), 'int'))
132  );
133  }
+ Here is the call graph for this function:

◆ updateGeoLocationTimestampByCoordinates()

ilGeoLocationDBRepository::updateGeoLocationTimestampByCoordinates ( float  $a_searched_latitude,
float  $a_searched_longitude,
\DateTimeImmutable  $a_update_timestamp 
)

Example for updating multiple objects at once.

Implements ilGeoLocationRepository.

Definition at line 135 of file ilGeoLocationDBRepository.php.

136  {
137  // Update for single attribute of a set of geo location objects
138  $this->db->update($this->db->quoteIdentifier(self::TABLE_NAME),
139  // Update columns (in this case only the timestamp):
140  array('expiration_timestamp' => array('timestamp', $a_update_timestamp->getTimestamp())),
141  // Where (in this case every object on the given location):
142  array('latitude' => array($a_searched_latitude, 'float'),
143  'longitude' => array($a_searched_longitude, 'float'))
144  );
145  }

Field Documentation

◆ TABLE_NAME

const ilGeoLocationDBRepository::TABLE_NAME = 'geo_location'

Definition at line 5 of file ilGeoLocationDBRepository.php.


The documentation for this class was generated from the following file: