%PDF- %PDF-
Direktori : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Model/ |
Current File : /var/www/html/bbw/farmaci/kritik-portale/module/ReviewBase/src/ReviewBase/Model/Utility.php |
<?php namespace ReviewBase\Model; /** * Description of Utility * * @author Florian Koller ( conlabz GmbH ) <florian.koller at conlabz.de> */ class Utility { protected $config; public function __construct($config) { $this->config = $config; } /** * sluggify creates a slug out of the supplied string * * converts to lowercase * trim whitespace left and right * replaces ä, ü, ö, ß with ae, ue, oe, ss * removes any special chars (NOT LIKE a-z0-9) with - (dash) * replaces every empty space with - (dash) * removes consecutive dashes (like --, ---) preserving only one * remove - (dash) from beginning and end of string * * @param $string */ public function sluggify($string, $debugOutput = false) { $debugInformation = []; $string = strtolower($string); $debugInformation[] = $string; $string = trim($string); $debugInformation[] = $string; $string = str_replace('ä', 'ae', $string); $string = str_replace('ü', 'ue', $string); $string = str_replace('ö', 'oe', $string); $string = str_replace('ß', 'ss', $string); $debugInformation[] = $string; $string = preg_replace('/[^a-z0-9 -]+/', '-', $string); $debugInformation[] = $string; $string = str_replace(' ', '-', $string); $debugInformation[] = $string; $string = preg_replace('/-{2,}/','-', $string); $debugInformation[] = $string; $string = trim($string, '-'); $debugInformation[] = $string; //output replace steps for debug purposes $debugOutput ? var_dump($debugInformation) : false; return $string; } /** * Calculate rating upper and lower possible value depending on the defined global $config['review']['chart'] * configuration key * * @return array [0,1] containing worst possible rating and best possible rating in that order */ public function getRatingBounds() { $recommendation = ($this->config['review']['rating_type'] === 'recommendation') ? true : false; $keys = array_keys($this->config['review']['chart']); sort($keys); $highestRatingValue = end($keys); $lowestRatingValue = $keys[0]; $secondLowestRatingValue = $keys[1]; $lowestRatingValue = ($lowestRatingValue === 0) ? $secondLowestRatingValue : $lowestRatingValue; //check if recommendation type of review if ($recommendation) { //hard reset for lowest to highest in case of recommendation $lowestRatingValue = $highestRatingValue; } $lowestRatingValue = $recommendation ? $highestRatingValue : $lowestRatingValue; $ratingBounds = [$lowestRatingValue, $highestRatingValue]; return $ratingBounds; } }