|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package midcom.services |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This is a base class which is targeted at MidCOM content object indexing. It should |
|
11
|
|
|
* be used whenever MidCOM documents are indexed, either directly or as a base class. |
|
12
|
|
|
* |
|
13
|
|
|
* It will take an arbitrary Midgard Object, for which Metadata must be available. |
|
14
|
|
|
* The document class will then load the metadata information out of the database |
|
15
|
|
|
* and populate all metadata fields of the document from there. |
|
16
|
|
|
* |
|
17
|
|
|
* If you want to index datamanager driven objects, you should instead look at |
|
18
|
|
|
* the datamanager's document class. |
|
19
|
|
|
* |
|
20
|
|
|
* The GUID of the object being referred is used as a RI. |
|
21
|
|
|
* |
|
22
|
|
|
* The documents type is "midcom". |
|
23
|
|
|
* |
|
24
|
|
|
* @package midcom.services |
|
25
|
|
|
* @see midcom_services_indexer |
|
26
|
|
|
*/ |
|
27
|
|
|
class midcom_services_indexer_document_midcom extends midcom_services_indexer_document |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var midcom_core_dbaobject |
|
31
|
|
|
*/ |
|
32
|
|
|
private $object; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The constructor initializes the content object, loads the metadata object |
|
36
|
|
|
* and populates the metadata fields accordingly. |
|
37
|
|
|
* |
|
38
|
|
|
* The source member is automatically populated with the GUID of the document, |
|
39
|
|
|
* the RI is set to it as well. The URL is set to an on-site permalink. |
|
40
|
|
|
*/ |
|
41
|
6 |
|
public function __construct(midcom_core_dbaobject $object) |
|
42
|
|
|
{ |
|
43
|
6 |
|
parent::__construct(); |
|
44
|
|
|
|
|
45
|
6 |
|
if (!midcom::get()->config->get('indexer_backend')) { |
|
46
|
6 |
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$this->_set_type('midcom'); |
|
50
|
|
|
|
|
51
|
|
|
$this->object = $object; |
|
52
|
|
|
$this->source = $object->guid; |
|
53
|
|
|
$this->lang = $this->_i18n->get_current_language(); |
|
54
|
|
|
// Add language code to RI as well so that different language versions of the object have unique identifiers |
|
55
|
|
|
$this->RI = "{$this->source}_{$this->lang}"; |
|
56
|
|
|
$this->document_url = midcom::get()->permalinks->create_permalink($this->source); |
|
57
|
|
|
|
|
58
|
|
|
$this->_process_metadata(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Processes the information contained in the metadata instance. |
|
63
|
|
|
*/ |
|
64
|
|
|
private function _process_metadata() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->read_metadata_from_object($this->object); |
|
67
|
|
|
foreach ($this->object->metadata->get_datamanager()->get_content_html() as $key => $value) { |
|
68
|
|
|
/** |
|
69
|
|
|
* @see parent::read_metadata_from_object() |
|
70
|
|
|
*/ |
|
71
|
|
|
if (!in_array($key, ['revised', 'revisor', 'created', 'creator'])) { |
|
72
|
|
|
if (in_array($key, ['keywords', 'tags'])) { |
|
73
|
|
|
$this->content .= $value . "\n"; |
|
74
|
|
|
} |
|
75
|
|
|
$this->add_text("META_{$key}", $value); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* This will translate all member variables into appropriate |
|
82
|
|
|
* field records, missing topic data is auto-detected |
|
83
|
|
|
*/ |
|
84
|
|
|
public function members_to_fields() |
|
85
|
|
|
{ |
|
86
|
|
|
if ( empty($this->topic_guid) |
|
87
|
|
|
|| empty($this->topic_url) |
|
88
|
|
|
|| empty($this->component)) { |
|
89
|
|
|
//if one of those is missing, we override all three to ensure consistency |
|
90
|
|
|
$this->process_topic(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
parent::members_to_fields(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|