<?php
/**
 * Elgg questions plugin owner page
 *
 * @package Questions
 */

$page_owner = elgg_get_page_owner_entity();
if (empty($page_owner)) {
	elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
	$page_owner = elgg_get_page_owner_entity();
}

if (empty($page_owner)) {
	forward(REFERER);
}

elgg_push_breadcrumb($page_owner->name);

elgg_register_title_button();

$title = elgg_echo('questions:owner', [$page_owner->name]);

$options = [
	'type' => 'object',
	'subtype' => 'question',
	'full_view' => false,
	'list_type_toggle' => false,
	'no_results' => elgg_echo('questions:none'),
];
if ($page_owner instanceof ElggGroup) {
	// groups are containers
	$options['container_guid'] = $page_owner->getGUID();
} else {
	// users list all owned questions
	$options['owner_guid'] = $page_owner->getGUID();
}

$content = elgg_list_entities($options);

$vars = [
	'title' => $title,
	'content' => $content,
	'filter_context' => ($page_owner->getGUID() === elgg_get_logged_in_user_guid()) ? 'mine' : '',
];

$body = elgg_view_layout('content', $vars);

echo elgg_view_page($title, $body);
