Subversion Repositories SmartDukaan

Rev

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

Rev 15043 Rev 15508
Line 51... Line 51...
51
 */
51
 */
52
	public function add() {
52
	public function add() {
53
		$this->layout = 'ajax';
53
		$this->layout = 'ajax';
54
		$this->response->type('json');
54
		$this->response->type('json');
55
		if ($this->request->is('post')) {
55
		if ($this->request->is('post')) {
56
			$dataForModel = $this->request->data;
-
 
57
			$this->log('before find '.print_r($dataForModel,1),'gcm');
-
 
58
			$data = $this->GcmUser->find('first',array('conditions'=>array('user_id'=>$this->request->data['user_id'],'imeinumber'=>$this->request->data['imeinumber'])));
56
			if(empty($this->request->data['user_id']) || empty($this->request->data['gcm_regid'])){
59
			$this->log("found row ".print_r($data,1),'gcm');
-
 
60
			if(!empty($data)){
-
 
61
				$dataForModel['id'] = $data['GcmUser']['id'];
-
 
62
			}else{
-
 
63
				$this->GcmUser->create();
-
 
64
			}			
-
 
65
			$this->log('lets save '.print_r($dataForModel,1),'gcm');
-
 
66
			if ($this->GcmUser->save($dataForModel)) {
-
 
67
				$result = array('success'=>true);
-
 
68
//				$this->Session->setFlash(__('The gcm user has been saved.'));
-
 
69
//				return $this->redirect(array('action' => 'index'));
-
 
70
			} else {
-
 
71
				$result = array('success'=>false);
57
				$result = array('success'=>false);
-
 
58
			} else {
-
 
59
				$dataForModel = $this->request->data;
-
 
60
				$this->log('before find '.print_r($dataForModel,1),'gcm');
-
 
61
				$data = $this->GcmUser->find('first',array('conditions'=>array('user_id'=>$this->request->data['user_id'],'imeinumber'=>$this->request->data['imeinumber'])));
-
 
62
				$this->log("found row ".print_r($data,1),'gcm');
-
 
63
				if(!empty($data)){
-
 
64
					$dataForModel['id'] = $data['GcmUser']['id'];
-
 
65
				}else{
-
 
66
					$this->GcmUser->create();
-
 
67
				}			
-
 
68
				$this->log('lets save '.print_r($dataForModel,1),'gcm');
-
 
69
				if ($this->GcmUser->save($dataForModel)) {
-
 
70
					$result = array('success'=>true);
-
 
71
	//				$this->Session->setFlash(__('The gcm user has been saved.'));
-
 
72
	//				return $this->redirect(array('action' => 'index'));
-
 
73
				} else {
-
 
74
					$result = array('success'=>false);
72
//				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
75
	//				$this->Session->setFlash(__('The gcm user could not be saved. Please, try again.'));
-
 
76
				}
73
			}
77
			}
74
		}
78
		}
75
		$this->set(array(
79
		$this->set(array(
76
		    'result' => $result,
80
		    'result' => $result,
77
		    '_serialize' => array('result')
81
		    '_serialize' => array('result')