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 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace Civi\Api4\Action\Contact; |
21 | ||
22 | use Civi\Api4\Generic\Result; | |
23 | ||
24 | /** | |
25 | * Generate a security checksum for anonymous access to CiviCRM. | |
26 | * | |
27 | * @method $this setContactId(int $cid) Set contact ID (required) | |
28 | * @method int getContactId() Get contact ID param | |
29 | * @method $this setTtl(int $ttl) Set TTL param | |
30 | * @method int getTtl() Get TTL param | |
31 | */ | |
32 | class GetChecksum extends \Civi\Api4\Generic\AbstractAction { | |
33 | ||
34 | /** | |
35 | * ID of contact | |
36 | * | |
37 | * @var int | |
38 | * @required | |
39 | */ | |
40 | protected $contactId; | |
41 | ||
42 | /** | |
43 | * Expiration time (hours). Defaults to 168 (24 * [7 or value of checksum_timeout system setting]). | |
44 | * | |
45 | * Set to 0 for infinite. | |
46 | * | |
47 | * @var int | |
48 | */ | |
49 | protected $ttl = NULL; | |
50 | ||
51 | /** | |
52 | * @param \Civi\Api4\Generic\Result $result | |
53 | */ | |
54 | public function _run(Result $result) { | |
55 | $ttl = ($this->ttl === 0 || $this->ttl === '0') ? 'inf' : $this->ttl; | |
56 | $result[] = [ | |
57 | 'id' => $this->contactId, | |
58 | 'checksum' => \CRM_Contact_BAO_Contact_Utils::generateChecksum($this->contactId, NULL, $ttl), | |
59 | ]; | |
60 | } | |
61 | ||
62 | } |