source: sandbox/2.4.1-3/prototype/modules/catalog/interceptors/DBMapping.php @ 6439

Revision 6439, 2.8 KB checked in by douglasz, 12 years ago (diff)

Ticket #2766 - Possibilitar remoção de contatos dinâmicos.

  • Property svn:executable set to *
Line 
1 <?php
2
3//Definindo Constantes
4require_once ROOTPATH . '/modules/catalog/constants.php';
5
6//require_once ROOTPATH . '/modules/calendar/interceptors/Helpers.php';
7
8use prototype\api\Config as Config;
9
10class DBMapping {
11
12
13    public function findConnections(&$uri, &$params, &$criteria, $original) {
14
15                if(count($params)>0 && isset($params[0]['id'])){
16                        for($i=0; $i < count($params); $i++){
17                                //Retorna o telefone e o e-mail padrao de um determinado contato
18                                $sql = ' SELECT phpgw_cc_contact_conns.id_typeof_contact_connection as type, phpgw_cc_connections.connection_value as value '
19                                        .'FROM phpgw_cc_contact_conns '
20                                        .'JOIN phpgw_cc_connections '
21                                        .'ON (phpgw_cc_connections.id_connection = phpgw_cc_contact_conns.id_connection) '
22                                        .'WHERE phpgw_cc_contact_conns.id_contact = ' . $params[$i]['id'] . ' AND '
23                                        .'phpgw_cc_connections.connection_is_default = TRUE ';
24
25                                $array = Controller::service('PostgreSQL')->execResultSql($sql);
26                                if(count($array)>0){
27                                        foreach($array as $connection){
28                                                switch($connection['type']){
29                                                        case TYPE_EMAIL         : $params[$i][INDEX_EMAIL]      = $connection['value']; break;
30                                                        case TYPE_TELEPHONE     : $params[$i][INDEX_TELEPHONE]  = $connection['value']; break;
31                                                        default                 : $params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
32                                                }
33
34                                        }
35                                }
36                                else{
37                                        $params[$i][INDEX_EMAIL] = $params[$i][INDEX_TELEPHONE] = '';
38                                }
39                        }
40                }
41    }
42
43        public function findGroupConnections(&$uri, &$params, &$criteria, $original) {
44
45                if(count($params)>0 && isset($params[0]['id'])){
46                $z = 0;
47                $count = count($params);
48                for($i=0; $i < $count; $i++){
49                                //Retorna o telefone e o e-mail padrao de um determinado contato
50                                $sql = 'SELECT contato.names_ordered as name, contato.id_contact as id, conexao.connection_value as value '
51                                        .'FROM phpgw_cc_groups grupo '
52                                        .'JOIN phpgw_cc_contact_grps grupo_contato '
53                                        .'ON (grupo.id_group = grupo_contato.id_group) '
54                                        .'JOIN phpgw_cc_connections conexao '
55                                        .'ON (grupo_contato.id_connection = conexao.id_connection) '
56                                        .'JOIN phpgw_cc_contact_conns conexaoCon '
57                                        .'ON (conexao.id_connection = conexaoCon.id_connection) '
58                                        .'JOIN phpgw_cc_contact contato '
59                                        .'ON (contato.id_contact = conexaoCon.id_contact) '
60                                        .'WHERE grupo.id_group = ' . $params[$i]['id'] . ' AND '
61                                        .'conexao.connection_is_default = TRUE';
62
63                                $array = Controller::service('PostgreSQL')->execResultSql($sql);
64
65                                if(count($array)>0){
66                                        $params[$i]['contacts'][$z] = array();
67                                        foreach($array as $connection){
68                                                $params[$i]['contacts'][$z]['id'] = $connection['id'];         
69                                                $params[$i]['contacts'][$z]['name'] = $connection['name'];                                                     
70                                                $params[$i]['contacts'][$z][INDEX_EMAIL] = $connection['value'];                                                       
71                                                $z++;
72                                        }
73                                }
74                                else{                                   
75                                        $params[$i]['contacts'] = null;
76                                }
77                        }
78                }
79    }
80       
81}
82
83?>
Note: See TracBrowser for help on using the repository browser.