示例#1
0
 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;
 }
示例#2
0
 /**
  *
  * @param mixed $object
  * @param CollectionInterface $config
  * @return array
  */
 public function getChildren($object, CollectionInterface $collection)
 {
     $config = $collection->getConfig();
     if (empty($config['parentfield'])) {
         throw new \midcom_error('parentfield was not defined in config');
     }
     $parentfield = $config['parentfield'];
     // if storage is not defined, we assume it's the same as object
     if (empty($config['storage'])) {
         $storage = get_class($object);
     } else {
         $storage = $config['storage'];
     }
     $reflector = new \midgard_reflection_property(\midcom_helper_reflector::resolve_baseclass($storage));
     if (!$reflector->is_link($parentfield)) {
         throw new \midcom_error('could not determine storage class');
     }
     $qb = call_user_func(array($storage, 'new_query_builder'));
     $qb->add_constraint($parentfield, '=', $object->id);
     // order the children by their score values
     $qb->add_order('score', 'ASC');
     return $qb->execute();
 }
示例#3
0
 function sort_schema_fields($first, $second)
 {
     $preferred_fields = $this->_config->get('object_preferred_fields');
     $timerange_fields = $this->_config->get('object_timerange_fields');
     $address_fields = $this->_config->get('object_address_fields');
     $phone_fields = $this->_config->get('object_phone_fields');
     $location_fields = $this->_config->get('object_location_fields');
     // We handle the cases, and then their subcases
     if (in_array($first, $preferred_fields) && $this->_reflector->get_midgard_type($first) != MGD_TYPE_LONGTEXT) {
         // This is one of the preferred fields, check subcases
         if (in_array($second, $preferred_fields)) {
             return strnatcmp($first, $second);
         }
         return -1;
     }
     if ($this->_reflector->get_midgard_type($first) == MGD_TYPE_LONGTEXT) {
         // This is a longtext field, they come next
         if (in_array($second, $preferred_fields) && $this->_reflector->get_midgard_type($second) != MGD_TYPE_LONGTEXT) {
             return 1;
         }
         if ($this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT) {
             return strnatcmp($first, $second);
         }
         return -1;
     }
     if ($this->_reflector->is_link($first)) {
         // This is a linked property, they come next
         if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT) {
             return 1;
         }
         if ($this->_reflector->is_link($second)) {
             return strnatcmp($first, $second);
         }
         return -1;
     }
     if (in_array($first, $timerange_fields)) {
         if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second)) {
             return 1;
         }
         if (in_array($second, $timerange_fields)) {
             // Both are phone fields, arrange them in proper order
             return array_search($first, $timerange_fields) < array_search($second, $timerange_fields) ? -1 : 1;
         }
         return -1;
     }
     if (in_array($first, $phone_fields)) {
         if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields)) {
             return 1;
         }
         if (in_array($second, $phone_fields)) {
             // Both are phone fields, arrange them in proper order
             return array_search($first, $phone_fields) < array_search($second, $phone_fields) ? -1 : 1;
         }
         return -1;
     }
     if (in_array($first, $address_fields)) {
         if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields)) {
             return 1;
         }
         if (in_array($second, $address_fields)) {
             // Both are address fields, arrange them in proper order
             return array_search($first, $address_fields) < array_search($second, $address_fields) ? -1 : 1;
         }
         return -1;
     }
     if (in_array($first, $location_fields)) {
         if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields) || in_array($second, $address_fields)) {
             return 1;
         }
         if (in_array($second, $location_fields)) {
             // Both are address fields, arrange them in proper order
             return array_search($first, $location_fields) < array_search($second, $location_fields) ? -1 : 1;
         }
         return -1;
     }
     if (in_array($second, $preferred_fields) || $this->_reflector->get_midgard_type($second) == MGD_TYPE_LONGTEXT || $this->_reflector->is_link($second) || in_array($second, $timerange_fields) || in_array($second, $phone_fields) || in_array($second, $address_fields) || in_array($second, $location_fields)) {
         // First field was not a preferred field, but second is
         return 1;
     }
     // Others come as they do
     return strnatcmp($first, $second);
 }
示例#4
0
 /**
  * Check that the id_field is replication-safe
  */
 private function _is_replication_safe()
 {
     if ($this->id_field == 'guid' || is_a($this->_type, 'midcom_helper_datamanager2_type_mnrelation')) {
         return true;
     }
     switch ($this->_field['storage']['location']) {
         case 'parameter':
         case 'configuration':
             // Storing IDs to parameters is not replication safe
             debug_add("Field \"{$this->name}\" is set to store to a parameter but links via ID which is not replication-safe, aborting.", MIDCOM_LOG_WARN);
             midcom::get('uimessages')->add($this->_l10n->get('midcom.helper.datamanager2'), sprintf($this->_l10n->get('field %s is set to store to a parameter but links via ID which is not replication-safe, aborting'), $this->name), 'error');
             return false;
     }
     // Normal field, verify that it is a link
     if ($this->_type->storage->object !== null && !is_a($this->_type->storage->object, 'midcom_core_temporary_object')) {
         // We have an object, check the link type
         // Note: in creation mode we do not have this so we have no way to check)
         $mgdschema_object = midcom::get('dbfactory')->convert_midcom_to_midgard($this->_type->storage->object);
         if ($mgdschema_object !== null && $this->_field['storage']['location'] !== null) {
             $mrp = new midgard_reflection_property(get_class($mgdschema_object));
             if (($mrp->get_midgard_type($this->_field['storage']['location']) === MGD_TYPE_INT || $mrp->get_midgard_type($this->_field['storage']['location']) === MGD_TYPE_UINT) && !$mrp->is_link($this->_field['storage']['location'])) {
                 // Storing IDs to non-linked fields is not replication safe
                 debug_add("Field \"{$this->name}\" is set to store to property \"{$this->_field['storage']['location']}\" which is not link, making it replication-unsafe, aborting.", MIDCOM_LOG_WARN);
                 midcom::get('uimessages')->add($this->_l10n->get('midcom.helper.datamanager2'), sprintf($this->_l10n->get('field %s is set to store to property %s but links via ID which is not replication-safe, aborting'), $this->name, $this->_field['storage']['location']), 'error');
                 return false;
             }
         }
     }
     return true;
 }
示例#5
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 {