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
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * @return array
16 */
17function module_last_tracker_comments_info()
18{
19	return [
20		'name' => tra('Newest Tracker Comments'),
21		'description' => tra('Lists the specified number of tracker comments (optionally restricting to those in a specific tracker or tracker item) starting from the most recently posted.'),
22		'prefs' => ['feature_trackers'],
23		'params' => [
24			'trackerId' => [
25				'name' => tra('Tracker identifier'),
26				'description' => tra('If set to a tracker identifier, only displays the comments on the given tracker.') . " " . tra('Example value: 13.') . " " . tr('Not set by default.'),
27				'filter' => 'int',
28				'profile_reference' => 'tracker',
29			],
30			'itemId' => [
31				'name' => tra('Item identifier'),
32				'description' => tra('If set to an item identifier, only displays the comments on the given item.') . " " . tra('Example value: 13.') . " " . tr('Not set by default.'),
33				'filter' => 'int',
34				'profile_reference' => 'tracker_item',
35			]
36		],
37		'common_params' => ['rows', 'nonums']
38	];
39}
40
41/**
42 * @param $mod_reference
43 * @param $module_params
44 */
45function module_last_tracker_comments($mod_reference, $module_params)
46{
47	global $prefs;
48	$smarty = TikiLib::lib('smarty');
49	$trackerId = isset($module_params["trackerId"]) ? $module_params["trackerId"] : 0;
50
51	$itemId = isset($module_params["itemId"]) ? $module_params["itemId"] : 0;
52
53	$trklib = TikiLib::lib('trk');
54
55	$ranking = $trklib->list_last_comments($trackerId, $itemId, 0, $mod_reference["rows"]);
56	$smarty->assign('modLastModifComments', isset($ranking['data']) ? $ranking["data"] : []);
57}
58