HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/fvr.creativefellows.nl/src/Domain/Field/SectionRow.php
<?php

namespace App\Domain\Field;


/**
 * Lease Term data
 */
final class SectionRow
{
	protected $value = null;		
	protected $class_prefix = "page-section__";
	protected $nested_prefix = "section-row";
	protected $nested = false;
	protected $default_class = null;
	protected $legacy = false;
	protected $legacy_element = '<div class="nec-legacy-container">{legacy_content}</div>';
	protected $legacy_class = 'page-section__legacy ';
	
	function __construct($data =null,$nested=false)
	{
		foreach((array) $data as $key => $val)
		{
			$this->$key = $val;
		}
		
		$this->nested = $nested;
	}	
	
	public function elementId()
	{
		return $this->element_id ? ' id="'. $this->element_id .'"' : ''; 
	}
	
	public function getHtml($force_wrap=true)
	{
		return $this->legacy && $force_wrap == true ? $this->wrapLagacyContainer() : $this->html;
	}
	
	public function wrapLagacyContainer()
	{
		return preg_replace("/{legacy_content}/",$this->html,$this->legacy_element);
	}
	
	public function html($default_class=null)
	{	
		return '<div'. $this->elementId() .' class="'. $this->rowClass($default_class) .'">'. $this->getHtml(false) .'</div>';
	}
	
	public function setHtml($html)
	{
		$this->html = $html;
	}
	
	
	private function rowClass($default_class)
	{
		$this->default_class = $default_class;
		return trim(implode(" ",[$this->default_class,$this->elementClass()]));
	}
	
	public function elementClass()
	{
		return $this->nested == false ? $this->rowClassName()  : $this->nestedRowClass(); 
	}
	
	public function rowClassName()
	{
		return $this->legacy == false ? $this->getDefaultClass() : $this->getDefaultClass(). " " .$this->legacy_class; 
	}
	
	public function getDefaultClass()
	{
		return $this->element_class != "" ? $this->class_prefix.$this->element_class : ""; 
	}
	
	private function nestedRowClass()
	{	
		return $this->element_class && $this->nested == true ? implode("",[$this->nested_prefix," ",$this->nested_prefix,"__",$this->element_class]) : $this->nested_prefix;
	}

	

	
	public function setLegacy()
	{
		$this->legacy = true;
	}
	
}