ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTermsOfServiceHelper.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  public static function isEnabled()
14  {
15  global $DIC;
16 
17  return (bool) $DIC['ilSetting']->get('tos_status', 0);
18  }
19 
23  public static function setStatus($status)
24  {
25  global $DIC;
26 
27  $DIC['ilSetting']->set('tos_status', (int) $status);
28  }
29 
33  public static function deleteAcceptanceHistoryByUser($usr_id)
34  {
35  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
36  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
37  $entity->setUserId($usr_id);
38  $data_gateway->deleteAcceptanceHistoryByUser($entity);
39  }
40 
45  public static function getCurrentAcceptanceForUser(ilObjUser $user)
46  {
47  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
48  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
49  $entity->setUserId($user->getId());
50  return $data_gateway->loadCurrentAcceptanceOfUser($entity);
51  }
52 
57  public static function getById($id)
58  {
59  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
60  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
61  $entity->setId($id);
62  return $data_gateway->loadById($entity);
63  }
64 
69  public static function trackAcceptance(ilObjUser $user, ilTermsOfServiceSignableDocument $document)
70  {
71  if (self::isEnabled() && $document->exists()) {
72  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
73  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
74  $entity->setUserId($user->getId());
75  $entity->setTimestamp(time());
76  $entity->setIso2LanguageCode($document->getIso2LanguageCode());
77  $entity->setSource($document->getSource());
78  $entity->setSourceType($document->getSourceType());
79  $entity->setText($document->getContent());
80  $entity->setHash(md5($document->getContent()));
81  $data_gateway->trackAcceptance($entity);
82 
83  $user->writeAccepted(); // <- Has to be refactored in future releases
84 
86  }
87  }
88 
92  private static function getEntityFactory()
93  {
94  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceEntityFactory.php';
95  return new ilTermsOfServiceEntityFactory();
96  }
97 
101  private static function getDataGatewayFactory()
102  {
103  global $DIC;
104 
105  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceDataGatewayFactory.php';
107  $factory->setDatabaseAdapter($DIC['ilDB']);
108  return $factory;
109  }
110 }
global $DIC
Definition: saml.php:7
$factory
Definition: metadata.php:47
if(!array_key_exists('StateId', $_REQUEST)) $id
writeAccepted()
write accept date of user agreement to db
getId()
get object id public
static getCurrentAcceptanceForUser(ilObjUser $user)
static trackAcceptance(ilObjUser $user, ilTermsOfServiceSignableDocument $document)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
hasToAcceptTermsOfServiceInSession($status=null)