3 require_once '../env.inc.php';
4 require_once $gfwww.'include/pre.php';
5 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
6 require_once $gfcommon.'pm/ProjectCategory.class.php';
7 require_once $gfcommon.'pm/ProjectGroup.class.php';
8 require_once $gfcommon.'pm/ProjectTask.class.php';
9 require_once($gfcommon.'include/User.class.php');
10 //require_once($gfcommon.'import/import_arrays.php');
14 function __construct($trackers, $group_id, $users) {
16 $this->group =& group_get_object($group_id);
17 if (!$this->group || !is_object($this->group)) {
18 print "error retrieving group from id";
19 } elseif ($this->group->isError()) {
22 $this->hashrn=array();
23 $this->hashlogin=array();
24 //create hash table hashrn{real_name:mail} & hashlogin{id:mail}
25 foreach($users as $user => $infos){
26 $this->hashrn[$infos['real_name']] = $infos['mail'];
27 $this->hashlogin[$user] = $infos['mail'];
29 $this->trackers = $trackers;
32 * addComments - Add followup comments to an Artifact Object
33 * @param Artifact the artifact object where history should be added
34 * @param array the artifact's data in json format (an array)
36 function addComments($artifact, $comments){
37 foreach($comments as $c){
38 $time = strtotime($c['date']);
39 $uid =&user_get_object_by_name($c['submitter'])->getID();
40 $importData = array('time' => $time, 'user' => $uid);
41 $artifact->addMessage($c['comment'], $importData);
46 * addHistory - Add history of changes to an Artifact Object
47 * @param Artifact the artifact object where history should be added
48 * @param array the artifact's data in json format (an array)
50 function addHistory($artifact, $history){
51 foreach($history as $h){
52 $time = strtotime($h['date']);
53 $uid =&user_get_object_by_name($h['by'])->getID();
54 $importData = array('time' => $time, 'user' => $uid);
57 // if($h['field']=='assigned_to'){
59 // $old =&user_get_object_by_name($old)->getID();
64 // if($h['field']=='status_id'){
65 // $status = array('Open' =>1, 'Closed' => 2, 'Deleted' => 3);
66 // $old = $status[$old];
68 // if($h['field']=='close_date'){
69 // $old = strtotime($old);
72 $artifact->addHistory($h['field'],$old, $importData);
77 * createTaskTracker - Create a specific tracker from data in the specified group
78 * @param string Tracker type (bugs, support, ...)
79 * @param Group The group which the tracker belongs to
80 * @param array Tracker data from JSON
81 * @return ArtifactType the tracker created
84 function createTaskTracker($data){
86 $tracker = $data['type'];
89 $pg = new ProjectGroup($this->group);
90 if (!$pg || !is_object($pg)) {
94 // include $GLOBALS['gfcommon'].'import/import_arrays.php';
95 // if(array_key_exists($tracker, $base_tracker_association)){
96 // $valueType = $base_tracker_association[$tracker];
100 if (!$pg->create($data["label"], $data["label"])) {
105 if (count($data['vocabulary']['category']) >1){
106 // Create each category
107 $cats = $this->createCategories($pg, $data['vocabulary']['category']);
109 $cats = array('None'=>100);
111 if (count($data['artifacts']) >0){
112 // Create each task in the TaskTracker
113 $output = array($pg, $data, $cats);
114 // $this->createTasks($pg, $data, $cats);
124 * Create each category for a single project group
125 * @param ProjectGroup $pg
126 * @param array $categoriesList
128 function createCategories($pg, $categoriesList){
130 foreach($categoriesList as $cat){
132 $pc = new ProjectCategory($pg);
134 if (!$pc->create($cat)) {
138 $cats[$cat] = $pc->getID();
151 * Create each task for the considered project group
152 * @param ProjectGroup $pg
155 function createTasks($pg, $data, $cats){
156 // Stores each atid in a name:id array
158 // Stores each artifact dependent on another artifact in a id:dependent_on_id array, with dependent tasks represented with their name
159 $dependent = array();
160 foreach($data['artifacts'] as $a){
162 $artifact = new ProjectTask($pg);
164 $start = strtotime($a['start_date']);
165 $end = strtotime($a['end_date']);
167 if(is_array($a['assigned_to[]'])){
168 foreach($a['assigned_to[]'] as $realname){
169 if($realname == 'None'){
172 $assigned[] = user_get_object_by_mail($this->hashrn[$realname])->getID(); // this should be done once instead of for each artifact, TODO
176 if($a['assigned_to[]']=='None'){
179 $assigned[] = user_get_object_by_mail($this->hashrn[$a['assigned_to[]']])->getID();
182 $uid =user_get_object_by_name($a['submitter'])->getID();
183 $dependentTemp = array();
184 // new dBug(array($a['summary'], $a['description'], $a['priority'], $a['hours'], $start, $end, $cats[$a['category']], $a['percent_complete'], &$assigned, &$dependentTemp, 0, 0, array('user' => $uid)));
185 if(!$artifact->create($a['summary'], $a['description'], $a['priority'], $a['hours'], $start, $end, $cats[$a['category']], $a['percent_complete'], $assigned, $dependentTemp, 0, 0, array('user' => $uid))){
189 $atid = $artifact->getID();
190 $atids[$a['summary']] = $atid;
191 $dependent[$atid] = $a['dependent_on[]'];
192 $this->addComments($artifact, $a['comments']);
193 $this->addHistory($artifact, $a['history']);
194 // addTimeTracking($artifact, $a);
198 //Sets dependent tasks for each artifact, must be done after all artifacts are created
199 foreach($dependent as $mainId => $depNames){
200 if($depNames!='None'){
201 $artifact = new ProjectTask($pg, $mainId);
202 $dependentIds = array();
203 if(is_array($depNames)){
204 foreach($depNames as $taskName){
205 $dependentIds[$atids[$taskName]] = 'FS'; // Default to PM_LINK_DEFAULT defined as FS in ProjectTask class, it seems there is no way to use any of the other relations anyway...
208 $dependentIds[$atids[$depNames]] = 'FS';
210 $artifact->setDependentOn($dependentIds);
216 * deleteTrackers - Delete all existing default trackers from a projet
217 * @param Group A Group object
219 function deleteTrackers(){
220 $pgf = new ProjectGroupFactory($this->group);
221 $pgs = $pgf->getProjectGroups();
223 foreach($pgs as $pg){
224 $pg->delete(true, true);
229 function createAllTasks(){
230 if($this->taskCreationArray){
231 foreach($this->taskCreationArray as $taskCreation){
232 $this->createTasks($taskCreation[0],$taskCreation[1],$taskCreation[2]);
238 * tracker_fill - Create trackers from an array in a given group
239 * @param array Trackers part of a JSON pluck, including label, artifacts, vocabulary...
240 * @param int Group id of the group where the trackers should be added
242 function tasks_fill(){
244 //existing tracker deletion
245 $this->deleteTrackers();
248 $this->taskCreationArray = array(); // This array is used to store each projectGroup and each artifacts which will be imported later, we need to stop the script so as to update permissions again (default to Read for each new TaskTracker, and thus nobody can be assigned to a task except userid 100 which is Nobody)
249 foreach ($this->trackers as $data){
250 $output = $this->createTaskTracker($data);
252 $this->taskCreationArray[]=$output;