Commit | Line | Data |
---|---|---|
fcfb2732 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
fcfb2732 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
fcfb2732 | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Provide data to the CRM_Contact_Form_Search_Custom_SampleTest class | |
30 | * | |
31 | * @package CiviCRM | |
32 | */ | |
33 | class CRM_Contact_Form_Search_Custom_SampleTestDataProvider implements Iterator { | |
34 | ||
35 | /** | |
9f266042 | 36 | * Current count. |
37 | * | |
38 | * @var int | |
fcfb2732 | 39 | */ |
40 | private $i = 0; | |
41 | ||
42 | /** | |
43 | * @var mixed[] | |
44 | * This dataset describes various form values and what contact | |
45 | * IDs should be selected when the form values are applied to the | |
46 | * database in dataset.xml | |
47 | */ | |
9099cab3 | 48 | private $dataset = [ |
fcfb2732 | 49 | // Search by Household name: 'Household 9' |
9099cab3 CW |
50 | [ |
51 | 'fv' => ['household_name' => 'Household 9'], | |
52 | 'id' => [ | |
fcfb2732 | 53 | '9', |
9099cab3 CW |
54 | ], |
55 | ], | |
fcfb2732 | 56 | // Search by Household name: 'Household' |
9099cab3 CW |
57 | [ |
58 | 'fv' => ['household_name' => 'Household'], | |
59 | 'id' => [ | |
fcfb2732 | 60 | '9', |
61 | '10', | |
62 | '11', | |
63 | '12', | |
9099cab3 CW |
64 | ], |
65 | ], | |
fcfb2732 | 66 | // Search by State: California |
9099cab3 CW |
67 | [ |
68 | 'fv' => ['state_province_id' => '1004'], | |
69 | 'id' => [ | |
fcfb2732 | 70 | '10', |
71 | '11', | |
9099cab3 CW |
72 | ], |
73 | ], | |
fcfb2732 | 74 | // Search by State: New York |
9099cab3 CW |
75 | [ |
76 | 'fv' => ['state_province_id' => '1031'], | |
77 | 'id' => [ | |
fcfb2732 | 78 | '12', |
9099cab3 CW |
79 | ], |
80 | ], | |
81 | ]; | |
fcfb2732 | 82 | |
83 | public function _construct() { | |
84 | $this->i = 0; | |
85 | } | |
86 | ||
87 | public function rewind() { | |
88 | $this->i = 0; | |
89 | } | |
90 | ||
91 | /** | |
92 | * @return array | |
93 | */ | |
94 | public function current() { | |
95 | $count = count($this->dataset[$this->i]['id']); | |
96 | $ids = $this->dataset[$this->i]['id']; | |
9099cab3 | 97 | $full = []; |
fcfb2732 | 98 | foreach ($this->dataset[$this->i]['id'] as $key => $value) { |
9099cab3 | 99 | $full[] = [ |
fcfb2732 | 100 | 'contact_id' => $value, |
101 | 'contact_type' => 'Household', | |
102 | 'household_name' => "Household $value", | |
9099cab3 | 103 | ]; |
fcfb2732 | 104 | } |
9099cab3 | 105 | return [$this->dataset[$this->i]['fv'], $count, $ids, $full]; |
fcfb2732 | 106 | } |
107 | ||
108 | /** | |
109 | * @return int | |
110 | */ | |
111 | public function key() { | |
112 | return $this->i; | |
113 | } | |
114 | ||
115 | public function next() { | |
116 | $this->i++; | |
117 | } | |
118 | ||
119 | /** | |
120 | * @return bool | |
121 | */ | |
122 | public function valid() { | |
123 | return isset($this->dataset[$this->i]); | |
124 | } | |
125 | ||
126 | } |