本文整理汇总了PHP中BFCHelper::orderByStay方法的典型用法代码示例。如果您正苦于以下问题:PHP BFCHelper::orderByStay方法的具体用法?PHP BFCHelper::orderByStay怎么用?PHP BFCHelper::orderByStay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BFCHelper
的用法示例。
在下文中一共展示了BFCHelper::orderByStay方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: groupResultsByMerchant
private function groupResultsByMerchant($results, $ordering, $direction)
{
$catValues = array();
foreach ($results as $key => $row) {
$catValues[$key] = $row->IsCatalog;
}
if (isset($ordering) && is_array($results)) {
// 'stay' ordering should take place before grouping
if (strtolower($ordering) == 'stay') {
$pricesValues = array();
foreach ($results as $key => $row) {
$pricesValues[$key] = $row->TotalPrice;
}
array_multisort($catValues, SORT_ASC, $pricesValues, $direction == 'desc' ? SORT_DESC : SORT_ASC, $results);
// usort($results, function($a,$b) use ( $ordering, $direction) {
// return BFCHelper::orderBy($a, $b, 'TotalPrice', $direction);
// });
}
if (strtolower($ordering) == 'offer') {
$pricesValues = array();
foreach ($results as $key => $row) {
$pricesValues[$key] = $row->PercentVariation;
}
array_multisort($catValues, SORT_ASC, $pricesValues, $direction == 'desc' ? SORT_DESC : SORT_ASC, $results);
// usort($results, function($a,$b) use ( $ordering, $direction) {
// return BFCHelper::orderBy($a, $b, 'PercentVariation', $direction);
//// return BFCHelper::orderBySingleDiscount($a, $b, $direction);
// });
}
}
$arr = array();
foreach ($results as $result) {
if (!array_key_exists($result->MerchantId, $arr)) {
$merchant = new stdClass();
$merchant->MerchantId = $result->MerchantId;
$merchant->MrcCategoryName = $result->DefaultLangMrcCategoryName;
$merchant->Name = $result->MrcName;
$merchant->XGooglePos = $result->MrcLat;
$merchant->YGooglePos = $result->MrcLng;
$merchant->MerchantTypeId = $result->MerchantTypeId;
$merchant->Rating = $result->MrcRating;
$merchant->RatingsContext = $result->RatingsContext;
$merchant->RatingsType = $result->RatingsType;
$merchant->PaymentType = $result->PaymentType;
$merchant->reviewValue = $result->MrcAVG;
$merchant->reviewCount = $result->MrcAVGCount;
$merchant->LogoUrl = $result->LogoUrl;
$merchant->Weight = $result->MrcWeight;
$merchant->MrcTagsIdList = $result->MrcTagsIdList;
$merchant->ImageUrl = $result->MrcImageUrl;
$merchant->Resources = array();
$merchant->Resources[] = $result;
$arr[$merchant->MerchantId] = $merchant;
} else {
$merchant = $arr[$result->MerchantId];
$merchant->Resources[] = $result;
}
}
if (!empty($ordering)) {
switch (strtolower($ordering)) {
case 'stay':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderByStay($a, $b, $direction);
});
break;
case 'rating':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'Rating', $direction);
});
break;
case 'reviewvalue':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'reviewValue', $direction);
});
break;
case 'offer':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a->Resources[0], $b->Resources[0], 'PercentVariation', $direction);
// return BFCHelper::orderByDiscount($a, $b, $direction);
});
break;
default:
$mrcCatalog = array();
$mrcIndexes = array();
foreach ($arr as $key => $row) {
/*
usort($row->Resources, function($a,$b) use ( $ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'ResWeight', 'asc');
});
*/
$totalResources = count($row->Resources);
$catRes = count(array_filter($row->Resources, function ($rs) {
return $rs->IsCatalog;
}));
$mrcCatalog[$key] = $catRes * 100 / $totalResources;
$mrcIndexes[$key] = $key;
}
array_multisort($mrcCatalog, SORT_ASC, $mrcIndexes, SORT_ASC, $arr);
// usort($arr, function($a,$b) use ( $ordering, $direction) {
// return BFCHelper::orderBy($a, $b, 'PaymentType', 'desc');
//.........这里部分代码省略.........
示例2: groupResultsByMerchant
private function groupResultsByMerchant($results, $ordering, $direction)
{
if (isset($ordering) && is_array($results)) {
// 'stay' ordering should take place before grouping
if (strtolower($ordering) == 'stay') {
usort($results, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'TotalPrice', $direction);
});
}
if (strtolower($ordering) == 'offer') {
usort($results, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'PercentVariation', $direction);
// return BFCHelper::orderBySingleDiscount($a, $b, $direction);
});
}
}
$arr = array();
foreach ($results as $result) {
if (!array_key_exists($result->MerchantId, $arr)) {
$merchant = new stdClass();
$merchant->MerchantId = $result->MerchantId;
$merchant->Name = $result->MrcName;
$merchant->XGooglePos = $result->MrcLat;
$merchant->YGooglePos = $result->MrcLng;
$merchant->MerchantTypeId = $result->MerchantTypeId;
$merchant->Rating = $result->MrcRating;
$merchant->RatingsContext = $result->RatingsContext;
$merchant->PaymentType = $result->PaymentType;
$merchant->reviewValue = $result->MrcAVG;
$merchant->reviewCount = $result->MrcAVGCount;
$merchant->LogoUrl = $result->LogoUrl;
$merchant->Weight = $result->MrcWeight;
$merchant->MrcTagsIdList = $result->MrcTagsIdList;
$merchant->ImageUrl = $result->MrcImageUrl;
$merchant->Resources = array();
$merchant->Resources[] = $result;
$arr[$merchant->MerchantId] = $merchant;
} else {
$merchant = $arr[$result->MerchantId];
$merchant->Resources[] = $result;
}
}
if (isset($ordering)) {
switch (strtolower($ordering)) {
case 'stay':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderByStay($a, $b, $direction);
});
break;
case 'rating':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'Rating', $direction);
});
break;
case 'reviewvalue':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'reviewValue', $direction);
});
break;
case 'offer':
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a->Resources[0], $b->Resources[0], 'PercentVariation', $direction);
// return BFCHelper::orderByDiscount($a, $b, $direction);
});
break;
default:
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'PaymentType', 'desc');
});
}
} else {
usort($arr, function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'Weight', 'asc');
});
usort($arr->Resources[], function ($a, $b) use($ordering, $direction) {
return BFCHelper::orderBy($a, $b, 'ResWeight', 'asc');
});
}
return $arr;
}