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

Last change on this file since 714 was 714, checked in by namnd, 10 years ago
File size: 2.4 KB
Line 
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
15                        $this->load->model('Services_model');
16                       
17                        //$totalpage = 10213;
18                       
19                        // get total page
20                        $totalpage = 1;
21                       
22                        $default = $this->Services_model->getCollaborator(2,1,100);
23                        //var_dump($default);
24                        $data = mb_convert_encoding($default, 'UTF-8', 'ISO-8859-1');
25                        if($data){
26                                $xml = simplexml_load_string($data);
27                                $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
28                               
29                                $xml = $xml->xpath('//S:Body');
30                                $xml = $xml[0];
31
32                                $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
33                               
34                                $totalpage = $xml->xpath('//return//totalpage');
35                                $totalpage = (int)$totalpage[0];
36                        }
37                       
38                        for ($i=1; $i<=$totalpage; $i++){
39                                $result = $this->Services_model->getCollaborator(2,$i,100);
40                                $data = mb_convert_encoding($result, 'UTF-8', 'ISO-8859-1');
41                                if($data && $data != -1){
42                                        $xml = simplexml_load_string($data);
43                                        $xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
44                                        $xml = $xml->xpath('//S:Body');
45                                        $xml = $xml[0];
46                                        $xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
47                                        $lst = $xml->xpath('//return//lst');
48                                        foreach($lst as $item){
49                                                $item = (array)$item;
50                               
51                                                $data = array(
52                                                                'address'=> (string)$item['address'],
53                                                                'code'=>(string)$item['code'],
54                                                                'district'=>(string)$item['district'],
55                                                                'email'=>(string)$item['email'],
56                                                                'id'=>(int)$item['id'],
57                                                                'full_name'=>(string)$item['name'],
58                                                                'cellphone'=>(string)$item['phone'],
59                                                                'precinct'=>(string)$item['precinct'],
60                                                                'province'=>(string)$item['province'],
61                                                                'created_time'=>date('Y-m-d H:i:s'),
62                                                                'updated_time'=>date('Y-m-d H:i:s')
63                                                        );
64                                                write_file('./log/sync_collaborator.log', var_export($data, TRUE), FOPEN_WRITE_CREATE);
65                                                if ((string)$item['phone']){
66                                                        $this->Services_model->syncCollaborator($data);
67                                                }
68                                        }
69                                }else{
70                                        $logMsg = date('Y-m-d H:i:s') . " Result is null \n";
71                                        write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
72                                }
73                        }
74                }
75        }
76}
Note: See TracBrowser for help on using the repository browser.