Loader = $loader; $this->DBManager = new DBManager(); } public function CreateLink($entryId, $options) { $reference = IdUtils::GetUniqueId(); $this->DBManager->Insert($this->Loader->LINKS, array( 'reference' => $reference, 'entry_id' => $entryId, 'date' => date('c'), 'expiration_date' => date('c', strtotime('+1 month')), 'options' => \json_encode($options) )); return IntegrationURL::PublicEntryURL($this->Loader, $entryId, $reference); } /** * @param $reference * @return LinkData */ public function GetLinkData($entryId, $reference) { $result = $this->DBManager->GetResult('select entry_id, options from ' . $this->Loader->LINKS . ' where entry_id=%s and reference=%s and dateoptions); $linkOptions = (new LinkOptions())->Merge($options); return new LinkData($result->entry_id, $linkOptions); } } class LinkData{ public $EntryId; /** @var LinkOptions */ public $LinkOptions; public function __construct($entryId, $linkOptions) { $this->EntryId = $entryId; $this->LinkOptions = $linkOptions; } } class LinkOptions{ public $AllowEdition; public $RequiresAuthentication; public function __construct($allowEdition = false, $requiresAuthentication = false) { $this->AllowEdition = $allowEdition; $this->RequiresAuthentication = false; } public function Merge($data) { foreach($this as $propertyName => $value) { if(isset($data->$propertyName)) $this->$propertyName = $data->$propertyName; } return $this; } }