From b30c5537395d6de6b50b5af9d2d27067615017de Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Wed, 6 Nov 2013 18:09:57 +0600 Subject: [PATCH 1/6] =?UTF-8?q?*=20The=20error=20because=20of=20which=20th?= =?UTF-8?q?e=20placeholder=20=E2=80=9C[+total+]=E2=80=9D=20used=20to=20be?= =?UTF-8?q?=20parsed=20correctly=20inside=20of=20a=20wrapping=20chunk=20(p?= =?UTF-8?q?assed=20via=20=E2=80=9CtplWrap=E2=80=9D)=20only=20if=20?= =?UTF-8?q?=E2=80=9Cplaceholders=E2=80=9D=20had=20been=20set=20has=20been?= =?UTF-8?q?=20eliminated.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddGetMultipleField.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index d4c09e6..e956e2c 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -341,9 +341,9 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ $val = explode('::', $val); $res[$val[0]] = $val[1]; } - - $res['total'] = $resLength; } + + $res['total'] = $resLength; $result = $modx->parseChunk($tplWrap, $res, '[+','+]'); } From c76c6cbcb46be50c820ee5c5bc0e4cb76d7bc5c5 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Thu, 7 Nov 2013 15:16:38 +0600 Subject: [PATCH 2/6] =?UTF-8?q?*=20The=20internal=20variable=20=E2=80=9C$r?= =?UTF-8?q?esLength=E2=80=9D=20has=20been=20renamed=20as=20=E2=80=9C$resul?= =?UTF-8?q?tTotal=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddGetMultipleField.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index e956e2c..8ca4e79 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -236,11 +236,11 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ } //Общее количество строк - $resLength = count($res); + $resultTotal = count($res); //Плэйсхолдер с общим количеством if (isset($totalPlaceholder) && strlen(trim($totalPlaceholder)) != ''){ - $modx->setPlaceholder($totalPlaceholder, $resLength); + $modx->setPlaceholder($totalPlaceholder, $resultTotal); } //Если вывод в массив @@ -278,7 +278,7 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ //Запишем номер строки $res[$key]['row_number'] = $key + 1; //И общее количество элементов - $res[$key]['total'] = $resLength; + $res[$key]['total'] = $resultTotal; $res[$key] = $modx->parseChunk($tplY, $res[$key], '[+', '+]'); } }else{ @@ -343,7 +343,7 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ } } - $res['total'] = $resLength; + $res['total'] = $resultTotal; $result = $modx->parseChunk($tplWrap, $res, '[+','+]'); } From 7e06fa909d35f1dd329e71fa37cab5219209f59e Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Fri, 8 Nov 2013 13:41:24 +0600 Subject: [PATCH 3/6] =?UTF-8?q?+=20The=20new=20placeholder=20=E2=80=9C[+re?= =?UTF-8?q?sultTotal+]=E2=80=9D=20being=20used=20in=20=E2=80=9C$tplY?= =?UTF-8?q?=E2=80=9D=20and=20=E2=80=9C$tplWrap=E2=80=9D=20chunks=20holds?= =?UTF-8?q?=20the=20total=20number=20of=20RETURNED=20elements.=20*=20Pleas?= =?UTF-8?q?e=20note=20the=20placeholder=20=E2=80=9C[+total+]=E2=80=9D=20th?= =?UTF-8?q?at=20currently=20holds=20the=20total=20number=20of=20ALL=20elem?= =?UTF-8?q?ents.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddGetMultipleField.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index 8ca4e79..85c3543 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -27,9 +27,9 @@ * @param $typographing {0; 1} - Typographing status. Default: 0. * @param $urlencode {0; 1} - URL encoding status. Default: 0. * @param $format {'JSON'; 'array'; 'html'} - Format being returned. Default: 'html'. - * @param $tplY {string: chunkName} - Row output template (the format parameter must be empty). Available placeholders: [+row_number+] (returns row number starting from 1), [+total+] (the number of all rows), [+val0+],[+val1+],…. Default: ''. + * @param $tplY {string: chunkName} - Row output template (the format parameter must be empty). Available placeholders: [+row_number+] (returns row number starting from 1), [+total+] (the number of all rows), [+resultTotal+] (the number of outputted rows), [+val0+],[+val1+],…. Default: ''. * @param $tplX {comma separated string: chunkName; 'null'} - List of templates for columns output separated by comma. The last template would be applied to other rows if the number of templates was less than the number of columns. The 'null' value — without a template. Available placeholder: [+val+]. Default: ''. - * @param $tplWrap {string: chunkName} - Wrapper template. Available placeholders: [+wrapper+], [+total+]. Default: ''. + * @param $tplWrap {string: chunkName} - Wrapper template. Available placeholders: [+wrapper+], [+total+] (the number of all rows), [+resultTotal+] (the number of outputted rows). Default: ''. * @param $placeholders {separated string} - Additional data which has to be transferred (available only in tplWrap!). Format: string separated by '::' betweeb key-value pair and '||' between pairs. Default: ''. * @param $totalPlaceholder {string} - The name of an external placeholder to output the total number of rows into. The total number does not return if the parameter is empty. Default: ''. * @param $resultToPlaceholder {0; 1} - Add the obtained result to the placeholder 'ddGetMultipleField' instead of return. Default: 0. @@ -104,6 +104,9 @@ //Разбиваем на строки $res = $splYisRegexp ? preg_split($splY, $field) : explode($splY, $field); + + //Общее количество строк + $total = count($res); //Перебираем строки, разбиваем на колонки foreach ($res as $key => $val){ @@ -235,7 +238,7 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ $res = array_slice($res, $num, $count); } - //Общее количество строк + //Общее количество возвращаемых строк $resultTotal = count($res); //Плэйсхолдер с общим количеством @@ -278,7 +281,8 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ //Запишем номер строки $res[$key]['row_number'] = $key + 1; //И общее количество элементов - $res[$key]['total'] = $resultTotal; + $res[$key]['total'] = $total; + $res[$key]['resultTotal'] = $resultTotal; $res[$key] = $modx->parseChunk($tplY, $res[$key], '[+', '+]'); } }else{ @@ -343,7 +347,8 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ } } - $res['total'] = $resultTotal; + $res['total'] = $total; + $res['resultTotal'] = $resultTotal; $result = $modx->parseChunk($tplWrap, $res, '[+','+]'); } From a31bcf418ec6b0f5d27598f6fc7bbdc486fa88c0 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 11 Nov 2013 12:03:13 +0600 Subject: [PATCH 4/6] =?UTF-8?q?+=20The=20placeholders=20of=20the=20form=20?= =?UTF-8?q?=E2=80=9C[+rowY.valX+]=E2=80=9D=20(where=20=E2=80=9CY=E2=80=9D?= =?UTF-8?q?=20=E2=80=94=20row=20number,=20=E2=80=9CX=E2=80=9D=20=E2=80=94?= =?UTF-8?q?=20column=20number)=20that=20contains=20all=20values=20are=20av?= =?UTF-8?q?ailable=20during=20=E2=80=9CtplWrap=E2=80=9D=20parsing.=20*=20B?= =?UTF-8?q?e=20advised!=20The=20snippet=20is=20now=20using=20the=20modx.dd?= =?UTF-8?q?Tools=200.10=20library!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddGetMultipleField.php | 54 +++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index 85c3543..26a3f74 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -6,6 +6,7 @@ * A snippet for separated by delimiters data output. * The fields formed by the mm_ddMultipleFields widget values ooutput gets more convinient with the snippet. * + * @uses The library modx.ddTools 0.10. * @uses The snippet ddGetDocumentField 2.4 might be used if field getting is required. * @uses The snippet ddTypograph 1.4.3 (if typographing is required). * @@ -250,6 +251,8 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ if ($format == 'array'){ $result = $res; }else{ + $resTemp = array(); + //Если вывод просто в формате html if ($format == 'html'){ /*//Если вывод в формате изображения @@ -263,27 +266,27 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ if (isset($tplY)){ //Перебираем строки foreach ($res as $key => $val){ - $res[$key] = array(); + $resTemp[$key] = array(); //Перебираем колонки foreach ($val as $k => $v){ //Если нужно удалять пустые значения if ($removeEmptyCols && !strlen($v)){ - $res[$key]['val'.$k] = ''; + $resTemp[$key]['val'.$k] = ''; }else{ //Если есть шаблоны значений колонок if ($tplX && strlen($tplX[$k])){ - $res[$key]['val'.$k] = $modx->parseChunk($tplX[$k], array('val' => $v), '[+', '+]'); + $resTemp[$key]['val'.$k] = $modx->parseChunk($tplX[$k], array('val' => $v), '[+', '+]'); }else{ - $res[$key]['val'.$k] = $v; + $resTemp[$key]['val'.$k] = $v; } } } //Запишем номер строки - $res[$key]['row_number'] = $key + 1; + $resTemp[$key]['row_number'] = $key + 1; //И общее количество элементов - $res[$key]['total'] = $total; - $res[$key]['resultTotal'] = $resultTotal; - $res[$key] = $modx->parseChunk($tplY, $res[$key], '[+', '+]'); + $resTemp[$key]['total'] = $total; + $resTemp[$key]['resultTotal'] = $resultTotal; + $resTemp[$key] = $modx->parseChunk($tplY, $resTemp[$key], '[+', '+]'); } }else{ foreach ($res as $key => $val){ @@ -298,11 +301,11 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ } } } - $res[$key] = implode($glueX, $val); + $resTemp[$key] = implode($glueX, $val); } } - $result = implode($glueY, $res); + $result = implode($glueY, $resTemp); //Если вывод в формате JSON }else if ($format == 'json'){ //Добавляем 'val' к названиям колонок @@ -312,16 +315,18 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ foreach ($val as $k => $v) $res[$key]['val'.$k] = $v; } */ + $resTemp = $res; + //Если нужно выводить только одну колонку if ($colNum != 'all' && count($colNum) == 1){ - $res = array_map('implode', $res); + $resTemp = array_map('implode', $resTemp); } //Если нужно получить какой-то конкретный элемент, а не все if ($count == '1'){ - $result = json_encode($res[$num]); + $result = json_encode($resTemp[$num]); }else{ - $result = json_encode($res); + $result = json_encode($resTemp); } //Это чтобы модекс не воспринимал как вызов сниппета @@ -330,10 +335,21 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ //Если оборачивающий шаблон задан (и вывод не в массив), парсим его if (isset($tplWrap)){ - $res = array(); + //Подключаем modx.ddTools + require_once $modx->config['base_path'].'assets/snippets/ddTools/modx.ddtools.class.php'; + + $resTemp = array(); //Элемент массива 'wrapper' должен находиться самым первым, иначе дополнительные переданные плэйсхолдеры в тексте не найдутся! - $res['wrapper'] = $result; + $resTemp['wrapper'] = $result; + + //Преобразуем результат в одномерный массив + $res = ddTools::unfoldArray($res); + + //Добавляем 'row' и 'val' к ключам + foreach ($res as $key => $val){ + $resTemp[preg_replace('/(\d)\.(\d)/', 'row$1.val$2', $key)] = $val; + } //Если есть дополнительные данные if (isset($placeholders)){ @@ -343,13 +359,13 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ foreach ($placeholders as $val){ //Разбиваем на ключ-значение $val = explode('::', $val); - $res[$val[0]] = $val[1]; + $resTemp[$val[0]] = $val[1]; } } - $res['total'] = $total; - $res['resultTotal'] = $resultTotal; - $result = $modx->parseChunk($tplWrap, $res, '[+','+]'); + $resTemp['total'] = $total; + $resTemp['resultTotal'] = $resultTotal; + $result = $modx->parseChunk($tplWrap, $resTemp, '[+','+]'); } //Если нужно типографировать From 33265152a180040c672d5a948c628ddc5dfd6e24 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 11 Nov 2013 15:17:03 +0600 Subject: [PATCH 5/6] =?UTF-8?q?*=20The=20string=20with=20placeholders=20th?= =?UTF-8?q?at=20is=20passed=20through=20=E2=80=9Cplaceholders=E2=80=9D=20i?= =?UTF-8?q?s=20currently=20splitted=20by=20the=20method=20=E2=80=9CddTools?= =?UTF-8?q?::explodeAssoc=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddGetMultipleField.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index 26a3f74..6cbf428 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -353,14 +353,7 @@ function ddMasHoarSort($arr, $key, $direct, $i = 0){ //Если есть дополнительные данные if (isset($placeholders)){ - $arrPlaceholders = array(); - //Разбиваем по парам - $placeholders = explode('||', $placeholders); - foreach ($placeholders as $val){ - //Разбиваем на ключ-значение - $val = explode('::', $val); - $resTemp[$val[0]] = $val[1]; - } + $resTemp = array_merge($resTemp, ddTools::explodeAssoc($placeholders)); } $resTemp['total'] = $total; From 67642a20980c96701e36fa61cdcc6a84f2029b61 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 11 Nov 2013 15:21:27 +0600 Subject: [PATCH 6/6] Prerelease 2.18 --- ddGetMultipleField.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddGetMultipleField.php b/ddGetMultipleField.php index 6cbf428..a6ef9f1 100644 --- a/ddGetMultipleField.php +++ b/ddGetMultipleField.php @@ -1,7 +1,7 @@