source: pro-violet-viettel/sourcecode/application/modules/services/controllers/sync.php @ 848

Last change on this file since 848 was 838, checked in by namnd, 10 years ago
File size: 4.6 KB
RevLine 
[714]1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class Sync extends MX_Controller
4{
5        public function __construct()
6        {
7                parent::__construct();
8        }
9       
10        public function collaborator ()
11        {
12                if($this->input->is_cli_request()){
13                        error_reporting(E_ALL);
14                        $this->load->model('Services_model');
15                        $totalpage = 1;
16                       
[822]17                        $data = $this->Services_model->getCollaborator(2,1,5000);
18                        //$data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1');
[714]19                        if($data){
20                                $xml = simplexml_load_string($data);
[721]21                                $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
[714]22                                $xml = $xml->xpath('//S:Body');
23                                $xml = $xml[0];
24                                $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
25                                $totalpage = $xml->xpath('//return//totalpage');
26                                $totalpage = (int)$totalpage[0];
27                        }
28                       
29                        for ($i=1; $i<=$totalpage; $i++){
[822]30                                $data = $this->Services_model->getCollaborator(2,$i,500);
31                                //$data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1');
[714]32                                if($data && $data != -1){
33                                        $xml = simplexml_load_string($data);
34                                        $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
35                                        $xml = $xml->xpath('//S:Body');
36                                        $xml = $xml[0];
37                                        $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
38                                        $lst = $xml->xpath('//return//lst');
39                                        foreach($lst as $item){
40                                                $item = (array)$item;
[838]41                                                $phoneNumber = $this->Services_model->formatPhoneNumber((string)$item['phone'], 2);
[714]42                                                $data = array(
43                                                                'address'=> (string)$item['address'],
44                                                                'code'=>(string)$item['code'],
45                                                                'district'=>(string)$item['district'],
46                                                                'email'=>(string)$item['email'],
47                                                                'id'=>(int)$item['id'],
48                                                                'full_name'=>(string)$item['name'],
[838]49                                                                'passwd' => md5($phoneNumber),
50                                                                'cellphone'=>$phoneNumber,
[714]51                                                                'precinct'=>(string)$item['precinct'],
52                                                                'province'=>(string)$item['province'],
53                                                                'created_time'=>date('Y-m-d H:i:s'),
54                                                                'updated_time'=>date('Y-m-d H:i:s')
55                                                        );
56                                                write_file('./log/sync_collaborator.log', var_export($data, TRUE), FOPEN_WRITE_CREATE);
57                                                if ((string)$item['phone']){
58                                                        $this->Services_model->syncCollaborator($data);
59                                                }
60                                        }
61                                }else{
62                                        $logMsg = date('Y-m-d H:i:s') . " Result is null \n";
63                                        write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
64                                }
65                        }
[721]66                }else{
67                        show_404();
[714]68                }
69        }
[721]70       
71        public function deleteCollaborator ()
72        {
73               
74                if($this->input->is_cli_request()){
75                        error_reporting(E_ALL);
76                        $this->load->model('Services_model');
77                        $totalpage = 1;
78       
79                        $default = $this->Services_model->getCollaborator(2,1,5000);
80                        $data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1');
81                        if($data){
82                                $xml = simplexml_load_string($data);
83                                $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");         
84                                $xml = $xml->xpath('//S:Body');
85                                $xml = $xml[0];
86                                $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");       
87                                $totalpage = $xml->xpath('//return//totalpage');
88                                $totalpage = (int)$totalpage[0];
89                        }
90
91                        $collaboratorIds = array();
92                       
93                        $logMsg = "Start XML Process: " . date('Y-m-d H:i:s') . "\n";
94                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
95                       
96                        for ($i=1; $i<$totalpage; $i++){
97                                $result = $this->Services_model->getCollaborator(2,$i,5000);
98                                $data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1');
99                                if($data && $data != -1){
100                                        $xml = simplexml_load_string($data);
101                                        $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
102                                        $xml = $xml->xpath('//S:Body');
103                                        $xml = $xml[0];
104                                        $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
105                                        $lst = $xml->xpath('//return//lst');
106                                        foreach($lst as $item){
107                                                $item = (array)$item;
108                                                if ((string)$item['phone']){
109                                                        array_push($collaboratorIds, (int)$item['id']);
110                                                }
111                                        }
112                                }else{
113                                        $logMsg = date('Y-m-d H:i:s') . " Result is null \n";
114                                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
115                                }
116                        }
117                       
118                        $logMsg = "Finish XML Process: " . date('Y-m-d H:i:s') . "\n";
119                        write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
120                       
121                        $collaboratorIdsSync = $this->Services_model->getAllCollaboratorID();
122                       
123                        if ($collaboratorIdsSync){
124                                foreach($collaboratorIdsSync as $collaborator){
125                                        $id = (int)$collaborator->id;
126                                        if (in_array($id, $collaboratorIds) == false){
127                                                $this->Services_model->deleteCollaborator($id);
128                                        }
129                                }
130                        }
131                }else{
132                        show_404();
133                }
134
135        }
[714]136}
Note: See TracBrowser for help on using the repository browser.