queryable; } /** * Condition label * * @return string */ public function getLabel(){ return ''; } /** * Condition description * * @return string|null */ public function getDescription(){ return null; } /** * Retrieves control options * * @return array */ public function getControlOptions(){ $options = [ 'defaultValue' => $this->defaultValue ]; if( $this->queryable() ){ $options['query'] = $this->slug; } return $options; } /** * Retrieves properties which can be exposed * * @return array */ public function getProperties(){ $properties = [ 'slug' => $this->slug, 'label' => $this->getLabel(), 'control' => $this->control, 'tier' => $this->tier, 'controlOptions' => $this->getControlOptions() ]; if( $this->getDescription() ){ $properties['description'] = $this->getDescription(); } return $properties; } /** * Get query results for dynamic options of this condition * * @return array|null */ public function getQueryResults(){ return null; } /** * Check if the condition is qualified or not * * @param $value * * @return bool */ public function check( $value = null ){ return false; } /** * Compare two variables * * @param $var * @param $operator * @param $value * * @return bool */ public function compare( $var, $operator, $value ): bool{ switch( $operator ) { case 'equal': return $var == $value; case 'greaterThan': return (float) $var > (float) $value; case 'lowerThan': return (float) $var < (float) $value; case 'greaterThanOrEqual': return (float) $var >= (float) $value; case 'lowerThanOrEqual': return (float) $var <= (float) $value; case 'containing': return false !== strpos( $var, $value ); case 'notContaining': return false === strpos( $var, $value ); case 'endsWith': return Str::ends( $var, $value ); case 'beginsWith': return Str::starts( $var, $value ); case 'regExpMatch': return (bool) preg_match( "/$value/", $var ); case 'oneOf': $lines = explode( '\n', $value ); return in_array( $var, $lines); case 'nonOf': $lines = explode( '\n', $value ); return ! in_array( $var, $lines); default: return false; } } /** * Check if condition is visible or not * * @return boolean */ public function isVisible() { return true; } }