annotate ismi_ext/ismi_ext.module @ 41:5b3cd0b66b30

fix bug with multiple-saved nodes.
author casties
date Wed, 02 Nov 2016 16:56:27 +0100
parents 3585573999b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 // alter indexing
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
4
22
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
5 function ismi_ext_apachesolr_index_documents_alter($documents, $entity, $entity_type, $env_id) {
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
6
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
7 if (!property_exists($entity, "field_attribute")) {
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
8 // not an openmind_entity
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
9 return;
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
10 }
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
11
3585573999b6 fix error messages when indexing.
casties
parents: 0
diff changeset
12 // hole entities die sich auf diese beziehen
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
13
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 $attributes = $entity->field_attribute[LANGUAGE_NONE];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
15
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 //TODO nimme nur das erste, kann es mehr geben?
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 if (isset ($documents[0])){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 foreach ($attributes as $attribute){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
19
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 #attributes als felder in solr
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 $txt = $attribute['ov'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
22
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 $txt_chunks = str_split($txt,$split_length=10000); # teile den String falls zu lang in chunks
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
24
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
25
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 foreach ($txt_chunks as $txt_chunk){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 $documents[0]->addField("attr_" . $attribute['name'],$txt_chunk);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 $documents[0]->addField("attrtext_" . $attribute['name'],$txt_chunk);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
30
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
33
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 #relations als felder in solr
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
35
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 $rels = relation_query($entity_type, $entity->nid)->execute();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
37
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
38 foreach($rels as $rel){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
39
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
40
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 $rel_type = $rel->relation_type;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
42
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 $relation = relation_load($rel->rid);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
44
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 $endpoints = relation_get_endpoints($relation);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
46
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
47
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 //store only the endpoint which is differes from the current _entity
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
49
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
50
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 $nodes = $endpoints['node'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
52
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
53
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
54
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 foreach ($nodes as $nid => $node){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 if ($nid != $entity->nid){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 $title = $node->title;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
60
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 //TODO nimme nur das erste, kann es mehr geben?
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 if (isset ($documents[0])){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
63
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 $documents[0]->addField("rel_" . $rel_type,$title);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
65
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
68
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
69
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
71
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
72
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
73
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 function ismi_ext_facetapi_facet_info($searcher_info) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 $facets = array();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
76
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 $facets['entityType'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 'label' => t('Entity Types'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 'description' => t('Filter by Entity Type'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 'field' => 'sm_vid_openmind_types',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 //'map callback' => 'facetapi_map_language',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 //'values callback' => 'facetapi_callback_language_values',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 'facet mincount allowed' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 'dependency plugins' => array('bundle', 'role'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
86
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 $facets['explicit'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 'label' => t('Explicit'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 'description' => t('Filter by Explicit'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 'field' => 'attrtext_explicit',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 //'map callback' => 'facetapi_map_language',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 //'values callback' => 'facetapi_callback_language_values',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 'facet mincount allowed' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
94 'dependency plugins' => array('bundle', 'role'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
96
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 $facets['incipit'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
98 'label' => t('Incipit'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
99 'description' => t('Filter by Incipit'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
100 'field' => 'attrtext_incipit',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 //'map callback' => 'ismi_ext_map_incipit',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
102 //'values callback' => 'facetapi_callback_language_values',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 'facet mincount allowed' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
104 'dependency plugins' => array('bundle', 'role'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
106
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 $facets['persons'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
108 'label' => t('Persons (created)'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
109 'description' => t('Filter by Persons (was_created_by)'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 'field' => 'rel_was_created_by',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
111 //'map callback' => 'facetapi_map_language',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 //'values callback' => 'facetapi_callback_language_values',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 'facet mincount allowed' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 'dependency plugins' => array('bundle', 'role'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
116
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 return $facets;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
119
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
120 function ismi_ext_theme_registry_alter(&$theme_registry){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 $link_active = $theme_registry['facetapi_link_inactive'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 $link_active['preprocess_functions'][]='ismi_ext_process_link';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 $theme_registry['facetapi_link_active']=$link_active;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
124
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
125
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
127
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 function imi_ext_process_link(&$value){
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
129 dpm($value);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
130
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
131 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
132