Last active
March 13, 2020 07:07
-
-
Save imsmo/03b659a53d4b0693d68fc9e9fb7d16c5 to your computer and use it in GitHub Desktop.
PHP userful code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//--------------------------key value pair array setup start---------------------------- | |
$MatchContest = MatchContest::find()->where(['match_log_id'=>$MatchLog->id])->orderBy(['id'=>SORT_ASC])->all(); | |
if($MatchContest) | |
{ | |
$temp_data = []; | |
foreach ($MatchContest as $key => $contest){ | |
$temp_data[$contest->contestType->name][] = $this->SetContestData($contest); | |
} | |
$i =0; | |
foreach ($temp_data as $key =>$value){ | |
foreach ($value as $k => $v){ | |
$data[$i]['name'] = $key; | |
$data[$i]['data'][$k] = $v; | |
} | |
$i++; | |
} | |
} | |
return $data; | |
//--------------------------key value pair array setup end---------------------------- | |
//--------------------------hashmap array setup start---------------------------- | |
$PlayerModel = PlayerModel::find()->where(['IN','team_id',[$MatchLog->first_team_id,$MatchLog->second_team_id]])->active()->NotDeleted()->orderBy(['credit'=>SORT_DESC])->all(); | |
foreach ($PlayerModel as $key => $Player){ | |
$data[$Player->playerRole->short_description][] = $this->SetPlayerData($Player); | |
} | |
//--------------------------hashmap array setup start---------------------------- | |
//--------------------------Yii2 database cache get value---------------------------- | |
$PlayerModel = PlayerModel::getDb()->cache(function ($db) use($MatchLog) { | |
return PlayerModel::find()->where(['IN','team_id',[$MatchLog->first_team_id,$MatchLog->second_team_id]])->active()->NotDeleted()->orderBy(['credit'=>SORT_DESC])->all(); | |
}); | |
//--------------------------Yii2 database cache get value---------------------------- | |
//-------------------------- near by mysql query------------------------------------- | |
$query = "SELECT distinct orders.orders_id, orders. , 111.045 DEGREES(ACOS(COS(RADIANS(".$latitude.")) * COS(RADIANS(orders.latitude)) * COS(RADIANS(orders.longitude) - RADIANS(".$longitude."))+ SIN(RADIANS(".$latitude.")) * SIN(RADIANS(orders.latitude)))) AS distance_in_km FROM orders"; | |
$query .= " having status = 'S' ORDER BY distance_in_km ASC"; | |
$Orders = Orders::findBySql($query)->With(['item','user'])->all(); | |
$InprocessOrders = Orders::find()->With(['item','user'])->where(['driver_id'=>$user->driver_id,'status'=>'P'])->all(); | |
//---------------------------near by mysql query------------------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment