Subversion Repositories SmartDukaan

Rev

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

Rev 15815 Rev 16013
Line 850... Line 850...
850
		$json = array('success'=>true);
850
		$json = array('success'=>true);
851
		$this->response->type('json');
851
		$this->response->type('json');
852
		$this->layout = 'ajax';
852
		$this->layout = 'ajax';
853
	    echo(json_encode($json));die;
853
	    echo(json_encode($json));die;
854
	}
854
	}
-
 
855
 
-
 
856
	public function getlinks($userId) {		
-
 
857
		$links = array();
-
 
858
		$links[3] = $this->getCatergoryLinks($userId,3);
-
 
859
		$links[5] = $this->getCatergoryLinks($userId,5);
-
 
860
	 	if ($this->request->is('requested')) {
-
 
861
            return $links;
-
 
862
        }
-
 
863
        $this->set('links', $links);
-
 
864
	}
-
 
865
 
-
 
866
	public function getCatergoryLinks($userId,$categoryId) {
-
 
867
		$temp = $links = $fixed = $random = array();		
-
 
868
		//populate fixed brands array
-
 
869
		if($categoryId == 3){
-
 
870
			$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";
-
 
871
		} else {
-
 
872
			$sql = "SELECT id,name FROM brands WHERE lower(name) IN('lenovo','dell','hp','iball','digiflip','samsung','datavent','apple','micromax','asus') AND category_id = $categoryId";
-
 
873
		}
-
 
874
		$brandnames = $this->User->query($sql);
-
 
875
		if(!empty($brandnames)){
-
 
876
			foreach ($brandnames as $key => $value) {
-
 
877
				if($categoryId == 3){
-
 
878
					if($value['brands']['name'] == 'Samsung' || $value['brands']['name'] == 'Micromax'){
-
 
879
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
-
 
880
					} else {
-
 
881
						$temp[] = $value['brands'];
-
 
882
					}							
-
 
883
				}else{
-
 
884
					if($value['brands']['name'] == 'Dell' || $value['brands']['name'] == 'Lenovo'){
-
 
885
						$fixed[$value['brands']['name']] = "?filter=brand&brands=".$value['brands']['id'];
-
 
886
					} else {
-
 
887
						$temp[] = $value['brands'];
-
 
888
					}							
-
 
889
				}			
-
 
890
			}		
-
 
891
		}
-
 
892
		$rand_keys = array_rand(array_keys($temp), 3);
-
 
893
		$sql = "select p.brand,count(p.brand) count,b.id from pushnotificationusergroups p left join brands b on p.brand = b.name where p.userids = $userId and p.category_id = $categoryId group by p.brand order by count desc limit 5";
-
 
894
		$brands = $this->User->query($sql);
-
 
895
		if(!empty($brands)){
-
 
896
			foreach ($brands as $key => $brand) {
-
 
897
				if($key>2 && !empty($temp))continue;
-
 
898
				$links[$categoryId][$brand['p']['brand']] = "?filter=brand&brands=".$brand['b']['id'];
-
 
899
			}	
-
 
900
			if(!empty($temp)){
-
 
901
				for($i=0;$i<2;$i++) {
-
 
902
					$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];
-
 
903
				}
-
 
904
			}
-
 
905
		} else {
-
 
906
			if(!empty($fixed) && !empty($temp)){
-
 
907
				foreach ($fixed as $key => $value) {
-
 
908
					$links[$categoryId][$key] = $value;
-
 
909
				}			
-
 
910
				for($i=0;$i<3;$i++){
-
 
911
					$links[$categoryId][$temp[$rand_keys[$i]]['name']] = "?filter=brand&brands=".$temp[$rand_keys[$i]]['id'];	
-
 
912
				}
-
 
913
			}
-
 
914
		}		
-
 
915
		return $links[$categoryId];		
-
 
916
	}
855
}
917
}
856
918