Commit | Line | Data |
---|---|---|
8adcd073 TO |
1 | <?php |
2 | namespace Civi\Token\Event; | |
3 | ||
4 | /** | |
5 | * Class TokenValueEvent | |
6 | * @package Civi\Token\Event | |
7 | * | |
8 | * A TokenValueEvent is fired to convert raw query data into mergeable | |
9 | * tokens. For example: | |
10 | * | |
11 | * @code | |
12 | * $event = new TokenValueEvent($myContext, 'text/html', array( | |
13 | * array('contact_id' => 123), | |
14 | * array('contact_id' => 456), | |
15 | * )); | |
16 | * | |
17 | * // Compute tokens one row at a time. | |
18 | * foreach ($event->getRows() as $row) { | |
19 | * $row->setTokens('contact', array( | |
20 | * 'profileUrl' => CRM_Utils_System::url('civicrm/profile/view', 'reset=1&gid=456&id=' . $row['contact_id']'), | |
21 | * )); | |
22 | * } | |
23 | * | |
24 | * // Compute tokens with a bulk lookup. | |
25 | * $ids = implode(',', array_filter(CRM_Utils_Array::collect('contact_id', $event->getRows()), 'is_numeric')); | |
26 | * $dao = CRM_Core_DAO::executeQuery("SELECT contact_id, foo, bar FROM foobar WHERE contact_id in ($ids)"); | |
27 | * while ($dao->fetch) { | |
28 | * $row->setTokens('oddball', array( | |
29 | * 'foo' => $dao->foo, | |
30 | * 'bar' => $dao->bar, | |
31 | * )); | |
32 | * } | |
33 | * @encode | |
34 | * | |
35 | */ | |
36 | class TokenValueEvent extends TokenEvent { | |
37 | ||
38 | /** | |
39 | * @return \Traversable<TokenRow> | |
40 | */ | |
41 | public function getRows() { | |
42 | return $this->tokenProcessor->getRows(); | |
43 | } | |
44 | ||
45 | } |