Customer names stored with ي/ك were missed when typing ی/ک; fold both sides of LIKE. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
720 B
PHP
26 lines
720 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
/**
|
|
* ی/ک عربی (ي ك ى) را با معادل فارسی یکی میکند تا جستجو و مقایسه قاطی نشود.
|
|
*/
|
|
class PersianText
|
|
{
|
|
public static function fold(string $value): string
|
|
{
|
|
return str_replace(['ي', 'ى', 'ك'], ['ی', 'ی', 'ک'], $value);
|
|
}
|
|
|
|
/** عبارت SQL روی ستون مورد اعتماد (نه ورودی کاربر). */
|
|
public static function sqlFoldExpr(string $sqlExpr): string
|
|
{
|
|
return "REPLACE(REPLACE(REPLACE({$sqlExpr}, 'ي', 'ی'), 'ى', 'ی'), 'ك', 'ک')";
|
|
}
|
|
|
|
public static function likePattern(string $search): string
|
|
{
|
|
return '%'.self::fold($search).'%';
|
|
}
|
|
}
|