1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class Search_ContentSource_GoalEventSource implements Search_ContentSource_Interface
9{
10	private $table;
11
12	function __construct()
13	{
14		$this->table = TikiDb::get()->table('tiki_goal_events');
15	}
16
17	function getDocuments()
18	{
19		return $this->table->fetchColumn('eventId', []);
20	}
21
22	function getDocument($objectId, Search_Type_Factory_Interface $typeFactory)
23	{
24		global $prefs;
25
26		$event = $this->table->fetchRow(['eventType', 'eventDate', 'user', 'groups', 'targetType', 'targetObject'], [
27			'eventId' => $objectId,
28		]);
29
30		if ($event) {
31			$target = null;
32			if ($event['targetType'] && $event['targetObject']) {
33				$target = "{$event['targetType']}:{$event['targetObject']}";
34			}
35			return [
36				'modification_date' => $typeFactory->timestamp($event['eventDate']),
37				'date' => $typeFactory->timestamp($event['eventDate']),
38				'event_type' => $typeFactory->identifier($event['eventType']),
39				'user' => $typeFactory->identifier($event['user']),
40				'goal_groups' => $typeFactory->multivalue(json_decode($event['groups'], true)),
41				'target' => $typeFactory->identifier($target),
42			];
43		} else {
44			return false;
45		}
46	}
47
48	function getProvidedFields()
49	{
50		return ['event_type', 'modification_date', 'user', 'goal_groups', 'target', 'date'];
51	}
52
53	function getGlobalFields()
54	{
55		return [
56			'date' => true,
57		];
58	}
59}
60