Beispiel #1
0
 public function prepareObject(TypeInterface $controller, $parent = null)
 {
     $config = $controller->getConfig();
     $class = $config['storage'];
     $object = new $class();
     if (null !== $parent) {
         $baseclass = \midcom_helper_reflector::resolve_baseclass($class);
         $reflector = new \midgard_reflection_property($baseclass);
         $up_property = \midgard_object_class::get_property_up($baseclass);
         if (!empty($up_property)) {
             $target_property = $reflector->get_link_target($up_property);
             $target_class = $reflector->get_link_name($up_property);
             if (\midcom_helper_reflector::resolve_baseclass($parent) === $target_class) {
                 $object->{$up_property} = $parent->{$target_property};
             }
         }
         $parent_property = \midgard_object_class::get_property_parent($baseclass);
         if (!empty($parent_property)) {
             $target_property = $reflector->get_link_target($parent_property);
             $target_class = $reflector->get_link_name($parent_property);
             if (\midcom_helper_reflector::resolve_baseclass($parent) === $target_class) {
                 $object->{$parent_property} = $parent->{$target_property};
             } else {
                 $object->{$parent_property} = $parent->{$parent_property};
             }
         }
     }
     return $object;
 }
 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;
 }
Beispiel #3
0
 private function _add_linked_field($key)
 {
     $linked_type = $this->_reflector->get_link_name($key);
     $linked_type_reflector = midcom_helper_reflector::get($linked_type);
     $field_type = $this->_reflector->get_midgard_type($key);
     if ($key == 'up') {
         $field_label = sprintf($this->_l10n->get('under %s'), midgard_admin_asgard_plugin::get_type_label($linked_type));
     } else {
         $type_label = midgard_admin_asgard_plugin::get_type_label($linked_type);
         if (substr($type_label, 0, strlen($key)) == $key) {
             // Handle abbreviations like "lang" for "language"
             $field_label = $type_label;
         } else {
             if ($key == $type_label) {
                 $field_label = $key;
             } else {
                 $ref = midcom_helper_reflector::get($this->_object);
                 $component_l10n = $ref->get_component_l10n();
                 $field_label = sprintf($this->_l10n->get('%s (%s)'), $component_l10n->get($key), $type_label);
             }
         }
     }
     // Get the chooser widgets
     switch ($field_type) {
         case MGD_TYPE_UINT:
         case MGD_TYPE_STRING:
         case MGD_TYPE_GUID:
             $class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($linked_type);
             if (!$class) {
                 break;
             }
             $component = midcom::get('dbclassloader')->get_component_for_class($linked_type);
             $this->_schemadb['object']->append_field($key, array('title' => $field_label, 'storage' => $key, 'type' => 'select', 'type_config' => array('require_corresponding_option' => false, 'options' => array(), 'allow_other' => true, 'allow_multiple' => false), 'widget' => 'chooser', 'widget_config' => array('class' => $class, 'component' => $component, 'titlefield' => $linked_type_reflector->get_label_property(), 'id_field' => $this->_reflector->get_link_target($key), 'searchfields' => $linked_type_reflector->get_search_properties(), 'result_headers' => $this->_get_result_headers($linked_type_reflector), 'orders' => array(), 'creation_mode_enabled' => true, 'creation_handler' => midcom_connection::get_url('self') . "__mfa/asgard/object/create/chooser/{$linked_type}/", 'creation_default_key' => $linked_type_reflector->get_label_property(), 'generate_path_for' => midcom_helper_reflector::get_name_property($this->_object))));
             break;
     }
 }
Beispiel #4
0
 function _resolve_child_classes_links_back($property, $prospect_type, $schema_type)
 {
     if (empty($property)) {
         return false;
     }
     $ref = new midgard_reflection_property($prospect_type);
     $link_class = $ref->get_link_name($property);
     if (empty($link_class) && $ref->get_midgard_type($property) === MGD_TYPE_GUID) {
         return true;
     }
     if (midcom_helper_reflector::is_same_class($link_class, $schema_type)) {
         return true;
     }
     return false;
 }
Beispiel #5
0
 /**
  * Get the GUID of the object's parent. This is done by reading up or parent
  * property values, which will give us the parent's ID. Since the ID => GUID relation
  * won't change, the corresponding GUID is then stored in an in-request static cache
  */
 public static function get_parent_guid_uncached_static($object_guid, $class_name)
 {
     static $parent_mapping = array();
     $class_name = midcom::get('dbclassloader')->get_mgdschema_class_name_for_midcom_class($class_name);
     $reflector = new midgard_reflection_property($class_name);
     $up_property = midgard_object_class::get_property_up($class_name);
     if (!empty($up_property)) {
         $target_property = $reflector->get_link_target($up_property);
         // Up takes precedence over parent
         $mc = new midgard_collector($class_name, 'guid', $object_guid);
         $mc->set_key_property($up_property);
         $mc->execute();
         $link_values = $mc->list_keys();
         if (!empty($link_values)) {
             list($link_value, $dummy) = each($link_values);
             unset($mc, $link_values, $dummy);
             if (!empty($link_value)) {
                 if (!array_key_exists($class_name, $parent_mapping)) {
                     $parent_mapping[$class_name] = array();
                 }
                 if (array_key_exists($link_value, $parent_mapping[$class_name])) {
                     return $parent_mapping[$class_name][$link_value];
                 }
                 $mc2 = new midgard_collector($class_name, $target_property, $link_value);
                 $mc2->set_key_property('guid');
                 $mc2->execute();
                 $guids = $mc2->list_keys();
                 if (!is_array($guids)) {
                     unset($mc2, $guids, $link_value);
                     $parent_mapping[$class_name][$link_value] = null;
                     return $parent_mapping[$class_name][$link_value];
                 }
                 list($parent_guid, $dummy) = each($guids);
                 $parent_mapping[$class_name][$link_value] = $parent_guid;
                 unset($mc2, $guids, $link_value, $dummy);
                 return $parent_guid;
             }
         } else {
             unset($mc, $link_values);
         }
     }
     $parent_property = midgard_object_class::get_property_parent($class_name);
     if (!empty($parent_property) && $reflector->get_link_target($parent_property)) {
         $target_property = $reflector->get_link_target($parent_property);
         $target_class = $reflector->get_link_name($parent_property);
         $mc = new midgard_collector($class_name, 'guid', $object_guid);
         $mc->set_key_property($parent_property);
         $mc->execute();
         $link_values = $mc->list_keys();
         if (!empty($link_values)) {
             list($link_value, $dummy) = each($link_values);
             unset($mc, $link_values, $dummy);
             if (!empty($link_value)) {
                 if (!array_key_exists($target_class, $parent_mapping)) {
                     $parent_mapping[$target_class] = array();
                 }
                 if (array_key_exists($link_value, $parent_mapping[$target_class])) {
                     return $parent_mapping[$target_class][$link_value];
                 }
                 $mc2 = new midgard_collector($target_class, $target_property, $link_value);
                 $mc2->set_key_property('guid');
                 $mc2->execute();
                 $guids = $mc2->list_keys();
                 if (!is_array($guids)) {
                     unset($mc2, $guids, $link_value);
                     $parent_mapping[$target_class][$link_value] = null;
                     return $parent_mapping[$target_class][$link_value];
                 }
                 list($parent_guid, $dummy) = each($guids);
                 $parent_mapping[$target_class][$link_value] = $parent_guid;
                 unset($mc2, $guids, $link_value, $dummy);
                 return $parent_guid;
             }
         } else {
             unset($mc, $link_values);
         }
     }
     // FIXME: Handle GUID linking
     return null;
 }
Beispiel #6
0
}
if (count($results) <= 0 || !is_array($results)) {
    $response->status = 2;
    $response->errstr = "No results found";
    $response->send();
}
$response->status = 1;
$response->errstr = "";
$items = array();
foreach ($results as $object) {
    if (isset($reflector_key) && !empty($reflector_key)) {
        debug_add("Using reflector with key {$reflector_key}");
        $reflector_type = get_class($object);
        $reflector = new midgard_reflection_property($reflector_type);
        if ($reflector->is_link($reflector_key)) {
            $linked_type = $reflector->get_link_name($reflector_key);
            $object = new $linked_type($object->{$reflector_key});
        }
        debug_print_r('reflected object', $object);
    }
    $id = @$object->id;
    $guid = @$object->guid;
    debug_add("adding result: id={$id} guid={$guid}");
    $result = array('id' => $id, 'guid' => $guid);
    debug_print_r('$result_headers', $result_headers);
    if (!is_array($result_headers) || !empty($reflector_key) && !$result_headers) {
        $value = @$object->get_label();
        debug_add("adding header item: name=label value={$value}");
        $result['label'] = "<![CDATA[{$value}]]>";
    } else {
        foreach ($result_headers as $header_item) {
Beispiel #7
0
 private function getChildTypes($midgard_class)
 {
     $mgdschemas = $this->getTypes();
     $child_types = array();
     foreach ($mgdschemas as $mgdschema) {
         if ($mgdschema == 'midgard_attachment' || $mgdschema == 'midgard_parameter') {
             continue;
         }
         $link_properties = array('parent' => \midgard_object_class::get_property_parent($mgdschema), 'up' => \midgard_object_class::get_property_up($mgdschema));
         $ref = new \midgard_reflection_property($mgdschema);
         foreach ($link_properties as $type => $property) {
             $link_class = $ref->get_link_name($property);
             if (empty($link_class) && $ref->get_midgard_type($property) === MGD_TYPE_GUID) {
                 $child_types[] = $mgdschema;
                 continue;
             }
             if ($link_class == $parent_class) {
                 $child_types[] = $mgdschema;
             }
         }
     }
     return $child_types;
 }