ILIAS  release_4-4 Revision
ilLicense Class Reference
+ Collaboration diagram for ilLicense:

Public Member Functions

 ilLicense ($a_obj_id)
 Constructor public. More...
 
 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...
 
 _checkAccess ($a_usr_id, $a_obj_id)
 Check, if a user can access an object by license. More...
 
 _noteAccess ($a_obj_id, $a_type, $a_ref_id)
 Note the access of the current usr to an object. More...
 
 _getLicensedObjects ()
 Get a list of all objects with activated licensing. More...
 
 _getLicensedChildObjects ($a_ref_id)
 Get a list of all sub objects with activated licensing. More...
 
 _isLicensed ($a_obj_id)
 Check if an object has licensing activated. More...
 

Detailed Description

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

Member Function Documentation

◆ _checkAccess()

ilLicense::_checkAccess (   $a_usr_id,
  $a_obj_id 
)

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.

static

Parameters
intuser id
intobject id (not reference)
Returns
boolean access is possible (true/false)

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

References ilLicenseAccess\_checkAccess().

194  {
195  // Implementation moved
196  require_once("Services/License/classes/class.ilLicenseAccess.php");
197  return ilLicenseAccess::_checkAccess($a_usr_id, $a_obj_id);
198  }
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()

ilLicense::_getLicensedChildObjects (   $a_ref_id)

Get a list of all sub objects with activated licensing.

static

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

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

References $data.

Referenced by ilObjCourseGUI\checkLicenses(), and ilLicenseOverviewGUI\showLicenses().

292  {
293  global $ilDB, $tree;
294  $objects = array();
295 
296  $childs = $tree->getChilds($a_ref_id, 'title');
297  foreach ($childs as $data)
298  {
299  if (in_array($data['type'], array('sahs','htlm'))
300  and self::_isLicensed($data['obj_id']))
301  {
302  $objects[] = $data;
303  }
304  }
305  return $objects;
306  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the caller graph for this function:

◆ _getLicensedObjects()

ilLicense::_getLicensedObjects ( )

Get a list of all objects with activated licensing.

static

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

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

References $query, $result, and $row.

Referenced by ilLicenseOverviewGUI\showLicenses().

260  {
261  global $ilDB;
262  $objects = array();
263 
264  $query = 'SELECT od.obj_id, od.type, od.title, od.description, re.ref_id '
265  . 'FROM license_data ld '
266  . 'INNER JOIN object_data od ON od.obj_id = ld.obj_id '
267  . 'INNER JOIN object_reference re ON re.obj_id = od.obj_id '
268  . 'WHERE ld.licenses > 0 '
269  . 'ORDER BY od.title, od.obj_id';
270 
271  $result = $ilDB->query($query);
272  $obj_id = 0;
273  while ($row = $ilDB->fetchAssoc($result))
274  {
275  if ($row['obj_id'] != $obj_id)
276  {
277  $objects[] = $row;
278  $obj_id = $row['obj_id'];
279  }
280  }
281  return $objects;
282  }
$result
+ Here is the caller graph for this function:

◆ _isLicensed()

ilLicense::_isLicensed (   $a_obj_id)

Check if an object has licensing activated.

static

Parameters
intobject id
Returns
boolean object has licensing (true/false)

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

References $query, $result, and $row.

316  {
317  global $ilDB;
318 
319  $query = "SELECT licenses FROM license_data ".
320  "WHERE obj_id = %s ".
321  "AND licenses > 0";
322  $result = $ilDB->queryF($query, array('integer'), array($a_obj_id));
323  if ($row = $ilDB->fetchObject($result))
324  {
325  return true;
326  }
327  }
$result

◆ _noteAccess()

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

Note the access of the current usr to an object.

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

static

Parameters
intobject id (not reference)

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

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

Referenced by ilSAHSPresentationGUI\executeCommand(), and ilObjFileBasedLMGUI\showLearningModule().

210  {
211  global $ilDB, $ilUser, $ilSetting;
212 
213 
214  // don't note the access if licensing is globally disabled
215  require_once("Services/License/classes/class.ilLicenseAccess.php");
217  {
218  return;
219  }
220 
221  // check if user has already accessed
222  $query = 'SELECT read_count FROM read_event '
223  .'WHERE usr_id = %s AND obj_id = %s';
224  $result = $ilDB->queryF($query,
225  array('integer','integer'),
226  array($ilUser->getId(), $a_obj_id));
227 
228  if ($row = $ilDB->fetchObject($result))
229  {
230  // already accessed -> nothing to do
231  return;
232  }
233  else
234  {
235  // note access
236  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
237  ilChangeEvent::_recordReadEvent($a_type, $a_ref_id, $a_obj_id, $ilUser->getId());
238 
239  if (self::_isLicensed($a_obj_id))
240  {
241  // increase used licenses
242  $query = "UPDATE license_data SET used = used + 1 "
243  ."WHERE obj_id = %s";
244  $ilDB->manipulateF($query, array('integer'), array($a_obj_id));
245  }
246  }
247  }
$result
static _isEnabled()
Check, if licencing is enabled This check is called from the ilAccessHandler class.
_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.
global $ilUser
Definition: imgupload.php:15
global $ilSetting
Definition: privfeed.php:40
+ 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 169 of file class.ilLicense.php.

References $query.

170  {
171  global $ilDB;
172 
173  $query = 'DELETE FROM license_data WHERE obj_id = %s';
174  $ilDB->manipulateF($query, array('integer'), array($this->obj_id));
175  }

◆ getAccesses()

ilLicense::getAccesses ( )

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

45  {
46  return $this->accesses;
47  }

◆ getLicenses()

ilLicense::getLicenses ( )

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

33  {
34  return $this->licenses;
35  }

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

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

60  {
61  global $ilDB;
62 
63  // get the operation id for read access
64  $ops_ids = ilRbacReview::_getOperationIdsByName(array('read'));
65 
66  // first get all roles with read access
67  $role_ids = array();
68  $query = 'SELECT DISTINCT pa.rol_id'
69  . ' FROM rbac_pa pa'
70  . ' INNER JOIN object_reference ob ON ob.ref_id = pa.ref_id'
71  . ' WHERE '.$ilDB->like('pa.ops_id', 'text', '%%i:'.$ops_ids[0].';%%')
72  . ' AND ob.obj_id = ' . $ilDB->quote($this->obj_id, 'integer');
73 
74  $result = $ilDB->query($query);
75  while ($row = $ilDB->fetchObject($result))
76  {
77  $role_ids[] = $row->rol_id;
78  }
79 
80  if (!count($role_ids))
81  {
82  return 0;
83  }
84 
85  // then count all users of these roles without read events
86  $query = 'SELECT COUNT(DISTINCT(usr_id)) accesses '
87  . ' FROM rbac_ua'
88  . ' WHERE '. $ilDB->in('rol_id', $role_ids, false, 'integer')
89  . ' AND usr_id NOT IN'
90  . ' (SELECT usr_id FROM read_event'
91  . ' WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ')';
92 
93  $result = $ilDB->query($query);
94  $row = $ilDB->fetchObject($result);
95  return $row->accesses;
96  }
$result
static _getOperationIdsByName($operations)
get ops_id's by name.
+ Here is the call graph for this function:

◆ getRemainingLicenses()

ilLicense::getRemainingLicenses ( )

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

49  {
50  return max(0, $this->licenses - $this->accesses);
51  }

◆ getRemarks()

ilLicense::getRemarks ( )

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

41  {
42  return $this->remarks;
43  }

◆ ilLicense()

ilLicense::ilLicense (   $a_obj_id)

Constructor public.

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

References read().

20  {
21  $this->obj_id = (int) $a_obj_id;
22  $this->read();
23  }
read()
Read the license data from the database.
+ Here is the call graph for this function:

◆ read()

ilLicense::read ( )

Read the license data from the database.

public

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

References $query, $result, and $row.

Referenced by ilLicense().

108  {
109  global $ilDB;
110 
111  $query = 'SELECT * FROM license_data WHERE obj_id = %s';
112  $result = $ilDB->queryF($query, array('integer'), array($this->obj_id));
113 
114  if ($row = $ilDB->fetchObject($result))
115  {
116  $this->licenses = $row->licenses;
117  $this->accesses = $row->used;
118  $this->remarks = $row->remarks;
119  }
120  else
121  {
122  $this->licenses = 0;
123  $this->accesses = 0;
124  $this->remarks = '';
125  }
126  }
$result
+ Here is the caller graph for this function:

◆ setLicenses()

ilLicense::setLicenses (   $a_licenses = 0)

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

29  {
30  $this->licenses = (int) $a_licenses;
31  }

◆ setRemarks()

ilLicense::setRemarks (   $a_remarks = '')

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

37  {
38  $this->remarks = $a_remarks;
39  }

◆ update()

ilLicense::update ( )

Update the license data in the database.

public

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

References $query, $result, and $row.

134  {
135  global $ilDB;
136 
137  $query = 'SELECT * FROM license_data WHERE obj_id = %s';
138  $result = $ilDB->queryF($query, array('integer'), array($this->obj_id));
139 
140  if ($row = $ilDB->fetchObject($result))
141  {
142  $ilDB->update('license_data',
143  array(
144  'licenses' => array('integer', $this->licenses),
145  'used' => array('integer', $this->accesses),
146  'remarks' => array('clob', $this->remarks)
147  ),
148  array(
149  'obj_id' => array('integer', $this->obj_id),
150  )
151  );
152  }
153  else
154  {
155  $ilDB->insert('license_data', array(
156  'obj_id' => array('integer', $this->obj_id),
157  'licenses' => array('integer', $this->licenses),
158  'used' => array('integer', $this->accesses),
159  'remarks' => array('clob', $this->remarks)
160  ));
161  }
162  }
$result

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