ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

public

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

References read().

37  {
38  $this->obj_id = (int)$a_obj_id;
39  $this->read();
40  }
read()
Read the license data from the database.
+ 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 229 of file class.ilLicense.php.

References ilLicenseAccess\_checkAccess().

229  {
230  // Implementation moved
231  require_once("Services/License/classes/class.ilLicenseAccess.php");
232 
233  return ilLicenseAccess::_checkAccess($a_usr_id, $a_obj_id);
234  }
static _checkAccess($a_usr_id, $a_obj_id)
Check, if a user can access an object by license.
+ 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 311 of file class.ilLicense.php.

References $data, and array.

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

311  {
312  global $tree;
313  $objects = array();
314 
315  $childs = $tree->getChilds($a_ref_id, 'title');
316  foreach ($childs as $data) {
317  if (in_array($data['type'], array( 'sahs', 'htlm' )) and self::_isLicensed($data['obj_id'])) {
318  $objects[] = $data;
319  }
320  }
321 
322  return $objects;
323  }
Create styles array
The data for the language used.
+ 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 284 of file class.ilLicense.php.

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

Referenced by ilLicenseOverviewTableGUI\getItems().

284  {
285  global $ilDB;
286  $objects = array();
287 
288  $query = 'SELECT od.obj_id, od.type, od.title, od.description, re.ref_id ' . 'FROM license_data ld '
289  . 'INNER JOIN object_data od ON od.obj_id = ld.obj_id ' . 'INNER JOIN object_reference re ON re.obj_id = od.obj_id '
290  . 'WHERE ld.licenses > 0 ' . 'ORDER BY od.title, od.obj_id';
291 
292  $result = $ilDB->query($query);
293  $obj_id = 0;
294  while ($row = $ilDB->fetchAssoc($result)) {
295  if ($row['obj_id'] != $obj_id) {
296  $objects[] = $row;
297  $obj_id = $row['obj_id'];
298  }
299  }
300 
301  return $objects;
302  }
$result
Create styles array
The data for the language used.
global $ilDB
+ 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 332 of file class.ilLicense.php.

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

332  {
333  global $ilDB;
334 
335  $query = "SELECT licenses FROM license_data " . "WHERE obj_id = %s " . "AND licenses > 0";
336  $result = $ilDB->queryF($query, array( 'integer' ), array( $a_obj_id ));
337  if ($row = $ilDB->fetchObject($result)) {
338  return true;
339  }
340  }
$result
Create styles array
The data for the language used.
global $ilDB

◆ _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 246 of file class.ilLicense.php.

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

Referenced by ilSAHSPresentationGUI\executeCommand().

246  {
247  global $ilDB, $ilUser;
248 
249  // don't note the access if licensing is globally disabled
250  require_once("Services/License/classes/class.ilLicenseAccess.php");
252  return;
253  }
254 
255  // check if user has already accessed
256  $query = 'SELECT read_count FROM read_event ' . 'WHERE usr_id = %s AND obj_id = %s';
257  $result = $ilDB->queryF($query, array( 'integer', 'integer' ), array( $ilUser->getId(), $a_obj_id ));
258 
259  if ($row = $ilDB->fetchObject($result)) {
260  // already accessed -> nothing to do
261  return;
262  } else {
263  // note access
264  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
265  ilChangeEvent::_recordReadEvent($a_type, $a_ref_id, $a_obj_id, $ilUser->getId());
266 
267  if (self::_isLicensed($a_obj_id)) {
268  // increase used licenses
269  $query = "UPDATE license_data SET used = used + 1 " . "WHERE obj_id = %s";
270  $ilDB->manipulateF($query, array( 'integer' ), array( $a_obj_id ));
271  }
272  }
273  }
$result
static _isEnabled()
Check, if licencing is enabled This check is called from the ilAccessHandler class.
$a_type
Definition: workflow.php:93
$ilUser
Definition: imgupload.php:18
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.
Create styles array
The data for the language used.
global $ilDB
+ 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.

public

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

References $ilDB, $query, and array.

205  {
206  global $ilDB;
207 
208  $query = 'DELETE FROM license_data WHERE obj_id = %s';
209  $ilDB->manipulateF($query, array( 'integer' ), array( $this->obj_id ));
210  }
Create styles array
The data for the language used.
global $ilDB

◆ getAccesses()

ilLicense::getAccesses ( )
Returns
int

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

References $accesses.

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

◆ getLicenses()

ilLicense::getLicenses ( )
Returns
int

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

References $licenses.

70  {
71  return $this->licenses;
72  }

◆ getObjId()

ilLicense::getObjId ( )
Returns
int

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

References $obj_id.

Referenced by getPotentialAccesses(), and read().

46  {
47  return $this->obj_id;
48  }
+ 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.

public

Returns
int number of potential accesses

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

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

113  {
114  global $ilDB;
115 
116  // get the operation id for read access
117  $ops_ids = ilRbacReview::_getOperationIdsByName(array( 'read' ));
118 
119  // first get all roles with read access
120  $role_ids = array();
121  $query = 'SELECT DISTINCT pa.rol_id' . ' FROM rbac_pa pa' . ' INNER JOIN object_reference ob ON ob.ref_id = pa.ref_id' . ' WHERE '
122  . $ilDB->like('pa.ops_id', 'text', '%%i:' . $ops_ids[0] . ';%%') . ' AND ob.obj_id = ' . $ilDB->quote($this->getObjId(), 'integer');
123 
124  $result = $ilDB->query($query);
125  while ($row = $ilDB->fetchObject($result)) {
126  $role_ids[] = $row->rol_id;
127  }
128 
129  if (!count($role_ids)) {
130  return 0;
131  }
132 
133  // then count all users of these roles without read events
134  $query = 'SELECT COUNT(DISTINCT(usr_id)) accesses ' . ' FROM rbac_ua' . ' WHERE ' . $ilDB->in('rol_id', $role_ids, false, 'integer')
135  . ' AND usr_id NOT IN' . ' (SELECT usr_id FROM read_event' . ' WHERE obj_id = ' . $ilDB->quote($this->getObjId(), 'integer') . ')';
136 
137  $result = $ilDB->query($query);
138  $row = $ilDB->fetchObject($result);
139 
140  return $row->accesses;
141  }
$result
static _getOperationIdsByName($operations)
get ops_id's by name.
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ getRemainingLicenses()

ilLicense::getRemainingLicenses ( )
Returns
int

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

102  {
103  return max(0, $this->licenses - $this->accesses);
104  }

◆ getRemarks()

ilLicense::getRemarks ( )
Returns
string

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

References $remarks.

86  {
87  return $this->remarks;
88  }

◆ read()

ilLicense::read ( )

Read the license data from the database.

public

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

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

Referenced by __construct().

152  {
153  global $ilDB;
154 
155  $query = 'SELECT * FROM license_data WHERE obj_id = %s';
156  $result = $ilDB->queryF($query, array( 'integer' ), array( $this->getObjId() ));
157 
158  if ($row = $ilDB->fetchObject($result)) {
159  $this->licenses = $row->licenses;
160  $this->accesses = $row->used;
161  $this->remarks = $row->remarks;
162  } else {
163  $this->licenses = 0;
164  $this->accesses = 0;
165  $this->remarks = '';
166  }
167  }
$result
Create styles array
The data for the language used.
global $ilDB
+ 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 62 of file class.ilLicense.php.

62  {
63  $this->licenses = (int)$a_licenses;
64  }

◆ setObjId()

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

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

References $obj_id.

54  {
55  $this->obj_id = $obj_id;
56  }

◆ setRemarks()

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

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

78  {
79  $this->remarks = $a_remarks;
80  }

◆ update()

ilLicense::update ( )

Update the license data in the database.

public

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

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

175  {
176  global $ilDB;
177 
178  $query = 'SELECT * FROM license_data WHERE obj_id = %s';
179  $result = $ilDB->queryF($query, array( 'integer' ), array( $this->obj_id ));
180 
181  if ($row = $ilDB->fetchObject($result)) {
182  $ilDB->update('license_data', array(
183  'licenses' => array( 'integer', $this->licenses ),
184  'used' => array( 'integer', $this->accesses ),
185  'remarks' => array( 'clob', $this->remarks ),
186  ), array(
187  'obj_id' => array( 'integer', $this->obj_id ),
188  ));
189  } else {
190  $ilDB->insert('license_data', array(
191  'obj_id' => array( 'integer', $this->obj_id ),
192  'licenses' => array( 'integer', $this->licenses ),
193  'used' => array( 'integer', $this->accesses ),
194  'remarks' => array( 'clob', $this->remarks ),
195  ));
196  }
197  }
$result
Create styles array
The data for the language used.
global $ilDB

Field Documentation

◆ $accesses

ilLicense::$accesses = 0
protected

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

Referenced by getAccesses().

◆ $licenses

ilLicense::$licenses = 0
protected

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

Referenced by getLicenses().

◆ $obj_id

ilLicense::$obj_id = 0
protected

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

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

◆ $remarks

ilLicense::$remarks = ''
protected

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

Referenced by getRemarks().


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