1 | <?php namespace Qualia\Submission; |
||
15 | class Entry |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $additional; |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $data; |
||
25 | /** |
||
26 | * @var \Qualia\Client |
||
27 | */ |
||
28 | private $client; |
||
29 | |||
30 | |||
31 | 78 | private function __construct(Client $client) { |
|
38 | |||
39 | /** |
||
40 | * Build a configuration |
||
41 | * |
||
42 | * @param \Qualia\Client $client |
||
43 | * @return \Qualia\Submission\Entry |
||
44 | */ |
||
45 | 78 | public static function build(Client $client) |
|
49 | |||
50 | /** |
||
51 | * Provide an unique identifier for an entry. It can be either string or integer e.g. incremental id from your database |
||
52 | * This ensures you are not submitting the entry twice and even if you do submit it, it will update the previous entry |
||
53 | * rather than creating a new one. |
||
54 | * |
||
55 | * @param $identifier |
||
56 | * @return $this |
||
57 | */ |
||
58 | 20 | public function uniqueId($identifier) |
|
64 | |||
65 | /** |
||
66 | * Provide a language for an entry. e.g. 'en', 'es', 'pt' |
||
67 | * |
||
68 | * @param $language |
||
69 | * @return $this |
||
70 | */ |
||
71 | 12 | public function language($language) |
|
77 | |||
78 | /** |
||
79 | * By default we will check and only allow submitting entries with unique email address. |
||
80 | * You may want to allow duplicate emails in some cases |
||
81 | * |
||
82 | * @param bool $allow |
||
83 | * @return $this |
||
84 | */ |
||
85 | 6 | public function allowDuplicates($allow = true) |
|
86 | { |
||
87 | 6 | $this->additional['allow_duplicates'] = $allow ? 1 : 0; |
|
88 | |||
89 | 6 | return $this; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Append name question |
||
94 | * |
||
95 | * @param $id Question identifier |
||
96 | * @param $firstName First name |
||
97 | * @param null $lastName Last name |
||
98 | * @return $this |
||
99 | */ |
||
100 | 6 | public function name($id, $firstName = null, $lastName = null) { |
|
101 | |||
102 | 6 | $this->data[$id] = array( |
|
103 | 6 | 'first_name' => $firstName, |
|
104 | 6 | 'last_name' => $lastName, |
|
105 | ); |
||
106 | |||
107 | 6 | return $this; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * Append email question |
||
112 | * |
||
113 | * @param $id Question identifier |
||
114 | * @param $address E-mail address |
||
115 | * @return $this |
||
116 | */ |
||
117 | 54 | public function email($id, $address) { |
|
122 | |||
123 | |||
124 | /** |
||
125 | * Append date question |
||
126 | * |
||
127 | * @param $id Question identifier |
||
128 | * @param $date Date in Y-m-d format |
||
129 | * @return $this |
||
130 | */ |
||
131 | 24 | public function date($id, $date) |
|
141 | |||
142 | /** |
||
143 | * Append any other type of response |
||
144 | * |
||
145 | * @param $id Question identifier |
||
146 | * @param $response Response to a question |
||
147 | * @return $this |
||
148 | */ |
||
149 | 12 | public function response($id, $response) |
|
155 | |||
156 | /** |
||
157 | * Once we have everything added, we can submit. |
||
158 | * |
||
159 | * @param bool $markComplete If you would like submit the survey and mark it as completed,please set this field to true, |
||
160 | * otherwise, survey will not be marked as completed and an email will be sent to the user |
||
161 | * asking to complete the rest of the survey. |
||
162 | * |
||
163 | * Depending on survey distribution channels this may vary: |
||
164 | * Institution may have an Enrollment form enabled where it collects some data on site, |
||
165 | * some through this API, some maybe shared in social media. If that's the case, must likely |
||
166 | * you do not need to mark it as completed. |
||
167 | * |
||
168 | * However, |
||
169 | * If all responses are collected via this API and second survey is send later, you may |
||
170 | * need to mark it as completed. |
||
171 | * @return array |
||
172 | * @throws \Qualia\Exceptions\RequestException |
||
173 | */ |
||
174 | 72 | public function send($markComplete = false) |
|
182 | |||
183 | } |