url = $url; if(isset($fieldConfig))$instance->fieldConfig = $fieldConfig; if(isset($sortConfig))$instance->sortConfig = $sortConfig; if(isset($conditions)&&!empty($conditions)){ $instance->conditions = $conditions; } else { $instance->conditions = array(); } foreach($instance->conditions as $k=>$v) { if($v==null)unset($instance->conditions[$k]); } if(isset($keywordName))$instance->keywordName = $keywordName; if(isset($filterAll))$instance->filterAll = $filterAll; if(!isset($filterAll))$instance->filterAll = false; if(isset($filterTypes)&&!empty($filterTypes)){ $instance->filterTypes = $filterTypes; } else { $instance->filterTypes = array(); } if(isset($_GET[$instance->keywordName]))$instance->keyword = safe_replace($_GET[$instance->keywordName]); $instance->existConditions = $instance->getSearchConditions(); return $instance; } /**根据搜索条件组合后的Url(格式 a1-b2-c10) * @param $conditions * @return string */ public function createSimpleSearchCondition() { $conditionStr = ''; $conditionList = array(); if(is_array($this->conditions)) { foreach($this->conditions as $key=>$value) { $conditionList[] = $key.$value; } } asort($conditionList); if(!empty($conditionList)) { $conditionStr = join($this->splitFlag,$conditionList); $this->url .= $conditionStr.'/'; } return $this->url; } /**在已有搜索条件上组合传入的搜索条件生成新的Url * @return string */ public function createSearchCondition() { //条件类型 $types = array(); $diffTypes = array(); $inputTypes = array(); if(is_array($this->existConditions)) { foreach($this->existConditions as $condition) { $types[] = $this->_getTypeFromCondition($condition); } } //排除掉传入的相同选项类型 if(!empty($types))$types = array_unique($types); if(!empty($this->conditions))$inputTypes = array_keys($this->conditions); if(isset($inputTypes)&&isset($diffTypes))$diffTypes = array_unique(array_diff($types,$inputTypes)); //排除掉已经存在的搜索条件中不满足条件的项目(被过滤的项目和被新传入条件替换的项目) if(is_array($this->existConditions)) { foreach($this->existConditions as $key=>$condition) { $type =$this->_getTypeFromCondition($condition); if(empty($diffTypes)||(!in_array($type,$diffTypes)&&!empty($diffTypes))||in_array($type,$this->filterTypes)||$this->filterAll==true) { unset($this->existConditions[$key]); } } } //对新传入条件排序 $conditionStr = ''; if(!empty($this->conditions))ksort($this->conditions); $conditionList = array(); if(is_array($this->conditions)) { foreach($this->conditions as $key=>$value) { if(!in_array($key,$diffTypes)||empty($this->existConditions)) { $conditionList[] = $key.$value; } } } //合并已有条件和新条件 if(is_array($this->existConditions)&&!empty($this->existConditions)) { $conditionList = array_merge($conditionList,$this->existConditions); } return $this->_createUrl($conditionList); } /**选择不限帅选条件时候Url重新生成 * @return string */ public function stickOut() { $conditionList = array(); if(!empty($this->existConditions)) { foreach($this->existConditions as $condition) { $type = $this->_getTypeFromCondition($condition); if(!in_array($type,$this->filterTypes)) { $conditionList[] = $condition; } } } return $this->_createUrl($conditionList); } /**获取当前帅选条件 * @return array|mixed */ public function getSearchConditions() { $searchCondition = isset($_GET[$this->conditionParamName])?safe_replace($_GET[$this->conditionParamName]):array(); if(!empty($searchCondition)) { $searchCondition = explode($this->splitFlag,$searchCondition); } return $searchCondition; } //当前条件类型 public function getConditionsTypes() { //条件类型 $types = array(); if(is_array($this->existConditions)) { foreach($this->existConditions as $condition) { $types[] = $this->_getTypeFromCondition($condition); } } return $types; } /**反序列化筛选条件 * @return array */ public function sqllizeConditions() { $where = ''; $order = ''; $sortValue=null;//当前排序条件键值 $typeField = $this->getTypeFieldConfig(); //搜索条件键名和字段值对应关系 if(is_array($this->existConditions)) { foreach($this->existConditions as $condition) { if(strpos($condition,$this->keywordName) === 0){ $type = $this->keywordName; $value = str_replace($this->keywordName,'',$condition); } else { $type = $this->_getTypeFromCondition($condition); $value = $this->_getValueFromCondition($condition); } if($type==$this->orderTypeName)//如果为排序条件 { $sortInfo = $this->getSortConditionConfig($value); $order = " order by ".$sortInfo['order']; $sortValue = $value; } else { if(isset($typeField[$type])) { $field = $typeField[$type]['field']; $flag = $typeField[$type]['flag']; $sqlType = $typeField[$type]['type']; switch($sqlType) { case 'cat_id': $where .= " and $field $flag $value "; break; case 'cat_ids': $where .= " and $field $flag '%,".$value.",%' "; break; case 'boollist': $field = $field[$value-1]; $where .= " and $field = 1 "; break; case 'commonlike': $where .= " and $field like '%".$value."%'"; break; case 'leftlike': $where .= " and $field like '%".$value."'"; break; case 'rightlike': $where .= " and $field like '".$value."%'"; break; case 'equals': $fieldRs = explode(",",$field); $kk = 0; $songwhere = ''; foreach($fieldRs as $frs) { if($kk==0){ $songwhere = " $frs $flag $value "; } else { $songwhere .= " or $frs $flag $value "; } $kk++; } $where .= " and ($songwhere) "; break; case 'equal': $where .= " and $field $flag $value "; break; case 'gt': $where .= " and $field $flag $value "; break; case 'lt': $where .= " and $field $flag $value "; break; case 'linkmenu': $menu = \app\models\Linkmenu::findOne($value); $childIds = $menu->arr_child_ids; $where .= !empty($childIds)?" and $field in($childIds) ":" and $field $flag $value "; break; case 'day': $starttime = TIMESTAMP-$value*24*3600; $where .= " and $field $flag $starttime "; break; } } } } } return array('order'=>$order,'where'=>$where,'sortValue'=>$sortValue); } //根据搜索选项类型获取搜索选项值 public function getSearchConditionValue($key,$onCondition) { if($onCondition)return; if(!empty($this->existConditions)) { foreach($this->existConditions as $condition) { $type = $this->_getTypeFromCondition($condition); if($type==$key) { return $this->_getValueFromCondition($condition); //return preg_replace('/'.$key.'+/','',$condition); } } } } //根据最终的搜索条件生成URL private function _createUrl($conditionList) { asort($conditionList); if(strpos($this->url,'.html')!==false) { $this->url = str_replace('.html','',$this->url).'/'; $suffix = '.html'; } if(!empty($conditionList)) { $conditionStr = join("-",$conditionList); $this->url.=$conditionStr.'/'; /*if(!empty($this->keyword))//如果有关键词,在搜索条件后增加关键词条件 { $this->url .= $this->keywordName.'/'.$this->keyword.'/'; }*/ } else { /*if(!empty($this->keyword))//如果有关键词,在搜索条件后增加关键词条件 { $this->url .= $this->keywordName.'/'.$this->keyword.'/'; }*/ } if($suffix!='') { return rtrim($this->url,'/').$suffix; } else { return $this->url; } } //根据条件获取条件类型(如传入a1返回a) public function _getTypeFromCondition($condition) { return preg_replace('/[0-9_]+/','',$condition); } //根据条件获取条件值(如传入a1返回1) public function _getValueFromCondition($condition) { return preg_replace('/[a-zA-Z]+/','',$condition); } //根据搜索条件类型获取条件值 public function getConditionValueByType($searchConditions,$searchType) { if(is_array($searchConditions))foreach($searchConditions as $condition) { $type = preg_replace('/[0-9]+/','',$condition); $value = preg_replace('/[a-zA-Z]+/','',$condition); if($type==$searchType) { return $value; } } } //获取搜索关键词 public function getKeyword($searchConditions) { if(is_array($searchConditions))foreach($searchConditions as $condition) { if(strpos($condition,$this->keywordName) === 0){ return str_replace($this->keywordName,'',$condition); } } } //搜索条件字段对应值配置 public function getTypeFieldConfig() { $array = $this->fieldConfig; /*$array = array( 'r'=>array('type'=>'linkmenu','flag'=>'=', 'field'=>'region_id'), 'c'=>array('type'=>'equal','flag'=>'=','field'=>'cat_id'), 't'=>array('type'=>'equal','flag'=>'=','field'=>'doc_type'), 't1'=>array('type'=>'equal','flag'=>'=','field'=>'ext_type1'), 't2'=>array('type'=>'equal','flag'=>'=','field'=>'ext_type2'), 't3'=>array('type'=>'equal','flag'=>'=','field'=>'ext_type3'), );*/ return $array; } //排序条件配置 public function getSortConditionConfig($value = NULL) { $array = $this->sortConfig; /* $array = array( //文库 '1'=>array('value'=>1, 'order'=>'create_time desc','title'=>'按发布时间排序','tips'=>'点击按发布时间排序'), '2'=>array('value'=>2, 'order'=>'down_num desc','title'=>'按下载数量排序','tips'=>'点击按下载数量排序'), '3'=>array('value'=>3, 'order'=>'views desc','title'=>'按浏览数排序','tips'=>'点击按浏览数排序'), //商城 '7'=>array('value'=>7, 'order'=>'sales desc','title'=>'按销量排序','tips'=>'按销量排序'), '8'=>array('value'=>8, 'order'=>'sales asc','title'=>'按销量排序','tips'=>'按销量排序'), '9'=>array('value'=>9, 'order'=>'market_price desc','title'=>'按价格排序','tips'=>'按价格排序'), '10'=>array('value'=>10, 'order'=>'market_price asc','title'=>'按价格排序','tips'=>'按价格排序'), '11'=>array('value'=>11, 'order'=>'create_time desc','title'=>'按上架时间排序','tips'=>'按销量排序'), '12'=>array('value'=>12, 'order'=>'create_time asc','title'=>'按上架时间排序','tips'=>'按销量排序'), '999'=>array('value'=>999, 'order'=>'is_recommend desc','title'=>'推荐','tips'=>'推荐'), '1000'=>array('value'=>1000, 'order'=>'is_recommend asc','title'=>'推荐','tips'=>'推荐'), //论坛 '13'=>array('value'=>13, 'order'=>'create_time desc','title'=>'按最新','tips'=>'按最新'), '14'=>array('value'=>14, 'order'=>'post_num desc','title'=>'按热议','tips'=>'按热议'), '15'=>array('value'=>15, 'order'=>'reward desc','title'=>'按报酬排序','tips'=>'按报酬排序'), '16'=>array('value'=>16, 'order'=>'reward asc','title'=>'按报酬排序','tips'=>'按报酬排序'), '17'=>array('value'=>17, 'order'=>'stock desc','title'=>'按需求数量排序','tips'=>'按需求数量排序'), '18'=>array('value'=>18, 'order'=>'stock asc','title'=>'按需求数量排序','tips'=>'按需求数量排序'), );*/ if(!is_null($value)) { return $array[$value]; } else { return $array; } } } /* HTML 示例:

所在年级:

  • class="on" > 全部
  • class="on" >
  • class="on" >
  • 课程分类:

  • class="on" > 全部
  • class="on" >
  • 授课方式:

  • class="on" > 全部
  • $name){ if($key==Yii::app()->params['weiCourseTypeId'])continue; ?>
  • class="on" >
  • */ /*php示例 public function actionAllCourse() { //初始化栏目信息 $topCat = $this->categorys[Yii::app()->params['teacherCatId']]; $catList = array(); $catIds = explode(",",$topCat['arr_child_id']); if(is_array($catIds))foreach($catIds as $id) { $cat = $this->categorys[$id]; if($cat['cat_id']!=$topCat['cat_id']) { $catList[] = $cat; } } //解析组合条件 $searchConditions = MultiSearchUrl::getSelfInstance(array())->getSearchConditions(); $childCatList = array(); $currentCatId = $this->_getCatId($searchConditions); if($this->categorys[$currentCatId]['arr_child_id']) { $catIds = explode(",", $this->categorys[$currentCatId]['arr_child_id']); if(is_array($catIds))foreach($catIds as $id) { $cat = $this->categorys[$id]; if($cat['cat_id']!=$currentCatId) { $childCatList[] = $cat; } } } //当选取三级栏目时候的处理 if($currentCatId&&!$childCatList) { $catIds = explode(",", $this->categorys[$this->categorys[$currentCatId]['parent_id']]['arr_child_id']); if(is_array($catIds))foreach($catIds as $id) { $cat = $this->categorys[$id]; if($cat['cat_id']!=$this->categorys[$currentCatId]['parent_id']) { $childCatList[] = $cat; } } } //类别 if($currentCatId) { $typeList = json_decode(Yii::app()->filecache->get(CacheId::typeCacheId($this->siteId)),true); if($this->categorys[$currentCatId]['usable_type']) { $types = explode(",",$this->categorys[$currentCatId]['usable_type']); if(is_array($types))foreach($types as $typeId) { $getTypeList[] = $typeList[$typeId]; } } } $teachTypeList = Yii::app()->params['options']['teachType']; $keyword = isset($_GET[MultiSearchUrl::getSelfInstance()->keywordName])?safe_replace($_GET[MultiSearchUrl::getSelfInstance()->keywordName]):''; //获取搜索条件类型 $conditionsTypes = MultiSearchUrl::getSelfInstance()->getConditionsTypes(); //分页参数 $page = isset($_GET['page'])?intval($_GET['page']):1; $pageSize = Yii::app()->params['teacherPageSize']; $offset = ($page-1)*$pageSize; //解析SQL $sqlInfo = MultiSearchUrl::getSelfInstance(array())->sqllizeConditions(); $where = " where status=1 "; $where .= !empty($sqlInfo['where'])?$sqlInfo['where']:''; $likeStr = !empty($keyword)?" and (title like '%".$keyword."%')":''; $orderStr = !empty($sqlInfo['order'])?$sqlInfo['order']:' order by point desc'; $sqlCount = "select count(distinct(user_name)) as count from {{cource}} $where $likeStr"; $sqlList = "select * from (select * from {{user}} where user_name in(select distinct(user_name) from {{cource}} $where ) $orderStr limit $offset,$pageSize ) a left join {{user_teacher}} b on a.user_id=b.user_id "; $countModel = Yii::app()->db->createCommand($sqlCount); $result = $countModel->queryAll(); $count = $result[0]['count']; $listModel = Yii::app()->db->createCommand($sqlList); $resultlist = $listModel->queryAll(); $pages = new CPagination($count); $pages->pageSize = intval($pageSize); $this->render('allcourse',array('resultlist'=>$resultlist,'pages'=>$pages,'catList'=>$catList,'searchConditions'=>$searchConditions,'conditionsTypes'=>$conditionsTypes,'childCatList'=>$childCatList,'getTypeList'=>$getTypeList,'teachTypeList'=>$teachTypeList)); } */