From c3c78b440c4da68d1de64c62ca2665d4bc82f9f9 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sun, 14 May 2023 23:06:08 +0400 Subject: [PATCH 01/13] * `\ddTools::getTpl` is used instead of `$modx->getTpl` (means a bit less bugs). * Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.60 is required. --- README.md | 2 +- composer.json | 2 +- ddGetParentId_snippet.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5184b01..79d6c1f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Gets document parent ID(s) of the required level. ## Requires * PHP >= 5.4 * [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1 -* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.40.1 +* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.60 ## Documentation diff --git a/composer.json b/composer.json index 11b56bf..4fb4ed8 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,6 @@ ], "require": { "php": ">=5.4.0", - "dd/evolutioncms-libraries-ddtools": ">=0.40.1" + "dd/evolutioncms-libraries-ddtools": ">=0.60.0" } } \ No newline at end of file diff --git a/ddGetParentId_snippet.php b/ddGetParentId_snippet.php index c4e527c..af2fc7b 100644 --- a/ddGetParentId_snippet.php +++ b/ddGetParentId_snippet.php @@ -43,7 +43,7 @@ ; $result_itemTpl = isset($result_itemTpl) ? - $modx->getTpl($result_itemTpl) : + \ddTools::getTpl($result_itemTpl) : '[+id+]' ; $result_itemsGlue = From e6ecdbe01cb4d5bd93a03084ea597cb0964c684b Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:18:39 +0400 Subject: [PATCH 02/13] + Composer.json: + `homepage` + `support`. + `authors`. --- composer.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/composer.json b/composer.json index 4fb4ed8..cfef754 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,18 @@ "evolution cms", "ddgetparentid" ], + "homepage": "https://code.divandesign.biz/modx/ddgetparentid", + "support": { + "chat": "https://t.me/dd_code" + }, + "authors": [ + { + "name": "Ilyas Ronef", + "email": "ilyas@DivanDesign.ru", + "homepage": "https://ronef.ru", + "role": "Owner" + } + ], "require": { "php": ">=5.4.0", "dd/evolutioncms-libraries-ddtools": ">=0.60.0" From 1a2cff4c9a09d9dd9d56d9b9e93ed5c69cd59705 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:33:10 +0400 Subject: [PATCH 03/13] * Refactoring, the `$params` variable is used instead of a standalone variable for each parameter. * Attention! PHP >= 5.6 is required. --- README.md | 2 +- composer.json | 2 +- ddGetParentId_snippet.php | 91 +++++++++++++++++---------------------- 3 files changed, 42 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 79d6c1f..17672e9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Gets document parent ID(s) of the required level. ## Requires -* PHP >= 5.4 +* PHP >= 5.6 * [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1 * [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.60 diff --git a/composer.json b/composer.json index cfef754..ad8d5ea 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=5.6.0", "dd/evolutioncms-libraries-ddtools": ">=0.60.0" } } \ No newline at end of file diff --git a/ddGetParentId_snippet.php b/ddGetParentId_snippet.php index af2fc7b..90c06d7 100644 --- a/ddGetParentId_snippet.php +++ b/ddGetParentId_snippet.php @@ -12,14 +12,15 @@ global $modx; +//# Include //Include (MODX)EvolutionCMS.libraries.ddTools require_once( $modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php' ); -//The snippet must return an empty string even if result is absent -$snippetResult = ''; + +//# Prepare params //Bacward compatibility extract(\ddTools::verifyRenamedParams([ @@ -31,55 +32,43 @@ ] ])); -$id = - isset($id) ? - $id : - $modx->documentIdentifier -; -$result_itemsNumber = - isset($result_itemsNumber) ? - $result_itemsNumber : - 1 -; -$result_itemTpl = - isset($result_itemTpl) ? - \ddTools::getTpl($result_itemTpl) : - '[+id+]' -; -$result_itemsGlue = - isset($result_itemsGlue) ? - $result_itemsGlue : - '' -; -$result_toPlaceholder = - ( - isset($result_toPlaceholder) && - $result_toPlaceholder == '1' - ) ? - true : - false -; -$result_toPlaceholder_name = - isset($result_toPlaceholder_name) ? - $result_toPlaceholder_name : - 'ddParent' -; - -if (!isset($level)){ - $level = 1; +//Defaults +$params = \DDTools\ObjectTools::extend([ + 'objects' => [ + (object) [ + 'id' => $modx->documentIdentifier, + 'result_itemsNumber' => 1, + 'result_itemTpl' => '@CODE:[+id+]', + 'result_itemsGlue' => '', + 'result_toPlaceholder' => false, + 'result_toPlaceholder_name' => 'ddParent', + 'level' => 1, + ], + $params + ] +]); + +$params->result_itemTpl = \ddTools::getTpl($params->result_itemTpl); + +$params->result_toPlaceholder = boolval($params->result_toPlaceholder); + +//For backward compatibility +if ($params->level == 'ultimate'){ + $params->level = -1; }else{ - //For backward compatibility - if ($level == 'ultimate'){ - $level = -1; - }else{ - $level = intval($level); - } + $params->level = intval($params->level); } + +//# Run + +//The snippet must return an empty string even if result is absent +$snippetResult = ''; + $parents = \ddTools::getDocumentParentIds([ - 'docId' => $id, - 'level' => $level, - 'totalResults' => $result_itemsNumber + 'docId' => $params->id, + 'level' => $params->level, + 'totalResults' => $params->result_itemsNumber ]); foreach ( @@ -89,7 +78,7 @@ ){ //Parse item $parents[$parentIndex] = \ddTools::parseText([ - 'text' => $result_itemTpl, + 'text' => $params->result_itemTpl, 'data' => [ 'id' => $parentId ] @@ -102,14 +91,14 @@ } $snippetResult = implode( - $result_itemsGlue, + $params->result_itemsGlue, $parents ); //Если надо, выводим в плэйсхолдер -if ($result_toPlaceholder){ +if ($params->result_toPlaceholder){ $modx->setPlaceholder( - $result_toPlaceholder_name, + $params->result_toPlaceholder_name, $snippetResult ); From 6a2a323f4f0ec70ad8efe5cbccd944c43804c920 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:34:22 +0400 Subject: [PATCH 04/13] =?UTF-8?q?-=20README=20=E2=86=92=20Documentation:?= =?UTF-8?q?=20Useless=20header=20level=20has=20been=20deleted.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 17672e9..bd6d328 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,7 @@ Gets document parent ID(s) of the required level. * [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.60 -## Documentation - - -### Installation +## Installation Elements → Snippets: Create a new snippet with the following data @@ -23,7 +20,7 @@ Elements → Snippets: Create a new snippet with the following data 5. Snippet code (php): Insert content of the `ddGetParentId_snippet.php` file from the archive. -### Parameters description +## Parameters description * `id` * Desctription: Document Id. From 6f50f8dded831ef25f0c83f02cdb400415ab4593 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:35:26 +0400 Subject: [PATCH 05/13] * README, CHANGELOG: CSS is included directly from GitHub. --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e17a868..473acd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,5 +28,5 @@ * \+ The first release. - + \ No newline at end of file diff --git a/README.md b/README.md index bd6d328..5c8004d 100644 --- a/README.md +++ b/README.md @@ -78,4 +78,4 @@ Elements → Snippets: Create a new snippet with the following data * [Telegram chat](https://t.me/dd_code) - \ No newline at end of file + \ No newline at end of file From 8c04ceceedba72f98640d66ae7369084bf70b103 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:37:29 +0400 Subject: [PATCH 06/13] * Minor changes (fixed inactive DivanDesign.biz links). --- README.md | 4 ++-- composer.json | 2 +- ddGetParentId_snippet.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5c8004d..1f39700 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Gets document parent ID(s) of the required level. ## Requires * PHP >= 5.6 * [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1 -* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.biz/modx/ddtools) >= 0.60 +* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) >= 0.60 ## Installation @@ -74,7 +74,7 @@ Elements → Snippets: Create a new snippet with the following data ## Links -* [Home page](https://code.divandesign.biz/modx/ddgetparentid) +* [Home page](https://code.divandesign.ru/modx/ddgetparentid) * [Telegram chat](https://t.me/dd_code) diff --git a/composer.json b/composer.json index ad8d5ea..dbb366b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "evolution cms", "ddgetparentid" ], - "homepage": "https://code.divandesign.biz/modx/ddgetparentid", + "homepage": "https://code.divandesign.ru/modx/ddgetparentid", "support": { "chat": "https://t.me/dd_code" }, diff --git a/ddGetParentId_snippet.php b/ddGetParentId_snippet.php index 90c06d7..2c1800e 100644 --- a/ddGetParentId_snippet.php +++ b/ddGetParentId_snippet.php @@ -5,9 +5,9 @@ * * @see README.md * - * @link https://code.divandesign.biz/modx/ddgetparentid + * @link https://code.divandesign.ru/modx/ddgetparentid * - * @copyright 2011–2020 DD Group {@link https://DivanDesign.biz } + * @copyright 2011–2020 Ronef {@link https://Ronef.ru } */ global $modx; From 8b64a6543d44078967b9e3f361cca8329e4e934a Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:39:00 +0400 Subject: [PATCH 07/13] =?UTF-8?q?+=20README=20=E2=86=92=C2=A0Links:=20=09+?= =?UTF-8?q?=20Packagist.=20=09+=20GitHub.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1f39700..654a371 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ Elements → Snippets: Create a new snippet with the following data * [Home page](https://code.divandesign.ru/modx/ddgetparentid) * [Telegram chat](https://t.me/dd_code) +* [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddgetparentid) +* [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetParentId) \ No newline at end of file From f547993f81b40c55b68cf3e7e0209495c4007678 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 02:54:40 +0400 Subject: [PATCH 08/13] =?UTF-8?q?+=20You=20can=20just=20call=20`\DDTools\S?= =?UTF-8?q?nippet::runSnippet`=20to=20run=20the=20snippet=20without=20DB?= =?UTF-8?q?=20and=20eval=20(see=20README=20=E2=86=92=20Examples).=20+=20RE?= =?UTF-8?q?ADME=20=E2=86=92=C2=A0Installation=20=E2=86=92=20Using=20(MODX)?= =?UTF-8?q?EvolutionCMS.libraries.ddInstaller.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 56 +++++++++++++++++++- composer.json | 5 ++ ddGetParentId_snippet.php | 92 ++------------------------------ require.php | 13 +++++ src/Snippet.php | 109 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 90 deletions(-) create mode 100644 require.php create mode 100644 src/Snippet.php diff --git a/README.md b/README.md index 654a371..16d2e01 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,33 @@ Gets document parent ID(s) of the required level. ## Installation -Elements → Snippets: Create a new snippet with the following data + +### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller) + +Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console): + +```php +//Include (MODX)EvolutionCMS.libraries.ddInstaller +require_once( + $modx->getConfig('base_path') . + 'assets/libs/ddInstaller/require.php' +); + +//Install (MODX)EvolutionCMS.snippets.ddGetParentId +\DDInstaller::install([ + 'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetParentId', + 'type' => 'snippet' +]); +``` + +* If `ddGetParentId` is not exist on your site, `ddInstaller` will just install it. +* If `ddGetParentId` is already exist on your site, `ddInstaller` will check it version and update it if needed. + + +### Manually + + +#### 1. Elements → Snippets: Create a new snippet with the following data 1. Snippet name: `ddGetParentId`. 2. Description: `1.3.1 Gets document parent ID(s) of the required level.`. @@ -20,6 +46,12 @@ Elements → Snippets: Create a new snippet with the following data 5. Snippet code (php): Insert content of the `ddGetParentId_snippet.php` file from the archive. +#### 2. Elements → Manage Files + +1. Create a new folder `assets/snippets/ddGetParentId/`. +2. Extract the archive to the folder (except `ddGetParentId_snippet.php`). + + ## Parameters description * `id` @@ -72,6 +104,28 @@ Elements → Snippets: Create a new snippet with the following data * Default value: `'ddParent'` +## Examples + + +### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval + +```php +//Include (MODX)EvolutionCMS.libraries.ddTools +require_once( + $modx->getConfig('base_path') . + 'assets/libs/ddTools/modx.ddtools.class.php' +); + +//Run (MODX)EvolutionCMS.snippets.ddGetParentId +\DDTools\Snippet::runSnippet([ + 'name' => 'ddGetParentId', + 'params' => [ + 'level' => -1 + ] +]); +``` + + ## Links * [Home page](https://code.divandesign.ru/modx/ddgetparentid) diff --git a/composer.json b/composer.json index dbb366b..e6aa27c 100644 --- a/composer.json +++ b/composer.json @@ -27,5 +27,10 @@ "require": { "php": ">=5.6.0", "dd/evolutioncms-libraries-ddtools": ">=0.60.0" + }, + "autoload": { + "psr-4": { + "ddGetParentId\\": "src/" + } } } \ No newline at end of file diff --git a/ddGetParentId_snippet.php b/ddGetParentId_snippet.php index 2c1800e..2540128 100644 --- a/ddGetParentId_snippet.php +++ b/ddGetParentId_snippet.php @@ -10,100 +10,14 @@ * @copyright 2011–2020 Ronef {@link https://Ronef.ru } */ -global $modx; - -//# Include //Include (MODX)EvolutionCMS.libraries.ddTools require_once( $modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php' ); - -//# Prepare params - -//Bacward compatibility -extract(\ddTools::verifyRenamedParams([ - 'params' => $params, - 'compliance' => [ - 'result_itemTpl' => 'tpl', - 'result_toPlaceholder' => 'toPlaceholder', - 'result_toPlaceholder_name' => 'placeholderName', - ] -])); - -//Defaults -$params = \DDTools\ObjectTools::extend([ - 'objects' => [ - (object) [ - 'id' => $modx->documentIdentifier, - 'result_itemsNumber' => 1, - 'result_itemTpl' => '@CODE:[+id+]', - 'result_itemsGlue' => '', - 'result_toPlaceholder' => false, - 'result_toPlaceholder_name' => 'ddParent', - 'level' => 1, - ], - $params - ] +return \DDTools\Snippet::runSnippet([ + 'name' => 'ddGetParentId', + 'params' => $params ]); - -$params->result_itemTpl = \ddTools::getTpl($params->result_itemTpl); - -$params->result_toPlaceholder = boolval($params->result_toPlaceholder); - -//For backward compatibility -if ($params->level == 'ultimate'){ - $params->level = -1; -}else{ - $params->level = intval($params->level); -} - - -//# Run - -//The snippet must return an empty string even if result is absent -$snippetResult = ''; - -$parents = \ddTools::getDocumentParentIds([ - 'docId' => $params->id, - 'level' => $params->level, - 'totalResults' => $params->result_itemsNumber -]); - -foreach ( - $parents as - $parentIndex => - $parentId -){ - //Parse item - $parents[$parentIndex] = \ddTools::parseText([ - 'text' => $params->result_itemTpl, - 'data' => [ - 'id' => $parentId - ] - ]); - - //Remove empty items - if (empty($parents[$parentIndex])){ - unset($parents[$parentIndex]); - } -} - -$snippetResult = implode( - $params->result_itemsGlue, - $parents -); - -//Если надо, выводим в плэйсхолдер -if ($params->result_toPlaceholder){ - $modx->setPlaceholder( - $params->result_toPlaceholder_name, - $snippetResult - ); - - $snippetResult = ''; -} - -return $snippetResult; ?> \ No newline at end of file diff --git a/require.php b/require.php new file mode 100644 index 0000000..68aea4c --- /dev/null +++ b/require.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/src/Snippet.php b/src/Snippet.php new file mode 100644 index 0000000..2415bc0 --- /dev/null +++ b/src/Snippet.php @@ -0,0 +1,109 @@ + 0, + 'result_itemsNumber' => 1, + 'result_itemTpl' => '@CODE:[+id+]', + 'result_itemsGlue' => '', + 'result_toPlaceholder' => false, + 'result_toPlaceholder_name' => 'ddParent', + 'level' => 1, + ], + + $paramsTypes = [ + 'id' => 'integer', + 'result_toPlaceholder' => 'boolean', + ], + + $renamedParamsCompliance = [ + 'result_itemTpl' => 'tpl', + 'result_toPlaceholder' => 'toPlaceholder', + 'result_toPlaceholder_name' => 'placeholderName', + ] + ; + + /** + * prepareParams + * @version 1.0 (2023-09-04) + * + * @param $params {stdClass|arrayAssociative|stringJsonObject|stringHjsonObject|stringQueryFormatted} + * + * @return {void} + */ + protected function prepareParams($params = []){ + //Call base method + parent::prepareParams($params); + + //ID is not set or invalid + if ($this->params->id <= 0){ + $this->params->id = \ddTools::$modx->documentIdentifier; + } + + $this->params->result_itemTpl = \ddTools::getTpl($this->params->result_itemTpl); + + //For backward compatibility + if ($this->params->level == 'ultimate'){ + $this->params->level = -1; + }else{ + $this->params->level = intval($this->params->level); + } + } + + /** + * run + * @version 1.0 (2023-09-04) + * + * @return {string|object|array} + */ + public function run(){ + $result = ''; + + $parents = \ddTools::getDocumentParentIds([ + 'docId' => $this->params->id, + 'level' => $this->params->level, + 'totalResults' => $this->params->result_itemsNumber + ]); + + foreach ( + $parents as + $parentIndex => + $parentId + ){ + //Parse item + $parents[$parentIndex] = \ddTools::parseText([ + 'text' => $this->params->result_itemTpl, + 'data' => [ + 'id' => $parentId + ] + ]); + + //Remove empty items + if (empty($parents[$parentIndex])){ + unset($parents[$parentIndex]); + } + } + + $result = implode( + $this->params->result_itemsGlue, + $parents + ); + + //Если надо, выводим в плэйсхолдер + if ($this->params->result_toPlaceholder){ + \ddTools::$modx->setPlaceholder( + $this->params->result_toPlaceholder_name, + $result + ); + + $result = ''; + } + + return $result; + } +} \ No newline at end of file From b3d1032b52920570a92b7417bf9744660c34e2ee Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 03:06:58 +0400 Subject: [PATCH 09/13] + CHANGELOG: Some missed versions have been added. --- CHANGELOG.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 473acd4..92e632a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,31 @@ * \* Refactoring and other changes. +## Version 1.2.1 (2018-12-09) +* \* Wrong variable name was fixed. + + +## Version 1.2 (2017-10-09) +* \+ Added support of the `@CODE:` keyword prefix in the `tpl` parameter. +* \+ Added an ability to return several parents (see the `result_itemsNumber` and `result_itemsGlue` parameters). +* \* The following parameters have been renamed (with backward compatibility): + * \* `tpl` → `result_itemTpl`. + * \* `toPlaceholder` → `result_toPlaceholder`. + * \* `placeholderName` → `result_toPlaceholder_name`. +* \* The snippet result will be returned in anyway (empty string for empty result). +* \* Attention! PHP >= 5.4 is required. +* \* Attention! (MODX)EvolutionCMS >= 1.1 is required. +* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.20 is required. + + +## Version 1.1 (2014-11-05) +* \+ Negative values can now be passed to the `level` parameter for setting parent level from the end (`-1` — the last parent; `-2` — the parent before the last; etc). + + +## Version 1.0.1 (2013-08-10) +* \* The id of a current document will be returned if it has no parent (root document). + + ## Version 1.0 (2011-12-18) * \+ The first release. From 8fc3f47e879052dcdb22ebc19158dd057fab125d Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 03:16:27 +0400 Subject: [PATCH 10/13] + CHANGELOG_ru. --- CHANGELOG_ru.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 CHANGELOG_ru.md diff --git a/CHANGELOG_ru.md b/CHANGELOG_ru.md new file mode 100644 index 0000000..2464543 --- /dev/null +++ b/CHANGELOG_ru.md @@ -0,0 +1,57 @@ +# (MODX)EvolutionCMS.snippets.ddGetParentId changelog + + +## Версия 1.3.1 (2020-06-22) +* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.40.1 (не тестировался с более ранними версиями). +* \* Совместимость с новыми версиями (MODX)EvolutionCMS.libraries.ddTools. +* \* README, CHANGELOG: Изменения стиля. +* \* README: + * \- Home. + * \+ Links. +* \* Composer.json → `require` → `dd/evolutioncms-libraries-ddtools`: + * \* Переименована из `dd/modxevo-library-ddtools`. + * \* Исправлен формат версии. + + +## Версия 1.3 (2020-03-02) +* \+ Пустые элементы после парсинга `result_itemTpl` будут игнорироваться (можно вызывать сторонние сниппеты в шаблоне и задавать свои условия отображения). +* \+ Composer.json → Require. + + +## Версия 1.2.2 (2020-02-11) +* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.30. +* \* Исправлена ошибка, при которой `result_itemsNumber` всегда было равно `'all'`. +* \* Рефакторинг и прочие изменения. + + +## Версия 1.2.1 (2018-12-09) +* \* Исправлено неправильное имя переменной. + + +## Версия 1.2 (2017-10-09) +* \+ Добавлено указание шаблона `tpl` без чанка, через префикс `@CODE:` +* \+ Добавлена возможность возвращать несколько родителей (см. параметры `result_itemsNumber` и `result_itemsGlue`). +* \* Следующие параметры были переименованы (с обратной совместимостью): + * \* `tpl` → `result_itemTpl`. + * \* `toPlaceholder` → `result_toPlaceholder`. + * \* `placeholderName` → `result_toPlaceholder_name`. +* \* Результат сниппета возвращается всегда (пустой для пустой строки). +* \* Внимание! Требуется PHP >= 5.4. +* \* Внимание! Требуется (MODX)EvolutionCMS >= 1.1. +* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.20. + + +## Версия 1.1 (2014-11-05) +* \+ Параметр `level` теперь может принимать отрицательные значения, чтобы задать уровень родителя с конца (`-1` соответствует последнему; `-2` — предпоследнему и т.д.). + + +## Версия 1.0.1 (2013-08-10) +* \* Если родителя нет (документ в корне), возвращается ID текущего документа. + + +## Версия 1.0 (2011-12-18) +* \+ Первый релиз. + + + + \ No newline at end of file From dc131bafb593aaf939defcd823c57c1abbd218a8 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 03:26:06 +0400 Subject: [PATCH 11/13] * README: Small text improvements. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 16d2e01..55d7a67 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ require_once( * Default value: `[*id*]` (current document) * `level` - * Desctription: Parent level + * Desctription: Parent level. + * Valid values: * `1` — the immediate parent * `2` — the parent of the immediate parent * `-1` — the last parent * `-2` — the parent before the last - * etc. - * Valid values: `integer` + * `integer` — etc * Default value: `1` * `result_itemsNumber` @@ -82,7 +82,7 @@ require_once( Available placeholders: * `[+id+]` — Parent ID. * Valid values: - * `string_chunkName` + * `stringChunkName` * `string` — use inline templates starting with `@CODE:` * Default value: `'@CODE:[+id+]'` From 5a840a5fc120645a135196a2cb3ca08b550d2365 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 03:26:36 +0400 Subject: [PATCH 12/13] + README_ru. --- README_ru.md | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 README_ru.md diff --git a/README_ru.md b/README_ru.md new file mode 100644 index 0000000..ec474b9 --- /dev/null +++ b/README_ru.md @@ -0,0 +1,136 @@ +# (MODX)EvolutionCMS.snippets.ddGetParentId + +Получает ID родителя(ей) необходимого уровня. + + +## Использует +* PHP >= 5.6 +* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1 +* [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) >= 0.60 + + +## Установка + + +### Используя [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller) + +Просто вызовите следующий код в своих исходинках или модуле [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console): + +```php +//Подключение (MODX)EvolutionCMS.libraries.ddInstaller +require_once( + $modx->getConfig('base_path') . + 'assets/libs/ddInstaller/require.php' +); + +//Установка (MODX)EvolutionCMS.snippets.ddGetParentId +\DDInstaller::install([ + 'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetParentId', + 'type' => 'snippet' +]); +``` + +* Если `ddGetParentId` отсутствует на вашем сайте, `ddInstaller` просто установит его. +* Если `ddGetParentId` уже есть на вашем сайте, `ddInstaller` проверит его версию и обновит, если нужно. + + +### Вручную + + +#### 1. Элементы → Сниппеты: Создайте новый сниппет со следующими параметрами + +1. Название сниппета: `ddGetParentId`. +2. Описание: `1.3.1 Получает ID родителя(ей) необходимого уровня.`. +3. Категория: `Core`. +4. Анализировать DocBlock: `no`. +5. Код сниппета (php): Вставьте содержимое файла `ddGetParentId_snippet.php` из архива. + + +#### 2. Элементы → Управление файлами + +1. Создайте новую папку `assets/snippets/ddGetParentId/`. +2. Извлеките содержимое архива в неё (кроме файла `ddGetParentId_snippet.php`). + + +## Описание параметров + +* `id` + * Описание: ID документа. + * Допустимые значения: `integer` + * Значение по умолчанию: `[*id*]` (текущий документ) + +* `level` + * Описание: Уровень родителя. + * Допустимые значения: + * `1` — непосредственный родитель + * `2` — родитель родителя + * `-1` — последний родитель + * `-2` — предпоследний родитель + * `integer` — etc + * Значение по умолчанию: `1` + +* `result_itemsNumber` + * Описание: Количество возвращаемых родителей. + * Допустимые значения: + * `integer` + * `'all'` + * Значение по умолчанию: `1` + +* `result_itemTpl` + * Описание: Шаблон (имя чанка) для вывода. + Пустые элементы после парсинга шаблона будут игнорироваться (можно вызывать сторонние сниппеты в шаблоне и задавать свои условия отображения). + Доступные плейсхолдеры: + * `[+id+]` — Parent ID. + * Допустимые значения: + * `stringChunkName` + * `string` — передавать код напрямую без чанка можно начиная значение с `@CODE:` + * Значение по умолчанию: `'@CODE:[+id+]'` + +* `result_itemsGlue` + * Описание: Строка, объединяющая элементы при рендеринге. + * Допустимые значения: `string` + * Значение по умолчанию: `''` + +* `result_toPlaceholder` + * Описание: Возвращать значение в плэйсхолдер. + * Допустимые значения: + * `0` + * `1` + * Значение по умолчанию: `0` + +* `result_toPlaceholder_name` + * Описание: Имя плэйсхолдера. + * Допустимые значения: `string` + * Значение по умолчанию: `'ddParent'` + + +## Примеры + +### Запустить сниппет через `\DDTools\Snippet::runSnippet` без DB и eval + +```php +//Подключение (MODX)EvolutionCMS.libraries.ddTools +require_once( + $modx->getConfig('base_path') . + 'assets/libs/ddTools/modx.ddtools.class.php' +); + +//Запуск (MODX)EvolutionCMS.snippets.ddGetParentId +\DDTools\Snippet::runSnippet([ + 'name' => 'ddGetParentId', + 'params' => [ + 'level' => -1 + ] +]); +``` + + +## Ссылки + +* [Home page](https://code.divandesign.ru/modx/ddgetparentid) +* [Telegram chat](https://t.me/dd_code) +* [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddgetparentid) +* [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetParentId) + + + \ No newline at end of file From c767dbf637e53c3f7328ff612ca4645433f5603f Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 4 Sep 2023 03:32:36 +0400 Subject: [PATCH 13/13] Prerelease --- CHANGELOG.md | 7 +++++++ CHANGELOG_ru.md | 7 +++++++ README.md | 2 +- README_ru.md | 2 +- composer.json | 2 +- ddGetParentId_snippet.php | 4 ++-- src/Snippet.php | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e632a..72f66a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # (MODX)EvolutionCMS.snippets.ddGetParentId changelog +## Version 1.4 (2023-09-04) +* \+ You can just call `\DDTools\Snippet::runSnippet` to run the snippet without DB and eval (see README → Examples). +* \+ README → Installation → Using (MODX)EvolutionCMS.libraries.ddInstaller. +* \+ README_ru, CHANGELOG_ru. +* \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.60 is required. + + ## Version 1.3.1 (2020-06-22) * \* Attention! (MODX)EvolutionCMS.libraries.ddTools >= 0.40.1 is required (not tested in older versions). * \* Compatibility with new versions of (MODX)EvolutionCMS.libraries.ddTools. diff --git a/CHANGELOG_ru.md b/CHANGELOG_ru.md index 2464543..d9e5c59 100644 --- a/CHANGELOG_ru.md +++ b/CHANGELOG_ru.md @@ -1,6 +1,13 @@ # (MODX)EvolutionCMS.snippets.ddGetParentId changelog +## Версия 1.4 (2023-09-04) +* \+ Запустить сниппет без DB и eval можно через `\DDTools\Snippet::runSnippet` (см. README → Примеры). +* \+ README → Установка → Используя (MODX)EvolutionCMS.libraries.ddInstaller. +* \+ README_ru, CHANGELOG_ru. +* \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.60. + + ## Версия 1.3.1 (2020-06-22) * \* Внимание! Требуется (MODX)EvolutionCMS.libraries.ddTools >= 0.40.1 (не тестировался с более ранними версиями). * \* Совместимость с новыми версиями (MODX)EvolutionCMS.libraries.ddTools. diff --git a/README.md b/README.md index 55d7a67..a6ae9fb 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ require_once( #### 1. Elements → Snippets: Create a new snippet with the following data 1. Snippet name: `ddGetParentId`. -2. Description: `1.3.1 Gets document parent ID(s) of the required level.`. +2. Description: `1.4 Gets document parent ID(s) of the required level.`. 3. Category: `Core`. 4. Parse DocBlock: `no`. 5. Snippet code (php): Insert content of the `ddGetParentId_snippet.php` file from the archive. diff --git a/README_ru.md b/README_ru.md index ec474b9..025df59 100644 --- a/README_ru.md +++ b/README_ru.md @@ -40,7 +40,7 @@ require_once( #### 1. Элементы → Сниппеты: Создайте новый сниппет со следующими параметрами 1. Название сниппета: `ddGetParentId`. -2. Описание: `1.3.1 Получает ID родителя(ей) необходимого уровня.`. +2. Описание: `1.4 Получает ID родителя(ей) необходимого уровня.`. 3. Категория: `Core`. 4. Анализировать DocBlock: `no`. 5. Код сниппета (php): Вставьте содержимое файла `ddGetParentId_snippet.php` из архива. diff --git a/composer.json b/composer.json index e6aa27c..e80f795 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dd/evolutioncms-snippets-ddgetparentid", "type": "modxevo-snippet", - "version": "1.3.1", + "version": "1.4.0", "description": "Gets document parent ID(s) of the required level.", "keywords": [ "modx", diff --git a/ddGetParentId_snippet.php b/ddGetParentId_snippet.php index 2540128..762e3bf 100644 --- a/ddGetParentId_snippet.php +++ b/ddGetParentId_snippet.php @@ -1,13 +1,13 @@