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\Generic; |
23 | ||
24 | /** | |
25 | * Base class for all batch actions (Update, Delete, Replace). | |
26 | * | |
27 | * This differs from the AbstractQuery class in that the "Where" clause is required. | |
28 | * | |
29 | * @package Civi\Api4\Generic | |
30 | */ | |
31 | abstract class AbstractBatchAction extends AbstractQueryAction { | |
32 | ||
33 | /** | |
34 | * Criteria for selecting items to process. | |
35 | * | |
36 | * @var array | |
37 | * @required | |
38 | */ | |
39 | protected $where = []; | |
40 | ||
41 | /** | |
42 | * @var array | |
43 | */ | |
44 | private $select; | |
45 | ||
46 | /** | |
47 | * BatchAction constructor. | |
48 | * @param string $entityName | |
49 | * @param string $actionName | |
50 | * @param string|array $select | |
51 | * One or more fields to load for each item. | |
52 | */ | |
53 | public function __construct($entityName, $actionName, $select = 'id') { | |
54 | $this->select = (array) $select; | |
55 | parent::__construct($entityName, $actionName); | |
56 | } | |
57 | ||
58 | /** | |
59 | * @return array | |
60 | */ | |
61 | protected function getBatchRecords() { | |
62 | $params = [ | |
63 | 'checkPermissions' => $this->checkPermissions, | |
64 | 'where' => $this->where, | |
65 | 'orderBy' => $this->orderBy, | |
66 | 'limit' => $this->limit, | |
67 | 'offset' => $this->offset, | |
68 | ]; | |
69 | if (empty($this->reload)) { | |
70 | $params['select'] = $this->select; | |
71 | } | |
72 | ||
73 | return (array) civicrm_api4($this->getEntityName(), 'get', $params); | |
74 | } | |
75 | ||
76 | /** | |
77 | * @return array | |
78 | */ | |
79 | protected function getSelect() { | |
80 | return $this->select; | |
81 | } | |
82 | ||
83 | } |