Skip to content

Commit

Permalink
latest ss3 version with php 7.2 support (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemiacsik authored and Aaron Carlino committed Oct 24, 2018
1 parent ca910ac commit 0fb06bf
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 74 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# For more information about the properties used in this file,
# please see the EditorConfig documentation:
# http://editorconfig.org

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
indent_size = 2

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
69 changes: 69 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
inherit: true

checks:
php:
verify_property_names: true
verify_argument_usable_as_reference: true
verify_access_scope_valid: true
useless_calls: true
use_statement_alias_conflict: true
variable_existence: true
unused_variables: true
unused_properties: true
unused_parameters: true
unused_methods: true
unreachable_code: true
too_many_arguments: true
sql_injection_vulnerabilities: true
simplify_boolean_return: true
side_effects_or_types: true
security_vulnerabilities: true
return_doc_comments: true
return_doc_comment_if_not_inferrable: true
require_scope_for_properties: true
require_scope_for_methods: true
require_php_tag_first: true
psr2_switch_declaration: true
psr2_class_declaration: true
property_assignments: true
prefer_while_loop_over_for_loop: true
precedence_mistakes: true
precedence_in_conditions: true
phpunit_assertions: true
php5_style_constructor: true
parse_doc_comments: true
parameter_non_unique: true
parameter_doc_comments: true
param_doc_comment_if_not_inferrable: true
optional_parameters_at_the_end: true
one_class_per_file: true
no_unnecessary_if: true
no_trailing_whitespace: true
no_property_on_interface: true
no_non_implemented_abstract_methods: true
no_error_suppression: true
no_duplicate_arguments: true
no_commented_out_code: true
newline_at_end_of_file: true
missing_arguments: true
method_calls_on_non_object: true
instanceof_class_exists: true
foreach_traversable: true
fix_line_ending: true
fix_doc_comments: true
duplication: true
deprecated_code_usage: true
deadlock_detection_in_loops: true
code_rating: true
closure_use_not_conflicting: true
catch_class_exists: true
blank_line_after_namespace_declaration: false
avoid_multiple_statements_on_same_line: true
avoid_duplicate_types: true
avoid_conflicting_incrementers: true
avoid_closing_tag: true
assignment_of_null_return: true
argument_type_checks: true

filter:
paths: [code/*, tests/*]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $shipping->displayIf("ProductType")->isEqualTo("furniture")
- isNotEmpty
- isBetween
- isChecked
- isNotChecked()
- hasCheckedOption
- hasCheckedAtLeast
- hasCheckedLessThan
Expand Down
6 changes: 6 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php

define('DISPLAY_LOGIC_DIR', basename(dirname(__FILE__)));

// Ensure compatibility with PHP 7.2 ("object" is a reserved word),
// with SilverStripe 3.6 (using Object) and SilverStripe 3.7 (using SS_Object)
if (!class_exists('SS_Object')) {
class_alias('Object', 'SS_Object');
}
8 changes: 7 additions & 1 deletion _config/display_logic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ DisplayLogicCriteria:
- isNotEmpty
- isBetween
- isChecked
- isNotChecked
- hasCheckedOption
- hasCheckedAtLeast
- hasCheckedLessThan
animations:
- toggle
- slide
- fade
default_animation: toggle

FormField:
extensions:
- DisplayLogicFormField
DisplayLogic:
jquery_included: true
jquery_included: true
1 change: 1 addition & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When having discussions about this module in issues or pull request please adhere to the [SilverStripe Community Code of Conduct](https://docs.silverstripe.org/en/contributing/code_of_conduct).
91 changes: 80 additions & 11 deletions code/DisplayLogicCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class DisplayLogicCriteria extends SS_Object {



/**
* The animation method to use
* @var string
*/
protected $animation = null;



/**
* Either "and" or "or", determines disjunctive or conjunctive logic for the whole criteria set
* @var string
Expand All @@ -50,6 +58,17 @@ class DisplayLogicCriteria extends SS_Object {



/**
* Changes the configured default animation method
* @param string $animation
*/
public static function set_default_animation($animation) {
if(in_array($animation, Config::inst()->get(__CLASS__, 'animations'))) {
Config::inst()->update(__CLASS__, 'default_animation', $animation);
}
}



/**
* Constructor
Expand All @@ -74,9 +93,9 @@ public function __construct(FormField $slave, $master, $parent = null) {
* @param array $args The arguments
* @return DisplayLogicCriteria
*/
public function __call($method, $args) {
if(in_array($method, $this->config()->comparisons)) {
$val = isset($args[0]) ? $args[0] : null;
public function __call($method, $args) {
if(in_array($method, $this->config()->comparisons)) {
$val = isset($args[0]) ? $args[0] : null;
if(substr($method, 0, 2) == "is") {
$operator = substr($method, 2);
}
Expand All @@ -86,7 +105,7 @@ public function __call($method, $args) {

$this->addCriterion(DisplayLogicCriterion::create($this->master, $operator, $val, $this));
return $this;
}
}
return parent::__call($method, $args);
}

Expand All @@ -99,7 +118,7 @@ public function __call($method, $args) {
* @param int $max The maxiumum value
* @return DisplayLogicCriteria
*/
public function isBetween($min, $max) {
public function isBetween($min, $max) {
$this->addCriterion(DisplayLogicCriterion::create($this->master, "Between", "{$min}-{$max}", $this));
return $this;
}
Expand Down Expand Up @@ -142,9 +161,9 @@ public function orIf($master = null) {

/**
* Adds a new criterion
* @param DisplayLogicCriterion $c
* @param DisplayLogicCriterion|DisplayLogicCriteria $c
*/
public function addCriterion(DisplayLogicCriterion $c) {
public function addCriterion($c) {
$this->criteria[] = $c;
}

Expand All @@ -168,7 +187,27 @@ public function getLogicalOperator() {
return $this->logicalOperator == "or" ? "||" : "&&";
}

/**
* Accessor for the master field
* @return string
*/
public function getMaster() {
return $this->master;
}

/**
* @return $this
*/
public function setMaster($fieldName) {
$this->master = $fieldName;
$criteria = $this->getCriteria();
if ($criteria) {
foreach ($criteria as $criterion) {
$criterion->setMaster($fieldName);
}
}
return $this;
}

/**
* Creates a nested {@link DisplayLogicCriteria}
Expand All @@ -180,6 +219,35 @@ public function group() {



/**
*
* Defines the animation method to use
* @param string $animation
* @return DisplayLogicCriteria
*/
public function useAnimation($animation) {
if(in_array($animation, $this->config()->animations)) {
$this->animation = $animation;
}
return $this;
}




/**
* Answers the animation method to use
* @return string
*/
public function getAnimation() {
if(!$this->animation) {
return $this->config()->default_animation;
}
return $this->animation;
}




/**
* Ends the chaining and returns the parent object, either {@link DisplayLogicCriteria} or {@link FormField}
Expand All @@ -188,6 +256,7 @@ public function group() {
public function end() {
if($this->parent) {
$this->parent->addCriterion($this);
return $this->parent;
}
return $this->slave;
}
Expand All @@ -196,7 +265,7 @@ public function end() {


/**
* Creates a JavaScript readable representation of the logic
* Creates a JavaScript readable representation of the logic
* @return string
*/
public function toScript() {
Expand All @@ -206,7 +275,7 @@ public function toScript() {
$script .= $first ? "" : " {$this->getLogicalOperator()} ";
$script .= $c->toScript();
$first = false;
}
}
$script .= ")";
return $script;
}
Expand All @@ -222,7 +291,7 @@ public function getMasterList() {
$list = array ();
foreach($this->getCriteria() as $c) {
if($c instanceof DisplayLogicCriteria) {
$list += $c->getMasterList();
$list=array_merge($list, $c->getMasterList());
}
else {
$list[] = $c->getMaster();
Expand All @@ -236,4 +305,4 @@ public function getMasterList() {



}
}
14 changes: 10 additions & 4 deletions code/DisplayLogicCriterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,25 @@ public function getMaster() {
return $this->master;
}


/**
* @return $this
*/
public function setMaster($fieldName) {
$this->master = $fieldName;
return $this;
}


/**
* Creates a JavaScript-readable representation of this criterion
* @return string
*/
public function toScript() {
public function toScript() {
return sprintf(
"this.closest('form').find(this.escapeSelector('#%s')).evaluate%s('%s')",
"this.findHolder('%s').evaluate%s('%s')",
$this->master,
$this->operator,
addslashes($this->value)
);
}
}
}
17 changes: 16 additions & 1 deletion code/DisplayLogicFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function setDisplayLogicCriteria(DisplayLogicCriteria $c) {
$this->displayLogicCriteria = $c;
}


public function getDisplayLogicCriteria() {
return $this->displayLogicCriteria;
}


/**
Expand All @@ -104,6 +106,18 @@ public function DisplayLogicMasters() {
}


/**
* Answers the animation method to use from the criteria object
*
* @return string
*/
public function DisplayLogicAnimation() {
if($this->displayLogicCriteria) {
return $this->displayLogicCriteria->getAnimation();
}
}


/**
* Loads the dependencies and renders the JavaScript-readable logic to the form HTML
*
Expand All @@ -126,6 +140,7 @@ public function onBeforeRender($field) {
if($logic = $field->DisplayLogic()) {
$field->setAttribute('data-display-logic-masters', $field->DisplayLogicMasters());
$field->setAttribute('data-display-logic-eval', $logic);
$field->setAttribute('data-display-logic-animation', $field->DisplayLogicAnimation());
}
}

Expand Down

0 comments on commit 0fb06bf

Please sign in to comment.