From 2a0045d0625dc7bca9616e14ef1af11845fef42e Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Mon, 8 Aug 2011 12:57:37 +0200 Subject: Search Lib hinzugefügt --- library/Poolctrl/Search.php | 169 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 library/Poolctrl/Search.php (limited to 'library') diff --git a/library/Poolctrl/Search.php b/library/Poolctrl/Search.php new file mode 100644 index 0000000..c798d38 --- /dev/null +++ b/library/Poolctrl/Search.php @@ -0,0 +1,169 @@ +type == ''){ + $str .= "/user/".$this->module."/search"; + } + else{ + $str .= "/user/".$this->module."/search/type/".$this->type; + } + $str .= "'> +
searchTerm != '')?'value="'.htmlentities($this->searchTerm, ENT_QUOTES).'"':'')." /> +
"; + + $highlight = array(); + if($this->searchTerm != ''){ + $str .= "Delete Client"; + $str .= "
$this->countresult result".(($this->countresult==1)?'':'s')." found
"; + $str .=""; + foreach($this->getSearchTerms() as $term){ + $highlight[] = "$('table').highlight('".$term."');"; + $highlight[] = "$('.element .number').highlight('".$term."');"; + $highlight[] = "$('.element .title').highlight('".$term."');"; + $highlight[] = "$('.element .subtitle').highlight('".$term."');"; + $highlight[] = "$('.element .item').highlight('".$term."');"; + } + + } + $str .= "
Display searchfilter
"; + $str .= ""; + $str .= ""; + return $str; + } + public function setModule($m){ + $this->module = $m; + return $this; + } + public function setType($t){ + $this->type = $t; + return $this; + } + public function setSearchTerm($search){ + $this->searchTerm = trim($search); + + // search for "text" + preg_match_all("!\"(.*?)\"!is",$this->searchTerm,$matches); + $tmpsearch = $this->searchTerm; + for($i=0;$i<=count($matches[0]);$i++){ + @$replace = str_replace(" ","<|>",$matches[0][$i]); + @$tmpsearch = str_replace($matches[0][$i],$replace,$tmpsearch); + } + $parts = explode(" ",$tmpsearch); + foreach($parts as $search){ + if(stristr($search,":") && preg_match('/^[a-z_A-Z]+$/',$search) >= 0){ + $key = substr($search,0,strpos($search,":")); + $value = substr($search,strpos($search,":")+1); + if(stristr($value,'"')){ + $value = substr(str_replace('<|>',' ',$value),1,-1); + } + $searcha[$key] = $value; + } + else{ + if(stristr($search,'"')){ + $search = substr(str_replace('<|>',' ',$search),1,-1); + } + $searchb[] = $search; + } + } + $this->searcha = @$searcha; + $this->searchb = @$searchb; + return $this; + } + public function getSearchTerm(){ + return $this->searchTerm; + } + public function getSearchTerms(){ + $beta = $this->searcha; + foreach($this->searchb as $b) + $beta[] = $b; + return $beta; + } + public function search($array){ + $this->countall = count($array); + foreach($array as $counter => $cig){ + if(is_object($cig)){ + $cig = $cig->toArray(); + } + foreach($cig as $k => $v){ + if(count($this->searcha) > 0){ + foreach($this->searcha as $sk => $sv){ + if($k == $sk){ + if(stristr($v,$sv) || $v == $sv){ + $com1[$counter] += 1; + } + } + } + } + if(count($this->searchb) >= 0){ + foreach($this->searchb as $sk => $sv){ + $comm = stristr($v,$sv); + if($comm != false || $v == $sv){ + $com2[$counter] += 1; + } + } + } + } + #print_a($com2[$counter]." >= ".count($this->searchb)." && ".$com1[$counter]." >= ".count($this->searcha)); + if($com2[$counter] >= count($this->searchb) && $com1[$counter] >= count($this->searcha)){ + // add item in resultlist + $data[] = $counter; + } + } + foreach( $data as $c) + $ges[] = $array[$c]; + $this->countresult = count($ges); + return $ges; + } +} -- cgit v1.2.3-55-g7522