Example #1
0
 /**
  * @dataProvider providerGet_search_properties
  */
 public function testGet_search_properties($classname, $properties)
 {
     $reflector = new midcom_helper_reflector($classname);
     $search_properties = $reflector->get_search_properties();
     sort($search_properties);
     sort($properties);
     $this->assertEquals($properties, $search_properties);
 }
Example #2
0
 private function _initialize_from_reflector()
 {
     $matching_type = false;
     $matched_types = array();
     foreach (midcom_connection::get_schema_types() as $schema_type) {
         $pos = strpos($schema_type, $this->clever_class);
         if ($pos !== false) {
             $matched_types[] = $schema_type;
         }
     }
     if (count($matched_types) == 1) {
         $matching_type = $matched_types[0];
     } else {
         if ($this->clever_class == 'event') {
             $this->creation_default_key = 'title';
         } else {
             if ($this->clever_class == 'person') {
                 $matching_type = 'midgard_person';
             } else {
                 if (count($matched_types) > 0) {
                     $matching_type = $matched_types[0];
                 }
             }
         }
     }
     if (!$matching_type) {
         debug_add("no matches found for {$this->clever_class}!");
         return false;
     }
     $midcom_reflector = new midcom_helper_reflector($matching_type);
     $labels = array();
     $dummy_object = new $matching_type();
     $type_fields = array_keys(get_object_vars($dummy_object));
     unset($type_fields['metadata']);
     foreach ($type_fields as $key) {
         if (in_array($key, array('title', 'firstname', 'lastname', 'name', 'email', 'start', 'end', 'location'))) {
             if (!in_array($key, $labels)) {
                 $labels[] = $key;
             }
         }
     }
     if (empty($labels)) {
         $label_properties = $midcom_reflector->get_label_property();
         if (is_array($label_properties)) {
             foreach ($label_properties as $key) {
                 if (!in_array($key, array('id', 'guid'))) {
                     if (!in_array($key, $labels)) {
                         $labels[] = $key;
                     }
                 }
             }
         }
     }
     $this->class = midcom::get('dbclassloader')->get_midcom_class_name_for_mgdschema_object($matching_type);
     $this->component = midcom::get('dbclassloader')->get_component_for_class($matching_type);
     if (empty($this->constraints)) {
         $this->constraints = array();
     }
     if (empty($this->searchfields)) {
         $this->searchfields = $midcom_reflector->get_search_properties();
         if (empty($this->searchfields)) {
             //TODO: Special rules for objects that need them
         }
     }
     if (empty($this->orders)) {
         $this->orders = array();
     }
     $reflection_l10n = $midcom_reflector->get_component_l10n();
     if (empty($this->result_headers)) {
         $this->result_headers = array();
         foreach ($labels as $label) {
             $header = array();
             $header['title'] = $reflection_l10n->get($label);
             $header['name'] = $label;
             $this->result_headers[] = $header;
         }
         if (empty($this->result_headers)) {
             //Special rules for objects that need them
         }
     }
     if ($this->creation_mode_enabled && empty($this->creation_default_key)) {
         $this->creation_default_key = $this->result_headers[0]['name'];
     }
 }