ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ResourceLinkShareKey.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
17 {
18 
22  const MAX_SHARE_KEY_LIFE = 168; // in hours (1 week)
26  const DEFAULT_SHARE_KEY_LIFE = 24; // in hours
35 
41  public $resourceLinkId = null;
47  public $length = null;
53  public $life = null; // in hours
59  public $autoApprove = false;
65  public $expires = null;
66 
72  private $id = null;
78  private $dataConnector = null;
79 
86  public function __construct($resourceLink, $id = null)
87  {
88 
89  $this->initialize();
90  $this->dataConnector = $resourceLink->getDataConnector();
91  $this->resourceLinkId = $resourceLink->getRecordId();
92  $this->id = $id;
93  if (!empty($id)) {
94  $this->load();
95  }
96 
97  }
98 
102  public function initialize()
103  {
104 
105  $this->length = null;
106  $this->life = null;
107  $this->autoApprove = false;
108  $this->expires = null;
109 
110  }
111 
117  public function initialise()
118  {
119 
120  $this->initialize();
121 
122  }
123 
129  public function save()
130  {
131 
132  if (empty($this->life)) {
133  $this->life = self::DEFAULT_SHARE_KEY_LIFE;
134  } else {
135  $this->life = max(min($this->life, self::MAX_SHARE_KEY_LIFE), 0);
136  }
137  $this->expires = time() + ($this->life * 60 * 60);
138  if (empty($this->id)) {
139  if (empty($this->length) || !is_numeric($this->length)) {
140  $this->length = self::MAX_SHARE_KEY_LENGTH;
141  } else {
142  $this->length = max(min($this->length, self::MAX_SHARE_KEY_LENGTH), self::MIN_SHARE_KEY_LENGTH);
143  }
144  $this->id = DataConnector::getRandomString($this->length);
145  }
146 
147  return $this->dataConnector->saveResourceLinkShareKey($this);
148 
149  }
150 
156  public function delete()
157  {
158 
159  return $this->dataConnector->deleteResourceLinkShareKey($this);
160 
161  }
162 
168  public function getId()
169  {
170 
171  return $this->id;
172 
173  }
174 
175 ###
176 ### PRIVATE METHOD
177 ###
178 
182  private function load()
183  {
184 
185  $this->initialize();
186  $this->dataConnector->loadResourceLinkShareKey($this);
187  if (!is_null($this->id)) {
188  $this->length = strlen($this->id);
189  }
190  if (!is_null($this->expires)) {
191  $this->life = ($this->expires - time()) / 60 / 60;
192  }
193 
194  }
195 
196 }
save()
Save the resource link share key to the database.
initialize()
Initialise the resource link share key.
load()
Load the resource link share key from the database.
$autoApprove
Whether the sharing arrangement should be automatically approved when first used. ...
const DEFAULT_SHARE_KEY_LIFE
Default life for a share key value.
initialise()
Initialise the resource link share key.
const MIN_SHARE_KEY_LENGTH
Minimum length for a share key value.
const MAX_SHARE_KEY_LENGTH
Maximum length for a share key value.
Class to represent a tool consumer resource link share key.
const MAX_SHARE_KEY_LIFE
Maximum permitted life for a share key value.
$expires
Date/time when the share key expires.
static getRandomString($length=8)
Generate a random string.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$resourceLinkId
ID for resource link being shared.
__construct($resourceLink, $id=null)
Class constructor.