<?php
/** 
 * @package     VikRestaurants
 * @subpackage  core
 * @author      E4J s.r.l.
 * @copyright   Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @link        https://vikwp.com
 */

// No direct access
defined('ABSPATH') or die('No script kiddies please!');

/**
 * Widget class used to display a wall of admin notes.
 *
 * @since 1.10
 */
class VREStatisticsWidgetAdminnotes extends VREStatisticsWidget
{
	/**
	 * @override
	 * Returns the form parameters required to the widget.
	 *
	 * @return 	array
	 */
	public function getForm()
	{
		return [
			/**
			 * Whether the archived notes should be displayed or not.
			 *
			 * @var checkbox
			 */
			'archived' => [
				'type'    => 'checkbox',
				'label'   => JText::translate('VRE_STATS_WIDGET_ADMINNOTES_SHOW_ARCHIVED_LABEL'),
				'default' => false,
			],
		];
	}

	/**
	 * @override
	 * Checks whether the specified group is supported
	 * by the widget. Children classes can override this
	 * method to drop the support for a specific group.
	 *
	 * This widget supports only the "restaurant" group.
	 *
	 * @param 	string 	 $group  The group to check.
	 *
	 * @return 	boolean  True if supported, false otherwise.
	 */
	public function isSupported($group)
	{
		return true;
	}

	/**
	 * @override
	 * Loads the dataset(s) that will be recovered asynchronously
	 * for being displayed within the widget.
	 *
	 * It is possible to return an array of records to be passed
	 * to a chart or directly the HTML to replace.
	 *
	 * @return 	mixed
	 */
	public function getData()
	{
		// load filters
		$filters = [];
		$filters['archived'] = $this->getOption('archived', false);
			
		/** @var object[] */
		$notes = JModelVRE::getInstance('adminnote')->loadNotes(JFactory::getUser()->id, $filters);

		// return overview layout
		return JLayoutHelper::render('statistics.widgets.adminnotes.wall', [
			'filters' => $filters,
			'notes' => $notes,
			'widget' => $this,
		]);
	}
}
