App\Repositories\Backend\History\EloquentHistoryRepository::renderDescription PHP Method

renderDescription() public method

public renderDescription ( $text, boolean $assets = false ) : mixed | string
$text
$assets boolean
return mixed | string
    public function renderDescription($text, $assets = false)
    {
        $assets = json_decode($assets, true);
        $count = 1;
        $asset_count = count($assets) + 1;
        if (count($assets)) {
            foreach ($assets as $name => $values) {
                switch ($name) {
                    case "string":
                        ${"asset_" . $count} = $values;
                        break;
                        //Cant have link be multiple array keys, allows for link, link1, link2, etc.
                    //Cant have link be multiple array keys, allows for link, link1, link2, etc.
                    case substr($name, 0, 4) == "link":
                        if (is_array($values)) {
                            switch (count($values)) {
                                case 1:
                                    ${"asset_" . $count} = link_to_route($values[0], $values[0]);
                                    break;
                                case 2:
                                    ${"asset_" . $count} = link_to_route($values[0], $values[1]);
                                    break;
                                case 3:
                                    ${"asset_" . $count} = link_to_route($values[0], $values[1], $values[2]);
                                    break;
                                default:
                                    break;
                            }
                        } else {
                            //Normal url
                            ${"asset_" . $count} = link_to($values, $values);
                        }
                        break;
                    default:
                        break;
                }
                $text = str_replace("\$" . $count, ${"asset_" . $count}, $text);
                $count++;
            }
        }
        if ($asset_count == $count) {
            //Evaluate all trans functions as PHP
            //We don't want to use eval() for security reasons so we're explicitly converting trans cases
            return preg_replace_callback('/trans\\(\\"([^"]+)\\"\\)/', function ($matches) {
                return trans($matches[1]);
            }, $text);
        }
        return '';
    }