<?php
/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */
namespace BlackSheepResearch\Component\UserPoints\Site\Controllers;

// no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Component\ComponentHelper;
use BlackSheepResearch\Component\UserPoints\Site\UserController;

/**
 * @package UserPoints
 */
class MedalsControl extends UserController
{
	/**
	 * Custom Constructor
	 */
 	public function __construct()	{
		parent::__construct( );
	}
	
	public function display($cachable = false, $urlparams = false) 
	{

		$model      = $this->getModel ( 'medals' );
		$view       = $this->getView  ( 'medals','html' );		
	
		$app 		= Factory::getApplication();
		$menus 		= $app->getMenu();	
		$menu       = $menus->getActive();
		$menuid     = $menu->id;

		$params     = $menus->getParams($menuid);		
		
		$_levelrank = $model->_getMedalsList();
		
		$this->viewdata['params'] = $params ;
		$this->viewdata['levelrank'] = $_levelrank[0] ;
		$this->viewdata['total'] = $_levelrank[1] ;
		$this->viewdata['limit'] = $_levelrank[2] ;
		$this->viewdata['limitstart'] = $_levelrank[3] ;
		
		$view->_displaylist();
	}
	
	public function detailsmedal()
	{	
	
		$app 						= Factory::getApplication();		
	
		$com_params 				= ComponentHelper::getParams( 'com_userpoints' );
		$_useAvatarFrom 			= $com_params->get('useAvatarFrom','');
		$_profilelink				= $com_params->get('linkToProfile','');	
		$_allowGuestUserViewProfil 	= $com_params->get('allowGuestUserViewProfil', 1);
		
		$model = $this->getModel( 'medals' );
		$view  = $this->getView  ( 'medals','html' );
		
		$menus 		= $app->getMenu();	
		$menu       = $menus->getActive();
		$menuid     = $menu->id;

		$params     = $menus->getParams($menuid);

		// load levelrank
		$_detailrank = $model->_getDetailsMedalsListUsers ();
		
		$this->viewdata['params'] = $params ;
		$this->viewdata['detailrank'] = $_detailrank[0] ;
		$this->viewdata['total'] = $_detailrank[1] ;
		$this->viewdata['limit'] = $_detailrank[2] ;
		$this->viewdata['limitstart'] = $_detailrank[3] ;
		$this->viewdata['useAvatarFrom'] = $_useAvatarFrom ;
		$this->viewdata['linkToProfile'] = $_profilelink ;
		$this->viewdata['allowGuestUserViewProfil'] = $_allowGuestUserViewProfil ;
		
		// Display
		$view->_displaydetailrank();				
	}

}
