| Server IP : 104.21.17.213 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/findnextproperty.com/frontend/components/ |
Upload File : |
<?php
namespace frontend\components;
use console\models\Housestable;
use yii\helpers\BaseArrayHelper;
class CityHelper extends BaseArrayHelper
{
// return all citys by State
public static function getCityListByState($stateModel = null)
{
if ($stateModel) {
$arrResult = [];
foreach ($stateModel as $house) {
if ($house->City != null) {
$arrResult[] = $house->City;
}
}
$result = array_unique($arrResult);
return $result;
} else {
return false;
}
}
public static function setLowDashed($city = null)
{
if ($city) {
$result = strtolower(str_replace(' ', '-', $city));
return $result;
} else {
return false;
}
}
public static function setToCorrectRoute($city = null)
{
if ($city) {
$result = strtolower(str_replace(' ', '_', $city));
return $result;
} else {
return false;
}
}
public static function getCorrectRoute($city = null)
{
if ($city) {
$result = strtolower(str_replace('_', ' ', $city));
return $result;
} else {
return false;
}
}
public static function getToNormalize($city = null)
{
if ($city) {
$result = strtoupper(str_replace('-', ' ', $city));
return $result;
} else {
return false;
}
}
public static function SetAsStringCities($arr = null)
{
$result = '';
if ($arr) {
foreach ($arr as $city) {
$result .= $city . ', ';
}
$result = substr(trim($result), 0, -1);
return $result;
} else {
return false;
}
}
public static function getListZipByCity($city = null)
{
$result = '';
if ($city) {
$arr = Housestable::find()->where(['City' => $city])->groupBy('Zip')->all();
foreach ($arr as $house) {
$result[] = $house->Zip;
}
return $result;
} else {
return false;
}
}
public static function getRandpmCityName()
{
$arr = Housestable::find()->select('City')->groupBy('City')->asArray()->all();
$count = count($arr);
$result = rand(1, $count);
$x = $arr[$result];
return $x['City'];
}
public static function getCityListByStateWord($word)
{
$arrResult =[];
$result =[];
$word = strtoupper($word);
$model = Housestable::find()
->select(['City'])
->where(['State' => $word])
->groupBy('City')
->asArray()
->limit(50)
->all();
if ($model) {
foreach ($model as $key => $city) {
if ($city['City'] != null) {
$arrResult[] = $city['City'];
}
}
if(!empty($arrResult)){
$result = array_unique($arrResult);
}
}
return $result;
}
}