Skip to content

Commit e7f6726

Browse files
authored
Merge pull request #19 from MonkDev/feature/support-multiple-shows
Support multiple shows
2 parents 7750c06 + f0f1900 commit e7f6726

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,45 @@ in associative array form. So, for example, a sermon's title can be accessed at
126126

127127
If a failure occurs, `get` throws a `Monk\Cms\Exception`.
128128

129+
### Multiple shows
130+
131+
If you want to use `show` key to format API output, there are 2 ways
132+
133+
#### 1. Using inline string
134+
135+
For example:
136+
137+
```php
138+
$cms->get(array(
139+
'module' => 'smallgroup',
140+
'display' => 'list',
141+
'order' => 'recent',
142+
'emailencode' => 'no',
143+
'howmany' => 1,
144+
'page' => 1,
145+
'show' => "___starttime format='g:ia'__ __endtime format='g:ia'__",
146+
));
147+
```
148+
149+
#### 2. Using an array
150+
151+
For example:
152+
153+
```php
154+
$cms->get(array(
155+
'module' => 'smallgroup',
156+
'display' => 'list',
157+
'order' => 'recent',
158+
'emailencode' => 'no',
159+
'howmany' => 1,
160+
'page' => 1,
161+
'show' => [
162+
"__starttime format='g:ia'__",
163+
"__endtime format='g:ia'__"
164+
]
165+
));
166+
```
167+
129168
Development
130169
-----------
131170

lib/Monk/Cms.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,23 @@ private static function buildRequestQueryParams(array $queryParams)
153153
$count = 0;
154154

155155
foreach ($queryParams as $key => $value) {
156-
$queryParam = "{$key}_:_{$value}";
157-
158-
if ($key == 'module') {
159-
$queryParam = $value;
160-
} elseif ($value === true) {
161-
$queryParam = $key;
156+
if ($key==="show" && is_array($value)) {
157+
foreach ($value as $showValue) {
158+
$queryParam = "{$key}_:_{$showValue}";
159+
$query["arg{$count}"] = $queryParam;
160+
$count++;
161+
}
162+
} else {
163+
$queryParam = "{$key}_:_{$value}";
164+
165+
if ($key == 'module') {
166+
$queryParam = $value;
167+
} elseif ($value === true) {
168+
$queryParam = $key;
169+
}
170+
$query["arg{$count}"] = $queryParam;
171+
$count++;
162172
}
163-
164-
$query["arg{$count}"] = $queryParam;
165-
$count++;
166173
}
167174

168175
return $query;
@@ -183,8 +190,14 @@ private function buildRequestQueryString(array $queryParams)
183190
$query['SITEID'] = $config['siteId'];
184191
$query['CMSCODE'] = $config['cmsCode'];
185192
$query['CMSTYPE'] = $config['cmsType'];
186-
$query['NR'] = count($queryParams);
187-
193+
if (isset($queryParams['show']) && is_array($queryParams['show'])) {
194+
// To count the number of params correctly , we do not count
195+
// if the value of the show key is an array. Therefore, we have -1.
196+
// However,we care about its total items, so we add it
197+
$query['NR'] = count($queryParams) + count($queryParams['show']) - 1;
198+
} else {
199+
$query['NR'] = count($queryParams);
200+
}
188201
$query = array_merge($query, self::buildRequestQueryParams($queryParams));
189202

190203
return http_build_query($query);
@@ -244,7 +257,7 @@ private function request(array $queryParams)
244257

245258
/**
246259
* Replace placeholder values with the expected values
247-
*
260+
*
248261
* @param string $body
249262
* @return string
250263
*/

0 commit comments

Comments
 (0)