Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/Customfield.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\View\Sky;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

// Display custom field (label and value) as inline or stacked.
class Customfield extends Bootstrap
{
  	public $value;

    public $layout;
  
  	public function display()
    {
        // $config - render_class, value_render_class, label_render_class, showlabel, prefix, suffix, label, tag
      	// layout (default, stacked, table, list)
      
      	if (empty($this->data))
        {
            return;
        }
      
      	$output = '';

        $this->layout = isset($this->config['layout']) && $this->config['layout'] ? $this->config['layout'] : 'default';
      	$function = 'layout_' . $this->layout;

		$tag = $this->config['tag'] ?? 'div';
		$render_class = $this->config['render_class'] ?? '';

        $output .= $this->html->open_tag($tag, array('class' => $render_class));

     		$output .= $this->$function();

        $output .= $this->html->close_tag($tag);
        
        return $output;
    }
  
	// Inline
  	public function layout_default()
    {
    	$output = '';

		$output .= $this->get_label_inline();

		$value_render_class = isset($this->config['value_render_class']) && $this->config['value_render_class'] ? ' class="' . $this->config['value_render_class'] . '"' : '';
      	
		if (isset($this->config['prefix']) && $this->config['prefix'])
        {
            $this->data = $this->config['prefix'] . $this->data;
        }

      	if (isset($this->config['suffix']) && $this->config['suffix'])
        {
            $this->data = $this->data . $this->config['suffix'];
        }

        $output .= $this->html->span($this->data, array('class' => $value_render_class));

      	return $output;
    }
  
  	public function layout_stacked()
    {
    	$output = '';
      
      	$output .= $this->get_label_stacked();
      	
      	$value_render_class = $this->config['value_render_class'] ? ' class="' . $this->config['value_render_class'] . '"' : '';
      	
      	if (isset($this->config['prefix']) && $this->config['prefix'])
        {
            $this->data = $this->config['prefix'] . $this->data;
        }

      	if (isset($this->config['suffix']) && $this->config['suffix'])
        {
            $this->data = $this->data . $this->config['suffix'];
        }

        $output .= $this->html->div($this->data, array('class' => $value_render_class));
      
      	return $output;
    }
  
  	public function layout_table()
    {
    	$output = '';
      
      	$output .= self::get_label_stacked();
      
      	$theads = [];
      	if (isset(self::$config['subfields']))
        {
        	$theads = array_column(self::$config['subfields'], 'label');  
        }

        self::$value['theads'] = $theads;
      
        $output .= $this->hrtml->table(self::$value, array('class' => self::$config['value_render_class']));
      
      	return $output;
    }
  
  	public function layout_cards()
    {
    	$output = '';
      
      	$output .= self::get_label_stacked();
      	
      	foreach (self::$value as $row)
        {
        	$i = 0;
          	$output .= '<div class="' . self::$config['value_render_class'] . '">';
          	foreach ($row as $col)
            {
              	$output .= '<div class="my-3 ' . self::$config['subfields'][$i]['render_class'] . '">';
              
              	if (isset(self::$config['subfields'][$i]['showlabel']) && self::$config['subfields'][$i]['showlabel'])
        		{
          			$label_render_class = self::$config['subfields'][$i]['label_render_class'] ? ' class="' . self::$config['subfields'][$i]['label_render_class'] . '"' : '';
          
          			$pre_label = '<div' . $label_render_class . '>';
          			$post_label = '</div>';
          
          			$output .= $pre_label . '<strong>' . self::$config['subfields'][$i]['label'] . '</strong>' . $post_label;
        		}
              
              	$value_render_class = self::$config['subfields'][$i]['value_render_class'] ? ' class="' . self::$config['subfields'][$i]['value_render_class'] . '"' : '';
      
       			$pre_value = '<div' . $value_render_class . '>';
        		$post_value = '</div>';
              
              	$output .= $pre_value . $col . $post_value;

              	$output .= '</div>';
              	$i++;
            }
          	$output .= '</div>';
        }

      	return $output;
    }
  
  	public function get_label_stacked()
    {
    	$output = '';
      
      	$showlabel = $this->config['showlabel'] ?? 0;
        $labelclass = isset($this->config['label_render_class']) && $this->config['label_render_class'] ? $this->config['label_render_class'] : 'fw-bold';

		$label = $this->config['label'] ?? '';
		
		if ($showlabel && $label)
        {
            $output .= $this->html->div($label, array('class' => $labelclass));
        }
      
      	return $output;
    }

	public function get_label_inline()
    {
		$output = '';
      
      	$showlabel = $this->config['showlabel'] ?? 0;
		$labelclass = isset($this->config['label_render_class']) && $this->config['label_render_class'] ? $this->config['label_render_class'] : 'fw-bold';

		$label = $this->config['label'] ?? '';

		if ($showlabel && $label)
        {
            $output .= $this->html->span($label, array('class' => $labelclass)) . ':';
        }
      	return $output;
    }
}