Subversion Repositories SmartDukaan

Rev

Rev 15085 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15085 Rev 15797
Line 73... Line 73...
73
		$options = array('conditions' => array('status'=>'active','starttime <=' => date('Y-m-d H:i:s',time()),'endtime >='  => date('Y-m-d H:i:s',time())));
73
		$options = array('conditions' => array('status'=>'active','starttime <=' => date('Y-m-d H:i:s',time()),'endtime >='  => date('Y-m-d H:i:s',time())));
74
		return $this->find('all',$options);
74
		return $this->find('all',$options);
75
	}
75
	}
76
 
76
 
77
	function getNotification($user_id) {
77
	function getNotification($user_id) {
-
 
78
		$cachekey = 'webnotifications-'.$user_id;
-
 
79
		$activeNotifications = Cache::read($cachekey,'hour');
-
 
80
		if(empty($activeNotifications)) {
78
		$activeNotifications = array();
81
			// $activeNotifications = array();
79
		$activeNotificationRules = $this->getActiveRules();
82
			$activeNotificationRules = $this->getActiveRules();
80
		if(!empty($activeNotificationRules)){
83
			if(!empty($activeNotificationRules)){
81
			foreach ($activeNotificationRules as $key => $rule) {
84
				foreach ($activeNotificationRules as $key => $rule) {
82
				$sql = $rule['NotificationRule']['sql'];
85
					$sql = $rule['NotificationRule']['sql'];
83
				if(strpos($sql, '{uid}')!==false){
86
					if(strpos($sql, '{uid}')!==false){
84
					$sql = str_replace('{uid}', $user_id, $sql);
87
						$sql = str_replace('{uid}', $user_id, $sql);
85
				}
88
					}
86
				$this->log($sql,'webnotifications');
89
					$this->log($sql,'webnotifications');
87
				$valid = $this->query($sql);
90
					$valid = $this->query($sql);
88
				if(!empty($valid)){
91
					if(!empty($valid)){
89
					$activeNotifications[] = $rule;
92
						$activeNotifications[] = $rule;
-
 
93
					}
90
				}
94
				}
91
			}
95
			}
-
 
96
			Cache::write($cachekey,$activeNotifications,'hour');			
92
		}
97
		}
93
		if(!empty($activeNotifications)){
98
		if(!empty($activeNotifications)){
94
			$randkey = array_rand($activeNotifications);
99
			$randkey = array_rand($activeNotifications);
95
			$this->log(print_r($activeNotifications,1),'webnotifications');
100
			$this->log(print_r($activeNotifications,1),'webnotifications');
96
			return $activeNotifications[$randkey];
101
			return $activeNotifications[$randkey];