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_GlobalSource_AdvancedRatingSource implements Search_GlobalSource_Interface
9{
10	private $ratinglib;
11	private $fields = null;
12	private $recalculate = false;
13
14	function __construct($recalculate = false)
15	{
16		$this->ratinglib = TikiLib::lib('rating');
17		$this->recalculate = $recalculate;
18	}
19
20	function getProvidedFields()
21	{
22		if (is_null($this->fields)) {
23			$ratingconfiglib = TikiLib::lib('ratingconfig');
24
25			$this->fields = [];
26			foreach ($ratingconfiglib->get_configurations() as $config) {
27				$this->fields[] = "adv_rating_{$config['ratingConfigId']}";
28			}
29		}
30
31		return $this->fields;
32	}
33
34	function getGlobalFields()
35	{
36		return [];
37	}
38
39	function getData($objectType, $objectId, Search_Type_Factory_Interface $typeFactory, array $data = [])
40	{
41		$ratings = $this->ratinglib->obtain_ratings($objectType, $objectId, $this->recalculate);
42
43		$data = [];
44
45		foreach ($ratings as $id => $value) {
46			$data["adv_rating_$id"] = $typeFactory->sortable($value);
47		}
48
49		return $data;
50	}
51}
52