<?php
/**
* Copyright (C) 2019 Rhyme Digital, LLC.
*
* @link https://rhyme.digital
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
*/
namespace Rhyme\WMassArtsHub\Helper;
use Contao\Controller;
use MaeEventCategories\MaeEventCatModel;
/**
* Class CategoryHelper
* @package Rhyme\WMassArtsHub\Helper
*/
class CategoryHelper extends Controller
{
/**
* Load category field options
* @param $objWidget
*/
public static function addOptionsToWidget(&$objWidget) {
$objCategories = MaeEventCatModel::findAll();
if ($objCategories !== null)
{
$arrOptions = array();
while ($objCategories->next())
{
$arrOptions[$objCategories->current()->id] = array
(
'value' => $objCategories->current()->id,
'label' => $objCategories->current()->title,
'default' => '',
'group' => '',
);
}
$objWidget->options = $arrOptions;
// Apply the "select2" library
$GLOBALS['TL_BODY'][] = "<script>
jQuery(document).ready(function(){ jQuery('#ctrl_".$objWidget->id."').select2({placeholder: 'Select categories'}); });
jQuery(window).on('ajax_change', function(){ jQuery('#ctrl_".$objWidget->id."').select2({placeholder: 'Select categories'}); });
</script>";
}
}
}