ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilLicense Class Reference
+ Collaboration diagram for ilLicense:

Public Member Functions

 __construct ($a_obj_id)
 Constructor. More...
 
 getObjId ()
 
 setObjId ($obj_id)
 
 setLicenses ($a_licenses=0)
 
 getLicenses ()
 
 setRemarks ($a_remarks='')
 
 getRemarks ()
 
 getAccesses ()
 
 getRemainingLicenses ()
 
 getPotentialAccesses ()
 Get the number of users who may access the object but don't have yet a license. More...
 
 read ()
 Read the license data from the database. More...
 
 update ()
 Update the license data in the database. More...
 
 delete ()
 Delete all data of the license. More...
 

Static Public Member Functions

static _checkAccess ($a_usr_id, $a_obj_id)
 Check, if a user can access an object by license. More...
 
static _noteAccess ($a_obj_id, $a_type, $a_ref_id)
 Note the access of the current usr to an object. More...
 
static _getLicensedObjects ()
 Get a list of all objects with activated licensing. More...
 
static _getLicensedChildObjects ($a_ref_id)
 Get a list of all sub objects with activated licensing. More...
 
static _isLicensed ($a_obj_id)
 Check if an object has licensing activated. More...
 

Protected Attributes

 $obj_id = 0
 
 $licenses = 0
 
 $remarks = ''
 
 $accesses = 0
 

Detailed Description

Definition at line 12 of file class.ilLicense.php.

Constructor & Destructor Documentation

◆ __construct()

ilLicense::__construct (   $a_obj_id)

Constructor.

@access public

Definition at line 38 of file class.ilLicense.php.

39 {
40 $this->obj_id = (int) $a_obj_id;
41 $this->read();
42 }
read()
Read the license data from the database.

References read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _checkAccess()

static ilLicense::_checkAccess (   $a_usr_id,
  $a_obj_id 
)
static

Check, if a user can access an object by license.

The user can access, if he/she already accessed the object or if a license is available for the object. This check is called from the ilAccessHandler class.

Deprecated:
use ilLicenseAccess::_checkAccess instead
Parameters
int$a_usr_id
int$a_obj_id(not reference)
Returns
boolean access is possible (true/false)

Definition at line 243 of file class.ilLicense.php.

244 {
245 // Implementation moved
246 require_once("Services/License/classes/class.ilLicenseAccess.php");
247
248 return ilLicenseAccess::_checkAccess($a_usr_id, $a_obj_id);
249 }
static _checkAccess($a_usr_id, $a_obj_id)
Check, if a user can access an object by license.

References ilLicenseAccess\_checkAccess().

+ Here is the call graph for this function:

◆ _getLicensedChildObjects()

static ilLicense::_getLicensedChildObjects (   $a_ref_id)
static

Get a list of all sub objects with activated licensing.

Parameters
int$a_ref_idof the repository node to check
Returns
array array of object data arrays (obj_id, title, desc)

Definition at line 328 of file class.ilLicense.php.

329 {
330 global $tree;
331 $objects = array();
332
333 $childs = $tree->getChilds($a_ref_id, 'title');
334 foreach ($childs as $data) {
335 if (in_array($data['type'], array( 'sahs', 'htlm' )) and self::_isLicensed($data['obj_id'])) {
336 $objects[] = $data;
337 }
338 }
339
340 return $objects;
341 }

References $data.

Referenced by ilObjCourseGUI\checkLicenses(), and ilLicenseOverviewTableGUI\getItems().

+ Here is the caller graph for this function:

◆ _getLicensedObjects()

static ilLicense::_getLicensedObjects ( )
static

Get a list of all objects with activated licensing.

Returns
array array of object data arrays (obj_id, type, title, description)

Definition at line 300 of file class.ilLicense.php.

301 {
302 global $ilDB;
303 $objects = array();
304
305 $query = 'SELECT od.obj_id, od.type, od.title, od.description, re.ref_id ' . 'FROM license_data ld '
306 . 'INNER JOIN object_data od ON od.obj_id = ld.obj_id ' . 'INNER JOIN object_reference re ON re.obj_id = od.obj_id '
307 . 'WHERE ld.licenses > 0 ' . 'ORDER BY od.title, od.obj_id';
308
309 $result = $ilDB->query($query);
310 $obj_id = 0;
311 while ($row = $ilDB->fetchAssoc($result)) {
312 if ($row['obj_id'] != $obj_id) {
313 $objects[] = $row;
314 $obj_id = $row['obj_id'];
315 }
316 }
317
318 return $objects;
319 }
$result
$query
global $ilDB

References $ilDB, $obj_id, $query, $result, and $row.

Referenced by ilLicenseOverviewTableGUI\getItems().

+ Here is the caller graph for this function:

◆ _isLicensed()

static ilLicense::_isLicensed (   $a_obj_id)
static

Check if an object has licensing activated.

Parameters
int$a_obj_id
Returns
boolean object has licensing (true/false)

Definition at line 350 of file class.ilLicense.php.

351 {
352 global $ilDB;
353
354 $query = "SELECT licenses FROM license_data " . "WHERE obj_id = %s " . "AND licenses > 0";
355 $result = $ilDB->queryF($query, array( 'integer' ), array( $a_obj_id ));
356 if ($row = $ilDB->fetchObject($result)) {
357 return true;
358 }
359 }

References $ilDB, $query, $result, and $row.

◆ _noteAccess()

static ilLicense::_noteAccess (   $a_obj_id,
  $a_type,
  $a_ref_id 
)
static

Note the access of the current usr to an object.

This function has to be called if an object is accessed for viewing.

Parameters
int$a_obj_id
string$a_type
int$a_ref_id

Definition at line 261 of file class.ilLicense.php.

262 {
263 global $ilDB, $ilUser;
264
265 // don't note the access if licensing is globally disabled
266 require_once("Services/License/classes/class.ilLicenseAccess.php");
268 return;
269 }
270
271 // check if user has already accessed
272 $query = 'SELECT read_count FROM read_event ' . 'WHERE usr_id = %s AND obj_id = %s';
273 $result = $ilDB->queryF($query, array( 'integer', 'integer' ), array( $ilUser->getId(), $a_obj_id ));
274
275 if ($row = $ilDB->fetchObject($result)) {
276 // already accessed -> nothing to do
277 return;
278 } else {
279 // note access
280 require_once('Services/Tracking/classes/class.ilChangeEvent.php');
281 ilChangeEvent::_recordReadEvent($a_type, $a_ref_id, $a_obj_id, $ilUser->getId());
282
283 if (self::_isLicensed($a_obj_id)) {
284 // increase used licenses
285 $query = "UPDATE license_data SET used = used + 1 " . "WHERE obj_id = %s";
286 $ilDB->manipulateF($query, array( 'integer' ), array( $a_obj_id ));
287 }
288 }
289 }
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
static _isEnabled()
Check, if licencing is enabled This check is called from the ilAccessHandler class.
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92

References $a_type, $ilDB, $ilUser, $query, $result, $row, ilLicenseAccess\_isEnabled(), and ilChangeEvent\_recordReadEvent().

Referenced by ilSAHSPresentationGUI\executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilLicense::delete ( )

Delete all data of the license.

@access public

Definition at line 218 of file class.ilLicense.php.

219 {
220 global $ilDB;
221
222 $query = 'DELETE FROM license_data WHERE obj_id = %s';
223 $ilDB->manipulateF($query, array( 'integer' ), array( $this->obj_id ));
224 }

References $ilDB, and $query.

◆ getAccesses()

ilLicense::getAccesses ( )
Returns
int

Definition at line 102 of file class.ilLicense.php.

103 {
104 return $this->accesses;
105 }

References $accesses.

◆ getLicenses()

ilLicense::getLicenses ( )
Returns
int

Definition at line 75 of file class.ilLicense.php.

76 {
77 return $this->licenses;
78 }

References $licenses.

◆ getObjId()

ilLicense::getObjId ( )
Returns
int

Definition at line 48 of file class.ilLicense.php.

49 {
50 return $this->obj_id;
51 }

References $obj_id.

Referenced by getPotentialAccesses(), and read().

+ Here is the caller graph for this function:

◆ getPotentialAccesses()

ilLicense::getPotentialAccesses ( )

Get the number of users who may access the object but don't have yet a license.

@access public

Returns
int number of potential accesses

Definition at line 123 of file class.ilLicense.php.

124 {
125 global $ilDB;
126
127 // get the operation id for read access
128 $ops_ids = ilRbacReview::_getOperationIdsByName(array( 'read' ));
129
130 // first get all roles with read access
131 $role_ids = array();
132 $query = 'SELECT DISTINCT pa.rol_id' . ' FROM rbac_pa pa' . ' INNER JOIN object_reference ob ON ob.ref_id = pa.ref_id' . ' WHERE '
133 . $ilDB->like('pa.ops_id', 'text', '%%i:' . $ops_ids[0] . ';%%') . ' AND ob.obj_id = ' . $ilDB->quote($this->getObjId(), 'integer');
134
135 $result = $ilDB->query($query);
136 while ($row = $ilDB->fetchObject($result)) {
137 $role_ids[] = $row->rol_id;
138 }
139
140 if (!count($role_ids)) {
141 return 0;
142 }
143
144 // then count all users of these roles without read events
145 $query = 'SELECT COUNT(DISTINCT(usr_id)) accesses ' . ' FROM rbac_ua' . ' WHERE ' . $ilDB->in('rol_id', $role_ids, false, 'integer')
146 . ' AND usr_id NOT IN' . ' (SELECT usr_id FROM read_event' . ' WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ')';
147
148 $result = $ilDB->query($query);
149 $row = $ilDB->fetchObject($result);
150
151 return $row->accesses;
152 }
static _getOperationIdsByName($operations)
get ops_id's by name.

References $ilDB, $query, $result, $row, ilRbacReview\_getOperationIdsByName(), and getObjId().

+ Here is the call graph for this function:

◆ getRemainingLicenses()

ilLicense::getRemainingLicenses ( )
Returns
int

Definition at line 111 of file class.ilLicense.php.

112 {
113 return max(0, $this->licenses - $this->accesses);
114 }

◆ getRemarks()

ilLicense::getRemarks ( )
Returns
string

Definition at line 93 of file class.ilLicense.php.

94 {
95 return $this->remarks;
96 }

References $remarks.

◆ read()

ilLicense::read ( )

Read the license data from the database.

@access public

Definition at line 163 of file class.ilLicense.php.

164 {
165 global $ilDB;
166
167 $query = 'SELECT * FROM license_data WHERE obj_id = %s';
168 $result = $ilDB->queryF($query, array( 'integer' ), array( $this->getObjId() ));
169
170 if ($row = $ilDB->fetchObject($result)) {
171 $this->licenses = $row->licenses;
172 $this->accesses = $row->used;
173 $this->remarks = $row->remarks;
174 } else {
175 $this->licenses = 0;
176 $this->accesses = 0;
177 $this->remarks = '';
178 }
179 }

References $ilDB, $query, $result, $row, and getObjId().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLicenses()

ilLicense::setLicenses (   $a_licenses = 0)
Parameters
int$a_licenses

Definition at line 66 of file class.ilLicense.php.

67 {
68 $this->licenses = (int) $a_licenses;
69 }

◆ setObjId()

ilLicense::setObjId (   $obj_id)
Parameters
int$obj_id

Definition at line 57 of file class.ilLicense.php.

58 {
59 $this->obj_id = $obj_id;
60 }

References $obj_id.

◆ setRemarks()

ilLicense::setRemarks (   $a_remarks = '')
Parameters
string$a_remarks

Definition at line 84 of file class.ilLicense.php.

85 {
86 $this->remarks = $a_remarks;
87 }

◆ update()

ilLicense::update ( )

Update the license data in the database.

@access public

Definition at line 187 of file class.ilLicense.php.

188 {
189 global $ilDB;
190
191 $query = 'SELECT * FROM license_data WHERE obj_id = %s';
192 $result = $ilDB->queryF($query, array( 'integer' ), array( $this->obj_id ));
193
194 if ($row = $ilDB->fetchObject($result)) {
195 $ilDB->update('license_data', array(
196 'licenses' => array( 'integer', $this->licenses ),
197 'used' => array( 'integer', $this->accesses ),
198 'remarks' => array( 'clob', $this->remarks ),
199 ), array(
200 'obj_id' => array( 'integer', $this->obj_id ),
201 ));
202 } else {
203 $ilDB->insert('license_data', array(
204 'obj_id' => array( 'integer', $this->obj_id ),
205 'licenses' => array( 'integer', $this->licenses ),
206 'used' => array( 'integer', $this->accesses ),
207 'remarks' => array( 'clob', $this->remarks ),
208 ));
209 }
210 }

References $ilDB, $query, $result, and $row.

Field Documentation

◆ $accesses

ilLicense::$accesses = 0
protected

Definition at line 30 of file class.ilLicense.php.

Referenced by getAccesses().

◆ $licenses

ilLicense::$licenses = 0
protected

Definition at line 22 of file class.ilLicense.php.

Referenced by getLicenses().

◆ $obj_id

ilLicense::$obj_id = 0
protected

Definition at line 18 of file class.ilLicense.php.

Referenced by _getLicensedObjects(), getObjId(), and setObjId().

◆ $remarks

ilLicense::$remarks = ''
protected

Definition at line 26 of file class.ilLicense.php.

Referenced by getRemarks().


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