api4 - Import CRM/, Civi/, templates/, ang/, css/, js/, xml/menu
[civicrm-core.git] / Civi / Api4 / Generic / AbstractBatchAction.php
1 <?php
2
3 namespace Civi\Api4\Generic;
4
5 /**
6 * Base class for all batch actions (Update, Delete, Replace).
7 *
8 * This differs from the AbstractQuery class in that the "Where" clause is required.
9 *
10 * @package Civi\Api4\Generic
11 */
12 abstract class AbstractBatchAction extends AbstractQueryAction {
13
14 /**
15 * Criteria for selecting items to process.
16 *
17 * @var array
18 * @required
19 */
20 protected $where = [];
21
22 /**
23 * @var array
24 */
25 private $select;
26
27 /**
28 * BatchAction constructor.
29 * @param string $entityName
30 * @param string $actionName
31 * @param string|array $select
32 * One or more fields to load for each item.
33 */
34 public function __construct($entityName, $actionName, $select = 'id') {
35 $this->select = (array) $select;
36 parent::__construct($entityName, $actionName);
37 }
38
39 /**
40 * @return array
41 */
42 protected function getBatchRecords() {
43 $params = [
44 'checkPermissions' => $this->checkPermissions,
45 'where' => $this->where,
46 'orderBy' => $this->orderBy,
47 'limit' => $this->limit,
48 'offset' => $this->offset,
49 ];
50 if (empty($this->reload)) {
51 $params['select'] = $this->select;
52 }
53
54 return (array) civicrm_api4($this->getEntityName(), 'get', $params);
55 }
56
57 /**
58 * @return array
59 */
60 protected function getSelect() {
61 return $this->select;
62 }
63
64 }