<?php

if ( ! function_exists('generateLink'))
{
    function generateLink($link, $classes = '', $suffix = '') {
        if (empty($link) ) { 
            return "";
        }                  
        if (is_string($link)) {
            $link = json_decode($link);
        }
        
        $url = "";
        
        if ($link->isExternal && !$link->url || !$link->isExternal && !$link->objectId) {
            return "";
        } else {
            $url = $link->url;
        }
        
        if ($link->isExternal) {
            return $link->url;
        } else {
            $uri = WebsiteObject::select('uri')
                ->where('website_object_id', $link->objectId)
                ->first();
            if (empty($uri)) {
                return "";
            }
            $url = lang_url($uri->uri);
        }
        
        $label = $link->label ? $link->label : "";
        
        return '<a href="' . $url . '" class="' . $classes . '" >' . $label . $suffix . '</a>';
    }
}

if ( ! function_exists('getFilterHash'))
{
    function getFilterHash($filtersInput) {
        $hash = "";
        foreach($filtersInput as $filterType => $value){
            if(!empty($value)){
                if(!empty($hash)){
                    $hash .= "&";    
                }
                 $hash .= $filterType . "=" . $value;        
            }    
        } 
        
        if(!empty($hash)){
            $hash = "#" . $hash;    
        } 
        
        return $hash;      
    }
}
