/** * Convert the Comparion's contents to a json string in order to validate this comparison client-side * * @internal * @param string $intDynamicPosition * @return string The generated JSON */ public function jsonSerialize($intDynamicPosition = null) { if (get_class($this->__subject) == "ValidFormBuilder\\GroupField") { $identifier = $this->__subject->getId(); } else { $identifier = $this->__subject->getName(); if ($intDynamicPosition > 0) { $identifier = $identifier . "_" . $intDynamicPosition; } } $arrReturn = array("subject" => $identifier, "comparison" => $this->__comparison, "value" => $this->__value); return $arrReturn; }
/** * toJson method creates an array representation of the current condition object and all * of it's comparions. * * In the future this class should extend the JsonSerializable interface * (http://php.net/manual/en/class.jsonserializable.php). Since this is only * supported in PHP >= 5.4, we now use our own implementation. * * @internal * @return array An array representation of this object and it's comparisons. */ public function jsonSerialize($intDynamicPosition = null) { if (get_class($this->__subject) == "ValidFormBuilder\\GroupField" || get_class($this->__subject) == "ValidFormBuilder\\Area") { $identifier = $this->__subject->getId(); } elseif (get_class($this->__subject) == "ValidFormBuilder\\StaticText") { $identifier = $this->__subject->getMeta("id"); } else { $identifier = $this->__subject->getName(); if ($intDynamicPosition > 0) { $identifier = $identifier . "_" . $intDynamicPosition; } } $arrReturn = array("subject" => $identifier, "property" => $this->__property, "value" => $this->__value, "comparisonType" => $this->__comparisontype, "comparisons" => array()); foreach ($this->__comparisons as $objComparison) { array_push($arrReturn["comparisons"], $objComparison->jsonSerialize($intDynamicPosition)); } return $arrReturn; }