diff --git a/common/components/Substringer.php b/common/components/Substringer.php new file mode 100644 index 0000000..9c0bf80 --- /dev/null +++ b/common/components/Substringer.php @@ -0,0 +1,152 @@ +changeStringByRegex($haystack,$regex1,$regex2,$firstConcatenateSymbol,$secondConcatenateSymbol,$requiredDelimiter); + * @example-return + * https://www.linija-svitla.ua/catalog/ulichnoe-osveshchenie?page=50&per-page=18&sort=test_test + * ================================================================================================================| + * @todo + * 1) Пока что метод работает только с 2 regex,надо будет поменять строго regex string => regex array + * 2) Метод полюбому обрезает первый символ результирующей строки regex + * 3) нужно сделать механизм замены строки только по 1 regex + * ================================================================================================================| + * + */ + /** + * @param string $haystack + * @param string $regex1 + * @param string $regex2 + * @param string $requiredDelimiter + * @param string $firstConcatenateSymbol + * @param string $secondConcatenateSymbol + * + * @return string + */ + public static function changeStringByRegex(string $haystack, string $regex1, string $regex2, string $requiredDelimiter = '', + string $firstConcatenateSymbol = '', + string $secondConcatenateSymbol = '' + ): string + { + + # 1 give rexe1/regex2 parts + # IF we have no consilience with both Regex == > return $haystack + if (preg_match($regex1, $haystack) !== 0 || preg_match($regex2, $haystack) !== 0) { + preg_match($regex1, $haystack, $matches[0]); + preg_match($regex2, $haystack, $matches[1]); + } else return $haystack; + + # 2 give must part of string + $mustPartOfstring = self::SimpleStringSubstring($haystack, $requiredDelimiter); + + # 3 if regex1/regex2 !empty concatenate they with $mustPartOfString + if (isset($matches[0][0]) && isset($matches[1][0])) { + # удаляем первый символ ( прим; $matches[0][0]='&sort=test_desc') + # нам надо только текст без первого спецсимвола + $matches[0][0] = substr($matches[0][0], 1); + $mustPartOfstring = (isset($matches[0][0])) ? $mustPartOfstring . $firstConcatenateSymbol . $matches[0][0] : $mustPartOfstring; + $matches[1][0] = substr($matches[1][0], 1); + $mustPartOfstring = (isset($matches[1][0])) ? $mustPartOfstring . $secondConcatenateSymbol . $matches[1][0] : $mustPartOfstring; + } # если найден только 1й regex + elseif (isset($matches[0][0]) && !isset($matches[1][0])) { + $matches[0][0] = substr($matches[0][0], 1); + $mustPartOfstring = (isset($matches[0][0])) ? $mustPartOfstring . $firstConcatenateSymbol . $matches[0][0] : $mustPartOfstring; + } # если найден 2й regex + elseif (!isset($matches[0][0]) && isset($matches[1][0])) { + $matches[1][0] = substr($matches[1][0], 1); + $mustPartOfstring = (isset($matches[1][0])) ? $mustPartOfstring . $firstConcatenateSymbol . $matches[1][0] : $mustPartOfstring; + } + + return $mustPartOfstring; + + + } + + +} \ No newline at end of file diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 720748f..b18ce43 100755 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -10,7 +10,8 @@ use yii\helpers\ArrayHelper; use yii\web\Controller; use yii\web\NotFoundHttpException; - + + /** * Class BlogController * @@ -52,15 +53,17 @@ ->distinct(), 'pagination' => [ 'pageSize' => 6, + ], ] ); - - return $this->render( + + return $this->render( 'index', [ 'categories' => $data, 'dataProvider' => $dataProvider, + ] ); } diff --git a/frontend/views/blog/index.php b/frontend/views/blog/index.php index ee68142..3a7a86c 100755 --- a/frontend/views/blog/index.php +++ b/frontend/views/blog/index.php @@ -61,29 +61,35 @@