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