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/**
9 * Handler class for PageSelector
10 *
11 * Letter key: ~k~
12 * Possibly doesn't need "non-simple" handling apart from defaultvalue?
13 *
14 */
15class Tracker_Field_PageSelector extends Tracker_Field_Abstract
16{
17	public static function getTypes()
18	{
19		return [
20			'k' => [
21				'name' => tr('Page Selector'),
22				'description' => tr('Allow a selection from the list of pages.'),
23				'help' => 'Page selector',
24				'prefs' => ['trackerfield_pageselector', 'feature_wiki'],
25				'tags' => ['advanced'],
26				'default' => 'y',
27				'params' => [
28					'autoassign' => [
29						'name' => tr('Auto-Assign'),
30						'description' => tr('Will auto-assign the creator of the item.'),
31						'filter' => 'int',
32						'options' => [
33							0 => tr('No'),
34							1 => tr('Yes'),
35						],
36						'legacy_index' => 0,
37					],
38					'size' => [
39						'name' => tr('Display Size'),
40						'description' => tr('Visible size of the input in characters.'),
41						'filter' => 'int',
42						'legacy_index' => 1,
43					],
44					'create' => [
45						'name' => tr('Create Page'),
46						'description' => tr('Create missing pages using the page name in this file as the template.'),
47						'filter' => 'pagename',
48						'legacy_index' => 2,
49						'profile_reference' => 'wiki_page',
50					],
51					'link' => [
52						'name' => tr('Link'),
53						'description' => tr('Display the value as a link to the page'),
54						'filter' => 'alpha',
55						'default' => 'y',
56						'options' => [
57							'y' => tr('Yes'),
58							'n' => tr('No'),
59						],
60						'legacy_index' => 3,
61					],
62				],
63			],
64		];
65	}
66
67	function getFieldData(array $requestData = [])
68	{
69		$ins_id = $this->getInsertId();
70
71		return [
72			'value' => isset($requestData[$ins_id])
73				? $requestData[$ins_id]
74				: $this->getValue(),
75			'defaultvalue' => $this->getOption('create')
76				? $this->getOption('create')
77				: $this->getValue(),
78		];
79	}
80
81	function renderInput($context = [])
82	{
83		return $this->renderTemplate('trackerinput/pageselector.tpl', $context);
84	}
85
86	function renderOutput($context = [])
87	{
88		$value = $this->getConfiguration('value');
89		if ($value) {
90			if ($this->getOption('link') === 'n' || $context['list_mode'] === 'csv') {
91				return $value;
92			} else {
93				$smarty = TikiLib::lib('smarty');
94				$smarty->loadPlugin('smarty_function_object_link');
95				return smarty_function_object_link(
96					[
97						'type' => 'wikipage',
98						'id' => $value,
99					],
100					$smarty->getEmptyInternalTemplate()
101				);
102			}
103		}
104	}
105}
106