source: sandbox/workflow/branches/993/inc/class.WorkflowObjects.inc.php @ 2429

Revision 2429, 6.3 KB checked in by pedroerp, 14 years ago (diff)

Ticket #993 - Melhorias internas na classe 'Settings' do módulo.

Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12/**
13 * Provê objetos de multipropósito do Workflow
14 * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
15 * @author Pedro Eugenio Rocha - pedro.eugenio.rocha@gmail.com
16 * @version 1.0
17 * @package Workflow
18 * @license http://www.gnu.org/copyleft/gpl.html GPL
19 */
20class WorkflowObjects
21{
22        /**
23         * @var array $cache Cache de objetos
24         * @access private
25         */
26        private $cache = array();
27
28
29        /**
30         * Retorna uma conexão com o banco de dados do Galaxia (normalmente associado ao banco de dados do Expresso (eGroupWare))
31         * @return object O objeto de acesso a banco de dados, já conectado
32         * @access public
33         */
34        function &getDBGalaxia()
35        {
36                if (!isset($this->cache['DBGalaxia']))
37                {
38                        /* check if all configuration is OK */
39                        $dedicatedDB = true;
40
41                        /* if any parameter is not set, then we will return expresso database */
42                        if ((Settings::get('workflow', 'galaxia', 'db', 'name') == '') or
43                                (Settings::get('workflow', 'galaxia', 'db', 'host') == '') or
44                                (Settings::get('workflow', 'galaxia', 'db', 'port') == '') or
45                                (Settings::get('workflow', 'galaxia', 'db', 'user') == '') or
46                                (Settings::get('workflow', 'galaxia', 'db', 'type') == ''))
47                                $dedicatedDB = false;
48
49                        /* should we connect to a dedicated database? */
50                        if ($dedicatedDB)
51                        {
52                                /* connect to the database */
53                                $this->cache['DBGalaxia'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
54                                $this->cache['DBGalaxia']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
55                                $this->cache['DBGalaxia']->Halt_On_Error = 'no';
56                                $this->cache['DBGalaxia']->connect(
57                                        Settings::get('workflow', 'galaxia', 'db', 'name'),
58                                        Settings::get('workflow', 'galaxia', 'db', 'host'),
59                                        Settings::get('workflow', 'galaxia', 'db', 'port'),
60                                        Settings::get('workflow', 'galaxia', 'db', 'user'),
61                                        Settings::get('workflow', 'galaxia', 'db', 'password'),
62                                        Settings::get('workflow', 'galaxia', 'db', 'type')
63                                );
64                                Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBGalaxia']);
65                                $this->cache['DBGalaxia']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBGalaxia']->Link_ID);
66                        }
67                        else
68                                $this->cache['DBGalaxia'] = &$this->getDBExpresso();
69                }
70
71                return $this->cache['DBGalaxia'];
72        }
73
74        /**
75         * Retorna uma conexão com o banco de dados do Expresso (eGroupWare)
76         * @return object O objeto de acesso a banco de dados, já conectado
77         * @access public
78         */
79        function &getDBExpresso()
80        {
81                if (!isset($this->cache['DBExpresso']))
82                {
83                        /* connect to the database */
84                        $this->cache['DBExpresso'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
85                        $this->cache['DBExpresso']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
86                        $this->cache['DBExpresso']->Halt_On_Error = 'no';
87                        $this->cache['DBExpresso']->connect(
88                                Settings::get('expresso', 'db', 'name'),
89                                Settings::get('expresso', 'db', 'host'),
90                                Settings::get('expresso', 'db', 'port'),
91                                Settings::get('expresso', 'db', 'user'),
92                                Settings::get('expresso', 'db', 'password'),
93                                Settings::get('expresso', 'db', 'type')
94                        );
95                        Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBExpresso']);
96                        $this->cache['DBExpresso']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBExpresso']->Link_ID);
97                }
98
99                return $this->cache['DBExpresso'];
100        }
101
102        /**
103         * Retorna uma conexão com o banco de dados do Workflow
104         * @return object O objeto de acesso a banco de dados, já conectado
105         * @access public
106         */
107        function &getDBWorkflow()
108        {
109                if (!isset($this->cache['DBWorkflow']))
110                {
111                        /* connect to the database */
112                        $this->cache['DBWorkflow'] = Factory::newInstance('WorkflowWatcher', Factory::newInstance('db'));
113                        $this->cache['DBWorkflow']->disconnect(); /* for some reason it won't connect to the desired database unless we disconnect it first */
114                        $this->cache['DBWorkflow']->Halt_On_Error = 'no';
115                        $this->cache['DBWorkflow']->connect(
116                                Settings::get('workflow', 'db', 'name'),
117                                Settings::get('workflow', 'db', 'host'),
118                                Settings::get('workflow', 'db', 'port'),
119                                Settings::get('workflow', 'db', 'admin_user'),
120                                Settings::get('workflow', 'db', 'admin_password'),
121                                Settings::get('workflow', 'db', 'type')
122                        );
123                        Factory::getInstance('WorkflowSecurity')->removeSensitiveInformationFromDatabaseObject($this->cache['DBWorkflow']);
124                        $this->cache['DBWorkflow']->Link_ID = Factory::newInstance('WorkflowWatcher', $this->cache['DBWorkflow']->Link_ID);
125                }
126
127                return $this->cache['DBWorkflow'];
128        }
129
130        /**
131         * Retorna um recurso de LDAP
132         * @return resource O recurso LDAP
133         * @access public
134         */
135        function &getLDAP()
136        {
137                if (!isset($this->cache['ldap']))
138                {
139                        /* which ldap host to connect? */
140                        $ldapHost = Settings::get('workflow', 'ldap', 'host');
141                        if (empty($ldapHost))
142                                $ldapHost = Settings::get('expresso', 'ldap', 'host');
143
144                        /* connect to the LDAP server */
145                        $this->cache['ldap'] = ldap_connect($ldapHost);
146
147                        /* configure the connection */
148                        ldap_set_option($this->cache['ldap'], LDAP_OPT_PROTOCOL_VERSION, 3);
149                        ldap_set_option($this->cache['ldap'], LDAP_OPT_REFERRALS, (Settings::get('workflow', 'ldap', 'follow_referrals') == 1) ? 1 : 0);
150
151                        /* if  username and password are available, bind the connection */
152                        if ((Settings::get('workflow', 'ldap', 'user') != '') and
153                                (Settings::get('workflow', 'ldap', 'password') != ''))
154                                ldap_bind(      $this->cache['ldap'],
155                                                        Settings::get('workflow', 'ldap', 'user'),
156                                                        Settings::get('workflow', 'ldap', 'password')
157                                                        );
158                }
159                return $this->cache['ldap'];
160        }
161}
162?>
Note: See TracBrowser for help on using the repository browser.