Merge pull request #13078 from agh1/contactdetail-no-or2
[civicrm-core.git] / Civi / Api4 / Action / Contact / GetChecksum.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
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 }