/** * Create a JObject using the properties of the class. * * @param bool $allFields To get all the fields * @param bool $recursive Make this method recursive * @param bool $convertToDatabase If the variables should be converted to database * * @return stdClass */ public function toObject($allFields = false, $recursive = false, $convertToDatabase = true) { $data = new stdClass(); // Getting all the properties marked as 'protected' $properties = $this->getProperties($allFields); // Go through them and assign a value to them if they exist in the argument passed as parameter. foreach ($properties as $property) { if ($property !== 'hasChanged') { $propertyConverted = NenoHelper::convertPropertyNameToDatabaseColumnName($property); if ($this->{$property} instanceof NenoObject) { $data->{$propertyConverted} = $this->{$property}->toObject($allFields, false); } elseif (is_array($this->{$property})) { $dataArray = array(); foreach ($this->{$property} as $key => $value) { if ($recursive && $value instanceof NenoObject) { $dataArray[$key] = $value->toObject($allFields, $recursive, $convertToDatabase); } elseif (!$value instanceof NenoObject) { $dataArray[$key] = $value; } } $data->{$propertyConverted} = $dataArray; } elseif ($this->{$property} instanceof Datetime) { $data->{$propertyConverted} = $this->{$property}->format('Y-m-d H:i:s'); } else { $data->{$propertyConverted} = $this->{$property}; } } } return $data; }