Subversion Repositories SmartDukaan

Rev

Rev 16925 | Rev 17172 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16925 Rev 16982
Line 891... Line 891...
891
		$this->response->type('json');
891
		$this->response->type('json');
892
		$this->layout = 'ajax';
892
		$this->layout = 'ajax';
893
	    echo(json_encode($json));die;
893
	    echo(json_encode($json));die;
894
	}
894
	}
895
 
895
 
896
	public function getlinks($userId) {		
896
	public function getlinks($userId) {	
897
		$cachekey = 'userlinks-'.$userId;
897
		$cachekey = 'userlinks-'.$userId;
898
		$links = Cache::read($cachekey,'day');
898
		$links = Cache::read($cachekey,'day');
899
		if(empty($links)) {
899
		if(empty($links)) {
900
			$links[3] = $this->getCatergoryLinks($userId,3);
900
			$links[3] = $this->getCatergoryLinks($userId,3);
901
			$links[5] = $this->getCatergoryLinks($userId,5);
901
			$links[5] = $this->getCatergoryLinks($userId,5);
Line 914... Line 914...
914
			$sql = "SELECT id,name FROM brands WHERE lower(name) IN('samsung','micromax','apple','intex','lava','spice','htc','lenovo','nokia','microsoft','xiaomi') AND category_id = $categoryId";
914
			$sql = "SELECT id,name FROM brands WHERE lower(name) IN('samsung','micromax','apple','intex','lava','spice','htc','lenovo','nokia','microsoft','xiaomi') AND category_id = $categoryId";
915
		} else {
915
		} else {
916
			$sql = "SELECT id,name FROM brands WHERE lower(name) IN('lenovo','dell','hp','iball','digiflip','samsung','datavent','apple','micromax','asus') AND category_id = $categoryId";
916
			$sql = "SELECT id,name FROM brands WHERE lower(name) IN('lenovo','dell','hp','iball','digiflip','samsung','datavent','apple','micromax','asus') AND category_id = $categoryId";
917
		}
917
		}
918
		$brandnames = $this->User->query($sql);
918
		$brandnames = $this->User->query($sql);
-
 
919
		
919
		if(!empty($brandnames)){
920
		if(!empty($brandnames)){
920
			foreach ($brandnames as $key => $value) {
921
			foreach ($brandnames as $key => $value) {
921
				if($categoryId == 3){
922
				if($categoryId == 3){
922
					if($value['brands']['name'] == 'Samsung' || $value['brands']['name'] == 'Micromax'){
923
					if($value['brands']['name'] == 'Samsung' || $value['brands']['name'] == 'Micromax'){
923
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
924
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
-
 
925
						// fixed for samsung and micromax
924
					} else {
926
					} else {
925
						$temp[] = $value['brands'];
927
						$temp[] = $value['brands']; //Any three brand except the above.
926
					}							
928
					}							
927
				}else{
929
				}else{
928
					if($value['brands']['name'] == 'Dell' || $value['brands']['name'] == 'Lenovo'){
930
					if($value['brands']['name'] == 'Dell' || $value['brands']['name'] == 'Lenovo'){
929
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
931
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
930
					} else {
932
					} else {
931
						$temp[] = $value['brands'];
933
						$temp[] = $value['brands'];
932
					}							
934
					}							
933
				}			
935
				}			
934
			}		
936
			}		
935
		}
937
		}
-
 
938
 
936
		$rand_keys = array_rand(array_keys($temp), 3);
939
		$rand_keys = array_rand(array_keys($temp), 3);
937
		$sql = "select b.id,u.user_id,u.brand,sum(u.weight) w from userlinkssegmentation u left join brands b on lower(u.brand) = lower(b.name) where u.user_id = $userId and u.category_id = $categoryId group by u.brand order by w desc limit 5";
940
		$sql = "select b.id,u.user_id,u.brand,sum(u.weight) w from userlinkssegmentation u left join brands b on lower(u.brand) = lower(b.name) where u.user_id = $userId and u.category_id = $categoryId group by u.brand order by w desc limit 5";
-
 
941
		
938
		$brands = $this->User->query($sql);
942
		$brands = $this->User->query($sql);
-
 
943
		
-
 
944
		$count = 0;
-
 
945
		$iterate= 0;
939
		if(!empty($brands)){
946
		if(!empty($brands)){
940
			foreach ($brands as $key => $brand) {
947
			foreach ($brands as $key => $brand) {
941
				if($key>2 && !empty($temp))continue;
948
				if($key>2 && !empty($temp))continue;
942
				$links[$categoryId][$brand['u']['brand']] = "?filter=brand&brands=".$brand['b']['id'];
949
				$links[$categoryId][$brand['u']['brand']] = "?filter=brand&brands=".$brand['b']['id'];
943
			}	
950
			}
-
 
951
			
944
			if(!empty($temp)){
952
			if(!empty($temp)){
-
 
953
				// for($i=0;$i<2;$i++) {//if brand in array and in while loop. first fix loop and then random.
-
 
954
				// 	$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];
-
 
955
				// 	echo "temp", $links[$categoryId][$temp[$rand_keys[$i]]['name']];
945
				for($i=0;$i<2;$i++) {
956
				while($count<2)
-
 
957
					{
-
 
958
						if(!array_key_exists($temp[$rand_keys[$iterate]]['name'], $links[$categoryId])) {							
946
					$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];
959
							$links[$categoryId][$temp[$rand_keys[$iterate]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$iterate]]['id'];							
-
 
960
							$count++;
-
 
961
						}
-
 
962
						$iterate++;
947
				}
963
					}
-
 
964
				
-
 
965
				
948
			}
966
			}
949
		} else {
967
		} else {
950
			if(!empty($fixed) && !empty($temp)){
968
			if(!empty($fixed) && !empty($temp)){
951
				foreach ($fixed as $key => $value) {
969
				foreach ($fixed as $key => $value) {
952
					$links[$categoryId][$key] = $value;
970
					$links[$categoryId][$key] = $value;
953
				}			
971
				}			
954
				for($i=0;$i<3;$i++){
972
				for($i=0;$i<3;$i++){
955
					$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];	
973
					$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];	
956
				}
974
				}
-
 
975
				 	
957
			}
976
			}
958
		}		
977
		}		
959
		return $links[$categoryId];		
978
		return $links[$categoryId];		
960
	}
979
	}
961
}
980
}
962
981