Merge in 5.29
[civicrm-core.git] / CRM / Core / PrevNextCache / Interface.php
CommitLineData
780fd0e3
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
780fd0e3 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
780fd0e3
TO
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * Interface CRM_Core_PrevNextCache_Interface
14 *
15 * The previous/next cache is a service for tracking query results. Results
16 * are stored in a cache, and they may be individually toggled.
17 */
18interface CRM_Core_PrevNextCache_Interface {
19
32a2c024
TO
20 /**
21 * Store the results of a SQL query in the cache.
22 *
83068a64 23 * @param string $cacheKey
32a2c024
TO
24 * @param string $sql
25 * A SQL query. The query *MUST* be a SELECT statement which yields
783b4b21 26 * the following columns (in order): cachekey, entity_id1, data
2c8b42d5 27 * @param array $sqlParams
f939667b
TO
28 * An array of parameters to be used with $sql.
29 * Use the same interpolation format as CRM_Core_DAO (composeQuery/executeQuery).
30 * Ex: [1 => ['foo', 'String']]
32a2c024 31 * @return bool
f939667b 32 * @see CRM_Core_DAO::composeQuery
32a2c024 33 */
569b8347 34 public function fillWithSql($cacheKey, $sql, $sqlParams = []);
32a2c024 35
83068a64
TO
36 /**
37 * Store the contents of an array in the cache.
38 *
39 * @param string $cacheKey
40 * @param array $rows
41 * A list of cache records. Each record should have keys:
83068a64 42 * - entity_id1
83068a64
TO
43 * - data
44 * @return bool
45 */
46 public function fillWithArray($cacheKey, $rows);
47
0b8038a6
TO
48 /**
49 * Save checkbox selections.
50 *
51 * @param string $cacheKey
52 * @param string $action
53 * Ex: 'select', 'unselect'.
e97c66ff 54 * @param array|int|null $ids
0b8038a6
TO
55 * A list of contact IDs to (un)select.
56 * To unselect all contact IDs, use NULL.
0b8038a6 57 */
bab1fd32 58 public function markSelection($cacheKey, $action, $ids = NULL);
0b8038a6 59
b7994703
TO
60 /**
61 * Get the selections.
62 *
63 * @param string $cacheKey
64 * Cache key.
65 * @param string $action
40ddbe99
TO
66 * One of the following:
67 * - 'get' - get only selection records
68 * - 'getall' - get all the records of the specified cache key
b7994703
TO
69 *
70 * @return array|NULL
71 */
40ddbe99 72 public function getSelection($cacheKey, $action = 'get');
b7994703 73
d379a6d9
TO
74 /**
75 * Get the previous and next keys.
76 *
77 * @param string $cacheKey
78 * @param int $id1
d379a6d9
TO
79 *
80 * @return array
ec192197
TO
81 * List of neighbors.
82 * [
83 * 'foundEntry' => 1,
84 * 'prev' => ['id1' => 123, 'data'=>'foo'],
85 * 'next' => ['id1' => 456, 'data'=>'foo'],
86 * ]
d379a6d9 87 */
ec192197 88 public function getPositions($cacheKey, $id1);
d379a6d9 89
744b4e34
TO
90 /**
91 * Delete an item from the prevnext cache table based on the entity.
92 *
93 * @param int $id
94 * @param string $cacheKey
744b4e34 95 */
ec192197 96 public function deleteItem($id = NULL, $cacheKey = NULL);
744b4e34 97
c93f3d19
TO
98 /**
99 * Get count of matching rows.
100 *
101 * @param string $cacheKey
102 * @return int
103 */
104 public function getCount($cacheKey);
105
2ca46d4d
TO
106 /**
107 * Fetch a list of contacts from the prev/next cache for displaying a search results page
108 *
109 * @param string $cacheKey
110 * @param int $offset
111 * @param int $rowCount
112 * @return array
113 * List of contact IDs (entity_id1).
114 */
115 public function fetch($cacheKey, $offset, $rowCount);
116
435fc552
SL
117 /**
118 * Remove items from prev/next cache no longer current
119 */
120 public function cleanup();
121
780fd0e3 122}