public static function get_property_documentation($class) { $property_docs = array(); $props = array(); $mgdschemas = midgardmvc_core::get_instance()->dispatcher->get_mgdschema_classes(); if (in_array($class, $mgdschemas)) { $dummy = new $class(); $props = get_object_vars($dummy); } elseif ($class == 'midgard_metadata') { $dummy = new midgard_person(); $props = get_object_vars($dummy->metadata); } if (empty($props)) { // Non-MgdSchema class, reflect using PHP method $reflector = new midgard_reflection_class($class); $props = $reflector->getProperties(); foreach ($props as $property) { if (!$property->isPublic()) { // No sense to document private properties continue; } $property_doc = array('name' => $property->name, 'type' => null, 'type_url' => null, 'link_url' => null, 'signature' => $property->name, 'documentation' => midgardmvc_core_helpers_documentation::render_docblock($property->getDocComment())); $property_docs[] = $property_doc; } return $property_docs; } $reflectionproperty = new midgard_reflection_property($class); foreach ($props as $property => $value) { if ($property == 'action') { continue; } $type = midgardmvc_core_helpers_documentation::get_midgard_type_signature($reflectionproperty->get_midgard_type($property)); if (!$type && $property == 'metadata') { $type = 'midgard_metadata'; } $property_doc = array('name' => $property, 'type' => $type, 'type_url' => null, 'link_url' => null, 'signature' => "{$type} {$property}", 'documentation' => $reflectionproperty->description($property)); try { // Link to the class documentation is the property is of particular type if (strpos($type, '_') !== false && class_exists($type)) { $property_doc['type_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('midcom_documentation_class', array('class' => $type)); } } catch (Exception $e) { } if ($reflectionproperty->is_link($property)) { $property_doc['link_url'] = midgardmvc_core::get_instance()->dispatcher->generate_url('midcom_documentation_class', array('class' => $reflectionproperty->get_link_name($property))); $property_doc['link'] = $reflectionproperty->get_link_name($property) . '::' . $reflectionproperty->get_link_target($property); } $property_docs[] = $property_doc; } return $property_docs; }
public static function object_to_form($object, midgardmvc_helper_forms_group $form) { // Go through object properties $props = get_object_vars($object); $reflectionproperty = new midgard_reflection_property(get_class($object)); foreach ($props as $property => $value) { if ($property == 'action' || $property == 'guid' || $property == 'id') { // TODO: Make the list of properties to not render configurable continue; } if ($property == 'metadata') { // Metadata is to be handled as a group $metadata = $form->add_group('metadata'); $metadata->set_label('metadata'); midgardmvc_helper_forms_mgdschema::object_to_form($value, $metadata); } $type = $reflectionproperty->get_midgard_type($property); switch ($type) { case MGD_TYPE_STRING: $field = $form->add_field($property, 'text'); $field->set_value($value); $widget = $field->set_widget('text'); $widget->set_label($property); $widget->set_placeholder($reflectionproperty->description($property)); // TODO: maxlength to 255 break; case MGD_TYPE_LONGTEXT: if ($reflectionproperty->get_user_value($property, 'contenttype') == 'html') { $field = $form->add_field($property, 'html'); $widget = $field->set_widget('html'); } else { $field = $form->add_field($property, 'text'); $widget = $field->set_widget('textarea'); } $field->set_value($value); $widget->set_label($property); $widget->set_placeholder($reflectionproperty->description($property)); break; case MGD_TYPE_INT: $field = $form->add_field($property, 'integer'); $field->set_value($value); $widget = $field->set_widget('number'); $widget->set_label($property); $widget->set_placeholder($reflectionproperty->description($property)); break; case MGD_TYPE_UINT: $field = $form->add_field($property, 'integer'); $field->set_value($value); // TODO: Set minimum value to 0 $widget = $field->set_widget('number'); $widget->set_label($property); $widget->set_placeholder($reflectionproperty->description($property)); break; case MGD_TYPE_BOOLEAN: $field = $form->add_field($property, 'boolean'); $field->set_value($value); break; case MGD_TYPE_FLOAT: case MGD_TYPE_TIMESTAMP: case MGD_TYPE_GUID: break; } } }