-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from venveo/develop
New strategies
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace venveo\bulkedit\fields\processors; | ||
|
||
use craft\base\Element; | ||
use craft\base\Field; | ||
use craft\fields\Number; | ||
use venveo\bulkedit\base\AbstractFieldProcessor; | ||
use venveo\bulkedit\services\BulkEdit; | ||
|
||
class NumberFieldProcessor extends AbstractFieldProcessor | ||
{ | ||
|
||
/** | ||
* The fully qualified class name for the element this processor works on | ||
* @return array | ||
*/ | ||
public static function getSupportedFields(): array | ||
{ | ||
return [ | ||
Number::class | ||
]; | ||
} | ||
|
||
/** | ||
* Returns the supported strategies for this field type | ||
* @return array | ||
*/ | ||
public static function getSupportedStrategies(): array | ||
{ | ||
return [BulkEdit::STRATEGY_REPLACE, BulkEdit::STRATEGY_SUBTRACT, BulkEdit::STRATEGY_ADD, BulkEdit::STRATEGY_MULTIPLY, BulkEdit::STRATEGY_DIVIDE]; | ||
} | ||
|
||
public static function performAddition(Element $element, Field $field, $value): void | ||
{ | ||
$fieldHandle = $field->handle; | ||
$originalValue = (int)$element->getFieldValue($fieldHandle); | ||
$value = $value['value'] ?? 0; | ||
$element->setFieldValue($fieldHandle, $originalValue + (int)$value); | ||
} | ||
|
||
public static function performSubtraction(Element $element, Field $field, $value): void | ||
{ | ||
$fieldHandle = $field->handle; | ||
$originalValue = (int)$element->getFieldValue($fieldHandle); | ||
|
||
$value = $value['value'] ?? 0; | ||
$element->setFieldValue($fieldHandle, $originalValue - (int)$value); | ||
} | ||
|
||
public static function performMultiplication(Element $element, Field $field, $value): void | ||
{ | ||
$fieldHandle = $field->handle; | ||
$originalValue = (int)$element->getFieldValue($fieldHandle); | ||
|
||
$value = $value['value'] ?? 0; | ||
$element->setFieldValue($fieldHandle, $originalValue * (int)$value); | ||
} | ||
|
||
public static function performDivision(Element $element, Field $field, $value): void | ||
{ | ||
$fieldHandle = $field->handle; | ||
$originalValue = (int)$element->getFieldValue($fieldHandle); | ||
|
||
$value = $value['value'] ?? 1; | ||
$element->setFieldValue($fieldHandle, $originalValue / (int)$value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters