Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
41498ac5 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
41498ac5 TO |
7 | | This work is published under the GNU AGPLv3 license with some | |
8 | | permitted exceptions and without any warranty. For full license | | |
9 | | and copyright information, see https://civicrm.org/licensing | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace Civi\Api4\Action\Contact; |
23 | ||
24 | use Civi\Api4\Generic\Result; | |
25 | ||
26 | /** | |
27 | * Generate a security checksum for anonymous access to CiviCRM. | |
28 | * | |
29 | * @method $this setContactId(int $cid) Set contact ID (required) | |
30 | * @method int getContactId() Get contact ID param | |
31 | * @method $this setTtl(int $ttl) Set TTL param | |
32 | * @method int getTtl() Get TTL param | |
33 | */ | |
34 | class GetChecksum extends \Civi\Api4\Generic\AbstractAction { | |
35 | ||
36 | /** | |
37 | * ID of contact | |
38 | * | |
39 | * @var int | |
40 | * @required | |
41 | */ | |
42 | protected $contactId; | |
43 | ||
44 | /** | |
45 | * Expiration time (hours). Defaults to 168 (24 * [7 or value of checksum_timeout system setting]). | |
46 | * | |
47 | * Set to 0 for infinite. | |
48 | * | |
49 | * @var int | |
50 | */ | |
51 | protected $ttl = NULL; | |
52 | ||
53 | /** | |
54 | * @param \Civi\Api4\Generic\Result $result | |
55 | */ | |
56 | public function _run(Result $result) { | |
57 | $ttl = ($this->ttl === 0 || $this->ttl === '0') ? 'inf' : $this->ttl; | |
58 | $result[] = [ | |
59 | 'id' => $this->contactId, | |
60 | 'checksum' => \CRM_Contact_BAO_Contact_Utils::generateChecksum($this->contactId, NULL, $ttl), | |
61 | ]; | |
62 | } | |
63 | ||
64 | } |