source: contrib/ProjectManager/inc/class.datasource_projectmanager.inc.php @ 3594

Revision 3594, 7.0 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado o módulo ProjectManager? para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * ProjectManager - DataSource for ProjectManger (Subprojects)
4 *
5 * @link http://www.egroupware.org
6 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
7 * @package projectmanager
8 * @copyright (c) 2005 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
9 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
10 * @version $Id: class.datasource_projectmanager.inc.php 24317 2007-07-18 12:29:59Z ralfbecker $
11 */
12
13include_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.datasource.inc.php');
14
15/**
16 * DataSource for ProjectManager itself
17 */
18class datasource_projectmanager extends datasource
19{
20        /**
21         * @var int/string $debug 0 = no debug-messages, 1 = main, 2 = more, 3 = all, or string function-name to debug
22         */
23        var $debug=false;
24        /**
25         * @var array $get_cache return value or the last call to the get method, used by the re-implemented read method
26         */
27        var $get_cache=null;
28
29        /**
30         * Constructor
31         */
32        function datasource_projectmanager()
33        {
34                $this->datasource('projectmanager');
35               
36                $this->valid = PM_ALL_DATA;
37        }
38       
39        /**
40         * read an item from a datasource (via the get methode) and try to set (guess) some not supported values
41         *
42         * Reimplemented from the datasource parent to set the start-date of the project itself and call it's sync-all
43         * method if necessary to move it's elements
44         *
45         * @param mixed $data_id id as used in the link-class for that app, or complete entry as array
46         * @param array $pe_data data of the project-element or null, eg. to use the constraints
47         * @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
48         */
49        function read($data_id,$pe_data=null)
50        {
51                $ds = parent::read($data_id,$pe_data);  // calls $this->get($data_id) to fetch the data
52                // we use $GLOBALS['boprojectmanager'] instanciated by get
53
54                if ((int) $this->debug > 1 || $this->debug == 'read')
55                {
56                        $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::read(pm_id=$data_id,".print_r($pe_data,true).')='.print_r($ds,true));
57                }
58                // check if datasource::read changed our planned start, because it's determined by the constrains or parent
59                if (!is_null($pe_data) && $pe_data['pe_id'] && $ds['pe_planned_start'] != $pe_data['pe_planned_start'])
60                {
61                        $pm_id = is_array($data_id) ? $data_id['pm_id'] : $data_id;
62
63                        $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::read(pm_id=$pm_id: $ds[pe_title]) planned start changed from $pe_data[pe_planned_start]=".date('Y-m-d H:i',$pe_data['pe_planned_start'])." to $ds[pe_planned_start]=".date('Y-m-d H:i',$ds['pe_planned_start'])/*.", pe_data=".print_r($pe_data,true)*/);
64
65                        $bope =& CreateObject('projectmanager.boprojectelements',$pm_id);
66                       
67                        if (!($bope->project->data['pm_overwrite'] & PM_PLANNED_START))
68                        {
69                                // set the planned start, as it came from the project elements and then call sync_all to move the elements
70                                $bope->project->data['pm_planned_start'] = $ds['pe_planned_start'];
71                                $bope->project->save(null,false,false); // not modification and NO notification
72                                if (($updated_pes = $bope->sync_all()))
73                                {
74                                        $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::read(pm_id=$pm_id: $ds[pe_title]) $updated_pes elements updated to new project-start $ds[pe_planned_start]=".date('Y-m-d H:i',$ds['pe_planned_start']));                                       
75                                }
76                        }
77                }
78                return $ds;
79        }
80
81        /**
82         * get an entry from the underlaying app (if not given) and convert it into a datasource array
83         *
84         * @param mixed $data_id id as used in the link-class for that app, or complete entry as array
85         * @return array/boolean array with the data supported by that source or false on error (eg. not found, not availible)
86         */
87        function get($data_id)
88        {
89                // we use $GLOBALS['boprojectmanager'] as an already running instance may be availible there
90                if (!is_object($GLOBALS['boprojectmanager']))
91                {
92                        include_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.boprojectmanager.inc.php');
93                        $GLOBALS['boprojectmanager'] =& new boprojectmanager();
94                }
95                if (!is_array($data_id))
96                {
97                        if (!$GLOBALS['boprojectmanager']->read((int) $data_id)) return false;
98
99                        $data =& $GLOBALS['boprojectmanager']->data;
100                }
101                else
102                {
103                        $data =& $data_id;
104                }
105                // if pm_ds_ignore_elements is set, ignore planned start&end for the element-list (not overwritten)
106                $ds = !$GLOBALS['phpgw_info']['flags']['projectmanager']['pm_ds_ignore_elements'] ? array() :   array(
107                        'ignore_planned_start' => !($data['pm_overwrite'] & PM_PLANNED_START),
108                        'ignore_planned_end'   => !($data['pm_overwrite'] & PM_PLANNED_END),
109                        'ignore_real_start'    => !($data['pm_overwrite'] & PM_REAL_START),
110                        'ignore_real_end'      => !($data['pm_overwrite'] & PM_REAL_END),
111                );
112                foreach($this->name2id as $name => $id)
113                {
114                        $pm_name = str_replace('pe_','pm_',$name);
115                       
116                        if (isset($data[$pm_name]))
117                        {
118                                $ds[$name] = $data[$pm_name];
119                        }
120                }
121                $ds['pe_title'] = $GLOBALS['boprojectmanager']->link_title($data['pm_id'],$data);
122                // return the projectmembers as resources
123                $ds['pe_resources'] = $data['pm_members'] ? array_keys($data['pm_members']) : array($data['pm_creator']);
124                $ds['pe_details'] = $data['pm_description'];
125                if (is_numeric($ds['pe_completion'])) $ds['pe_completion'] .= '%';
126
127                if ((int) $this->debug > 1 || $this->debug == 'get') $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::get($data_id) =".print_r($ds,true));
128
129                return $ds;
130        }
131       
132        /**
133         * Copy the datasource of a projectelement (sub-project) and re-link it with project $target
134         *
135         * @param array $element source project element representing an sub-project, $element['pe_app_id'] = pm_id
136         * @param int $target target project id
137         * @param array $target_data=null data of target-project, atm only pm_number is used
138         * @return array/boolean array(pm_id,link_id) on success, false otherwise
139         */
140        function copy($element,$target,$target_data=null)
141        {
142                if (!is_object($GLOBALS['boprojectmanager']))
143                {
144                        include_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.boprojectmanager.inc.php');
145                        $GLOBALS['boprojectmanager'] =& new boprojectmanager();
146                }
147                if ((int) $this->debug > 1 || $this->debug == 'copy') $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::copy(".print_r($element,true).",$target)");
148
149                $data_backup = $GLOBALS['boprojectmanager']->data;
150
151                if (($pm_id = $GLOBALS['boprojectmanager']->copy((int) $element['pe_app_id'],0,$target_data['pm_number'])))
152                {
153                        if ($this->debug > 3 || $this->debug == 'copy') $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::copy() data=".print_r($GLOBALS['boprojectmanager']->data,true));
154
155                        // link the new sub-project with the project
156                        $link_id = $GLOBALS['boprojectmanager']->link->link('projectmanager',$target,'projectmanager',$pm_id,$element['pe_remark'],0,0,1);
157                }
158                $GLOBALS['boprojectmanager']->data = $data_backup;
159
160                if ($this->debug > 2 || $this->debug == 'copy') $GLOBALS['boprojectmanager']->debug_message("datasource_projectmanager::copy() returning pm_id=$pm_id, link_id=$link_id, data=".print_r($GLOBALS['boprojectmanager']->data,true));
161
162                return $pm_id ? array($pm_id,$link_id) : false;
163        }
164}
Note: See TracBrowser for help on using the repository browser.