Skip to content

Commit

Permalink
Version 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Jun 3, 2023
2 parents f40b6cd + 9cb5f6a commit 861bb8b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 74 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# (MODX)EvolutionCMS.snippets.ddIf changelog


## Version 2.3.1 (2023-06-03)
* \* Compatibility with PHP < 8.
* \* Parameters → `trueChunk`, `falseChunk` → Placeholders: The following have been renamed (outdated names are still supported, but are not recommended):
* \* `[+snippetParams.operand1+]` → `[+ddIfParams.operand1+]`.
* \* `[+snippetParams.operand2+]` → `[+ddIfParams.operand2+]`.
* \* `[+snippetParams.operator+]` → `[+ddIfParams.operator+]`.


## Version 2.3 (2023-06-03)
* \+ Parameters → `operator` → Valid values → `'isIncludes'`: The new valid value. Case-sensitive check if `operand1` contains `operand2` (see README → Examples).
* \* `\ddTools::getTpl` is used instead of `$modx->getTpl` (means a bit less bugs).
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# (MODX)EvolutionCMS.snippets.ddIf changelog


## Версия 2.3.1 (2023-06-03)
* \* Совместимость с PHP < 8.
* \* Параметры → `trueChunk`, `falseChunk` → Плейсхолдеры: Следующие были переименованы (старые названия все ещё поддерживаются, но не рекомендуются):
* \* `[+snippetParams.operand1+]` → `[+ddIfParams.operand1+]`.
* \* `[+snippetParams.operand2+]` → `[+ddIfParams.operand2+]`.
* \* `[+snippetParams.operator+]` → `[+ddIfParams.operator+]`.


## Версия 2.3 (2023-06-03)
* \+ Параметры → `operator` → Допустимые значения → `'isIncludes'`: Новое значение. Проверяет, содержит ли `operand1` в себе `operand2` с учётом регистра, (см. README → Примеры).
* \* `\ddTools::getTpl` используется вместо `$modx->getTpl` (стало чуть меньше багов).
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require_once(
#### 1. Elements → Snippets: Create a new snippet with the following data

1. Snippet name: `ddIf`.
2. Description: `<b>2.3</b> This snippet compares different values and returns required chunk or string.`.
2. Description: `<b>2.3.1</b> This snippet compares different values and returns required chunk or string.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddIf_snippet.php` file from the archive.
Expand Down Expand Up @@ -86,9 +86,9 @@ require_once(
* `trueChunk`
* Desctription: This value is returning if result is true.
Available placeholders:
* `[+snippetParams.operand1+]` — contains `operand1` value.
* `[+snippetParams.operand2+]` — contains `operand2` value.
* `[+snippetParams.operator+]` — contains `operator` value.
* `[+ddIfParams.operand1+]` — contains `operand1` value.
* `[+ddIfParams.operand2+]` — contains `operand2` value.
* `[+ddIfParams.operator+]` — contains `operator` value.
* `[+`any placeholders from the `placeholders` parameter`+]`
* Valid values:
* `stringChunkName`
Expand All @@ -98,9 +98,9 @@ require_once(
* `falseChunk`
* Desctription: This value is returning if result is false.
Available placeholders:
* `[+snippetParams.operand1+]` — contains `operand1` value.
* `[+snippetParams.operand2+]` — contains `operand2` value.
* `[+snippetParams.operator+]` — contains `operator` value.
* `[+ddIfParams.operand1+]` — contains `operand1` value.
* `[+ddIfParams.operand2+]` — contains `operand2` value.
* `[+ddIfParams.operator+]` — contains `operator` value.
* `[+`any placeholders from the `placeholders` parameter`+]`
* Valid values:
* `stringChunkName`
Expand Down Expand Up @@ -222,7 +222,7 @@ An empty string is also considered as white space.
`
&operator=`isWhitespace`
&trueChunk=`@CODE:The string contains only some whitespace characters.`
&falseChunk=`@CODE:[+snippetParams.operand1+]`
&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]
```

Expand All @@ -239,7 +239,7 @@ If `operand1` contains any non-whitespace characters, `falseString` will be retu
&operand1=`All you need is love.`
&operator=`isWhitespace`
&trueChunk=`@CODE:The string contains only some whitespace characters.`
&falseChunk=`@CODE:[+snippetParams.operand1+]`
&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]
```

Expand Down Expand Up @@ -271,7 +271,7 @@ Code of the `general_good` chunk:

```html
<div>
<h2>[+title+], $[+snippetParams.operand1+]</h2>
<h2>[+title+], $[+ddIfParams.operand1+]</h2>
<img src="[+image+]" alt="[+title+]" />
</div>
```
Expand All @@ -280,7 +280,7 @@ Code of the `general_goodInexpensive` chunk:

```html
<div class="inexpensive">
<h2>[+title+], <strong>$[+snippetParams.operand1+]</strong></h2>
<h2>[+title+], <strong>$[+ddIfParams.operand1+]</strong></h2>
<img src="[+image+]" alt="[+title+]" />
<p>[+somethingText+]</p>
</div>
Expand Down
22 changes: 11 additions & 11 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require_once(
#### 1. Элементы → Сниппеты: Создайте новый сниппет со следующими параметрами

1. Название сниппета: `ddIf`.
2. Описание: `<b>2.3</b> Сравнивает значения и выводит необходимый чанк или строку.`.
2. Описание: `<b>2.3.1</b> Сравнивает значения и выводит необходимый чанк или строку.`.
3. Категория: `Core`.
4. Анализировать DocBlock: `no`.
5. Код сниппета (php): Вставьте содержимое файла `ddIf_snippet.php` из архива.
Expand Down Expand Up @@ -86,9 +86,9 @@ require_once(
* `trueChunk`
* Описание: Значение, возвращаемое при истинном условии.
Доступные плейсхолдеры:
* `[+snippetParams.operand1+]` — содержит значение `operand1`.
* `[+snippetParams.operand2+]` — содержит значение `operand2`.
* `[+snippetParams.operator+]` — содержит значение `operator`.
* `[+ddIfParams.operand1+]` — содержит значение `operand1`.
* `[+ddIfParams.operand2+]` — содержит значение `operand2`.
* `[+ddIfParams.operator+]` — содержит значение `operator`.
* `[+`любой плейсхолдер из параметра `placeholders` `+]`
* Допустимые значения:
* `stringChunkName`
Expand All @@ -98,9 +98,9 @@ require_once(
* `falseChunk`
* Описание: Значение, возвращаемое при ложном условии.
Доступные плейсхолдеры:
* `[+snippetParams.operand1+]` — содержит значение `operand1`.
* `[+snippetParams.operand2+]` — содержит значение `operand2`.
* `[+snippetParams.operator+]` — содержит значение `operator`.
* `[+ddIfParams.operand1+]` — содержит значение `operand1`.
* `[+ddIfParams.operand2+]` — содержит значение `operand2`.
* `[+ddIfParams.operator+]` — содержит значение `operator`.
* `[+`любой плейсхолдер из параметра `placeholders` `+]`
* Допустимые значения:
* `stringChunkName`
Expand Down Expand Up @@ -222,7 +222,7 @@ require_once(
`
&operator=`isWhitespace`
&trueChunk=`@CODE:Строка содержит только пробельные символы.`
&falseChunk=`@CODE:[+snippetParams.operand1+]`
&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]
```

Expand All @@ -239,7 +239,7 @@ require_once(
&operand1=`All you need is love.`
&operator=`isWhitespace`
&trueChunk=`@CODE:Строка содержит только пробельные символы.`
&falseChunk=`@CODE:[+snippetParams.operand1+]`
&falseChunk=`@CODE:[+ddIfParams.operand1+]`
]]
```

Expand Down Expand Up @@ -271,7 +271,7 @@ All you need is love.

```html
<div>
<h2>[+title+], $[+snippetParams.operand1+]</h2>
<h2>[+title+], $[+ddIfParams.operand1+]</h2>
<img src="[+image+]" alt="[+title+]" />
</div>
```
Expand All @@ -280,7 +280,7 @@ All you need is love.

```html
<div class="inexpensive">
<h2>[+title+], <strong>$[+snippetParams.operand1+]</strong></h2>
<h2>[+title+], <strong>$[+ddIfParams.operand1+]</strong></h2>
<img src="[+image+]" alt="[+title+]" />
<p>[+somethingText+]</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dd/evolutioncms-snippets-ddif",
"type": "modxevo-snippet",
"version": "2.3.0",
"version": "2.3.1",
"description": "This snippet compares different values and returns required chunk or string.",
"keywords": [
"modx",
Expand Down
2 changes: 1 addition & 1 deletion ddIf_snippet.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ddIf
* @version 2.3 (2023-06-03)
* @version 2.3.1 (2023-06-03)
*
* @see README.md
*
Expand Down
84 changes: 34 additions & 50 deletions src/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Snippet extends \DDTools\Snippet {
protected
$version = '2.3.0',
$version = '2.3.1',

$params = [
//Defaults
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function prepareParams($params = []){

/**
* run
* @version 1.2 (2023-06-03)
* @version 1.2.3 (2023-06-03)
*
* @return {string}
*/
Expand All @@ -92,58 +92,46 @@ public function run(){
//Выбираем сравнение в зависимости от оператора
switch ($this->params->operator){
case '!=':
$boolOut =
$this->params->operand1 != $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 != $this->params->operand2;
break;

case '>':
$boolOut =
$this->params->operand1 > $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 > $this->params->operand2;
break;

case '<':
$boolOut =
$this->params->operand1 < $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 < $this->params->operand2;
break;

case '>=':
$boolOut =
$this->params->operand1 >= $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 >= $this->params->operand2;
break;

case '<=':
$boolOut =
$this->params->operand1 <= $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 <= $this->params->operand2;
break;

case 'bool':
$boolOut =
$this->params->operand1 ?
true :
false
;
$boolOut = boolval($this->params->operand1);
break;

case 'isincludes':
$boolOut = str_contains(
$this->params->operand1,
$this->params->operand2
);
$boolOut =
function_exists('str_contains') ?
//PHP >= 8
str_contains(
$this->params->operand1,
$this->params->operand2
) :
//PHP < 8
(
$this->params->operand2 === '' ||
mb_strpos(
$this->params->operand1,
$this->params->operand2
) !== false
)
;
break;

case 'inarray':
Expand All @@ -152,14 +140,10 @@ public function run(){
$this->params->operand2
);

$boolOut =
in_array(
$this->params->operand1,
$operand2Array
) ?
true :
false
;
$boolOut = in_array(
$this->params->operand1,
$operand2Array
);
break;

case 'isnumeric':
Expand All @@ -175,11 +159,7 @@ public function run(){

case '==':
default:
$boolOut =
$this->params->operand1 == $this->params->operand2 ?
true :
false
;
$boolOut = $this->params->operand1 == $this->params->operand2;
}

//Select output chunk
Expand All @@ -196,9 +176,13 @@ public function run(){
'data' => \DDTools\ObjectTools::extend([
'objects' => [
[
'ddIfParams.operand1' => $this->params->operand1,
'ddIfParams.operand2' => $this->params->operand2,
'ddIfParams.operator' => $this->params->operator,
//Backward compatibility
'snippetParams.operand1' => $this->params->operand1,
'snippetParams.operand2' => $this->params->operand2,
'snippetParams.operator' => $this->params->operator
'snippetParams.operator' => $this->params->operator,
],
$this->params->placeholders
]
Expand Down

0 comments on commit 861bb8b

Please sign in to comment.