欢迎各位兄弟 发布技术文章
这里的技术是共享的
可以见见 /node-admin/13470
if ($view->name == 'allcontentview' && ($view->current_display=='page_35' || $view->current_display=='page_16')) {
//以地区咨询人数的大小来排的话 再以地区来排一下
if(_startWith($query->orderby[0],'node_data_field_xueshenname_field_xueshenzixuandiqu_num_value')){
$query->add_orderby(NULL, NULL, 'ASC', 'node_data_field_xueshenname_field_xueshenzixuandiqu_value');
}
}
function custom_nineteen_ad_info_views_query_alter(&$view, &$query)
{
if ($view->name == 'list_ad_user' && $view->current_display=='page') {
// $e = kprint_r($view,TRUE);
// print $e;
// $e = kprint_r($query,TRUE);
// print $e;
// var_dump($query->where[2]['conditions']);
$conditions = $query->where[2]['conditions'];
//此时至少以两个工号来查询了
if(!empty($conditions) && count($conditions)>1) {
//下面的目的,是以工号的顺序来依次排序
// 比如 url /list_ad_users?name=15403008+15429476即 15403008+15429476
// conditions[0]['value'] 的 为全部的值 15403008 15429476 ,,conditions[1]['value']为第一个值 15403008,conditions[2]['value']为第二个值15429476
//所以要 unset($conditions[0]);
unset($conditions[0]);
foreach($conditions as $key=>$condition){
$condition['value'] = _removeCnEnSpace(str_replace(',','',$condition['value']));//移除所有逗号,前后空格
}
$one_conditions =array_column($conditions, 'value');
$one_conditions = implode(",",$one_conditions);//把数组转成逗号分融的字符串
$query->add_orderby(NULL, NULL, 'asc', "find_in_set( users.name, '".$one_conditions."' )");//目的是以工号顺序来依次排序
$orderbys = $query->orderby;
$query->orderby = array_reverse($orderbys); //把 orderby 顺序颠倒, 就让这里add_orderby 新添加的 跑到了第一个
// $e = kprint_r($query,TRUE);
// print $e;
}
}
}