ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilGeoLocationDBRepository Class Reference
+ Inheritance diagram for ilGeoLocationDBRepository:
+ Collaboration diagram for ilGeoLocationDBRepository:

Public Member Functions

 __construct (\ilDBInterface $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)
 Example 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...
 
 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)
 Example 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 ( \ilDBInterface  $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 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ deleteExpiredGeoLocations()

ilGeoLocationDBRepository::deleteExpiredGeoLocations ( )

Example for a condition based deletion of multiple geo locations.

Implements ilGeoLocationRepository.

Definition at line 169 of file ilGeoLocationDBRepository.php.

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

◆ deleteGeoLocation()

ilGeoLocationDBRepository::deleteGeoLocation ( int  $a_id)

Example for deleting single geo location identified by its id.

Implements ilGeoLocationRepository.

Definition at line 148 of file ilGeoLocationDBRepository.php.

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

◆ deleteGeoLocationsByCoordinates()

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

Example for a condition based deletion of multiple geo locations.

Implements ilGeoLocationRepository.

Definition at line 158 of file ilGeoLocationDBRepository.php.

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

◆ 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.

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

◆ 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 67 of file ilGeoLocationDBRepository.php.

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

◆ 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 109 of file ilGeoLocationDBRepository.php.

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

◆ ifGeoLocationExistsById()

ilGeoLocationDBRepository::ifGeoLocationExistsById ( int  $a_id)

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

Implements ilGeoLocationRepository.

Definition at line 96 of file ilGeoLocationDBRepository.php.

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

◆ updateGeoLocation()

ilGeoLocationDBRepository::updateGeoLocation ( ilGeoLocation  $a_obj)

Example for updating all attributes of a given geo location.

Implements ilGeoLocationRepository.

Definition at line 122 of file ilGeoLocationDBRepository.php.

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

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

+ 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 136 of file ilGeoLocationDBRepository.php.

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

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: