| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Static content controller
|
|
|
6 |
*
|
|
|
7 |
* Override this controller by placing a copy in controllers directory of an application
|
|
|
8 |
*
|
|
|
9 |
* @package app.Controller
|
|
|
10 |
* @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
|
|
|
11 |
*/
|
|
|
12 |
class PrivatedealusersController extends AppController {
|
|
|
13 |
|
|
|
14 |
/**
|
|
|
15 |
* This controller does not use a model
|
|
|
16 |
*
|
|
|
17 |
* @var array
|
|
|
18 |
*/
|
|
|
19 |
// public $uses = array('Api');
|
|
|
20 |
|
|
|
21 |
public function beforeFilter() {
|
|
|
22 |
parent::beforeFilter();
|
|
|
23 |
$this->Privatedealuser->setDataSource('users');
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function index() {
|
|
|
27 |
$mlid = Configure::read('privatedeallistid');
|
|
|
28 |
$this->loadModel('ListUser');
|
|
|
29 |
$listedusers = $this->ListUser->find('list',array('fields'=>array('user_id'),'conditions'=>array('list_id'=>$mlid)));
|
|
|
30 |
$query = "select * from user u join privatedealuser p on u.id = p.id";
|
|
|
31 |
$users = $this->Privatedealuser->query($query);
|
|
|
32 |
$this->set(compact('users','listedusers'));
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function sync($id = null) {
|
|
|
36 |
$this->Privatedealuser->id = $id;
|
|
|
37 |
if (!$this->Privatedealuser->exists()) {
|
|
|
38 |
throw new NotFoundException(__('Invalid user'));
|
|
|
39 |
}
|
|
|
40 |
$query = "select * from user u join privatedealuser p on u.id = p.id where p.id = $id limit 1";
|
|
|
41 |
$result = $this->Privatedealuser->query($query);
|
|
|
42 |
$nameparts = explode(" ",$result[0]['u']['name']);
|
|
|
43 |
$fname = $nameparts[0];
|
|
|
44 |
if(isset($nameparts[1])){
|
|
|
45 |
$lname = $nameparts[1];
|
|
|
46 |
}else{
|
|
|
47 |
$lname = '';
|
|
|
48 |
}
|
|
|
49 |
$email = $result[0]['u']['email'];
|
|
|
50 |
$mlid = Configure::read('privatedeallistid');
|
|
|
51 |
$this->loadModel('Api');
|
|
|
52 |
$result = $this->Api->newmember($mlid,$email,$fname,$lname);
|
|
|
53 |
if(isset($result) && !empty($result)) {
|
|
|
54 |
if($result['DATASET']['TYPE'] == 'success') {
|
|
|
55 |
$this->loadModel('ListUser');
|
|
|
56 |
$data = array('user_id'=>$id,'list_id'=>$mlid);
|
|
|
57 |
$this->ListUser->create();
|
|
|
58 |
if($this->ListUser->save($data)){
|
|
|
59 |
$this->Session->setFlash(__('Private deal user added to list'));
|
|
|
60 |
$this->redirect(array('action'=>'index'));
|
|
|
61 |
}
|
|
|
62 |
}else{
|
|
|
63 |
$this->Session->setFlash(__($result['DATASET']['DATA']));
|
|
|
64 |
$this->redirect(array('action'=>'index'));
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
$this->set('user',$result);
|
|
|
68 |
}
|
|
|
69 |
}
|