ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
18  global $ilSetting;
19 
20  return (bool)$ilSetting->get('tos_status', 0);
21  }
22 
26  public static function setStatus($status)
27  {
31  global $ilSetting;
32 
33  $ilSetting->set('tos_status', (int)$status);
34  }
35 
39  public static function deleteAcceptanceHistoryByUser($usr_id)
40  {
41  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
42  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
43  $entity->setUserId($usr_id);
44  $data_gateway->deleteAcceptanceHistoryByUser($entity);
45  }
46 
51  public static function getCurrentAcceptanceForUser(ilObjUser $user)
52  {
53  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
54  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
55  $entity->setUserId($user->getId());
56  return $data_gateway->loadCurrentAcceptanceOfUser($entity);
57  }
58 
63  public static function getById($id)
64  {
65  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
66  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
67  $entity->setId($id);
68  return $data_gateway->loadById($entity);
69  }
70 
75  public static function trackAcceptance(ilObjUser $user, ilTermsOfServiceSignableDocument $document)
76  {
77  if(self::isEnabled())
78  {
79  $entity = self::getEntityFactory()->getByName('ilTermsOfServiceAcceptanceEntity');
80  $data_gateway = self::getDataGatewayFactory()->getByName('ilTermsOfServiceAcceptanceDatabaseGateway');
81  $entity->setUserId($user->getId());
82  $entity->setTimestamp(time());
83  $entity->setIso2LanguageCode($document->getIso2LanguageCode());
84  $entity->setSource($document->getSource());
85  $entity->setSourceType($document->getSourceType());
86  $entity->setText($document->getContent());
87  $entity->setHash(md5($document->getContent()));
88  $data_gateway->trackAcceptance($entity);
89 
90  $user->writeAccepted(); // <- Has to be refactored in future releases
91 
93  }
94  }
95 
99  private static function getEntityFactory()
100  {
101  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceEntityFactory.php';
102  return new ilTermsOfServiceEntityFactory();
103  }
104 
108  private static function getDataGatewayFactory()
109  {
113  global $ilDB;
114 
115  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceDataGatewayFactory.php';
116  $factory = new ilTermsOfServiceDataGatewayFactory();
117  $factory->setDatabaseAdapter($ilDB);
118  return $factory;
119  }
120 }